a bunch more work, ugh

This commit is contained in:
Ell 2021-12-08 00:31:29 +01:00
parent 78eaf11948
commit 559c4165e8
44 changed files with 724 additions and 790 deletions

View file

@ -108,7 +108,7 @@ dependencies {
/* compileOnly fg.deobf("mezz.jei:jei-1.16.5:7.6.1.75:api") /* compileOnly fg.deobf("mezz.jei:jei-1.16.5:7.6.1.75:api")
runtimeOnly fg.deobf("mezz.jei:jei-1.16.5:7.6.1.75")*/ runtimeOnly fg.deobf("mezz.jei:jei-1.16.5:7.6.1.75")*/
// TDOO Patchouli // TODO Patchouli
/* compileOnly fg.deobf("vazkii.patchouli:Patchouli:1.16.4-50:api") /* compileOnly fg.deobf("vazkii.patchouli:Patchouli:1.16.4-50:api")
runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:1.16.4-50")*/ runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:1.16.4-50")*/

View file

@ -7,14 +7,14 @@ import de.ellpeck.naturesaura.api.misc.ILevelData;
import de.ellpeck.naturesaura.api.multiblock.IMultiblock; import de.ellpeck.naturesaura.api.multiblock.IMultiblock;
import de.ellpeck.naturesaura.blocks.multi.Multiblock; import de.ellpeck.naturesaura.blocks.multi.Multiblock;
import de.ellpeck.naturesaura.misc.LevelData; import de.ellpeck.naturesaura.misc.LevelData;
import net.minecraft.entity.player.Player; import net.minecraft.core.BlockPos;
import net.minecraft.item.ItemStack; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Tuple; import net.minecraft.util.Tuple;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.entity.player.Player;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.level.Level;
import net.minecraft.level.Level; import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.apache.commons.lang3.mutable.MutableFloat; import org.apache.commons.lang3.mutable.MutableFloat;
import org.apache.commons.lang3.mutable.MutableInt; import org.apache.commons.lang3.mutable.MutableInt;
import org.apache.commons.lang3.mutable.MutableObject; import org.apache.commons.lang3.mutable.MutableObject;
@ -59,7 +59,7 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
@Override @Override
public void spawnParticleStream(float startX, float startY, float startZ, float endX, float endY, float endZ, float speed, int color, float scale) { public void spawnParticleStream(float startX, float startY, float startZ, float endX, float endY, float endZ, float speed, int color, float scale) {
Vector3d dir = new Vector3d(endX - startX, endY - startY, endZ - startZ); Vec3 dir = new Vec3(endX - startX, endY - startY, endZ - startZ);
double length = dir.length(); double length = dir.length();
if (length > 0) { if (length > 0) {
dir = dir.normalize(); dir = dir.normalize();
@ -90,9 +90,9 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
} }
@Override @Override
public List<Tuple<Vector3d, Integer>> getActiveEffectPowders(Level level, AxisAlignedBB area, ResourceLocation name) { public List<Tuple<Vec3, Integer>> getActiveEffectPowders(Level level, AABB area, ResourceLocation name) {
List<Tuple<Vector3d, Integer>> found = new ArrayList<>(); List<Tuple<Vec3, Integer>> found = new ArrayList<>();
for (Tuple<Vector3d, Integer> powder : ((LevelData) ILevelData.getLevelData(level)).effectPowders.get(name)) for (Tuple<Vec3, Integer> powder : ((LevelData) ILevelData.getLevelData(level)).effectPowders.get(name))
if (area.contains(powder.getA())) if (area.contains(powder.getA()))
found.add(powder); found.add(powder);
return found; return found;
@ -100,10 +100,10 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
@Override @Override
public boolean isEffectPowderActive(Level level, BlockPos pos, ResourceLocation name) { public boolean isEffectPowderActive(Level level, BlockPos pos, ResourceLocation name) {
Vector3d posVec = new Vector3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5); Vec3 posVec = new Vec3(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
List<Tuple<Vector3d, Integer>> powders = this.getActiveEffectPowders(level, new AxisAlignedBB(pos).grow(64), name); List<Tuple<Vec3, Integer>> powders = this.getActiveEffectPowders(level, new AABB(pos).inflate(64), name);
for (Tuple<Vector3d, Integer> powder : powders) { for (Tuple<Vec3, Integer> powder : powders) {
AxisAlignedBB bounds = Helper.aabb(powder.getA()).grow(powder.getB()); AABB bounds = Helper.aabb(powder.getA()).inflate(powder.getB());
if (bounds.contains(posVec)) if (bounds.contains(posVec))
return true; return true;
} }
@ -144,7 +144,7 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
public int triangulateAuraInArea(Level level, BlockPos pos, int radius) { public int triangulateAuraInArea(Level level, BlockPos pos, int radius) {
MutableFloat result = new MutableFloat(IAuraChunk.DEFAULT_AURA); MutableFloat result = new MutableFloat(IAuraChunk.DEFAULT_AURA);
IAuraChunk.getSpotsInArea(level, pos, radius, (blockPos, spot) -> { IAuraChunk.getSpotsInArea(level, pos, radius, (blockPos, spot) -> {
float percentage = 1F - (float) Math.sqrt(pos.distanceSq(blockPos)) / radius; float percentage = 1F - (float) Math.sqrt(pos.distSqr(blockPos)) / radius;
result.add(spot * percentage); result.add(spot * percentage);
}); });
return result.intValue(); return result.intValue();

View file

@ -4,8 +4,8 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.type.BasicAuraType; import de.ellpeck.naturesaura.api.aura.type.BasicAuraType;
import de.ellpeck.naturesaura.api.misc.WeightedOre; import de.ellpeck.naturesaura.api.misc.WeightedOre;
import de.ellpeck.naturesaura.chunk.effect.OreSpawnEffect; import de.ellpeck.naturesaura.chunk.effect.OreSpawnEffect;
import net.minecraft.entity.EntityType; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.ResourceLocation; import net.minecraft.world.entity.EntityType;
import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.ForgeConfigSpec.ConfigValue; import net.minecraftforge.common.ForgeConfigSpec.ConfigValue;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;

View file

@ -1,8 +1,8 @@
package de.ellpeck.naturesaura.api.aura.container; package de.ellpeck.naturesaura.api.aura.container;
import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.ItemStack;
public class ItemAuraContainer implements IAuraContainer { public class ItemAuraContainer implements IAuraContainer {

View file

@ -7,15 +7,7 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
public class Matcher { public record Matcher(BlockState defaultState, ICheck check) {
private final BlockState defaultState;
private final ICheck check;
public Matcher(BlockState defaultState, ICheck check) {
this.defaultState = defaultState;
this.check = check;
}
public static Matcher wildcard() { public static Matcher wildcard() {
return new Matcher(Blocks.AIR.defaultBlockState(), null); return new Matcher(Blocks.AIR.defaultBlockState(), null);
@ -25,14 +17,6 @@ public class Matcher {
return new Matcher(defaultBlock.defaultBlockState(), (level, start, offset, pos, state, c) -> state.getBlock().getTags().contains(tag.getName())); return new Matcher(defaultBlock.defaultBlockState(), (level, start, offset, pos, state, c) -> state.getBlock().getTags().contains(tag.getName()));
} }
public BlockState getDefaultState() {
return this.defaultState;
}
public ICheck getCheck() {
return this.check;
}
public interface ICheck { public interface ICheck {
boolean matches(Level level, BlockPos start, BlockPos offset, BlockPos pos, BlockState state, char c); boolean matches(Level level, BlockPos start, BlockPos offset, BlockPos pos, BlockState state, char c);

View file

@ -5,17 +5,18 @@ import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAncientLeaves;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.*; import de.ellpeck.naturesaura.reg.*;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.LeavesBlock;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.material.MaterialColor;
import net.minecraft.client.renderer.color.IBlockColor; import net.minecraft.client.renderer.color.IBlockColor;
import net.minecraft.client.renderer.color.IItemColor; import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.IBlockReader; import net.minecraft.level.IBlockReader;
import net.minecraft.level.Level; import net.minecraft.level.Level;
import net.minecraft.level.server.ServerLevel; import net.minecraft.level.server.ServerLevel;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@ -25,7 +26,7 @@ import java.util.Random;
public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorProvidingBlock, IColorProvidingItem, ICustomBlockState { public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorProvidingBlock, IColorProvidingItem, ICustomBlockState {
public BlockAncientLeaves() { public BlockAncientLeaves() {
super(Properties.create(Material.LEAVES, MaterialColor.PINK).hardnessAndResistance(0.2F).tickRandomly().notSolid().sound(SoundType.PLANT)); super(Block.Properties.of(Material.LEAVES, MaterialColor.COLOR_PINK).strength(0.2F).randomTicks().noOcclusion().sound(SoundType.GRASS));
ModRegistry.add(this); ModRegistry.add(this);
ModRegistry.add(new ModTileType<>(BlockEntityAncientLeaves::new, this)); ModRegistry.add(new ModTileType<>(BlockEntityAncientLeaves::new, this));
} }

View file

@ -4,11 +4,11 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.multiblock.IMultiblock; import de.ellpeck.naturesaura.api.multiblock.IMultiblock;
import de.ellpeck.naturesaura.api.multiblock.Matcher; import de.ellpeck.naturesaura.api.multiblock.Matcher;
import de.ellpeck.naturesaura.compat.patchouli.PatchouliCompat; import de.ellpeck.naturesaura.compat.patchouli.PatchouliCompat;
import net.minecraft.block.Block; import net.minecraft.core.BlockPos;
import net.minecraft.block.BlockState; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.ResourceLocation; import net.minecraft.world.level.Level;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.Block;
import net.minecraft.level.Level; import net.minecraft.world.level.block.state.BlockState;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -80,13 +80,11 @@ public class Multiblock implements IMultiblock {
continue; continue;
Object value = rawMatchers[i + 1]; Object value = rawMatchers[i + 1];
if (value instanceof BlockState) { if (value instanceof BlockState state) {
BlockState state = (BlockState) value;
matchers.put(c, new Matcher(state, matchers.put(c, new Matcher(state,
(level, start, offset, pos, other, otherC) -> other == state)); (level, start, offset, pos, other, otherC) -> other == state));
} else if (value instanceof Block) { } else if (value instanceof Block block) {
Block block = (Block) value; matchers.put(c, new Matcher(block.defaultBlockState(),
matchers.put(c, new Matcher(block.getDefaultState(),
(level, start, offset, pos, state, otherC) -> state.getBlock() == block)); (level, start, offset, pos, state, otherC) -> state.getBlock() == block));
} else } else
matchers.put(c, (Matcher) value); matchers.put(c, (Matcher) value);
@ -121,7 +119,7 @@ public class Multiblock implements IMultiblock {
for (Map.Entry<BlockPos, Matcher> entry : this.matchers.entrySet()) { for (Map.Entry<BlockPos, Matcher> entry : this.matchers.entrySet()) {
BlockPos offset = entry.getKey(); BlockPos offset = entry.getKey();
if (c == 0 || this.getChar(offset) == c) if (c == 0 || this.getChar(offset) == c)
if (!function.apply(start.add(offset), entry.getValue())) if (!function.apply(start.offset(offset), entry.getValue()))
return false; return false;
} }
return true; return true;
@ -129,7 +127,7 @@ public class Multiblock implements IMultiblock {
@Override @Override
public BlockPos getStart(BlockPos center) { public BlockPos getStart(BlockPos center) {
return center.add(-this.xOffset, -this.yOffset, -this.zOffset); return center.offset(-this.xOffset, -this.yOffset, -this.zOffset);
} }
@Override @Override

View file

@ -1,20 +1,19 @@
package de.ellpeck.naturesaura.blocks.tiles; package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.container.BasicAuraContainer; import de.ellpeck.naturesaura.api.aura.container.BasicAuraContainer;
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer; import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.block.Blocks; import net.minecraft.core.BlockPos;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.world.entity.Entity;
import net.minecraft.util.EntityPredicates; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import java.util.List; import java.util.List;
@ -46,8 +45,8 @@ public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBl
public boolean isDrainMode; public boolean isDrainMode;
public BlockEntityEndFlower() { public BlockEntityEndFlower(BlockPos pos, BlockState state) {
super(ModTileEntities.END_FLOWER); super(ModTileEntities.END_FLOWER, pos, state);
} }
@Override @Override
@ -57,10 +56,9 @@ public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBl
return; return;
if (!this.isDrainMode) { if (!this.isDrainMode) {
List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class, List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class, new AABB(this.worldPosition).inflate(1), Entity::isAlive);
new AxisAlignedBB(this.worldPosition).grow(1), EntityPredicates.IS_ALIVE);
for (ItemEntity item : items) { for (ItemEntity item : items) {
if (item.cannotPickup()) if (item.hasPickUpDelay())
continue; continue;
ItemStack stack = item.getItem(); ItemStack stack = item.getItem();
if (stack.getCount() != 1) if (stack.getCount() != 1)
@ -69,10 +67,10 @@ public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBl
continue; continue;
this.isDrainMode = true; this.isDrainMode = true;
item.remove(); item.kill();
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
new PacketParticles((float) item.getPosX(), (float) item.getPosY(), (float) item.getPosZ(), PacketParticles.Type.END_FLOWER_CONSUME, this.container.getAuraColor())); new PacketParticles((float) item.getX(), (float) item.getY(), (float) item.getZ(), PacketParticles.Type.END_FLOWER_CONSUME, this.container.getAuraColor()));
break; break;
} }
} else { } else {
@ -81,7 +79,7 @@ public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBl
this.generateAura(toDrain); this.generateAura(toDrain);
if (this.container.getStoredAura() <= 0) { if (this.container.getStoredAura() <= 0) {
this.level.setBlockState(this.worldPosition, Blocks.DEAD_BUSH.getDefaultState()); this.level.setBlockAndUpdate(this.worldPosition, Blocks.DEAD_BUSH.defaultBlockState());
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.END_FLOWER_DECAY, this.container.getAuraColor())); new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.END_FLOWER_DECAY, this.container.getAuraColor()));
} }
@ -89,13 +87,13 @@ public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBl
} else { } else {
if (this.isDrainMode && this.level.getGameTime() % 5 == 0) if (this.isDrainMode && this.level.getGameTime() % 5 == 0)
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
this.worldPosition.getX() + 0.25F + this.level.rand.nextFloat() * 0.5F, this.worldPosition.getX() + 0.25F + this.level.random.nextFloat() * 0.5F,
this.worldPosition.getY() + 0.25F + this.level.rand.nextFloat() * 0.5F, this.worldPosition.getY() + 0.25F + this.level.random.nextFloat() * 0.5F,
this.worldPosition.getZ() + 0.25F + this.level.rand.nextFloat() * 0.5F, this.worldPosition.getZ() + 0.25F + this.level.random.nextFloat() * 0.5F,
this.level.rand.nextGaussian() * 0.05F, this.level.random.nextGaussian() * 0.05F,
this.level.rand.nextFloat() * 0.1F, this.level.random.nextFloat() * 0.1F,
this.level.rand.nextGaussian() * 0.05F, this.level.random.nextGaussian() * 0.05F,
this.container.getAuraColor(), this.level.rand.nextFloat() * 2F + 1F, 50, 0F, false, true); this.container.getAuraColor(), this.level.random.nextFloat() * 2F + 1F, 50, 0F, false, true);
} }
} }

View file

@ -6,19 +6,15 @@ import de.ellpeck.naturesaura.api.misc.ILevelData;
import de.ellpeck.naturesaura.blocks.BlockEnderCrate; import de.ellpeck.naturesaura.blocks.BlockEnderCrate;
import de.ellpeck.naturesaura.gui.ContainerEnderCrate; import de.ellpeck.naturesaura.gui.ContainerEnderCrate;
import de.ellpeck.naturesaura.gui.ModContainers; import de.ellpeck.naturesaura.gui.ModContainers;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.entity.player.Player;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.BlockPos; import net.minecraft.network.chat.Component;
import net.minecraft.util.text.ITextComponent; import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.MenuProvider; import net.minecraft.world.MenuProvider;
import net.minecraft.world.WorldlyContainer; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.MenuConstructor; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.IItemHandlerModifiable;
@ -143,13 +139,13 @@ public class BlockEntityEnderCrate extends BlockEntityImpl implements MenuProvid
} }
@Override @Override
public ITextComponent getDisplayName() { public Component getDisplayName() {
return new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".ender_crate", TextFormatting.ITALIC + this.name + TextFormatting.RESET); return new TranslatableComponent("info." + NaturesAura.MOD_ID + ".ender_crate", ChatFormatting.ITALIC + this.name + ChatFormatting.RESET);
} }
@Nullable @Nullable
@Override @Override
public Container createMenu(int window, PlayerInventory inv, Player player) { public AbstractContainerMenu createMenu(int window, Inventory inv, Player player) {
return new ContainerEnderCrate(ModContainers.ENDER_CRATE, window, player, this.getItemHandler()); return new ContainerEnderCrate(ModContainers.ENDER_CRATE, window, player, this.getItemHandler());
} }
} }

View file

@ -6,24 +6,23 @@ import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticleStream; import de.ellpeck.naturesaura.packet.PacketParticleStream;
import net.minecraft.block.Block; import net.minecraft.core.BlockPos;
import net.minecraft.block.BlockState;
import net.minecraft.entity.item.ItemFrameEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.loot.LootContext;
import net.minecraft.loot.LootParameters;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.server.level.ServerLevel;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.util.Mth;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.entity.decoration.ItemFrame;
import net.minecraft.util.math.Mth; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.item.Items;
import net.minecraft.level.server.ServerLevel; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory; import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.event.level.BlockEvent; import net.minecraftforge.event.world.BlockEvent;
import java.util.List; import java.util.List;
@ -34,8 +33,8 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
public boolean isCharged; public boolean isCharged;
private int chargeTimer; private int chargeTimer;
public BlockEntityFieldCreator() { public BlockEntityFieldCreator(BlockPos pos, BlockState state) {
super(ModTileEntities.FIELD_CREATOR); super(ModTileEntities.FIELD_CREATOR, pos, state);
} }
@Override @Override
@ -44,7 +43,7 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
return; return;
BlockPos connectedPos = this.getConnectedPos(); BlockPos connectedPos = this.getConnectedPos();
if (connectedPos == null || !this.level.isBlockLoaded(connectedPos)) if (connectedPos == null || !this.level.isLoaded(connectedPos))
return; return;
BlockEntity other = this.level.getBlockEntity(connectedPos); BlockEntity other = this.level.getBlockEntity(connectedPos);
@ -95,16 +94,16 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
chunk.drainAura(spot, 20); chunk.drainAura(spot, 20);
ItemStack tool = this.getToolUsed(creator); ItemStack tool = this.getToolUsed(creator);
Vector3d dist = new Vector3d( Vec3 dist = new Vec3(
this.worldPosition.getX() - connectedPos.getX(), this.worldPosition.getX() - connectedPos.getX(),
this.worldPosition.getY() - connectedPos.getY(), this.worldPosition.getY() - connectedPos.getY(),
this.worldPosition.getZ() - connectedPos.getZ() this.worldPosition.getZ() - connectedPos.getZ()
); );
double length = dist.length(); double length = dist.length();
Vector3d normal = new Vector3d(dist.x / length, dist.y / length, dist.z / length); Vec3 normal = new Vec3(dist.x / length, dist.y / length, dist.z / length);
for (float i = Mth.floor(length); i > 0; i -= 0.5F) { for (float i = Mth.floor(length); i > 0; i -= 0.5F) {
Vector3d scaled = normal.scale(i); Vec3 scaled = normal.scale(i);
BlockPos pos = connectedPos.add( BlockPos pos = connectedPos.offset(
Mth.floor(scaled.x + 0.5F), Mth.floor(scaled.x + 0.5F),
Mth.floor(scaled.y + 0.5F), Mth.floor(scaled.y + 0.5F),
Mth.floor(scaled.z + 0.5F)); Mth.floor(scaled.z + 0.5F));
@ -114,18 +113,18 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
BlockState state = this.level.getBlockState(pos); BlockState state = this.level.getBlockState(pos);
Block block = state.getBlock(); Block block = state.getBlock();
if (!block.isAir(state, this.level, pos) && state.getBlockHardness(this.level, pos) >= 0F) { if (!state.isAir() && state.getDestroySpeed(this.level, pos) >= 0F) {
FakePlayer fake = FakePlayerFactory.getMinecraft((ServerLevel) this.level); FakePlayer fake = FakePlayerFactory.getMinecraft((ServerLevel) this.level);
if (!MinecraftForge.EVENT_BUS.post(new BlockEvent.BreakEvent(this.level, pos, state, fake))) { if (!MinecraftForge.EVENT_BUS.post(new BlockEvent.BreakEvent(this.level, pos, state, fake))) {
List<ItemStack> drops = state.getDrops(new LootContext.Builder((ServerLevel) this.level) List<ItemStack> drops = state.getDrops(new LootContext.Builder((ServerLevel) this.level)
.withParameter(LootParameters.THIS_ENTITY, fake) .withParameter(LootContextParams.THIS_ENTITY, fake)
.withParameter(LootParameters.field_237457_g_, Vector3d.copyCentered(pos)) .withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(pos))
.withParameter(LootParameters.BLOCK_STATE, state) .withParameter(LootContextParams.BLOCK_STATE, state)
.withParameter(LootParameters.TOOL, tool.isEmpty() ? new ItemStack(Items.DIAMOND_PICKAXE) : tool) .withParameter(LootContextParams.TOOL, tool.isEmpty() ? new ItemStack(Items.DIAMOND_PICKAXE) : tool)
.withNullableParameter(LootParameters.BLOCK_ENTITY, this.level.getBlockEntity(pos))); .withOptionalParameter(LootContextParams.BLOCK_ENTITY, this.level.getBlockEntity(pos)));
this.level.destroyBlock(pos, false); this.level.destroyBlock(pos, false);
for (ItemStack stack : drops) for (ItemStack stack : drops)
Block.spawnAsEntity(this.level, pos, stack); Block.popResource(this.level, pos, stack);
chunk.drainAura(spot, !tool.isEmpty() ? 300 : 100); chunk.drainAura(spot, !tool.isEmpty() ? 300 : 100);
this.sendParticles(); this.sendParticles();
} }
@ -140,16 +139,16 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
if (!myTool.isEmpty()) { if (!myTool.isEmpty()) {
// if both have tools, choose randomly // if both have tools, choose randomly
if (!otherTool.isEmpty()) if (!otherTool.isEmpty())
return this.level.rand.nextBoolean() ? myTool : otherTool; return this.level.random.nextBoolean() ? myTool : otherTool;
return myTool; return myTool;
} }
return otherTool; return otherTool;
} }
private ItemStack getMyTool() { private ItemStack getMyTool() {
List<ItemFrameEntity> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition); List<ItemFrame> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition);
for (ItemFrameEntity frame : frames) { for (ItemFrame frame : frames) {
ItemStack stack = frame.getDisplayedItem(); ItemStack stack = frame.getItem();
if (!stack.isEmpty()) if (!stack.isEmpty())
return stack; return stack;
} }
@ -160,26 +159,26 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
for (int j = 0; j < 2; j++) { for (int j = 0; j < 2; j++) {
BlockPos p = j == 0 ? this.worldPosition : this.getConnectedPos(); BlockPos p = j == 0 ? this.worldPosition : this.getConnectedPos();
PacketHandler.sendToAllAround(this.level, p, 32, new PacketParticleStream( PacketHandler.sendToAllAround(this.level, p, 32, new PacketParticleStream(
p.getX() + (float) this.level.rand.nextGaussian() * 3F, p.getX() + (float) this.level.random.nextGaussian() * 3F,
p.getY() + 1 + this.level.rand.nextFloat() * 3F, p.getY() + 1 + this.level.random.nextFloat() * 3F,
p.getZ() + (float) this.level.rand.nextGaussian() * 3F, p.getZ() + (float) this.level.random.nextGaussian() * 3F,
p.getX() + 0.5F, p.getX() + 0.5F,
p.getY() + 0.5F, p.getY() + 0.5F,
p.getZ() + 0.5F, p.getZ() + 0.5F,
this.level.rand.nextFloat() * 0.07F + 0.07F, IAuraType.forLevel(this.level).getColor(), this.level.rand.nextFloat() + 0.5F this.level.random.nextFloat() * 0.07F + 0.07F, IAuraType.forLevel(this.level).getColor(), this.level.random.nextFloat() + 0.5F
)); ));
} }
} }
public boolean isCloseEnough(BlockPos pos) { public boolean isCloseEnough(BlockPos pos) {
int range = ModConfig.instance.fieldCreatorRange.get() + 1; int range = ModConfig.instance.fieldCreatorRange.get() + 1;
return this.worldPosition.distanceSq(pos) <= range * range; return this.worldPosition.distSqr(pos) <= range * range;
} }
public BlockPos getConnectedPos() { public BlockPos getConnectedPos() {
if (this.connectionOffset == null) if (this.connectionOffset == null)
return null; return null;
return this.worldPosition.add(this.connectionOffset); return this.worldPosition.offset(this.connectionOffset);
} }
@Override @Override
@ -187,7 +186,7 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
super.writeNBT(compound, type); super.writeNBT(compound, type);
if (type != SaveType.BLOCK) { if (type != SaveType.BLOCK) {
if (this.connectionOffset != null) if (this.connectionOffset != null)
compound.putLong("connection", this.connectionOffset.toLong()); compound.putLong("connection", this.connectionOffset.asLong());
compound.putBoolean("main", this.isMain); compound.putBoolean("main", this.isMain);
compound.putBoolean("charged", this.isCharged); compound.putBoolean("charged", this.isCharged);
@ -201,7 +200,7 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
super.readNBT(compound, type); super.readNBT(compound, type);
if (type != SaveType.BLOCK) { if (type != SaveType.BLOCK) {
if (compound.contains("connection")) if (compound.contains("connection"))
this.connectionOffset = BlockPos.fromLong(compound.getLong("connection")); this.connectionOffset = BlockPos.of(compound.getLong("connection"));
else else
this.connectionOffset = null; this.connectionOffset = null;
this.isMain = compound.getBoolean("main"); this.isMain = compound.getBoolean("main");

View file

@ -1,21 +1,20 @@
package de.ellpeck.naturesaura.blocks.tiles; package de.ellpeck.naturesaura.blocks.tiles;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.core.BlockPos;
import net.minecraft.entity.projectile.FireworkRocketEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.INBT; import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.ListNBT; import net.minecraft.nbt.Tag;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.util.Mth;
import net.minecraft.util.EntityPredicates; import net.minecraft.world.entity.Entity;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.entity.projectile.FireworkRocketEntity;
import net.minecraft.util.math.Mth; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
@ -29,33 +28,33 @@ public class BlockEntityFireworkGenerator extends BlockEntityImpl implements ITi
private int toRelease; private int toRelease;
private int releaseTimer; private int releaseTimer;
public BlockEntityFireworkGenerator() { public BlockEntityFireworkGenerator(BlockPos pos, BlockState state) {
super(ModTileEntities.FIREWORK_GENERATOR); super(ModTileEntities.FIREWORK_GENERATOR, pos, state);
} }
@Override @Override
public void tick() { public void tick() {
if (!this.level.isClientSide) { if (!this.level.isClientSide) {
if (this.level.getGameTime() % 10 == 0) { if (this.level.getGameTime() % 10 == 0) {
List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class, List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class, new AABB(this.worldPosition).inflate(4), Entity::isAlive);
new AxisAlignedBB(this.worldPosition).grow(4), EntityPredicates.IS_ALIVE);
for (ItemEntity item : items) { for (ItemEntity item : items) {
if (item.cannotPickup()) if (item.hasPickUpDelay())
continue; continue;
ItemStack stack = item.getItem(); ItemStack stack = item.getItem();
if (stack.isEmpty() || stack.getItem() != Items.FIREWORK_ROCKET) if (stack.isEmpty() || stack.getItem() != Items.FIREWORK_ROCKET)
continue; continue;
if (this.trackedEntity == null && this.releaseTimer <= 0) { if (this.trackedEntity == null && this.releaseTimer <= 0) {
FireworkRocketEntity entity = new FireworkRocketEntity(this.level, item.getPosX(), item.getPosY(), item.getPosZ(), stack); FireworkRocketEntity entity = new FireworkRocketEntity(this.level, item.getX(), item.getY(), item.getZ(), stack);
this.trackedEntity = entity; this.trackedEntity = entity;
this.trackedItem = stack.copy(); this.trackedItem = stack.copy();
this.level.addEntity(entity); this.level.addFreshEntity(entity);
} }
stack.shrink(1); stack.shrink(1);
if (stack.isEmpty()) if (stack.isEmpty()) {
item.remove(); item.kill();
else } else {
item.setItem(stack); item.setItem(stack);
}
} }
} }
@ -68,11 +67,11 @@ public class BlockEntityFireworkGenerator extends BlockEntityImpl implements ITi
CompoundTag fireworks = compound.getCompound("Fireworks"); CompoundTag fireworks = compound.getCompound("Fireworks");
int flightTime = fireworks.getInt("Flight"); int flightTime = fireworks.getInt("Flight");
ListNBT explosions = fireworks.getList("Explosions", 10); ListTag explosions = fireworks.getList("Explosions", 10);
if (!explosions.isEmpty()) { if (!explosions.isEmpty()) {
generateFactor += flightTime; generateFactor += flightTime;
for (INBT base : explosions) { for (Tag base : explosions) {
CompoundTag explosion = (CompoundTag) base; CompoundTag explosion = (CompoundTag) base;
generateFactor += 1.5F; generateFactor += 1.5F;
@ -109,7 +108,7 @@ public class BlockEntityFireworkGenerator extends BlockEntityImpl implements ITi
data.add(this.worldPosition.getZ()); data.add(this.worldPosition.getZ());
data.addAll(usedColors); data.addAll(usedColors);
PacketHandler.sendToAllLoaded(this.level, this.worldPosition, new PacketParticles( PacketHandler.sendToAllLoaded(this.level, this.worldPosition, new PacketParticles(
(float) this.trackedEntity.getPosX(), (float) this.trackedEntity.getPosY(), (float) this.trackedEntity.getPosZ(), (float) this.trackedEntity.getX(), (float) this.trackedEntity.getY(), (float) this.trackedEntity.getZ(),
PacketParticles.Type.FIREWORK_GEN, Ints.toArray(data))); PacketParticles.Type.FIREWORK_GEN, Ints.toArray(data)));
} }
} }

View file

@ -0,0 +1,20 @@
package de.ellpeck.naturesaura.blocks.tiles;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public class BlockEntityGeneratorLimitRemover extends BlockEntityImpl {
public BlockEntityGeneratorLimitRemover(BlockPos pos, BlockState state) {
super(ModTileEntities.GENERATOR_LIMIT_REMOVER, pos, state);
}
@Override
@OnlyIn(Dist.CLIENT)
public AABB getRenderBoundingBox() {
return new AABB(this.worldPosition, this.worldPosition.offset(1, 2, 1));
}
}

View file

@ -2,15 +2,15 @@ package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.blocks.BlockGratedChute; import de.ellpeck.naturesaura.blocks.BlockGratedChute;
import net.minecraft.block.BlockState; import net.minecraft.core.BlockPos;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.core.Direction;
import net.minecraft.entity.item.ItemFrameEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.world.entity.decoration.ItemFrame;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.util.Direction; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.IItemHandlerModifiable;
@ -33,8 +33,8 @@ public class BlockEntityGratedChute extends BlockEntityImpl implements ITickable
}; };
private int cooldown; private int cooldown;
public BlockEntityGratedChute() { public BlockEntityGratedChute(BlockPos pos, BlockState state) {
super(ModTileEntities.GRATED_CHUTE); super(ModTileEntities.GRATED_CHUTE, pos, state);
} }
@Override @Override
@ -49,8 +49,8 @@ public class BlockEntityGratedChute extends BlockEntityImpl implements ITickable
push: push:
if (!curr.isEmpty()) { if (!curr.isEmpty()) {
BlockState state = this.level.getBlockState(this.worldPosition); BlockState state = this.level.getBlockState(this.worldPosition);
Direction facing = state.get(BlockGratedChute.FACING); Direction facing = state.getValue(BlockGratedChute.FACING);
BlockEntity tile = this.level.getBlockEntity(this.worldPosition.offset(facing)); BlockEntity tile = this.level.getBlockEntity(this.worldPosition.relative(facing));
if (tile == null) if (tile == null)
break push; break push;
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY,
@ -70,7 +70,7 @@ public class BlockEntityGratedChute extends BlockEntityImpl implements ITickable
} }
pull: pull:
if (curr.isEmpty() || curr.getCount() < curr.getMaxStackSize()) { if (curr.isEmpty() || curr.getCount() < curr.getMaxStackSize()) {
List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class, new AxisAlignedBB( List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class, new AABB(
this.worldPosition.getX(), this.worldPosition.getY() + 0.5, this.worldPosition.getZ(), this.worldPosition.getX(), this.worldPosition.getY() + 0.5, this.worldPosition.getZ(),
this.worldPosition.getX() + 1, this.worldPosition.getY() + 2, this.worldPosition.getZ() + 1)); this.worldPosition.getX() + 1, this.worldPosition.getY() + 2, this.worldPosition.getZ() + 1));
for (ItemEntity item : items) { for (ItemEntity item : items) {
@ -80,16 +80,17 @@ public class BlockEntityGratedChute extends BlockEntityImpl implements ITickable
if (stack.isEmpty()) if (stack.isEmpty())
continue; continue;
ItemStack left = this.items.insertItem(0, stack, false); ItemStack left = this.items.insertItem(0, stack, false);
if (!ItemStack.areItemStacksEqual(stack, left)) { if (!ItemStack.isSame(stack, left)) {
if (left.isEmpty()) if (left.isEmpty()) {
item.remove(); item.kill();
else } else {
item.setItem(left); item.setItem(left);
}
break pull; break pull;
} }
} }
BlockEntity tileUp = this.level.getBlockEntity(this.worldPosition.up()); BlockEntity tileUp = this.level.getBlockEntity(this.worldPosition.above());
if (tileUp == null) if (tileUp == null)
break pull; break pull;
IItemHandler handlerUp = tileUp.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.DOWN).orElse(null); IItemHandler handlerUp = tileUp.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.DOWN).orElse(null);
@ -112,11 +113,11 @@ public class BlockEntityGratedChute extends BlockEntityImpl implements ITickable
} }
private boolean isItemInFrame(ItemStack stack) { private boolean isItemInFrame(ItemStack stack) {
List<ItemFrameEntity> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition); List<ItemFrame> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition);
if (frames.isEmpty()) if (frames.isEmpty())
return false; return false;
for (ItemFrameEntity frame : frames) { for (ItemFrame frame : frames) {
ItemStack frameStack = frame.getDisplayedItem(); ItemStack frameStack = frame.getItem();
if (Helper.areItemsEqual(stack, frameStack, true)) { if (Helper.areItemsEqual(stack, frameStack, true)) {
return true; return true;
} }

View file

@ -1,23 +1,21 @@
package de.ellpeck.naturesaura.blocks.tiles; package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.misc.ILevelData; import de.ellpeck.naturesaura.api.misc.ILevelData;
import de.ellpeck.naturesaura.misc.LevelData; import de.ellpeck.naturesaura.misc.LevelData;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.block.Block; import net.minecraft.core.BlockPos;
import net.minecraft.block.BlockState; import net.minecraft.world.level.block.Block;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.math.BlockPos;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class BlockEntityMossGenerator extends BlockEntityImpl implements ITickableBlockEntity { public class BlockEntityMossGenerator extends BlockEntityImpl implements ITickableBlockEntity {
public BlockEntityMossGenerator() { public BlockEntityMossGenerator(BlockPos pos, BlockState state) {
super(ModTileEntities.MOSS_GENERATOR); super(ModTileEntities.MOSS_GENERATOR, pos, state);
} }
@Override @Override
@ -32,7 +30,7 @@ public class BlockEntityMossGenerator extends BlockEntityImpl implements ITickab
for (int x = -range; x <= range; x++) for (int x = -range; x <= range; x++)
for (int y = -range; y <= range; y++) for (int y = -range; y <= range; y++)
for (int z = -range; z <= range; z++) { for (int z = -range; z <= range; z++) {
BlockPos offset = this.worldPosition.add(x, y, z); BlockPos offset = this.worldPosition.offset(x, y, z);
boolean isRecent = data.recentlyConvertedMossStones.contains(offset); boolean isRecent = data.recentlyConvertedMossStones.contains(offset);
BlockState state = this.level.getBlockState(offset); BlockState state = this.level.getBlockState(offset);
if (NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.inverse().containsKey(state)) { if (NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.inverse().containsKey(state)) {
@ -46,7 +44,7 @@ public class BlockEntityMossGenerator extends BlockEntityImpl implements ITickab
if (possibleOffsets.isEmpty()) if (possibleOffsets.isEmpty())
return; return;
BlockPos offset = possibleOffsets.get(this.level.rand.nextInt(possibleOffsets.size())); BlockPos offset = possibleOffsets.get(this.level.random.nextInt(possibleOffsets.size()));
BlockState state = this.level.getBlockState(offset); BlockState state = this.level.getBlockState(offset);
BlockState result = NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.inverse().get(state); BlockState result = NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.inverse().get(state);
@ -57,8 +55,8 @@ public class BlockEntityMossGenerator extends BlockEntityImpl implements ITickab
new PacketParticles(offset.getX(), offset.getY(), offset.getZ(), PacketParticles.Type.MOSS_GENERATOR)); new PacketParticles(offset.getX(), offset.getY(), offset.getZ(), PacketParticles.Type.MOSS_GENERATOR));
} }
this.level.playEvent(2001, offset, Block.getStateId(state)); this.level.levelEvent(2001, offset, Block.getId(state));
this.level.setBlockState(offset, result); this.level.setBlockAndUpdate(offset, result);
} }
} }

View file

@ -11,16 +11,15 @@ import de.ellpeck.naturesaura.packet.PacketParticleStream;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import de.ellpeck.naturesaura.recipes.AltarRecipe; import de.ellpeck.naturesaura.recipes.AltarRecipe;
import de.ellpeck.naturesaura.recipes.ModRecipes; import de.ellpeck.naturesaura.recipes.ModRecipes;
import net.minecraft.block.BlockState; import net.minecraft.core.BlockPos;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.ResourceLocation; import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.SoundCategory; import net.minecraft.sounds.SoundSource;
import net.minecraft.util.SoundEvents; import net.minecraft.util.Mth;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.math.Mth; import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.IItemHandlerModifiable;
@ -67,21 +66,21 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
private int lastAura; private int lastAura;
private boolean firstTick = true; private boolean firstTick = true;
public BlockEntityNatureAltar() { public BlockEntityNatureAltar(BlockPos pos, BlockState state) {
super(ModTileEntities.NATURE_ALTAR); super(ModTileEntities.NATURE_ALTAR, pos, state);
} }
@Override @Override
public void tick() { public void tick() {
Random rand = this.level.rand; Random rand = this.level.random;
if (this.level.getGameTime() % 40 == 0) { if (this.level.getGameTime() % 40 == 0) {
int index = 0; int index = 0;
for (int x = -2; x <= 2; x += 4) { for (int x = -2; x <= 2; x += 4) {
for (int z = -2; z <= 2; z += 4) { for (int z = -2; z <= 2; z += 4) {
BlockPos offset = this.worldPosition.add(x, 1, z); BlockPos offset = this.worldPosition.offset(x, 1, z);
BlockState state = this.level.getBlockState(offset); BlockState state = this.level.getBlockState(offset);
this.catalysts[index] = state.getBlock().getItem(this.level, offset, state); this.catalysts[index] = state.getBlock().getCloneItemStack(this.level, offset, state);
index++; index++;
} }
} }
@ -156,8 +155,7 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
this.currentRecipe = null; this.currentRecipe = null;
this.timer = 0; this.timer = 0;
this.level.playSound(null, this.worldPosition.getX() + 0.5, this.worldPosition.getY() + 0.5, this.worldPosition.getZ() + 0.5, this.level.playSound(null, this.worldPosition.getX() + 0.5, this.worldPosition.getY() + 0.5, this.worldPosition.getZ() + 0.5, SoundEvents.ARROW_HIT_PLAYER, SoundSource.BLOCKS, 0.65F, 1F);
SoundEvents.ENTITY_ARROW_HIT_PLAYER, SoundCategory.BLOCKS, 0.65F, 1F);
} }
} }
} }
@ -203,7 +201,7 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
private AltarRecipe getRecipeForInput(ItemStack input) { private AltarRecipe getRecipeForInput(ItemStack input) {
IAuraType type = IAuraType.forLevel(this.level); IAuraType type = IAuraType.forLevel(this.level);
for (AltarRecipe recipe : this.level.getRecipeManager().getRecipes(ModRecipes.ALTAR_TYPE, null, null)) { for (AltarRecipe recipe : this.level.getRecipeManager().getRecipesFor(ModRecipes.ALTAR_TYPE, null, null)) {
if (recipe.input.test(input) && (recipe.requiredType == null || type.isSimilar(recipe.requiredType))) { if (recipe.input.test(input) && (recipe.requiredType == null || type.isSimilar(recipe.requiredType))) {
if (recipe.catalyst == Ingredient.EMPTY) if (recipe.catalyst == Ingredient.EMPTY)
return recipe; return recipe;
@ -251,7 +249,7 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
if (type == SaveType.TILE) { if (type == SaveType.TILE) {
if (compound.contains("recipe")) { if (compound.contains("recipe")) {
if (this.hasLevel()) if (this.hasLevel())
this.currentRecipe = (AltarRecipe) this.level.getRecipeManager().getRecipe(new ResourceLocation(compound.getString("recipe"))).orElse(null); this.currentRecipe = (AltarRecipe) this.level.getRecipeManager().byKey(new ResourceLocation(compound.getString("recipe"))).orElse(null);
this.timer = compound.getInt("timer"); this.timer = compound.getInt("timer");
} }
} }

View file

@ -1,11 +1,10 @@
package de.ellpeck.naturesaura.blocks.tiles; package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.core.BlockPos;
import net.minecraft.tags.BlockTags; import net.minecraft.tags.BlockTags;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.math.BlockPos;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.Queue; import java.util.Queue;
@ -14,8 +13,8 @@ public class BlockEntityOakGenerator extends BlockEntityImpl implements ITickabl
public Queue<BlockPos> scheduledBigTrees = new ArrayDeque<>(); public Queue<BlockPos> scheduledBigTrees = new ArrayDeque<>();
public BlockEntityOakGenerator() { public BlockEntityOakGenerator(BlockPos pos, BlockState state) {
super(ModTileEntities.OAK_GENERATOR); super(ModTileEntities.OAK_GENERATOR, pos, state);
} }
@Override @Override

View file

@ -6,18 +6,19 @@ import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import de.ellpeck.naturesaura.recipes.ModRecipes; import de.ellpeck.naturesaura.recipes.ModRecipes;
import de.ellpeck.naturesaura.recipes.OfferingRecipe; import de.ellpeck.naturesaura.recipes.OfferingRecipe;
import net.minecraft.block.Blocks; import net.minecraft.core.BlockPos;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.effect.LightningBoltEntity;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.INBT; import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.ListNBT; import net.minecraft.nbt.Tag;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.world.entity.EntityType;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.entity.LightningBolt;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.ItemStackHandler;
@ -26,6 +27,7 @@ import java.util.List;
import java.util.Queue; import java.util.Queue;
public class BlockEntityOfferingTable extends BlockEntityImpl implements ITickableBlockEntity { public class BlockEntityOfferingTable extends BlockEntityImpl implements ITickableBlockEntity {
public final ItemStackHandler items = new ItemStackHandlerNA(1, this, true) { public final ItemStackHandler items = new ItemStackHandlerNA(1, this, true) {
@Override @Override
public int getSlotLimit(int slot) { public int getSlotLimit(int slot) {
@ -34,12 +36,12 @@ public class BlockEntityOfferingTable extends BlockEntityImpl implements ITickab
}; };
private final Queue<ItemStack> itemsToSpawn = new ArrayDeque<>(); private final Queue<ItemStack> itemsToSpawn = new ArrayDeque<>();
public BlockEntityOfferingTable() { public BlockEntityOfferingTable(BlockPos pos, BlockState state) {
super(ModTileEntities.OFFERING_TABLE); super(ModTileEntities.OFFERING_TABLE, pos, state);
} }
private OfferingRecipe getRecipe(ItemStack input) { private OfferingRecipe getRecipe(ItemStack input) {
for (OfferingRecipe recipe : this.level.getRecipeManager().getRecipes(ModRecipes.OFFERING_TYPE, null, null)) for (OfferingRecipe recipe : this.level.getRecipeManager().getRecipesFor(ModRecipes.OFFERING_TYPE, null, null))
if (recipe.input.test(input)) if (recipe.input.test(input))
return recipe; return recipe;
return null; return null;
@ -56,7 +58,7 @@ public class BlockEntityOfferingTable extends BlockEntityImpl implements ITickab
if (stack.isEmpty()) if (stack.isEmpty())
return; return;
List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class, new AxisAlignedBB(this.worldPosition).grow(1)); List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class, new AABB(this.worldPosition).inflate(1));
if (items.isEmpty()) if (items.isEmpty())
return; return;
@ -65,7 +67,7 @@ public class BlockEntityOfferingTable extends BlockEntityImpl implements ITickab
return; return;
for (ItemEntity item : items) { for (ItemEntity item : items) {
if (!item.isAlive() || item.cannotPickup()) if (!item.isAlive() || item.hasPickUpDelay())
continue; continue;
ItemStack itemStack = item.getItem(); ItemStack itemStack = item.getItem();
@ -78,33 +80,30 @@ public class BlockEntityOfferingTable extends BlockEntityImpl implements ITickab
int amount = Helper.getIngredientAmount(recipe.input); int amount = Helper.getIngredientAmount(recipe.input);
int recipeCount = stack.getCount() / amount; int recipeCount = stack.getCount() / amount;
stack.shrink(recipeCount * amount); stack.shrink(recipeCount * amount);
item.remove(); item.kill();
this.sendToClients(); this.sendToClients();
for (int i = 0; i < recipeCount; i++) for (int i = 0; i < recipeCount; i++)
this.itemsToSpawn.add(recipe.output.copy()); this.itemsToSpawn.add(recipe.output.copy());
if (Multiblocks.OFFERING_TABLE.forEach(this.worldPosition, 'R', (pos, m) -> this.level.getBlockState(pos).getBlock() == Blocks.WITHER_ROSE)) { if (Multiblocks.OFFERING_TABLE.forEach(this.worldPosition, 'R', (pos, m) -> this.level.getBlockState(pos).getBlock() == Blocks.WITHER_ROSE)) {
for (int i = this.level.rand.nextInt(5) + 3; i >= 0; i--) for (int i = this.level.random.nextInt(5) + 3; i >= 0; i--)
this.itemsToSpawn.add(new ItemStack(Items.BLACK_DYE)); this.itemsToSpawn.add(new ItemStack(Items.BLACK_DYE));
} }
LightningBoltEntity lightningboltentity = EntityType.LIGHTNING_BOLT.create(this.level); LightningBolt lightningboltentity = EntityType.LIGHTNING_BOLT.create(this.level);
lightningboltentity.setEffectOnly(true); lightningboltentity.setVisualOnly(true);
lightningboltentity.moveForced(Vector3d.copyCenteredHorizontally(this.worldPosition)); lightningboltentity.moveTo(Vec3.atCenterOf(this.worldPosition));
this.level.addEntity(lightningboltentity); this.level.addFreshEntity(lightningboltentity);
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles( PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(
(float) item.getPosX(), (float) item.getPosY(), (float) item.getPosZ(), PacketParticles.Type.OFFERING_TABLE, (float) item.getX(), (float) item.getY(), (float) item.getZ(), PacketParticles.Type.OFFERING_TABLE,
this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ())); this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ()));
break; break;
} }
} else if (this.level.getGameTime() % 3 == 0) { } else if (this.level.getGameTime() % 3 == 0) {
if (!this.itemsToSpawn.isEmpty()) if (!this.itemsToSpawn.isEmpty())
this.level.addEntity(new ItemEntity( this.level.addFreshEntity(new ItemEntity(this.level, this.worldPosition.getX() + 0.5F, 256, this.worldPosition.getZ() + 0.5F, this.itemsToSpawn.remove()));
this.level,
this.worldPosition.getX() + 0.5F, 256, this.worldPosition.getZ() + 0.5F,
this.itemsToSpawn.remove()));
} }
} }
} }
@ -116,10 +115,9 @@ public class BlockEntityOfferingTable extends BlockEntityImpl implements ITickab
compound.put("items", this.items.serializeNBT()); compound.put("items", this.items.serializeNBT());
if (type != SaveType.SYNC) { if (type != SaveType.SYNC) {
ListNBT list = new ListNBT(); ListTag list = new ListTag();
for (ItemStack stack : this.itemsToSpawn) { for (ItemStack stack : this.itemsToSpawn)
list.add(stack.serializeNBT()); list.add(stack.serializeNBT());
}
compound.put("items_to_spawn", list); compound.put("items_to_spawn", list);
} }
} }
@ -133,10 +131,9 @@ public class BlockEntityOfferingTable extends BlockEntityImpl implements ITickab
if (type != SaveType.SYNC) { if (type != SaveType.SYNC) {
this.itemsToSpawn.clear(); this.itemsToSpawn.clear();
ListNBT list = compound.getList("items_to_spawn", 10); ListTag list = compound.getList("items_to_spawn", 10);
for (INBT base : list) { for (Tag base : list)
this.itemsToSpawn.add(ItemStack.read((CompoundTag) base)); this.itemsToSpawn.add(ItemStack.of((CompoundTag) base));
}
} }
} }
} }

View file

@ -1,9 +1,12 @@
package de.ellpeck.naturesaura.blocks.tiles; package de.ellpeck.naturesaura.blocks.tiles;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.state.BlockState;
public class BlockEntityPickupStopper extends BlockEntityImpl { public class BlockEntityPickupStopper extends BlockEntityImpl {
public BlockEntityPickupStopper() { public BlockEntityPickupStopper(BlockPos pos, BlockState state) {
super(ModTileEntities.PICKUP_STOPPER); super(ModTileEntities.PICKUP_STOPPER, pos, state);
} }
public float getRadius() { public float getRadius() {

View file

@ -5,19 +5,18 @@ import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.items.ModItems;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.block.BlockState; import net.minecraft.core.BlockPos;
import net.minecraft.block.Blocks; import net.minecraft.core.Direction;
import net.minecraft.entity.item.ItemFrameEntity; import net.minecraft.server.level.ServerLevel;
import net.minecraft.item.ItemStack; import net.minecraft.world.InteractionHand;
import net.minecraft.item.ItemUseContext; import net.minecraft.world.entity.decoration.ItemFrame;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.world.item.ItemStack;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.util.Direction; import net.minecraft.world.level.block.Blocks;
import net.minecraft.util.Hand; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.phys.Vec3;
import net.minecraft.level.server.ServerLevel;
import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory; import net.minecraftforge.common.util.FakePlayerFactory;
@ -29,8 +28,8 @@ import java.util.List;
public class BlockEntityPlacer extends BlockEntityImpl implements ITickableBlockEntity { public class BlockEntityPlacer extends BlockEntityImpl implements ITickableBlockEntity {
public BlockEntityPlacer() { public BlockEntityPlacer(BlockPos pos, BlockState state) {
super(ModTileEntities.PLACER); super(ModTileEntities.PLACER, pos, state);
} }
@Override @Override
@ -38,13 +37,13 @@ public class BlockEntityPlacer extends BlockEntityImpl implements ITickableBlock
if (!this.level.isClientSide && this.level.getGameTime() % 15 == 0) { if (!this.level.isClientSide && this.level.getGameTime() % 15 == 0) {
if (this.redstonePower > 0) if (this.redstonePower > 0)
return; return;
BlockEntity tileUp = this.level.getBlockEntity(this.worldPosition.up()); BlockEntity tileUp = this.level.getBlockEntity(this.worldPosition.above());
if (tileUp == null) if (tileUp == null)
return; return;
IItemHandler handler = tileUp.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.DOWN).orElse(null); IItemHandler handler = tileUp.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.DOWN).orElse(null);
if (handler == null) if (handler == null)
return; return;
List<ItemFrameEntity> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition); List<ItemFrame> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition);
if (frames.isEmpty()) if (frames.isEmpty())
return; return;
@ -53,11 +52,11 @@ public class BlockEntityPlacer extends BlockEntityImpl implements ITickableBlock
for (int x = -range; x <= range; x++) for (int x = -range; x <= range; x++)
for (int y = -range; y <= range; y++) for (int y = -range; y <= range; y++)
for (int z = -range; z <= range; z++) { for (int z = -range; z <= range; z++) {
BlockPos pos = this.worldPosition.add(x, y, z); BlockPos pos = this.worldPosition.offset(x, y, z);
if (!this.framesContain(frames, pos, this.level.getBlockState(pos))) if (!this.framesContain(frames, pos, this.level.getBlockState(pos)))
continue; continue;
BlockPos up = pos.up(); BlockPos up = pos.above();
BlockState state = this.level.getBlockState(up); BlockState state = this.level.getBlockState(up);
if (state.getMaterial().isReplaceable()) if (state.getMaterial().isReplaceable())
validPositions.add(up); validPositions.add(up);
@ -70,9 +69,9 @@ public class BlockEntityPlacer extends BlockEntityImpl implements ITickableBlock
if (stack.isEmpty()) if (stack.isEmpty())
continue; continue;
BlockPos pos = validPositions.get(this.level.rand.nextInt(validPositions.size())); BlockPos pos = validPositions.get(this.level.random.nextInt(validPositions.size()));
ItemStack left = this.tryPlace(stack.copy(), pos); ItemStack left = this.tryPlace(stack.copy(), pos);
if (ItemStack.areItemStacksEqual(stack, left)) if (ItemStack.isSame(stack, left))
continue; continue;
handler.extractItem(i, 1, false); handler.extractItem(i, 1, false);
@ -86,13 +85,13 @@ public class BlockEntityPlacer extends BlockEntityImpl implements ITickableBlock
} }
} }
private boolean framesContain(List<ItemFrameEntity> frames, BlockPos pos, BlockState state) { private boolean framesContain(List<ItemFrame> frames, BlockPos pos, BlockState state) {
ItemStack stack = state.getBlock().getItem(this.level, pos, state); ItemStack stack = state.getBlock().getCloneItemStack(this.level, pos, state);
if (stack.isEmpty()) if (stack.isEmpty())
return false; return false;
for (ItemFrameEntity frame : frames) { for (ItemFrame frame : frames) {
ItemStack frameStack = frame.getDisplayedItem(); ItemStack frameStack = frame.getItem();
if (frameStack.isEmpty()) if (frameStack.isEmpty())
continue; continue;
if (Helper.areItemsEqual(stack, frameStack, false)) if (Helper.areItemsEqual(stack, frameStack, false))
@ -108,9 +107,9 @@ public class BlockEntityPlacer extends BlockEntityImpl implements ITickableBlock
if (!(this.level instanceof ServerLevel)) if (!(this.level instanceof ServerLevel))
return stack; return stack;
FakePlayer fake = FakePlayerFactory.getMinecraft((ServerLevel) this.level); FakePlayer fake = FakePlayerFactory.getMinecraft((ServerLevel) this.level);
fake.inventory.mainInventory.set(fake.inventory.currentItem, stack); fake.getInventory().items.set(fake.getInventory().selected, stack);
BlockRayTraceResult ray = new BlockRayTraceResult(Vector3d.copyCentered(pos), Direction.UP, pos, false); BlockHitResult ray = new BlockHitResult(Vec3.atCenterOf(pos), Direction.UP, pos, false);
ForgeHooks.onPlaceItemIntoLevel(new ItemUseContext(fake, Hand.MAIN_HAND, ray)); ForgeHooks.onPlaceItemIntoWorld(new UseOnContext(fake, InteractionHand.MAIN_HAND, ray));
return fake.getHeldItemMainhand().copy(); return fake.getMainHandItem().copy();
} }
} }

View file

@ -1,25 +1,23 @@
package de.ellpeck.naturesaura.blocks.tiles; package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.blocks.multi.Multiblocks; import de.ellpeck.naturesaura.blocks.multi.Multiblocks;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.entity.AreaEffectCloudEntity; import net.minecraft.core.BlockPos;
import net.minecraft.potion.Effect; import net.minecraft.world.effect.MobEffect;
import net.minecraft.potion.EffectInstance; import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.potion.Potion; import net.minecraft.world.entity.AreaEffectCloud;
import net.minecraft.potion.PotionUtils; import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.world.item.alchemy.PotionUtils;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.phys.AABB;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import java.util.List; import java.util.List;
public class BlockEntityPotionGenerator extends BlockEntityImpl implements ITickableBlockEntity { public class BlockEntityPotionGenerator extends BlockEntityImpl implements ITickableBlockEntity {
public BlockEntityPotionGenerator() { public BlockEntityPotionGenerator(BlockPos pos, BlockState state) {
super(ModTileEntities.POTION_GENERATOR); super(ModTileEntities.POTION_GENERATOR, pos, state);
} }
@Override @Override
@ -28,19 +26,19 @@ public class BlockEntityPotionGenerator extends BlockEntityImpl implements ITick
if (Multiblocks.POTION_GENERATOR.isComplete(this.level, this.worldPosition)) { if (Multiblocks.POTION_GENERATOR.isComplete(this.level, this.worldPosition)) {
boolean addedOne = false; boolean addedOne = false;
List<AreaEffectCloudEntity> clouds = this.level.getEntitiesWithinAABB(AreaEffectCloudEntity.class, new AxisAlignedBB(this.worldPosition).grow(2)); List<AreaEffectCloud> clouds = this.level.getEntitiesOfClass(AreaEffectCloud.class, new AABB(this.worldPosition).inflate(2));
for (AreaEffectCloudEntity cloud : clouds) { for (AreaEffectCloud cloud : clouds) {
if (!cloud.isAlive()) if (!cloud.isAlive())
continue; continue;
if (!addedOne) { if (!addedOne) {
Potion type = ObfuscationReflectionHelper.getPrivateValue(AreaEffectCloudEntity.class, cloud, "field_184502_e"); Potion type = cloud.getPotion();
if (type == null) if (type == null)
continue; continue;
for (EffectInstance effect : type.getEffects()) { for (MobEffectInstance effect : type.getEffects()) {
Effect potion = effect.getPotion(); MobEffect potion = effect.getEffect();
if (!potion.isBeneficial() || potion.isInstant()) { if (!potion.isBeneficial() || potion.isInstantenous()) {
continue; continue;
} }
@ -51,7 +49,7 @@ public class BlockEntityPotionGenerator extends BlockEntityImpl implements ITick
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles( PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(
this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.POTION_GEN, this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.POTION_GEN,
PotionUtils.getPotionColor(type), canGen ? 1 : 0)); PotionUtils.getColor(type), canGen ? 1 : 0));
addedOne = true; addedOne = true;
break; break;
@ -59,10 +57,11 @@ public class BlockEntityPotionGenerator extends BlockEntityImpl implements ITick
} }
float newRadius = cloud.getRadius() - 0.25F; float newRadius = cloud.getRadius() - 0.25F;
if (newRadius < 0.5F) if (newRadius < 0.5F) {
cloud.remove(); cloud.kill();
else } else {
cloud.setRadius(newRadius); cloud.setRadius(newRadius);
}
} }
} }
} }

View file

@ -1,13 +1,12 @@
package de.ellpeck.naturesaura.blocks.tiles; package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.entity.monster.MagmaCubeEntity; import net.minecraft.core.BlockPos;
import net.minecraft.entity.monster.SlimeEntity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.world.entity.monster.MagmaCube;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.entity.monster.Slime;
import net.minecraft.world.level.block.state.BlockState;
public class BlockEntitySlimeSplitGenerator extends BlockEntityImpl implements ITickableBlockEntity { public class BlockEntitySlimeSplitGenerator extends BlockEntityImpl implements ITickableBlockEntity {
@ -15,8 +14,8 @@ public class BlockEntitySlimeSplitGenerator extends BlockEntityImpl implements I
private int amountToRelease; private int amountToRelease;
private int color; private int color;
public BlockEntitySlimeSplitGenerator() { public BlockEntitySlimeSplitGenerator(BlockPos pos, BlockState state) {
super(ModTileEntities.SLIME_SPLIT_GENERATOR); super(ModTileEntities.SLIME_SPLIT_GENERATOR, pos, state);
} }
@Override @Override
@ -42,13 +41,13 @@ public class BlockEntitySlimeSplitGenerator extends BlockEntityImpl implements I
return this.generationTimer > 0; return this.generationTimer > 0;
} }
public void startGenerating(SlimeEntity slime) { public void startGenerating(Slime slime) {
int size = slime.getSlimeSize(); int size = slime.getSize();
this.generationTimer = size * 30; this.generationTimer = size * 30;
this.amountToRelease = (size * this.getGenerationAmount(slime)) / this.generationTimer; this.amountToRelease = (size * this.getGenerationAmount(slime)) / this.generationTimer;
this.color = this.getSlimeColor(slime); this.color = this.getSlimeColor(slime);
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles((float) slime.getPosX(), (float) slime.getPosY(), (float) slime.getPosZ(), PacketParticles.Type.SLIME_SPLIT_GEN_START, PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles((float) slime.getX(), (float) slime.getY(), (float) slime.getZ(), PacketParticles.Type.SLIME_SPLIT_GEN_START,
this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), this.color)); this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), this.color));
} }
@ -72,16 +71,16 @@ public class BlockEntitySlimeSplitGenerator extends BlockEntityImpl implements I
} }
} }
private int getSlimeColor(SlimeEntity slime) { private int getSlimeColor(Slime slime) {
if (slime instanceof MagmaCubeEntity) { if (slime instanceof MagmaCube) {
return 0x942516; return 0x942516;
} else { } else {
return 0x4da84f; return 0x4da84f;
} }
} }
private int getGenerationAmount(SlimeEntity slime) { private int getGenerationAmount(Slime slime) {
if (slime instanceof MagmaCubeEntity) { if (slime instanceof MagmaCube) {
return 45000; return 45000;
} else { } else {
return 25000; return 25000;

View file

@ -1,20 +1,19 @@
package de.ellpeck.naturesaura.blocks.tiles; package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import net.minecraft.block.Block; import net.minecraft.core.BlockPos;
import net.minecraft.block.BlockState; import net.minecraft.core.Direction;
import net.minecraft.block.Blocks; import net.minecraft.sounds.SoundEvents;
import net.minecraft.block.CauldronBlock; import net.minecraft.sounds.SoundSource;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.tags.FluidTags; import net.minecraft.tags.FluidTags;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.util.Mth;
import net.minecraft.util.Direction; import net.minecraft.world.level.block.Block;
import net.minecraft.util.SoundCategory; import net.minecraft.world.level.block.Blocks;
import net.minecraft.util.SoundEvents; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.material.FluidState;
import net.minecraft.util.math.Mth; import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.common.FarmlandWaterManager; import net.minecraftforge.common.FarmlandWaterManager;
import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.ticket.AABBTicket; import net.minecraftforge.common.ticket.AABBTicket;
@ -30,23 +29,23 @@ public class BlockEntitySpring extends BlockEntityImpl implements ITickableBlock
private final LazyOptional<IFluidHandler> tank = LazyOptional.of(InfiniteTank::new); private final LazyOptional<IFluidHandler> tank = LazyOptional.of(InfiniteTank::new);
private AABBTicket waterTicket; private AABBTicket waterTicket;
public BlockEntitySpring() { public BlockEntitySpring(BlockPos pos, BlockState state) {
super(ModTileEntities.SPRING); super(ModTileEntities.SPRING, pos, state);
} }
@Override @Override
public void validate() { public void onLoad() {
super.validate(); super.onLoad();
if (!this.level.isClientSide) { if (!this.level.isClientSide) {
// add a ticket to water crops // add a ticket to water crops
AxisAlignedBB area = new AxisAlignedBB(this.worldPosition).grow(5, 1, 5); AABB area = new AABB(this.worldPosition).inflate(5, 1, 5);
this.waterTicket = FarmlandWaterManager.addAABBTicket(this.level, area); this.waterTicket = FarmlandWaterManager.addAABBTicket(this.level, area);
} }
} }
@Override @Override
public void remove() { public void setRemoved() {
super.remove(); super.setRemoved();
if (!this.level.isClientSide && this.waterTicket != null && this.waterTicket.isValid()) { if (!this.level.isClientSide && this.waterTicket != null && this.waterTicket.isValid()) {
this.waterTicket.invalidate(); this.waterTicket.invalidate();
this.waterTicket = null; this.waterTicket = null;
@ -60,13 +59,13 @@ public class BlockEntitySpring extends BlockEntityImpl implements ITickableBlock
return; return;
// fill cauldrons // fill cauldrons
BlockPos up = this.worldPosition.up(); BlockPos up = this.worldPosition.above();
BlockState upState = this.level.getBlockState(up); BlockState upState = this.level.getBlockState(up);
if (upState.hasProperty(CauldronBlock.LEVEL)) { if (upState.hasProperty(BlockStateProperties.LEVEL_CAULDRON)) {
int level = upState.get(CauldronBlock.LEVEL); int level = upState.getValue(BlockStateProperties.LEVEL_CAULDRON);
if (level < 3) { if (level < 3) {
this.level.setBlockState(up, upState.with(CauldronBlock.LEVEL, level + 1)); this.level.setBlockAndUpdate(up, upState.setValue(BlockStateProperties.LEVEL_CAULDRON, level + 1));
this.level.playSound(null, up, SoundEvents.ITEM_BUCKET_FILL, SoundCategory.BLOCKS, 1, 1); this.level.playSound(null, up, SoundEvents.BUCKET_FILL, SoundSource.BLOCKS, 1, 1);
this.consumeAura(2500); this.consumeAura(2500);
return; return;
} }
@ -77,11 +76,11 @@ public class BlockEntitySpring extends BlockEntityImpl implements ITickableBlock
for (int x = -spongeRadius; x <= spongeRadius; x++) { for (int x = -spongeRadius; x <= spongeRadius; x++) {
for (int y = -spongeRadius; y <= spongeRadius; y++) { for (int y = -spongeRadius; y <= spongeRadius; y++) {
for (int z = -spongeRadius; z <= spongeRadius; z++) { for (int z = -spongeRadius; z <= spongeRadius; z++) {
BlockPos pos = this.worldPosition.add(x, y, z); BlockPos pos = this.worldPosition.offset(x, y, z);
BlockState state = this.level.getBlockState(pos); BlockState state = this.level.getBlockState(pos);
if (state.getBlock() == Blocks.SPONGE) { if (state.getBlock() == Blocks.SPONGE) {
this.level.setBlockState(pos, Blocks.WET_SPONGE.getDefaultState(), 2); this.level.setBlock(pos, Blocks.WET_SPONGE.defaultBlockState(), 2);
this.level.playEvent(2001, pos, Block.getStateId(Blocks.WATER.getDefaultState())); this.level.levelEvent(2001, pos, Block.getId(Blocks.WATER.defaultBlockState()));
this.consumeAura(2500); this.consumeAura(2500);
return; return;
} }
@ -91,31 +90,31 @@ public class BlockEntitySpring extends BlockEntityImpl implements ITickableBlock
// generate obsidian // generate obsidian
for (Direction dir : Direction.Plane.HORIZONTAL) { for (Direction dir : Direction.Plane.HORIZONTAL) {
BlockPos side = this.worldPosition.offset(dir); BlockPos side = this.worldPosition.relative(dir);
if (this.isLava(side, true)) { if (this.isLava(side, true)) {
this.level.setBlockState(side, ForgeEventFactory.fireFluidPlaceBlockEvent(this.level, side, side, Blocks.OBSIDIAN.getDefaultState())); this.level.setBlockAndUpdate(side, ForgeEventFactory.fireFluidPlaceBlockEvent(this.level, side, side, Blocks.OBSIDIAN.defaultBlockState()));
this.level.playEvent(1501, side, 0); this.level.levelEvent(1501, side, 0);
this.consumeAura(1500); this.consumeAura(1500);
return; return;
} }
} }
// generate stone // generate stone
BlockPos twoUp = this.worldPosition.up(2); BlockPos twoUp = this.worldPosition.above(2);
if (this.isLava(twoUp, false) && (this.level.getBlockState(up).isAir(this.level, up) || this.isLava(up, false))) { if (this.isLava(twoUp, false) && (this.level.getBlockState(up).isAir() || this.isLava(up, false))) {
this.level.setBlockState(up, ForgeEventFactory.fireFluidPlaceBlockEvent(this.level, up, twoUp, Blocks.STONE.getDefaultState())); this.level.setBlockAndUpdate(up, ForgeEventFactory.fireFluidPlaceBlockEvent(this.level, up, twoUp, Blocks.STONE.defaultBlockState()));
this.level.playEvent(1501, up, 0); this.level.levelEvent(1501, up, 0);
this.consumeAura(150); this.consumeAura(150);
return; return;
} }
// generate cobblestone // generate cobblestone
for (Direction dir : Direction.Plane.HORIZONTAL) { for (Direction dir : Direction.Plane.HORIZONTAL) {
BlockPos twoSide = this.worldPosition.offset(dir, 2); BlockPos twoSide = this.worldPosition.relative(dir, 2);
BlockPos side = this.worldPosition.offset(dir); BlockPos side = this.worldPosition.relative(dir);
if (this.isLava(twoSide, false) && (this.level.getBlockState(side).isAir(this.level, side) || this.isLava(side, false))) { if (this.isLava(twoSide, false) && (this.level.getBlockState(side).isAir() || this.isLava(side, false))) {
this.level.setBlockState(side, ForgeEventFactory.fireFluidPlaceBlockEvent(this.level, side, twoSide, Blocks.COBBLESTONE.getDefaultState())); this.level.setBlockAndUpdate(side, ForgeEventFactory.fireFluidPlaceBlockEvent(this.level, side, twoSide, Blocks.COBBLESTONE.defaultBlockState()));
this.level.playEvent(1501, side, 0); this.level.levelEvent(1501, side, 0);
this.consumeAura(100); this.consumeAura(100);
return; return;
} }
@ -138,10 +137,11 @@ public class BlockEntitySpring extends BlockEntityImpl implements ITickableBlock
private boolean isLava(BlockPos offset, boolean source) { private boolean isLava(BlockPos offset, boolean source) {
FluidState state = this.level.getFluidState(offset); FluidState state = this.level.getFluidState(offset);
return (!source || state.isSource()) && state.getFluid().isIn(FluidTags.LAVA); return (!source || state.isSource()) && state.getType().is(FluidTags.LAVA);
} }
private class InfiniteTank implements IFluidTank, IFluidHandler { private class InfiniteTank implements IFluidTank, IFluidHandler {
@Override @Override
public FluidStack getFluid() { public FluidStack getFluid() {
return new FluidStack(Fluids.WATER, 1000); return new FluidStack(Fluids.WATER, 1000);
@ -159,7 +159,7 @@ public class BlockEntitySpring extends BlockEntityImpl implements ITickableBlock
@Override @Override
public boolean isFluidValid(FluidStack stack) { public boolean isFluidValid(FluidStack stack) {
return stack.getFluid().isIn(FluidTags.WATER); return stack.getFluid().is(FluidTags.WATER);
} }
@Override @Override

View file

@ -2,20 +2,18 @@ package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticleStream; import de.ellpeck.naturesaura.packet.PacketParticleStream;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.block.Block; import net.minecraft.core.BlockPos;
import net.minecraft.block.BlockState;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.INBT; import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.ListNBT; import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags; import net.minecraft.tags.BlockTags;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.world.level.block.Block;
import net.minecraft.util.ResourceLocation; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
import org.apache.commons.lang3.mutable.MutableInt; import org.apache.commons.lang3.mutable.MutableInt;
@ -28,8 +26,8 @@ public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITick
private final Map<BlockState, MutableInt> consumedRecently = new HashMap<>(); private final Map<BlockState, MutableInt> consumedRecently = new HashMap<>();
public BlockEntityFlowerGenerator() { public BlockEntityFlowerGenerator(BlockPos pos, BlockState state) {
super(ModTileEntities.FLOWER_GENERATOR); super(ModTileEntities.FLOWER_GENERATOR, pos, state);
} }
@Override @Override
@ -40,7 +38,7 @@ public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITick
for (int x = -range; x <= range; x++) { for (int x = -range; x <= range; x++) {
for (int y = -1; y <= 1; y++) { for (int y = -1; y <= 1; y++) {
for (int z = -range; z <= range; z++) { for (int z = -range; z <= range; z++) {
BlockPos offset = this.worldPosition.add(x, y, z); BlockPos offset = this.worldPosition.offset(x, y, z);
BlockState state = this.level.getBlockState(offset); BlockState state = this.level.getBlockState(offset);
if (BlockTags.SMALL_FLOWERS.contains(state.getBlock())) if (BlockTags.SMALL_FLOWERS.contains(state.getBlock()))
possible.add(offset); possible.add(offset);
@ -51,7 +49,7 @@ public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITick
if (possible.isEmpty()) if (possible.isEmpty())
return; return;
BlockPos pos = possible.get(this.level.rand.nextInt(possible.size())); BlockPos pos = possible.get(this.level.random.nextInt(possible.size()));
BlockState state = this.level.getBlockState(pos); BlockState state = this.level.getBlockState(pos);
MutableInt curr = this.consumedRecently.computeIfAbsent(state, s -> new MutableInt()); MutableInt curr = this.consumedRecently.computeIfAbsent(state, s -> new MutableInt());
@ -78,15 +76,15 @@ public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITick
int color = Helper.blendColors(0x5ccc30, 0xe53c16, toAdd / (float) addAmount); int color = Helper.blendColors(0x5ccc30, 0xe53c16, toAdd / (float) addAmount);
if (toAdd > 0) { if (toAdd > 0) {
for (int i = this.level.rand.nextInt(5) + 5; i >= 0; i--) for (int i = this.level.random.nextInt(5) + 5; i >= 0; i--)
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticleStream( PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticleStream(
pos.getX() + 0.25F + this.level.rand.nextFloat() * 0.5F, pos.getX() + 0.25F + this.level.random.nextFloat() * 0.5F,
pos.getY() + 0.25F + this.level.rand.nextFloat() * 0.5F, pos.getY() + 0.25F + this.level.random.nextFloat() * 0.5F,
pos.getZ() + 0.25F + this.level.rand.nextFloat() * 0.5F, pos.getZ() + 0.25F + this.level.random.nextFloat() * 0.5F,
this.worldPosition.getX() + 0.25F + this.level.rand.nextFloat() * 0.5F, this.worldPosition.getX() + 0.25F + this.level.random.nextFloat() * 0.5F,
this.worldPosition.getY() + 0.25F + this.level.rand.nextFloat() * 0.5F, this.worldPosition.getY() + 0.25F + this.level.random.nextFloat() * 0.5F,
this.worldPosition.getZ() + 0.25F + this.level.rand.nextFloat() * 0.5F, this.worldPosition.getZ() + 0.25F + this.level.random.nextFloat() * 0.5F,
this.level.rand.nextFloat() * 0.02F + 0.1F, color, 1F this.level.random.nextFloat() * 0.02F + 0.1F, color, 1F
)); ));
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.FLOWER_GEN_AURA_CREATION)); PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.FLOWER_GEN_AURA_CREATION));
} }
@ -104,7 +102,7 @@ public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITick
super.writeNBT(compound, type); super.writeNBT(compound, type);
if (type != SaveType.SYNC && !this.consumedRecently.isEmpty()) { if (type != SaveType.SYNC && !this.consumedRecently.isEmpty()) {
ListNBT list = new ListNBT(); ListTag list = new ListTag();
for (Map.Entry<BlockState, MutableInt> entry : this.consumedRecently.entrySet()) { for (Map.Entry<BlockState, MutableInt> entry : this.consumedRecently.entrySet()) {
BlockState state = entry.getKey(); BlockState state = entry.getKey();
Block block = state.getBlock(); Block block = state.getBlock();
@ -123,12 +121,12 @@ public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITick
super.readNBT(compound, type); super.readNBT(compound, type);
if (type != SaveType.SYNC) { if (type != SaveType.SYNC) {
this.consumedRecently.clear(); this.consumedRecently.clear();
ListNBT list = compound.getList("consumed_recently", 10); ListTag list = compound.getList("consumed_recently", 10);
for (INBT base : list) { for (Tag base : list) {
CompoundTag tag = (CompoundTag) base; CompoundTag tag = (CompoundTag) base;
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(tag.getString("block"))); Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(tag.getString("block")));
if (block != null) if (block != null)
this.consumedRecently.put(block.getDefaultState(), new MutableInt(tag.getInt("amount"))); this.consumedRecently.put(block.defaultBlockState(), new MutableInt(tag.getInt("amount")));
} }
} }

View file

@ -1,18 +0,0 @@
package de.ellpeck.naturesaura.blocks.tiles;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public class BlockEntityGeneratorLimitRemover extends BlockEntityImpl {
public BlockEntityGeneratorLimitRemover() {
super(ModTileEntities.GENERATOR_LIMIT_REMOVER);
}
@Override
@OnlyIn(Dist.CLIENT)
public AxisAlignedBB getRenderBoundingBox() {
return new AxisAlignedBB(this.worldPosition, this.worldPosition.add(1, 2, 1));
}
}

View file

@ -3,28 +3,29 @@ package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.block.HopperBlock; import net.minecraft.core.BlockPos;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.core.Direction;
import net.minecraft.item.ItemStack; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.tileentity.HopperBlockEntity; import net.minecraft.world.item.ItemStack;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.world.level.block.HopperBlock;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.util.Direction; import net.minecraft.world.level.block.entity.HopperBlockEntity;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.phys.AABB;
import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import java.util.List; import java.util.List;
public class BlockEntityHopperUpgrade extends BlockEntityImpl implements ITickableBlockEntity { public class BlockEntityHopperUpgrade extends BlockEntityImpl implements ITickableBlockEntity {
public BlockEntityHopperUpgrade() {
super(ModTileEntities.HOPPER_UPGRADE); public BlockEntityHopperUpgrade(BlockPos pos, BlockState state) {
super(ModTileEntities.HOPPER_UPGRADE, pos, state);
} }
private static boolean isValidHopper(BlockEntity tile) { private static boolean isValidHopper(BlockEntity tile) {
if (tile instanceof HopperBlockEntity) if (tile instanceof HopperBlockEntity)
return tile.getLevel().getBlockState(tile.getPos()).get(HopperBlock.ENABLED); return tile.getLevel().getBlockState(tile.getBlockPos()).getValue(HopperBlock.ENABLED);
if (tile instanceof BlockEntityGratedChute) if (tile instanceof BlockEntityGratedChute)
return ((BlockEntityGratedChute) tile).redstonePower <= 0; return ((BlockEntityGratedChute) tile).redstonePower <= 0;
return false; return false;
@ -35,20 +36,19 @@ public class BlockEntityHopperUpgrade extends BlockEntityImpl implements ITickab
if (!this.level.isClientSide && this.level.getGameTime() % 10 == 0) { if (!this.level.isClientSide && this.level.getGameTime() % 10 == 0) {
if (IAuraChunk.getAuraInArea(this.level, this.worldPosition, 25) < 100000) if (IAuraChunk.getAuraInArea(this.level, this.worldPosition, 25) < 100000)
return; return;
BlockEntity tile = this.level.getBlockEntity(this.worldPosition.down()); BlockEntity tile = this.level.getBlockEntity(this.worldPosition.below());
if (!isValidHopper(tile)) if (!isValidHopper(tile))
return; return;
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.UP).orElse(null); IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.UP).orElse(null);
if (handler == null) if (handler == null)
return; return;
List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class, List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class, new AABB(this.worldPosition).inflate(7));
new AxisAlignedBB(this.worldPosition).grow(7));
if (items.isEmpty()) if (items.isEmpty())
return; return;
for (ItemEntity item : items) { for (ItemEntity item : items) {
if (!item.isAlive() || item.cannotPickup()) if (!item.isAlive() || item.hasPickUpDelay())
continue; continue;
ItemStack stack = item.getItem(); ItemStack stack = item.getItem();
if (stack.isEmpty()) if (stack.isEmpty())
@ -62,16 +62,16 @@ public class BlockEntityHopperUpgrade extends BlockEntityImpl implements ITickab
} }
} }
if (!ItemStack.areItemStacksEqual(stack, copy)) { if (!ItemStack.isSame(stack, copy)) {
item.setItem(copy); item.setItem(copy);
if (copy.isEmpty()) if (copy.isEmpty())
item.remove(); item.kill();
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 25, this.worldPosition); BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 25, this.worldPosition);
IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, 500); IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, 500);
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
new PacketParticles((float) item.getPosX(), (float) item.getPosY(), (float) item.getPosZ(), PacketParticles.Type.HOPPER_UPGRADE)); new PacketParticles((float) item.getX(), (float) item.getY(), (float) item.getZ(), PacketParticles.Type.HOPPER_UPGRADE));
} }
} }
} }

View file

@ -1,11 +1,11 @@
package de.ellpeck.naturesaura.blocks.tiles; package de.ellpeck.naturesaura.blocks.tiles;
import net.minecraft.item.ItemStack; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.world.item.ItemStack;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.util.Direction; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
@ -18,8 +18,8 @@ public class BlockEntityItemDistributor extends BlockEntityImpl implements ITick
private Direction currentSide = Direction.NORTH; private Direction currentSide = Direction.NORTH;
public boolean isRandomMode; public boolean isRandomMode;
public BlockEntityItemDistributor() { public BlockEntityItemDistributor(BlockPos pos, BlockState state) {
super(ModTileEntities.ITEM_DISTRIBUTOR); super(ModTileEntities.ITEM_DISTRIBUTOR, pos, state);
} }
@Override @Override
@ -44,7 +44,7 @@ public class BlockEntityItemDistributor extends BlockEntityImpl implements ITick
continue; continue;
for (int j = 0; j < dest.getSlots(); j++) { for (int j = 0; j < dest.getSlots(); j++) {
ItemStack remain = dest.insertItem(j, stack, false); ItemStack remain = dest.insertItem(j, stack, false);
if (!ItemStack.areItemStacksEqual(remain, stack)) { if (!ItemStack.isSame(remain, stack)) {
above.extractItem(i, 1, false); above.extractItem(i, 1, false);
this.cooldown = 3; this.cooldown = 3;
return; return;
@ -54,7 +54,7 @@ public class BlockEntityItemDistributor extends BlockEntityImpl implements ITick
} }
private IItemHandler getHandler(Direction direction) { private IItemHandler getHandler(Direction direction) {
BlockPos offset = this.worldPosition.offset(direction); BlockPos offset = this.worldPosition.relative(direction);
BlockEntity tile = this.level.getBlockEntity(offset); BlockEntity tile = this.level.getBlockEntity(offset);
if (tile == null) if (tile == null)
return null; return null;
@ -65,16 +65,16 @@ public class BlockEntityItemDistributor extends BlockEntityImpl implements ITick
if (this.isRandomMode) { if (this.isRandomMode) {
List<IItemHandler> handlers = new ArrayList<>(); List<IItemHandler> handlers = new ArrayList<>();
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
IItemHandler handler = this.getHandler(Direction.byHorizontalIndex(i)); IItemHandler handler = this.getHandler(Direction.values()[i]);
if (handler != null) if (handler != null)
handlers.add(handler); handlers.add(handler);
} }
if (handlers.isEmpty()) if (handlers.isEmpty())
return null; return null;
return handlers.get(this.level.rand.nextInt(handlers.size())); return handlers.get(this.level.random.nextInt(handlers.size()));
} else { } else {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
this.currentSide = this.currentSide.rotateY(); this.currentSide = this.currentSide.getClockWise();
IItemHandler handler = this.getHandler(this.currentSide); IItemHandler handler = this.getHandler(this.currentSide);
if (handler != null) if (handler != null)
return handler; return handler;

View file

@ -2,11 +2,13 @@ package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.entities.EntityEffectInhibitor; import de.ellpeck.naturesaura.entities.EntityEffectInhibitor;
import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.items.ModItems;
import net.minecraft.item.ItemStack; import net.minecraft.core.BlockPos;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.core.Direction;
import net.minecraft.util.Direction; import net.minecraft.world.entity.Entity;
import net.minecraft.util.EntityPredicates; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
@ -14,19 +16,18 @@ import java.util.List;
public class BlockEntityPowderPlacer extends BlockEntityImpl { public class BlockEntityPowderPlacer extends BlockEntityImpl {
public BlockEntityPowderPlacer() { public BlockEntityPowderPlacer(BlockPos pos, BlockState state) {
super(ModTileEntities.POWDER_PLACER); super(ModTileEntities.POWDER_PLACER, pos, state);
} }
@Override @Override
public void onRedstonePowerChange(int newPower) { public void onRedstonePowerChange(int newPower) {
if (this.redstonePower <= 0 && newPower > 0) { if (this.redstonePower <= 0 && newPower > 0) {
List<EntityEffectInhibitor> powders = this.level.getEntitiesWithinAABB(EntityEffectInhibitor.class, List<EntityEffectInhibitor> powders = this.level.getEntitiesOfClass(EntityEffectInhibitor.class, new AABB(this.worldPosition, this.worldPosition.offset(1, 2, 1)), Entity::isAlive);
new AxisAlignedBB(this.worldPosition, this.worldPosition.add(1, 2, 1)), EntityPredicates.IS_ALIVE);
for (Direction facing : Direction.values()) { for (Direction facing : Direction.values()) {
if (!facing.getAxis().isHorizontal()) if (!facing.getAxis().isHorizontal())
continue; continue;
BlockEntity tile = this.level.getBlockEntity(this.worldPosition.offset(facing)); BlockEntity tile = this.level.getBlockEntity(this.worldPosition.relative(facing));
if (tile == null) if (tile == null)
continue; continue;
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite()).orElse(null); IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite()).orElse(null);
@ -39,7 +40,7 @@ public class BlockEntityPowderPlacer extends BlockEntityImpl {
for (int i = 0; i < handler.getSlots(); i++) { for (int i = 0; i < handler.getSlots(); i++) {
ItemStack remain = handler.insertItem(i, drop, false); ItemStack remain = handler.insertItem(i, drop, false);
if (remain.isEmpty()) { if (remain.isEmpty()) {
powder.remove(); powder.kill();
break; break;
} else if (remain.getCount() != drop.getCount()) { } else if (remain.getCount() != drop.getCount()) {
powder.setAmount(remain.getCount()); powder.setAmount(remain.getCount());

View file

@ -1,30 +1,30 @@
package de.ellpeck.naturesaura.blocks.tiles; package de.ellpeck.naturesaura.blocks.tiles;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Direction; import net.minecraft.world.level.block.state.BlockState;
public class BlockEntityProjectileGenerator extends BlockEntityImpl { public class BlockEntityProjectileGenerator extends BlockEntityImpl {
public Direction nextSide = Direction.NORTH; public Direction nextSide = Direction.NORTH;
public BlockEntityProjectileGenerator() { public BlockEntityProjectileGenerator(BlockPos pos, BlockState state) {
super(ModTileEntities.PROJECTILE_GENERATOR); super(ModTileEntities.PROJECTILE_GENERATOR, pos, state);
} }
@Override @Override
public void writeNBT(CompoundTag compound, SaveType type) { public void writeNBT(CompoundTag compound, SaveType type) {
super.writeNBT(compound, type); super.writeNBT(compound, type);
if (type != SaveType.BLOCK) { if (type != SaveType.BLOCK)
compound.putInt("next_side", this.nextSide.getHorizontalIndex()); compound.putInt("next_side", this.nextSide.ordinal());
}
} }
@Override @Override
public void readNBT(CompoundTag compound, SaveType type) { public void readNBT(CompoundTag compound, SaveType type) {
super.readNBT(compound, type); super.readNBT(compound, type);
if (type != SaveType.BLOCK) { if (type != SaveType.BLOCK)
this.nextSide = Direction.byHorizontalIndex(compound.getInt("next_side")); this.nextSide = Direction.values()[compound.getInt("next_side")];
}
} }
@Override @Override

View file

@ -5,12 +5,12 @@ import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.blocks.multi.Multiblocks; import de.ellpeck.naturesaura.blocks.multi.Multiblocks;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.util.Mth;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.util.Direction; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth;
import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.CapabilityEnergy;
@ -25,8 +25,8 @@ public class BlockEntityRFConverter extends BlockEntityImpl implements ITickable
private final LazyOptional<IEnergyStorage> storageOptional = LazyOptional.of(() -> this.storage); private final LazyOptional<IEnergyStorage> storageOptional = LazyOptional.of(() -> this.storage);
private int lastEnergy; private int lastEnergy;
public BlockEntityRFConverter() { public BlockEntityRFConverter(BlockPos pos, BlockState state) {
super(ModTileEntities.RF_CONVERTER); super(ModTileEntities.RF_CONVERTER, pos, state);
} }
@Override @Override
@ -50,7 +50,7 @@ public class BlockEntityRFConverter extends BlockEntityImpl implements ITickable
} }
for (Direction facing : Direction.values()) { for (Direction facing : Direction.values()) {
BlockEntity tile = this.level.getBlockEntity(this.worldPosition.offset(facing)); BlockEntity tile = this.level.getBlockEntity(this.worldPosition.relative(facing));
if (tile == null) if (tile == null)
continue; continue;
IEnergyStorage storage = tile.getCapability(CapabilityEnergy.ENERGY, facing.getOpposite()).orElse(null); IEnergyStorage storage = tile.getCapability(CapabilityEnergy.ENERGY, facing.getOpposite()).orElse(null);
@ -99,8 +99,8 @@ public class BlockEntityRFConverter extends BlockEntityImpl implements ITickable
} }
@Override @Override
public void remove() { public void setRemoved() {
super.remove(); super.setRemoved();
this.storageOptional.invalidate(); this.storageOptional.invalidate();
} }

View file

@ -4,24 +4,24 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.block.Blocks; import net.minecraft.core.BlockPos;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.SnowGolemEntity;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.util.Mth;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.entity.Entity;
import net.minecraft.util.math.Mth; import net.minecraft.world.entity.EntityType;
import net.minecraft.level.gen.Heightmap; import net.minecraft.world.entity.animal.SnowGolem;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.Fluids;
public class BlockEntitySnowCreator extends BlockEntityImpl implements ITickableBlockEntity { public class BlockEntitySnowCreator extends BlockEntityImpl implements ITickableBlockEntity {
private int snowmanCount; private int snowmanCount;
public BlockEntitySnowCreator() { public BlockEntitySnowCreator(BlockPos pos, BlockState state) {
super(ModTileEntities.SNOW_CREATOR); super(ModTileEntities.SNOW_CREATOR, pos, state);
} }
public int getRange() { public int getRange() {
@ -45,23 +45,23 @@ public class BlockEntitySnowCreator extends BlockEntityImpl implements ITickable
return; return;
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
double angle = this.level.rand.nextFloat() * Math.PI * 2; double angle = this.level.random.nextFloat() * Math.PI * 2;
BlockPos pos = this.worldPosition.add(Math.cos(angle) * range * this.level.rand.nextFloat(), 0, Math.sin(angle) * range * this.level.rand.nextFloat()); BlockPos pos = this.worldPosition.offset(Math.cos(angle) * range * this.level.random.nextFloat(), 0, Math.sin(angle) * range * this.level.random.nextFloat());
pos = this.level.getHeight(Heightmap.Type.MOTION_BLOCKING, pos); pos = this.level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, pos);
BlockPos down = pos.down(); BlockPos down = pos.below();
Fluid fluid = this.level.getFluidState(down).getFluid(); Fluid fluid = this.level.getFluidState(down).getType();
if (fluid == Fluids.WATER) { if (fluid == Fluids.WATER) {
if (this.level.getBlockState(down).getMaterial().isReplaceable()) if (this.level.getBlockState(down).getMaterial().isReplaceable())
this.level.setBlockState(down, Blocks.ICE.getDefaultState()); this.level.setBlockAndUpdate(down, Blocks.ICE.defaultBlockState());
} else if (Blocks.SNOW.getDefaultState().isValidPosition(this.level, pos) && this.level.getBlockState(pos).getBlock() != Blocks.SNOW && this.level.getBlockState(pos).getMaterial().isReplaceable()) { } else if (Blocks.SNOW.defaultBlockState().canSurvive(this.level, pos) && this.level.getBlockState(pos).getBlock() != Blocks.SNOW && this.level.getBlockState(pos).getMaterial().isReplaceable()) {
this.level.setBlockState(pos, Blocks.SNOW.getDefaultState()); this.level.setBlockAndUpdate(pos, Blocks.SNOW.defaultBlockState());
if (this.snowmanCount < range / 2 && this.level.rand.nextFloat() >= 0.995F) { if (this.snowmanCount < range / 2 && this.level.random.nextFloat() >= 0.995F) {
this.snowmanCount++; this.snowmanCount++;
Entity golem = new SnowGolemEntity(EntityType.SNOW_GOLEM, this.level); Entity golem = new SnowGolem(EntityType.SNOW_GOLEM, this.level);
golem.setPosition(pos.getX() + 0.5F, pos.getY(), pos.getZ() + 0.5F); golem.setPos(pos.getX() + 0.5F, pos.getY(), pos.getZ() + 0.5F);
this.level.addEntity(golem); this.level.addFreshEntity(golem);
} }
} else { } else {
continue; continue;
@ -78,15 +78,15 @@ public class BlockEntitySnowCreator extends BlockEntityImpl implements ITickable
if (this.level.getGameTime() % 30 != 0) if (this.level.getGameTime() % 30 != 0)
return; return;
for (int i = range * 4; i >= 0; i--) { for (int i = range * 4; i >= 0; i--) {
double angle = this.level.rand.nextFloat() * Math.PI * 2; double angle = this.level.random.nextFloat() * Math.PI * 2;
BlockPos pos = this.worldPosition.add( BlockPos pos = this.worldPosition.offset(
Math.cos(angle) * range * this.level.rand.nextFloat(), Math.cos(angle) * range * this.level.random.nextFloat(),
Mth.nextInt(this.level.rand, range / 2, range), Mth.nextInt(this.level.random, range / 2, range),
Math.sin(angle) * range * this.level.rand.nextFloat()); Math.sin(angle) * range * this.level.random.nextFloat());
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
pos.getX() + this.level.rand.nextFloat(), pos.getY() + 1, pos.getZ() + this.level.rand.nextFloat(), pos.getX() + this.level.random.nextFloat(), pos.getY() + 1, pos.getZ() + this.level.random.nextFloat(),
this.level.rand.nextGaussian() * 0.05, 0, this.level.rand.nextGaussian() * 0.05, this.level.random.nextGaussian() * 0.05, 0, this.level.random.nextGaussian() * 0.05,
0xdbe9ff, 1 + this.level.rand.nextFloat() * 1.5F, 10 * range, 0.05F + this.level.rand.nextFloat() * 0.05F, true, true 0xdbe9ff, 1 + this.level.random.nextFloat() * 1.5F, 10 * range, 0.05F + this.level.random.nextFloat() * 0.05F, true, true
); );
} }
} }

View file

@ -2,11 +2,13 @@ package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.api.misc.ILevelData; import de.ellpeck.naturesaura.api.misc.ILevelData;
import de.ellpeck.naturesaura.misc.LevelData; import de.ellpeck.naturesaura.misc.LevelData;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.state.BlockState;
public class BlockEntitySpawnLamp extends BlockEntityImpl { public class BlockEntitySpawnLamp extends BlockEntityImpl {
public BlockEntitySpawnLamp() { public BlockEntitySpawnLamp(BlockPos pos, BlockState state) {
super(ModTileEntities.SPAWN_LAMP); super(ModTileEntities.SPAWN_LAMP, pos, state);
} }
public int getRadius() { public int getRadius() {
@ -14,8 +16,8 @@ public class BlockEntitySpawnLamp extends BlockEntityImpl {
} }
@Override @Override
public void validate() { public void onLoad() {
super.validate(); super.onLoad();
if (!this.level.isClientSide) { if (!this.level.isClientSide) {
LevelData data = (LevelData) ILevelData.getLevelData(this.level); LevelData data = (LevelData) ILevelData.getLevelData(this.level);
data.spawnLamps.add(this); data.spawnLamps.add(this);
@ -23,8 +25,8 @@ public class BlockEntitySpawnLamp extends BlockEntityImpl {
} }
@Override @Override
public void remove() { public void setRemoved() {
super.remove(); super.setRemoved();
if (!this.level.isClientSide) { if (!this.level.isClientSide) {
LevelData data = (LevelData) ILevelData.getLevelData(this.level); LevelData data = (LevelData) ILevelData.getLevelData(this.level);
data.spawnLamps.remove(this); data.spawnLamps.remove(this);

View file

@ -5,21 +5,21 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.items.ModItems;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.core.BlockPos;
import net.minecraft.entity.item.ItemFrameEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.play.server.SUpdateTimePacket; import net.minecraft.network.protocol.game.ClientboundSetTimePacket;
import net.minecraft.server.management.PlayerList; import net.minecraft.server.level.ServerLevel;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.server.players.PlayerList;
import net.minecraft.util.EntityPredicates; import net.minecraft.util.Mth;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.entity.Entity;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.entity.decoration.ItemFrame;
import net.minecraft.util.math.Mth; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.level.GameRules; import net.minecraft.world.item.ItemStack;
import net.minecraft.level.server.ServerLevel; import net.minecraft.world.item.Items;
import net.minecraft.level.storage.IServerLevelInfo; import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.ServerLevelData;
import net.minecraft.world.phys.AABB;
import java.util.List; import java.util.List;
@ -27,16 +27,16 @@ public class BlockEntityTimeChanger extends BlockEntityImpl implements ITickable
private long goalTime; private long goalTime;
public BlockEntityTimeChanger() { public BlockEntityTimeChanger(BlockPos pos, BlockState state) {
super(ModTileEntities.TIME_CHANGER); super(ModTileEntities.TIME_CHANGER, pos, state);
} }
@Override @Override
public void tick() { public void tick() {
if (!this.level.isClientSide) { if (!this.level.isClientSide) {
List<ItemFrameEntity> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition); List<ItemFrame> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition);
for (ItemFrameEntity frame : frames) { for (ItemFrame frame : frames) {
ItemStack frameStack = frame.getDisplayedItem(); ItemStack frameStack = frame.getItem();
if (frameStack.isEmpty() || frameStack.getItem() != ModItems.CLOCK_HAND) if (frameStack.isEmpty() || frameStack.getItem() != ModItems.CLOCK_HAND)
continue; continue;
@ -48,16 +48,16 @@ public class BlockEntityTimeChanger extends BlockEntityImpl implements ITickable
this.sendToClients(); this.sendToClients();
return; return;
} }
((IServerLevelInfo) this.level.getLevelInfo()).setDayTime(current + toAdd); ((ServerLevelData) this.level.getLevelData()).setDayTime(current + toAdd);
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition); BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition);
IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, (int) toAdd * 20); IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, (int) toAdd * 20);
if (this.level instanceof ServerLevel) { if (this.level instanceof ServerLevel) {
PlayerList list = this.level.getServer().getPlayerList(); PlayerList list = this.level.getServer().getPlayerList();
list.sendPacketToAllPlayers(new SUpdateTimePacket( list.broadcastAll(new ClientboundSetTimePacket(
this.level.getGameTime(), this.level.getDayTime(), this.level.getGameTime(), this.level.getDayTime(),
this.level.getGameRules().getBoolean(GameRules.DO_DAYLIGHT_CYCLE))); this.level.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT)));
} }
return; return;
} }
@ -65,10 +65,9 @@ public class BlockEntityTimeChanger extends BlockEntityImpl implements ITickable
if (this.level.getGameTime() % 20 != 0) if (this.level.getGameTime() % 20 != 0)
return; return;
List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class, List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class, new AABB(this.worldPosition).inflate(1), Entity::isAlive);
new AxisAlignedBB(this.worldPosition).grow(1), EntityPredicates.IS_ALIVE);
for (ItemEntity item : items) { for (ItemEntity item : items) {
if (item.cannotPickup()) if (item.hasPickUpDelay())
continue; continue;
ItemStack stack = item.getItem(); ItemStack stack = item.getItem();
if (stack.isEmpty() || stack.getItem() != Items.CLOCK) if (stack.isEmpty() || stack.getItem() != Items.CLOCK)
@ -80,9 +79,9 @@ public class BlockEntityTimeChanger extends BlockEntityImpl implements ITickable
this.goalTime = current + toMove; this.goalTime = current + toMove;
this.sendToClients(); this.sendToClients();
if (stack.getCount() <= 1) if (stack.getCount() <= 1) {
item.remove(); item.kill();
else { } else {
stack.shrink(1); stack.shrink(1);
item.setItem(stack); item.setItem(stack);
} }
@ -93,7 +92,7 @@ public class BlockEntityTimeChanger extends BlockEntityImpl implements ITickable
this.goalTime = 0; this.goalTime = 0;
this.sendToClients(); this.sendToClients();
} }
} else if (this.goalTime > 0 && this.level.rand.nextFloat() >= 0.25F) { } else if (this.goalTime > 0 && this.level.random.nextFloat() >= 0.25F) {
double angle = Math.toRadians(this.level.getDayTime() * 5F % 360); double angle = Math.toRadians(this.level.getDayTime() * 5F % 360);
double x = this.worldPosition.getX() + 0.5 + Math.sin(angle) * 3F; double x = this.worldPosition.getX() + 0.5 + Math.sin(angle) * 3F;
double z = this.worldPosition.getZ() + 0.5 + Math.cos(angle) * 3F; double z = this.worldPosition.getZ() + 0.5 + Math.cos(angle) * 3F;
@ -101,12 +100,12 @@ public class BlockEntityTimeChanger extends BlockEntityImpl implements ITickable
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
x, this.worldPosition.getY() + 0.1F, z, x, this.worldPosition.getY() + 0.1F, z,
0F, 0.12F, 0F, 0F, 0.12F, 0F,
color, 1F + this.level.rand.nextFloat() * 2F, color, 1F + this.level.random.nextFloat() * 2F,
this.level.rand.nextInt(100) + 100, 0, false, true); this.level.random.nextInt(100) + 100, 0, false, true);
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
x, this.worldPosition.getY() + 0.1F, z, x, this.worldPosition.getY() + 0.1F, z,
0F, 0F, 0F, 0F, 0F, 0F,
IAuraType.forLevel(this.level).getColor(), 1F + this.level.rand.nextFloat(), IAuraType.forLevel(this.level).getColor(), 1F + this.level.random.nextFloat(),
150, 0, false, true); 150, 0, false, true);
} }
} }

View file

@ -4,14 +4,14 @@ import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.misc.WeatherType; import de.ellpeck.naturesaura.api.misc.WeatherType;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.core.BlockPos;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.EntityPredicates; import net.minecraft.world.entity.Entity;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.item.ItemStack;
import net.minecraft.level.server.ServerLevel; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import java.util.List; import java.util.List;
@ -23,8 +23,8 @@ public class BlockEntityWeatherChanger extends BlockEntityImpl implements ITicka
private WeatherType type; private WeatherType type;
private int itemAmount; private int itemAmount;
public BlockEntityWeatherChanger() { public BlockEntityWeatherChanger(BlockPos pos, BlockState state) {
super(ModTileEntities.WEATHER_CHANGER); super(ModTileEntities.WEATHER_CHANGER, pos, state);
} }
@Override @Override
@ -38,15 +38,15 @@ public class BlockEntityWeatherChanger extends BlockEntityImpl implements ITicka
for (int r = 0; r < 360; r += 20) { for (int r = 0; r < 360; r += 20) {
double xOff = Math.cos(Math.toRadians(r)) * 3F; double xOff = Math.cos(Math.toRadians(r)) * 3F;
double zOff = Math.sin(Math.toRadians(r)) * 3F; double zOff = Math.sin(Math.toRadians(r)) * 3F;
for (int i = this.level.rand.nextInt(3); i > 0; i--) { for (int i = this.level.random.nextInt(3); i > 0; i--) {
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
this.worldPosition.getX() + 0.5F + xOff, this.worldPosition.getX() + 0.5F + xOff,
this.worldPosition.getY(), this.worldPosition.getY(),
this.worldPosition.getZ() + 0.5F + zOff, this.worldPosition.getZ() + 0.5F + zOff,
this.level.rand.nextGaussian() * 0.02F, this.level.random.nextGaussian() * 0.02F,
this.level.rand.nextFloat() * 0.1F + 0.1F, this.level.random.nextFloat() * 0.1F + 0.1F,
this.level.rand.nextGaussian() * 0.02F, this.level.random.nextGaussian() * 0.02F,
color, this.level.rand.nextFloat() * 2 + 1, this.level.rand.nextInt(80) + 80, 0, false, true); color, this.level.random.nextFloat() * 2 + 1, this.level.random.nextInt(80) + 80, 0, false, true);
} }
} }
return; return;
@ -64,15 +64,9 @@ public class BlockEntityWeatherChanger extends BlockEntityImpl implements ITicka
int time = 6000 * this.itemAmount; int time = 6000 * this.itemAmount;
ServerLevel server = (ServerLevel) this.level; ServerLevel server = (ServerLevel) this.level;
switch (this.type) { switch (this.type) {
case SUN: case SUN -> server.setWeatherParameters(time, 0, false, false);
server.func_241113_a_(time, 0, false, false); case RAIN -> server.setWeatherParameters(0, time, true, false);
break; case THUNDERSTORM -> server.setWeatherParameters(0, time, true, true);
case RAIN:
server.func_241113_a_(0, time, true, false);
break;
case THUNDERSTORM:
server.func_241113_a_(0, time, true, true);
break;
} }
} }
} else { } else {
@ -110,17 +104,17 @@ public class BlockEntityWeatherChanger extends BlockEntityImpl implements ITicka
} }
private Pair<WeatherType, Integer> getNextWeatherType() { private Pair<WeatherType, Integer> getNextWeatherType() {
AxisAlignedBB area = new AxisAlignedBB(this.worldPosition).grow(2); AABB area = new AABB(this.worldPosition).inflate(2);
List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class, area, EntityPredicates.IS_ALIVE); List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class, area, Entity::isAlive);
for (ItemEntity entity : items) { for (ItemEntity entity : items) {
if (entity.cannotPickup()) if (entity.hasPickUpDelay())
continue; continue;
ItemStack stack = entity.getItem(); ItemStack stack = entity.getItem();
for (Map.Entry<ItemStack, WeatherType> entry : NaturesAuraAPI.WEATHER_CHANGER_CONVERSIONS.entrySet()) { for (Map.Entry<ItemStack, WeatherType> entry : NaturesAuraAPI.WEATHER_CHANGER_CONVERSIONS.entrySet()) {
if (!Helper.areItemsEqual(stack, entry.getKey(), true)) if (!Helper.areItemsEqual(stack, entry.getKey(), true))
continue; continue;
entity.setItem(ItemStack.EMPTY); entity.setItem(ItemStack.EMPTY);
entity.remove(); entity.kill();
return Pair.of(entry.getValue(), stack.getCount()); return Pair.of(entry.getValue(), stack.getCount());
} }
} }

View file

@ -7,23 +7,28 @@ import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect; import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect;
import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.api.misc.WeightedOre; import de.ellpeck.naturesaura.api.misc.WeightedOre;
import net.minecraft.block.Block; import net.minecraft.core.BlockPos;
import net.minecraft.block.BlockState; import net.minecraft.core.Direction;
import net.minecraft.block.Blocks; import net.minecraft.core.Registry;
import net.minecraft.entity.player.Player; import net.minecraft.resources.ResourceLocation;
import net.minecraft.item.BlockItemUseContext; import net.minecraft.server.level.ServerLevel;
import net.minecraft.item.ItemStack; import net.minecraft.tags.Tag;
import net.minecraft.item.ItemUseContext; import net.minecraft.util.Mth;
import net.minecraft.tags.ITag; import net.minecraft.util.Tuple;
import net.minecraft.util.*; import net.minecraft.util.random.WeightedRandom;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.InteractionHand;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.entity.player.Player;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.math.Mth; import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.level.chunk.Chunk; import net.minecraft.world.level.block.Block;
import net.minecraft.level.server.ServerLevel; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory; import net.minecraftforge.common.util.FakePlayerFactory;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
@ -55,12 +60,12 @@ public class OreSpawnEffect implements IDrainSpotEffect {
} }
@Override @Override
public ActiveType isActiveHere(Player player, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) { public ActiveType isActiveHere(Player player, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (!this.calcValues(player.level, pos, spot)) if (!this.calcValues(player.level, pos, spot))
return ActiveType.INACTIVE; return ActiveType.INACTIVE;
if (player.getDistanceSq(pos.getX(), pos.getY(), pos.getZ()) > this.dist * this.dist) if (player.distanceToSqr(pos.getX(), pos.getY(), pos.getZ()) > this.dist * this.dist)
return ActiveType.INACTIVE; return ActiveType.INACTIVE;
if (!NaturesAuraAPI.instance().isEffectPowderActive(player.level, player.getPosition(), NAME)) if (!NaturesAuraAPI.instance().isEffectPowderActive(player.level, player.getOnPos(), NAME))
return ActiveType.INHIBITED; return ActiveType.INHIBITED;
return ActiveType.ACTIVE; return ActiveType.ACTIVE;
} }
@ -71,7 +76,7 @@ public class OreSpawnEffect implements IDrainSpotEffect {
} }
@Override @Override
public void update(Level level, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) { public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (level.getGameTime() % 40 != 0) if (level.getGameTime() % 40 != 0)
return; return;
if (!this.calcValues(level, pos, spot)) if (!this.calcValues(level, pos, spot))
@ -88,46 +93,48 @@ public class OreSpawnEffect implements IDrainSpotEffect {
} }
int totalWeight = WeightedRandom.getTotalWeight(ores); int totalWeight = WeightedRandom.getTotalWeight(ores);
List<Tuple<Vector3d, Integer>> powders = NaturesAuraAPI.instance().getActiveEffectPowders(level, List<Tuple<Vec3, Integer>> powders = NaturesAuraAPI.instance().getActiveEffectPowders(level,
new AxisAlignedBB(pos).grow(this.dist), NAME); new AABB(pos).inflate(this.dist), NAME);
if (powders.isEmpty()) if (powders.isEmpty())
return; return;
for (int i = 0; i < this.amount; i++) { for (int i = 0; i < this.amount; i++) {
Tuple<Vector3d, Integer> powder = powders.get(i % powders.size()); Tuple<Vec3, Integer> powder = powders.get(i % powders.size());
Vector3d powderPos = powder.getA(); Vec3 powderPos = powder.getA();
int range = powder.getB(); int range = powder.getB();
int x = Mth.floor(powderPos.x + level.rand.nextGaussian() * range); int x = Mth.floor(powderPos.x + level.random.nextGaussian() * range);
int y = Mth.floor(powderPos.y + level.rand.nextGaussian() * range); int y = Mth.floor(powderPos.y + level.random.nextGaussian() * range);
int z = Mth.floor(powderPos.z + level.rand.nextGaussian() * range); int z = Mth.floor(powderPos.z + level.random.nextGaussian() * range);
BlockPos orePos = new BlockPos(x, y, z); BlockPos orePos = new BlockPos(x, y, z);
if (orePos.distanceSq(powderPos.x, powderPos.y, powderPos.z, true) <= range * range if (orePos.distSqr(powderPos.x, powderPos.y, powderPos.z, true) <= range * range
&& orePos.distanceSq(pos) <= this.dist * this.dist && level.isBlockLoaded(orePos)) { && orePos.distSqr(pos) <= this.dist * this.dist && level.isLoaded(orePos)) {
BlockState state = level.getBlockState(orePos); BlockState state = level.getBlockState(orePos);
if (state.getBlock() != requiredBlock) if (state.getBlock() != requiredBlock)
continue; continue;
outer: outer:
while (true) { while (true) {
WeightedOre ore = WeightedRandom.getRandomItem(level.rand, ores, totalWeight); WeightedOre ore = WeightedRandom.getRandomItem(level.random, ores, totalWeight).orElse(null);
ITag<Block> tag = level.getTags().func_241835_a().get(ore.tag); if (ore == null)
continue;
Tag<Block> tag = level.getTagManager().getOrEmpty(Registry.BLOCK_REGISTRY).getTag(ore.tag);
if (tag == null) if (tag == null)
continue; continue;
for (Block toPlace : tag.getAllElements()) { for (Block toPlace : tag.getValues()) {
if (toPlace == null || toPlace == Blocks.AIR) if (toPlace == null || toPlace == Blocks.AIR)
continue; continue;
FakePlayer player = FakePlayerFactory.getMinecraft((ServerLevel) level); FakePlayer player = FakePlayerFactory.getMinecraft((ServerLevel) level);
player.setHeldItem(Hand.MAIN_HAND, ItemStack.EMPTY); player.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY);
BlockRayTraceResult ray = new BlockRayTraceResult(Vector3d.copyCentered(pos), Direction.UP, pos, false); BlockHitResult ray = new BlockHitResult(Vec3.atCenterOf(pos), Direction.UP, pos, false);
BlockItemUseContext context = new BlockItemUseContext(new ItemUseContext(player, Hand.MAIN_HAND, ray)); BlockPlaceContext context = new BlockPlaceContext(new UseOnContext(player, InteractionHand.MAIN_HAND, ray));
BlockState stateToPlace = toPlace.getStateForPlacement(context); BlockState stateToPlace = toPlace.getStateForPlacement(context);
if (SPAWN_EXCEPTIONS.contains(stateToPlace)) if (SPAWN_EXCEPTIONS.contains(stateToPlace))
continue; continue;
level.setBlockState(orePos, stateToPlace); level.setBlockAndUpdate(orePos, stateToPlace);
level.playEvent(2001, orePos, Block.getStateId(stateToPlace)); level.levelEvent(2001, orePos, Block.getId(stateToPlace));
int toDrain = (20000 - ore.itemWeight * 2) * 2; int toDrain = (20000 - ore.getWeight().asInt() * 2) * 2;
BlockPos highestSpot = IAuraChunk.getHighestSpot(level, orePos, 30, pos); BlockPos highestSpot = IAuraChunk.getHighestSpot(level, orePos, 30, pos);
IAuraChunk.getAuraChunk(level, highestSpot).drainAura(highestSpot, toDrain); IAuraChunk.getAuraChunk(level, highestSpot).drainAura(highestSpot, toDrain);
break outer; break outer;
@ -138,7 +145,7 @@ public class OreSpawnEffect implements IDrainSpotEffect {
} }
@Override @Override
public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) { public boolean appliesHere(LevelChunk chunk, IAuraChunk auraChunk, IAuraType type) {
return ModConfig.instance.oreEffect.get() && return ModConfig.instance.oreEffect.get() &&
(type.isSimilar(NaturesAuraAPI.TYPE_OVERWORLD) || type.isSimilar(NaturesAuraAPI.TYPE_NETHER)); (type.isSimilar(NaturesAuraAPI.TYPE_OVERWORLD) || type.isSimilar(NaturesAuraAPI.TYPE_NETHER));
} }

View file

@ -1,49 +1,25 @@
package de.ellpeck.naturesaura.compat.patchouli; package de.ellpeck.naturesaura.compat.patchouli;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import de.ellpeck.naturesaura.ModConfig;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.multiblock.Matcher;
import de.ellpeck.naturesaura.compat.ICompat; import de.ellpeck.naturesaura.compat.ICompat;
import de.ellpeck.naturesaura.data.ItemTagProvider; import de.ellpeck.naturesaura.data.ItemTagProvider;
import de.ellpeck.naturesaura.events.ClientEvents;
import de.ellpeck.naturesaura.renderers.SupporterFancyHandler;
import de.ellpeck.naturesaura.renderers.SupporterFancyHandler.FancyInfo;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui; import net.minecraft.resources.ResourceLocation;
import net.minecraft.client.renderer.RenderHelper; import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.item.crafting.IRecipe; import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.item.crafting.RecipeManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DeferredWorkQueue;
import net.minecraftforge.fml.client.gui.GuiUtils;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import vazkii.patchouli.api.BookDrawScreenEvent;
import vazkii.patchouli.api.IMultiblock;
import vazkii.patchouli.api.IVariable;
import vazkii.patchouli.api.PatchouliAPI;
import java.time.LocalDateTime;
import java.time.Month;
import java.util.*;
import java.util.stream.Collectors;
// TODO Patchouli
public class PatchouliCompat implements ICompat { public class PatchouliCompat implements ICompat {
private static final ResourceLocation BOOK = new ResourceLocation(NaturesAura.MOD_ID, "book"); private static final ResourceLocation BOOK = new ResourceLocation(NaturesAura.MOD_ID, "book");
/*
private static final Map<ResourceLocation, IMultiblock> MULTIBLOCKS = new HashMap<>(); private static final Map<ResourceLocation, IMultiblock> MULTIBLOCKS = new HashMap<>();
*/
public static void addPatchouliMultiblock(ResourceLocation name, String[][] pattern, Object... rawMatchers) { public static void addPatchouliMultiblock(ResourceLocation name, String[][] pattern, Object... rawMatchers) {
for (int i = 1; i < rawMatchers.length; i += 2) { /* for (int i = 1; i < rawMatchers.length; i += 2) {
if (rawMatchers[i] instanceof Matcher) { if (rawMatchers[i] instanceof Matcher) {
Matcher matcher = (Matcher) rawMatchers[i]; Matcher matcher = (Matcher) rawMatchers[i];
Matcher.ICheck check = matcher.getCheck(); Matcher.ICheck check = matcher.getCheck();
@ -54,30 +30,31 @@ public class PatchouliCompat implements ICompat {
state -> check.matches(null, null, null, null, state, (char) 0)); state -> check.matches(null, null, null, null, state, (char) 0));
} }
} }
MULTIBLOCKS.put(name, PatchouliAPI.get().makeMultiblock(pattern, rawMatchers)); MULTIBLOCKS.put(name, PatchouliAPI.get().makeMultiblock(pattern, rawMatchers));*/
} }
public static <T extends IRecipe<?>> T getRecipe(String type, String name) { @SuppressWarnings("unchecked")
public static <T extends Recipe<?>> T getRecipe(String type, String name) {
RecipeManager manager = Minecraft.getInstance().level.getRecipeManager(); RecipeManager manager = Minecraft.getInstance().level.getRecipeManager();
ResourceLocation res = new ResourceLocation(name); ResourceLocation res = new ResourceLocation(name);
ResourceLocation pre = new ResourceLocation(res.getNamespace(), type + "/" + res.getPath()); ResourceLocation pre = new ResourceLocation(res.getNamespace(), type + "/" + res.getPath());
return (T) manager.getRecipe(pre).orElse(null); return (T) manager.byKey(pre).orElse(null);
} }
public static IVariable ingredientVariable(Ingredient ingredient) { /* public static IVariable ingredientVariable(Ingredient ingredient) {
return IVariable.wrapList(Arrays.stream(ingredient.getMatchingStacks()) return IVariable.wrapList(Arrays.stream(ingredient.getMatchingStacks())
.map(IVariable::from).collect(Collectors.toList())); .map(IVariable::from).collect(Collectors.toList()));
} }*/
@Override @Override
public void setup(FMLCommonSetupEvent event) { public void setup(FMLCommonSetupEvent event) {
event.enqueueWork(() -> { /* event.enqueueWork(() -> {
for (Map.Entry<ResourceLocation, IMultiblock> entry : MULTIBLOCKS.entrySet()) for (Map.Entry<ResourceLocation, IMultiblock> entry : MULTIBLOCKS.entrySet())
PatchouliAPI.get().registerMultiblock(entry.getKey(), entry.getValue()); PatchouliAPI.get().registerMultiblock(entry.getKey(), entry.getValue());
PatchouliAPI.get().setConfigFlag(NaturesAura.MOD_ID + ":rf_converter", ModConfig.instance.rfConverter.get()); PatchouliAPI.get().setConfigFlag(NaturesAura.MOD_ID + ":rf_converter", ModConfig.instance.rfConverter.get());
PatchouliAPI.get().setConfigFlag(NaturesAura.MOD_ID + ":chunk_loader", ModConfig.instance.chunkLoader.get()); PatchouliAPI.get().setConfigFlag(NaturesAura.MOD_ID + ":chunk_loader", ModConfig.instance.chunkLoader.get());
}); });*/
} }
@Override @Override
@ -90,7 +67,7 @@ public class PatchouliCompat implements ICompat {
} }
@SubscribeEvent /* @SubscribeEvent
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void onBookDraw(BookDrawScreenEvent event) { public void onBookDraw(BookDrawScreenEvent event) {
if (event.book == null || !event.book.equals(BOOK)) if (event.book == null || !event.book.equals(BOOK))
@ -151,5 +128,5 @@ public class PatchouliCompat implements ICompat {
event.mouseX, event.mouseY, event.gui.width, event.gui.height, 0, event.gui.getMinecraft().fontRenderer); event.mouseX, event.mouseY, event.gui.width, event.gui.height, 0, event.gui.getMinecraft().fontRenderer);
} }
} }*/
} }

View file

@ -1,46 +1,45 @@
package de.ellpeck.naturesaura.gui; package de.ellpeck.naturesaura.gui;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.screen.inventory.ContainerScreen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.entity.player.Player; import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.network.chat.Component;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.text.ITextComponent; import net.minecraft.world.entity.player.Inventory;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public class GuiEnderCrate extends ContainerScreen<ContainerEnderCrate> { public class GuiEnderCrate extends AbstractContainerScreen<ContainerEnderCrate> {
private static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("textures/gui/container/generic_54.png");
private final Player player;
public GuiEnderCrate(ContainerEnderCrate container, PlayerInventory inv, ITextComponent title) { private static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("textures/gui/container/generic_54.png");
public GuiEnderCrate(ContainerEnderCrate container, Inventory inv, Component title) {
super(container, inv, title); super(container, inv, title);
this.player = inv.player; this.imageHeight = 114 + 3 * 18;
this.ySize = 114 + 3 * 18;
} }
@Override @Override
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { public void render(PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) {
this.renderBackground(matrixStack); this.renderBackground(matrixStack);
super.render(matrixStack, mouseX, mouseY, partialTicks); super.render(matrixStack, mouseX, mouseY, partialTicks);
this.func_230459_a_(matrixStack, mouseX, mouseY); this.renderTooltip(matrixStack, mouseX, mouseY);
} }
@Override @Override
protected void drawGuiContainerForegroundLayer(MatrixStack matrixStack, int mouseX, int mouseY) { protected void renderLabels(PoseStack matrixStack, int mouseX, int mouseY) {
this.font.drawString(matrixStack, this.title.getString(), 8, 6, 4210752); this.font.draw(matrixStack, this.title.getString(), 8, 6, 4210752);
this.font.drawString(matrixStack, this.player.inventory.getDisplayName().getString(), 8, this.ySize - 96 + 2, 4210752); this.font.draw(matrixStack, this.playerInventoryTitle, 8, this.imageHeight - 96 + 2, 4210752);
} }
@Override @Override
protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int mouseX, int mouseY) { protected void renderBg(PoseStack matrixStack, float partialTicks, int mouseX, int mouseY) {
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShader(GameRenderer::getPositionTexShader);
this.getMinecraft().getTextureManager().bindTexture(CHEST_GUI_TEXTURE); RenderSystem.setShaderTexture(0, CHEST_GUI_TEXTURE);
int i = (this.width - this.xSize) / 2; int i = (this.width - this.imageWidth) / 2;
int j = (this.height - this.ySize) / 2; int j = (this.height - this.imageHeight) / 2;
this.blit(matrixStack, i, j, 0, 0, this.xSize, 3 * 18 + 17); this.blit(matrixStack, i, j, 0, 0, this.imageWidth, 3 * 18 + 17);
this.blit(matrixStack, i, j + 3 * 18 + 17, 0, 126, this.xSize, 96); this.blit(matrixStack, i, j + 3 * 18 + 17, 0, 126, this.imageHeight, 96);
} }
} }

View file

@ -2,19 +2,20 @@ package de.ellpeck.naturesaura.particles;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexFormat;
import de.ellpeck.naturesaura.ModConfig; import de.ellpeck.naturesaura.ModConfig;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.IParticleRenderType; import net.minecraft.client.ParticleStatus;
import net.minecraft.client.particle.Particle; import net.minecraft.client.particle.Particle;
import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.particle.ParticleRenderType;
import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.settings.ParticleStatus;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import org.lwjgl.opengl.GL11;
import java.util.Locale; import java.util.Locale;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -22,17 +23,18 @@ import java.util.function.Supplier;
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public final class ParticleHandler { public final class ParticleHandler {
public static final IParticleRenderType MAGIC = new IParticleRenderType() { public static final ParticleRenderType MAGIC = new ParticleRenderType() {
@Override @Override
public void beginRender(BufferBuilder buffer, TextureManager textureManager) { public void begin(BufferBuilder buffer, TextureManager textureManager) {
setupRendering(textureManager); setupRendering();
RenderSystem.enableDepthTest(); RenderSystem.enableDepthTest();
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP); buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.PARTICLE);
} }
@Override @Override
public void finishRender(Tessellator tessellator) { public void end(Tesselator tessellator) {
tessellator.draw(); tessellator.end();
} }
@Override @Override
@ -41,17 +43,17 @@ public final class ParticleHandler {
} }
}; };
public static final IParticleRenderType MAGIC_NO_DEPTH = new IParticleRenderType() { public static final ParticleRenderType MAGIC_NO_DEPTH = new ParticleRenderType() {
@Override @Override
public void beginRender(BufferBuilder buffer, TextureManager textureManager) { public void begin(BufferBuilder buffer, TextureManager textureManager) {
setupRendering(textureManager); setupRendering();
RenderSystem.disableDepthTest(); RenderSystem.disableDepthTest();
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP); buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.PARTICLE);
} }
@Override @Override
public void finishRender(Tessellator tessellator) { public void end(Tesselator tessellator) {
tessellator.draw(); tessellator.end();
} }
@Override @Override
@ -66,32 +68,30 @@ public final class ParticleHandler {
public static void spawnParticle(Supplier<Particle> particle, double x, double y, double z) { public static void spawnParticle(Supplier<Particle> particle, double x, double y, double z) {
Minecraft mc = Minecraft.getInstance(); Minecraft mc = Minecraft.getInstance();
if (mc.player.getDistanceSq(x, y, z) <= range * range) { if (mc.player.distanceToSqr(x, y, z) <= range * range) {
if (culling) { if (culling) {
if (ModConfig.instance.respectVanillaParticleSettings.get()) { if (ModConfig.instance.respectVanillaParticleSettings.get()) {
ParticleStatus setting = mc.gameSettings.particles; ParticleStatus setting = mc.options.particles;
if (setting != ParticleStatus.ALL && if (setting != ParticleStatus.ALL &&
(setting != ParticleStatus.DECREASED || mc.level.rand.nextInt(3) != 0) && (setting != ParticleStatus.DECREASED || mc.level.random.nextInt(3) != 0) &&
(setting != ParticleStatus.MINIMAL || mc.level.rand.nextInt(10) != 0)) (setting != ParticleStatus.MINIMAL || mc.level.random.nextInt(10) != 0))
return; return;
} }
double setting = ModConfig.instance.particleAmount.get(); double setting = ModConfig.instance.particleAmount.get();
if (setting < 1 && mc.level.rand.nextDouble() > setting) if (setting < 1 && mc.level.random.nextDouble() > setting)
return; return;
} }
mc.particles.addEffect(particle.get()); mc.particleEngine.add(particle.get());
} }
} }
private static void setupRendering(TextureManager textureManager) { private static void setupRendering() {
RenderSystem.enableAlphaTest();
RenderSystem.enableBlend(); RenderSystem.enableBlend();
RenderSystem.alphaFunc(516, 0.003921569F);
RenderSystem.disableCull(); RenderSystem.disableCull();
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE); RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE);
RenderSystem.enableFog(); RenderSystem.clearColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.depthMask(false); RenderSystem.depthMask(false);
textureManager.bindTexture(ParticleMagic.TEXTURE); RenderSystem.setShader(GameRenderer::getParticleShader);
RenderSystem.setShaderTexture(0, ParticleMagic.TEXTURE);
} }
} }

View file

@ -1,23 +1,21 @@
package de.ellpeck.naturesaura.particles; package de.ellpeck.naturesaura.particles;
import com.mojang.blaze3d.vertex.IVertexBuilder; import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Quaternion;
import com.mojang.math.Vector3f;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import net.minecraft.client.Camera;
import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.particle.IParticleRenderType;
import net.minecraft.client.particle.Particle; import net.minecraft.client.particle.Particle;
import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.particle.ParticleRenderType;
import net.minecraft.entity.Entity; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.Mth;
import net.minecraft.util.ReuseableStream; import net.minecraft.world.entity.Entity;
import net.minecraft.util.math.Mth; import net.minecraft.world.phys.Vec3;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.vector.Quaternion;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import java.util.stream.Stream; import java.util.Collections;
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public class ParticleMagic extends Particle { public class ParticleMagic extends Particle {
@ -32,41 +30,41 @@ public class ParticleMagic extends Particle {
public ParticleMagic(ClientLevel level, double posX, double posY, double posZ, double motionX, double motionY, double motionZ, int color, float scale, int maxAge, float gravity, boolean collision, boolean fade, boolean depth) { public ParticleMagic(ClientLevel level, double posX, double posY, double posZ, double motionX, double motionY, double motionZ, int color, float scale, int maxAge, float gravity, boolean collision, boolean fade, boolean depth) {
super(level, posX, posY, posZ); super(level, posX, posY, posZ);
this.desiredScale = scale; this.desiredScale = scale;
this.maxAge = maxAge; this.lifetime = maxAge;
this.canCollide = collision; this.hasPhysics = collision;
this.particleGravity = gravity; this.gravity = gravity;
this.fade = fade; this.fade = fade;
this.depth = depth; this.depth = depth;
this.motionX = motionX; this.xd = motionX;
this.motionY = motionY; this.yd = motionY;
this.motionZ = motionZ; this.zd = motionZ;
float r = (color >> 16 & 255) / 255F * (1F - this.rand.nextFloat() * 0.25F); float r = (color >> 16 & 255) / 255F * (1F - this.random.nextFloat() * 0.25F);
float g = (color >> 8 & 255) / 255F * (1F - this.rand.nextFloat() * 0.25F); float g = (color >> 8 & 255) / 255F * (1F - this.random.nextFloat() * 0.25F);
float b = (color & 255) / 255F * (1F - this.rand.nextFloat() * 0.25F); float b = (color & 255) / 255F * (1F - this.random.nextFloat() * 0.25F);
this.setColor(r, g, b); this.setColor(r, g, b);
this.particleAlpha = 1F; this.alpha = 1F;
this.particleScale = 0F; this.particleScale = 0F;
} }
@Override @Override
public void tick() { public void tick() {
this.prevPosX = this.posX; this.xo = this.x;
this.prevPosY = this.posY; this.yo = this.y;
this.prevPosZ = this.posZ; this.zo = this.z;
this.age++; this.age++;
if (this.age > this.maxAge) { if (this.age > this.lifetime) {
this.setExpired(); this.remove();
} else { } else {
this.motionY -= 0.04D * (double) this.particleGravity; this.yd -= 0.04D * (double) this.gravity;
this.move(this.motionX, this.motionY, this.motionZ); this.move(this.xd, this.yd, this.zd);
float lifeRatio = (float) this.age / (float) this.maxAge; float lifeRatio = (float) this.age / (float) this.lifetime;
if (this.fade && lifeRatio > 0.75F) if (this.fade && lifeRatio > 0.75F)
this.particleAlpha = 1F - (lifeRatio - 0.75F) / 0.25F; this.alpha = 1F - (lifeRatio - 0.75F) / 0.25F;
if (lifeRatio <= 0.25F) if (lifeRatio <= 0.25F)
this.particleScale = this.desiredScale * (lifeRatio / 0.25F); this.particleScale = this.desiredScale * (lifeRatio / 0.25F);
else if (this.fade) else if (this.fade)
@ -77,30 +75,30 @@ public class ParticleMagic extends Particle {
@Override @Override
public void move(double x, double y, double z) { public void move(double x, double y, double z) {
double lastY = y; double lastY = y;
if (this.canCollide && (x != 0 || y != 0 || z != 0)) { if (this.hasPhysics && (x != 0 || y != 0 || z != 0)) {
Vector3d motion = Entity.collideBoundingBoxHeuristically(null, new Vector3d(x, y, z), this.getBoundingBox(), this.level, ISelectionContext.dummy(), new ReuseableStream<>(Stream.empty())); Vec3 motion = Entity.collideBoundingBox(null, new Vec3(x, y, z), this.getBoundingBox(), this.level, Collections.emptyList());
x = motion.x; x = motion.x;
y = motion.y; y = motion.y;
z = motion.z; z = motion.z;
} }
if (x != 0 || y != 0 || z != 0) { if (x != 0 || y != 0 || z != 0) {
this.setBoundingBox(this.getBoundingBox().offset(x, y, z)); this.setBoundingBox(this.getBoundingBox().move(x, y, z));
this.resetPositionToBB(); this.setLocationFromBoundingbox();
} }
this.onGround = lastY != y && lastY < 0; this.onGround = lastY != y && lastY < 0;
if (this.onGround) { if (this.onGround) {
this.motionX = 0; this.xd = 0;
this.motionZ = 0; this.zd = 0;
} }
} }
@Override @Override
public void renderParticle(IVertexBuilder buffer, ActiveRenderInfo renderInfo, float partialTicks) { public void render(VertexConsumer buffer, Camera renderInfo, float partialTicks) {
Vector3d vec3d = renderInfo.getProjectedView(); Vec3 vec3d = renderInfo.getPosition();
float f = (float) (Mth.lerp(partialTicks, this.prevPosX, this.posX) - vec3d.getX()); float f = (float) (Mth.lerp(partialTicks, this.xo, this.x) - vec3d.x);
float f1 = (float) (Mth.lerp(partialTicks, this.prevPosY, this.posY) - vec3d.getY()); float f1 = (float) (Mth.lerp(partialTicks, this.yo, this.y) - vec3d.y);
float f2 = (float) (Mth.lerp(partialTicks, this.prevPosZ, this.posZ) - vec3d.getZ()); float f2 = (float) (Mth.lerp(partialTicks, this.zo, this.z) - vec3d.z);
Quaternion quaternion = renderInfo.getRotation(); Quaternion quaternion = renderInfo.rotation();
Vector3f[] avector3f = new Vector3f[]{new Vector3f(-1.0F, -1.0F, 0.0F), new Vector3f(-1.0F, 1.0F, 0.0F), new Vector3f(1.0F, 1.0F, 0.0F), new Vector3f(1.0F, -1.0F, 0.0F)}; Vector3f[] avector3f = new Vector3f[]{new Vector3f(-1.0F, -1.0F, 0.0F), new Vector3f(-1.0F, 1.0F, 0.0F), new Vector3f(1.0F, 1.0F, 0.0F), new Vector3f(1.0F, -1.0F, 0.0F)};
float f4 = 0.1F * this.particleScale; float f4 = 0.1F * this.particleScale;
@ -111,20 +109,20 @@ public class ParticleMagic extends Particle {
vector3f.add(f, f1, f2); vector3f.add(f, f1, f2);
} }
int j = this.getBrightnessForRender(partialTicks); int j = this.getLightColor(partialTicks);
buffer.pos(avector3f[0].getX(), avector3f[0].getY(), avector3f[0].getZ()).tex(0, 1).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j).endVertex(); buffer.vertex(avector3f[0].x(), avector3f[0].y(), avector3f[0].z()).uv(0, 1).color(this.rCol, this.gCol, this.bCol, this.alpha).uv2(j).endVertex();
buffer.pos(avector3f[1].getX(), avector3f[1].getY(), avector3f[1].getZ()).tex(1, 1).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j).endVertex(); buffer.vertex(avector3f[1].x(), avector3f[1].y(), avector3f[1].z()).uv(1, 1).color(this.rCol, this.gCol, this.bCol, this.alpha).uv2(j).endVertex();
buffer.pos(avector3f[2].getX(), avector3f[2].getY(), avector3f[2].getZ()).tex(1, 0).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j).endVertex(); buffer.vertex(avector3f[2].x(), avector3f[2].y(), avector3f[2].z()).uv(1, 0).color(this.rCol, this.gCol, this.bCol, this.alpha).uv2(j).endVertex();
buffer.pos(avector3f[3].getX(), avector3f[3].getY(), avector3f[3].getZ()).tex(0, 0).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j).endVertex(); buffer.vertex(avector3f[3].x(), avector3f[3].y(), avector3f[3].z()).uv(0, 0).color(this.rCol, this.gCol, this.bCol, this.alpha).uv2(j).endVertex();
} }
@Override @Override
public IParticleRenderType getRenderType() { public ParticleRenderType getRenderType() {
return this.depth ? ParticleHandler.MAGIC : ParticleHandler.MAGIC_NO_DEPTH; return this.depth ? ParticleHandler.MAGIC : ParticleHandler.MAGIC_NO_DEPTH;
} }
@Override @Override
public int getBrightnessForRender(float f) { protected int getLightColor(float p_107249_) {
return 15 << 20 | 15 << 4; return 15 << 20 | 15 << 4;
} }
} }

View file

@ -1,10 +1,10 @@
package de.ellpeck.naturesaura.potion; package de.ellpeck.naturesaura.potion;
import net.minecraft.potion.Effect; import net.minecraft.world.effect.MobEffect;
@SuppressWarnings("FieldNamingConvention") @SuppressWarnings("FieldNamingConvention")
public final class ModPotions { public final class ModPotions {
public static Effect BREATHLESS; public static MobEffect BREATHLESS;
} }

View file

@ -43,9 +43,9 @@ public class ClientProxy implements IProxy {
MenuScreens.register(ModContainers.ENDER_ACCESS, GuiEnderCrate::new); MenuScreens.register(ModContainers.ENDER_ACCESS, GuiEnderCrate::new);
ItemProperties.register(ModItems.COLOR_CHANGER, new ResourceLocation(NaturesAura.MOD_ID, "fill_mode"), ItemProperties.register(ModItems.COLOR_CHANGER, new ResourceLocation(NaturesAura.MOD_ID, "fill_mode"),
(stack, levelIn, entityIn) -> ItemColorChanger.isFillMode(stack) ? 1F : 0F); (stack, levelIn, entityIn, i) -> ItemColorChanger.isFillMode(stack) ? 1F : 0F);
ItemProperties.register(ModItems.COLOR_CHANGER, new ResourceLocation(NaturesAura.MOD_ID, "has_color"), ItemProperties.register(ModItems.COLOR_CHANGER, new ResourceLocation(NaturesAura.MOD_ID, "has_color"),
(stack, levelIn, entityIn) -> ItemColorChanger.getStoredColor(stack) != null ? 1F : 0F); (stack, levelIn, entityIn, i) -> ItemColorChanger.getStoredColor(stack) != null ? 1F : 0F);
} }
@Override @Override

View file

@ -3,9 +3,9 @@ package de.ellpeck.naturesaura.proxy;
import de.ellpeck.naturesaura.reg.IColorProvidingBlock; import de.ellpeck.naturesaura.reg.IColorProvidingBlock;
import de.ellpeck.naturesaura.reg.IColorProvidingItem; import de.ellpeck.naturesaura.reg.IColorProvidingItem;
import de.ellpeck.naturesaura.reg.ITESRProvider; import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.entity.Entity; import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.entity.EntityType; import net.minecraft.world.entity.Entity;
import net.minecraftforge.fml.client.registry.IRenderFactory; import net.minecraft.world.entity.EntityType;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -38,7 +38,7 @@ public class ServerProxy implements IProxy {
} }
@Override @Override
public void registerTESR(ITESRProvider provider) { public void registerTESR(ITESRProvider<?> provider) {
} }
@ -63,7 +63,7 @@ public class ServerProxy implements IProxy {
} }
@Override @Override
public <T extends Entity> void registerEntityRenderer(EntityType<T> entityClass, Supplier<IRenderFactory<T>> renderFactory) { public <T extends Entity> void registerEntityRenderer(EntityType<T> entityClass, Supplier<EntityRendererProvider<T>> renderFactory) {
} }
} }

View file

@ -3,10 +3,7 @@ package de.ellpeck.naturesaura.recipes;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.entity.SpawnReason;
import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.PacketBuffer;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;

View file

@ -3,17 +3,19 @@ package de.ellpeck.naturesaura.recipes;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import de.ellpeck.naturesaura.ModConfig; import de.ellpeck.naturesaura.ModConfig;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import net.minecraft.util.JSONUtils; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.GsonHelper;
import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.crafting.conditions.ICondition; import net.minecraftforge.common.crafting.conditions.ICondition;
import net.minecraftforge.common.crafting.conditions.IConditionSerializer; import net.minecraftforge.common.crafting.conditions.IConditionSerializer;
public class EnabledCondition implements ICondition { public class EnabledCondition implements ICondition {
private static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "enabled"); private static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "enabled");
private ForgeConfigSpec.ConfigValue<Boolean> config; private ForgeConfigSpec.ConfigValue<Boolean> config;
private final String name; private final String name;
@SuppressWarnings("unchecked")
public EnabledCondition(String name) { public EnabledCondition(String name) {
this.name = name; this.name = name;
try { try {
@ -34,6 +36,7 @@ public class EnabledCondition implements ICondition {
} }
public static class Serializer implements IConditionSerializer<EnabledCondition> { public static class Serializer implements IConditionSerializer<EnabledCondition> {
@Override @Override
public void write(JsonObject json, EnabledCondition value) { public void write(JsonObject json, EnabledCondition value) {
json.addProperty("config", value.name); json.addProperty("config", value.name);
@ -41,7 +44,7 @@ public class EnabledCondition implements ICondition {
@Override @Override
public EnabledCondition read(JsonObject json) { public EnabledCondition read(JsonObject json) {
return new EnabledCondition(JSONUtils.getString(json, "config")); return new EnabledCondition(GsonHelper.getAsString(json, "config"));
} }
@Override @Override

View file

@ -1,17 +1,13 @@
package de.ellpeck.naturesaura.renderers; package de.ellpeck.naturesaura.renderers;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonReader;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import net.minecraft.client.CameraType;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.PointOfView; import net.minecraft.client.renderer.BiomeColors;
import net.minecraft.entity.player.Player; import net.minecraft.world.entity.player.PlayerModelPart;
import net.minecraft.entity.player.PlayerModelPart;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.biome.BiomeColors;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
@ -22,7 +18,6 @@ import java.io.InputStreamReader;
import java.net.URL; import java.net.URL;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Random;
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public class SupporterFancyHandler { public class SupporterFancyHandler {
@ -38,32 +33,32 @@ public class SupporterFancyHandler {
public void onPlayerTick(TickEvent.PlayerTickEvent event) { public void onPlayerTick(TickEvent.PlayerTickEvent event) {
if (event.phase != TickEvent.Phase.END) if (event.phase != TickEvent.Phase.END)
return; return;
Player player = event.player; var player = event.player;
if (!player.level.isClientSide) if (!player.level.isClientSide)
return; return;
if (player.isInvisible() || !player.isWearing(PlayerModelPart.CAPE)) if (player.isInvisible() || !player.isModelPartShown(PlayerModelPart.CAPE))
return; return;
Minecraft mc = Minecraft.getInstance(); var mc = Minecraft.getInstance();
if (player == mc.player && mc.gameSettings.func_243230_g() == PointOfView.FIRST_PERSON) if (player == mc.player && mc.options.getCameraType() == CameraType.FIRST_PERSON)
return; return;
FancyInfo info = FANCY_INFOS.get(player.getGameProfile().getName()); var info = FANCY_INFOS.get(player.getGameProfile().getName());
if (info == null) if (info == null)
return; return;
Random rand = player.level.rand; var rand = player.level.random;
if (rand.nextFloat() >= 0.75F) { if (rand.nextFloat() >= 0.75F) {
int color; int color;
if (info.tier == 1) { if (info.tier == 1) {
BlockPos pos = player.getPosition(); var pos = player.getOnPos();
color = BiomeColors.getGrassColor(player.level, pos); color = BiomeColors.getAverageGrassColor(player.level, pos);
} else { } else {
color = info.color; color = info.color;
} }
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
player.getPosX() + rand.nextGaussian() * 0.15F, player.getX() + rand.nextGaussian() * 0.15F,
player.getPosY() + rand.nextFloat() * 1.8F, player.getY() + rand.nextFloat() * 1.8F,
player.getPosZ() + rand.nextGaussian() * 0.15F, player.getZ() + rand.nextGaussian() * 0.15F,
rand.nextGaussian() * 0.01F, rand.nextGaussian() * 0.01F,
rand.nextFloat() * 0.01F, rand.nextFloat() * 0.01F,
rand.nextGaussian() * 0.01F, rand.nextGaussian() * 0.01F,
@ -71,17 +66,12 @@ public class SupporterFancyHandler {
} }
} }
public static class FancyInfo { public record FancyInfo(int tier, int color) {
public final int tier;
public final int color;
public FancyInfo(int tier, int color) {
this.tier = tier;
this.color = color;
}
} }
private static class FetchThread extends Thread { private static class FetchThread extends Thread {
public FetchThread() { public FetchThread() {
this.setName(NaturesAura.MOD_ID + "_support_fetcher"); this.setName(NaturesAura.MOD_ID + "_support_fetcher");
this.setDaemon(true); this.setDaemon(true);
@ -91,15 +81,14 @@ public class SupporterFancyHandler {
@Override @Override
public void run() { public void run() {
try { try {
URL url = new URL("https://raw.githubusercontent.com/Ellpeck/NaturesAura/main/supporters.json"); var url = new URL("https://raw.githubusercontent.com/Ellpeck/NaturesAura/main/supporters.json");
JsonReader reader = new JsonReader(new InputStreamReader(url.openStream())); var reader = new JsonReader(new InputStreamReader(url.openStream()));
JsonParser parser = new JsonParser();
JsonObject main = parser.parse(reader).getAsJsonObject(); var main = JsonParser.parseReader(reader).getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : main.entrySet()) { for (var entry : main.entrySet()) {
JsonObject object = entry.getValue().getAsJsonObject(); var object = entry.getValue().getAsJsonObject();
int tier = object.get("tier").getAsInt(); var tier = object.get("tier").getAsInt();
int color = object.has("color") ? Integer.parseInt(object.get("color").getAsString(), 16) : 0; var color = object.has("color") ? Integer.parseInt(object.get("color").getAsString(), 16) : 0;
FANCY_INFOS.put(entry.getKey(), new FancyInfo(tier, color)); FANCY_INFOS.put(entry.getKey(), new FancyInfo(tier, color));
} }