Compare commits

...

3 commits

Author SHA1 Message Date
Ell
65cce7fae5 var 2021-12-15 16:30:22 +01:00
Ell
24cf4ae186 IT C O M P I L E S 2021-12-15 16:24:53 +01:00
Ell
584514944b did so much work, and it's still not over, I'm going to die 2021-12-15 14:26:42 +01:00
199 changed files with 3538 additions and 3630 deletions

View file

@ -23,6 +23,7 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Property; import net.minecraft.world.level.block.state.properties.Property;
@ -51,7 +52,7 @@ import java.util.function.Predicate;
public final class Helper { public final class Helper {
public static boolean getBlockEntitiesInArea(Level level, BlockPos pos, int radius, Function<BlockEntity, Boolean> consumer) { public static boolean getBlockEntitiesInArea(LevelAccessor level, BlockPos pos, int radius, Function<BlockEntity, Boolean> consumer) {
for (var x = pos.getX() - radius >> 4; x <= pos.getX() + radius >> 4; x++) { for (var x = pos.getX() - radius >> 4; x <= pos.getX() + radius >> 4; x++) {
for (var z = pos.getZ() - radius >> 4; z <= pos.getZ() + radius >> 4; z++) { for (var z = pos.getZ() - radius >> 4; z <= pos.getZ() + radius >> 4; z++) {
var chunk = getLoadedChunk(level, x, z); var chunk = getLoadedChunk(level, x, z);
@ -89,7 +90,7 @@ public final class Helper {
return frames; return frames;
} }
public static LevelChunk getLoadedChunk(Level level, int x, int z) { public static LevelChunk getLoadedChunk(LevelAccessor level, int x, int z) {
// DO NOT EDIT PLEASE FOR THE LOVE OF GOD // DO NOT EDIT PLEASE FOR THE LOVE OF GOD
// This is very finicky and easily causes the game to hang for some reason // This is very finicky and easily causes the game to hang for some reason
var provider = level.getChunkSource(); var provider = level.getChunkSource();

View file

@ -39,9 +39,9 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
private boolean auraPlayerInteraction(Player player, int amount, boolean extract, boolean simulate) { private boolean auraPlayerInteraction(Player player, int amount, boolean extract, boolean simulate) {
if (extract && player.isCreative()) if (extract && player.isCreative())
return true; return true;
ItemStack stack = Helper.getEquippedItem(s -> s.getCapability(NaturesAuraAPI.capAuraContainer).isPresent(), player); var stack = Helper.getEquippedItem(s -> s.getCapability(NaturesAuraAPI.capAuraContainer).isPresent(), player);
if (!stack.isEmpty()) { if (!stack.isEmpty()) {
IAuraContainer container = stack.getCapability(NaturesAuraAPI.capAuraContainer).orElse(null); var container = stack.getCapability(NaturesAuraAPI.capAuraContainer).orElse(null);
if (extract) { if (extract) {
amount -= container.drainAura(amount, simulate); amount -= container.drainAura(amount, simulate);
} else { } else {
@ -59,8 +59,8 @@ 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) {
Vec3 dir = new Vec3(endX - startX, endY - startY, endZ - startZ); var dir = new Vec3(endX - startX, endY - startY, endZ - startZ);
double length = dir.length(); var length = dir.length();
if (length > 0) { if (length > 0) {
dir = dir.normalize(); dir = dir.normalize();
this.spawnMagicParticle(startX, startY, startZ, this.spawnMagicParticle(startX, startY, startZ,
@ -92,7 +92,7 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
@Override @Override
public List<Tuple<Vec3, Integer>> getActiveEffectPowders(Level level, AABB area, ResourceLocation name) { public List<Tuple<Vec3, Integer>> getActiveEffectPowders(Level level, AABB area, ResourceLocation name) {
List<Tuple<Vec3, Integer>> found = new ArrayList<>(); List<Tuple<Vec3, Integer>> found = new ArrayList<>();
for (Tuple<Vec3, Integer> powder : ((LevelData) ILevelData.getLevelData(level)).effectPowders.get(name)) for (var 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) {
Vec3 posVec = new Vec3(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5); var posVec = new Vec3(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
List<Tuple<Vec3, Integer>> powders = this.getActiveEffectPowders(level, new AABB(pos).inflate(64), name); var powders = this.getActiveEffectPowders(level, new AABB(pos).inflate(64), name);
for (Tuple<Vec3, Integer> powder : powders) { for (var powder : powders) {
AABB bounds = Helper.aabb(powder.getA()).inflate(powder.getB()); var bounds = Helper.aabb(powder.getA()).inflate(powder.getB());
if (bounds.contains(posVec)) if (bounds.contains(posVec))
return true; return true;
} }
@ -117,22 +117,22 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
@Override @Override
public int getSpotAmountInArea(Level level, BlockPos pos, int radius) { public int getSpotAmountInArea(Level level, BlockPos pos, int radius) {
MutableInt result = new MutableInt(); var result = new MutableInt();
this.getAuraSpotsInArea(level, pos, radius, (blockpos, drainSpot) -> result.increment()); this.getAuraSpotsInArea(level, pos, radius, (blockpos, drainSpot) -> result.increment());
return result.intValue(); return result.intValue();
} }
@Override @Override
public int getAuraInArea(Level level, BlockPos pos, int radius) { public int getAuraInArea(Level level, BlockPos pos, int radius) {
MutableInt result = new MutableInt(IAuraChunk.DEFAULT_AURA); var result = new MutableInt(IAuraChunk.DEFAULT_AURA);
this.getAuraSpotsInArea(level, pos, radius, (blockPos, drainSpot) -> result.add(drainSpot)); this.getAuraSpotsInArea(level, pos, radius, (blockPos, drainSpot) -> result.add(drainSpot));
return result.intValue(); return result.intValue();
} }
@Override @Override
public Pair<Integer, Integer> getAuraAndSpotAmountInArea(Level level, BlockPos pos, int radius) { public Pair<Integer, Integer> getAuraAndSpotAmountInArea(Level level, BlockPos pos, int radius) {
MutableInt spots = new MutableInt(); var spots = new MutableInt();
MutableInt aura = new MutableInt(IAuraChunk.DEFAULT_AURA); var aura = new MutableInt(IAuraChunk.DEFAULT_AURA);
this.getAuraSpotsInArea(level, pos, radius, (blockPos, drainSpot) -> { this.getAuraSpotsInArea(level, pos, radius, (blockPos, drainSpot) -> {
aura.add(drainSpot); aura.add(drainSpot);
spots.increment(); spots.increment();
@ -142,9 +142,9 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
@Override @Override
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); var 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.distSqr(blockPos)) / radius; var percentage = 1F - (float) Math.sqrt(pos.distSqr(blockPos)) / radius;
result.add(spot * percentage); result.add(spot * percentage);
}); });
return result.intValue(); return result.intValue();
@ -152,15 +152,15 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
@Override @Override
public BlockPos getLowestAuraDrainSpot(Level level, BlockPos pos, int radius, BlockPos defaultSpot) { public BlockPos getLowestAuraDrainSpot(Level level, BlockPos pos, int radius, BlockPos defaultSpot) {
MutableInt lowestAmount = new MutableInt(Integer.MAX_VALUE); var lowestAmount = new MutableInt(Integer.MAX_VALUE);
MutableObject<BlockPos> lowestSpot = new MutableObject<>(); var lowestSpot = new MutableObject<BlockPos>();
this.getAuraSpotsInArea(level, pos, radius, (blockPos, drainSpot) -> { this.getAuraSpotsInArea(level, pos, radius, (blockPos, drainSpot) -> {
if (drainSpot < lowestAmount.intValue()) { if (drainSpot < lowestAmount.intValue()) {
lowestAmount.setValue(drainSpot); lowestAmount.setValue(drainSpot);
lowestSpot.setValue(blockPos); lowestSpot.setValue(blockPos);
} }
}); });
BlockPos lowest = lowestSpot.getValue(); var lowest = lowestSpot.getValue();
if (lowest == null || lowestAmount.intValue() >= 0) if (lowest == null || lowestAmount.intValue() >= 0)
lowest = defaultSpot; lowest = defaultSpot;
return lowest; return lowest;
@ -168,15 +168,15 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
@Override @Override
public BlockPos getHighestAuraDrainSpot(Level level, BlockPos pos, int radius, BlockPos defaultSpot) { public BlockPos getHighestAuraDrainSpot(Level level, BlockPos pos, int radius, BlockPos defaultSpot) {
MutableInt highestAmount = new MutableInt(Integer.MIN_VALUE); var highestAmount = new MutableInt(Integer.MIN_VALUE);
MutableObject<BlockPos> highestSpot = new MutableObject<>(); var highestSpot = new MutableObject<BlockPos>();
this.getAuraSpotsInArea(level, pos, radius, (blockPos, drainSpot) -> { this.getAuraSpotsInArea(level, pos, radius, (blockPos, drainSpot) -> {
if (drainSpot > highestAmount.intValue()) { if (drainSpot > highestAmount.intValue()) {
highestAmount.setValue(drainSpot); highestAmount.setValue(drainSpot);
highestSpot.setValue(blockPos); highestSpot.setValue(blockPos);
} }
}); });
BlockPos highest = highestSpot.getValue(); var highest = highestSpot.getValue();
if (highest == null || highestAmount.intValue() <= 0) if (highest == null || highestAmount.intValue() <= 0)
highest = defaultSpot; highest = defaultSpot;
return highest; return highest;

View file

@ -182,7 +182,7 @@ public final class ModConfig {
try { try {
for (String s : this.additionalBotanistPickaxeConversions.get()) { for (String s : this.additionalBotanistPickaxeConversions.get()) {
String[] split = s.split("->"); var split = s.split("->");
NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.put( NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.put(
Objects.requireNonNull(Helper.getStateFromString(split[0]), "state1"), Objects.requireNonNull(Helper.getStateFromString(split[0]), "state1"),
Objects.requireNonNull(Helper.getStateFromString(split[1]), "state2")); Objects.requireNonNull(Helper.getStateFromString(split[1]), "state2"));
@ -193,9 +193,9 @@ public final class ModConfig {
try { try {
for (String s : this.auraTypeOverrides.get()) { for (String s : this.auraTypeOverrides.get()) {
String[] split = s.split("->"); var split = s.split("->");
ResourceLocation dim = new ResourceLocation(split[0]); var dim = new ResourceLocation(split[0]);
BasicAuraType type = Objects.requireNonNull((BasicAuraType) NaturesAuraAPI.AURA_TYPES.get(new ResourceLocation(split[1])), "type"); var type = Objects.requireNonNull((BasicAuraType) NaturesAuraAPI.AURA_TYPES.get(new ResourceLocation(split[1])), "type");
type.addDimensionType(dim); type.addDimensionType(dim);
} }
} catch (Exception e) { } catch (Exception e) {
@ -204,9 +204,9 @@ public final class ModConfig {
try { try {
for (String s : this.additionalOres.get()) { for (String s : this.additionalOres.get()) {
String[] split = s.split("->"); var split = s.split("->");
WeightedOre ore = new WeightedOre(new ResourceLocation(split[0]), Integer.parseInt(split[1])); var ore = new WeightedOre(new ResourceLocation(split[0]), Integer.parseInt(split[1]));
String dimension = split[2]; var dimension = split[2];
if ("nether".equalsIgnoreCase(dimension)) { if ("nether".equalsIgnoreCase(dimension)) {
NaturesAuraAPI.NETHER_ORES.removeIf(o -> o.tag.equals(ore.tag)); NaturesAuraAPI.NETHER_ORES.removeIf(o -> o.tag.equals(ore.tag));
NaturesAuraAPI.NETHER_ORES.add(ore); NaturesAuraAPI.NETHER_ORES.add(ore);
@ -230,10 +230,10 @@ public final class ModConfig {
try { try {
for (String s : this.additionalProjectiles.get()) { for (String s : this.additionalProjectiles.get()) {
String[] split = s.split("->"); var split = s.split("->");
ResourceLocation name = new ResourceLocation(split[0]); var name = new ResourceLocation(split[0]);
EntityType<?> type = Objects.requireNonNull(ForgeRegistries.ENTITIES.getValue(name)); var type = Objects.requireNonNull(ForgeRegistries.ENTITIES.getValue(name));
int amount = Integer.parseInt(split[1]); var amount = Integer.parseInt(split[1]);
NaturesAuraAPI.PROJECTILE_GENERATIONS.put(type, amount); NaturesAuraAPI.PROJECTILE_GENERATIONS.put(type, amount);
} }
} catch (Exception e) { } catch (Exception e) {

View file

@ -2,10 +2,6 @@ package de.ellpeck.naturesaura;
import com.google.common.base.Strings; import com.google.common.base.Strings;
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.IAuraContainer;
import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge;
import de.ellpeck.naturesaura.api.misc.ILevelData;
import de.ellpeck.naturesaura.blocks.multi.Multiblocks; import de.ellpeck.naturesaura.blocks.multi.Multiblocks;
import de.ellpeck.naturesaura.chunk.effect.DrainSpotEffects; import de.ellpeck.naturesaura.chunk.effect.DrainSpotEffects;
import de.ellpeck.naturesaura.compat.Compat; import de.ellpeck.naturesaura.compat.Compat;
@ -49,7 +45,7 @@ public final class NaturesAura {
instance = this; instance = this;
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder(); var builder = new ForgeConfigSpec.Builder();
ModConfig.instance = new ModConfig(builder); ModConfig.instance = new ModConfig(builder);
ModLoadingContext.get().registerConfig(net.minecraftforge.fml.config.ModConfig.Type.COMMON, builder.build()); ModLoadingContext.get().registerConfig(net.minecraftforge.fml.config.ModConfig.Type.COMMON, builder.build());
} }
@ -61,11 +57,6 @@ public final class NaturesAura {
} }
private void preInit(FMLCommonSetupEvent event) { private void preInit(FMLCommonSetupEvent event) {
Helper.registerCap(IAuraContainer.class);
Helper.registerCap(IAuraRecharge.class);
Helper.registerCap(IAuraChunk.class);
Helper.registerCap(ILevelData.class);
Compat.setup(event); Compat.setup(event);
PacketHandler.init(); PacketHandler.init();
new Multiblocks(); new Multiblocks();

View file

@ -35,7 +35,7 @@ public interface IAuraChunk extends INBTSerializable<CompoundTag> {
* @return The {@link IAuraChunk} instance belonging to the chunk * @return The {@link IAuraChunk} instance belonging to the chunk
*/ */
static IAuraChunk getAuraChunk(Level level, BlockPos pos) { static IAuraChunk getAuraChunk(Level level, BlockPos pos) {
LevelChunk chunk = (LevelChunk) level.getChunk(pos); var chunk = (LevelChunk) level.getChunk(pos);
return chunk.getCapability(NaturesAuraAPI.capAuraChunk, null).orElse(null); return chunk.getCapability(NaturesAuraAPI.capAuraChunk, null).orElse(null);
} }

View file

@ -16,7 +16,7 @@ public class BasicAuraContainer implements IAuraContainer {
@Override @Override
public int storeAura(int amountToStore, boolean simulate) { public int storeAura(int amountToStore, boolean simulate) {
int actual = Math.min(amountToStore, this.maxAura - this.aura); var actual = Math.min(amountToStore, this.maxAura - this.aura);
if (!simulate) { if (!simulate) {
this.aura += actual; this.aura += actual;
} }
@ -25,7 +25,7 @@ public class BasicAuraContainer implements IAuraContainer {
@Override @Override
public int drainAura(int amountToDrain, boolean simulate) { public int drainAura(int amountToDrain, boolean simulate) {
int actual = Math.min(amountToDrain, this.aura); var actual = Math.min(amountToDrain, this.aura);
if (!simulate) { if (!simulate) {
this.aura -= actual; this.aura -= actual;
} }

View file

@ -18,8 +18,8 @@ public class ItemAuraContainer implements IAuraContainer {
@Override @Override
public int storeAura(int amountToStore, boolean simulate) { public int storeAura(int amountToStore, boolean simulate) {
int aura = this.getStoredAura(); var aura = this.getStoredAura();
int actual = Math.min(amountToStore, this.getMaxAura() - aura); var actual = Math.min(amountToStore, this.getMaxAura() - aura);
if (!simulate) { if (!simulate) {
this.setAura(aura + actual); this.setAura(aura + actual);
} }
@ -28,8 +28,8 @@ public class ItemAuraContainer implements IAuraContainer {
@Override @Override
public int drainAura(int amountToDrain, boolean simulate) { public int drainAura(int amountToDrain, boolean simulate) {
int aura = this.getStoredAura(); var aura = this.getStoredAura();
int actual = Math.min(amountToDrain, aura); var actual = Math.min(amountToDrain, aura);
if (!simulate) { if (!simulate) {
this.setAura(aura - actual); this.setAura(aura - actual);
} }

View file

@ -8,7 +8,7 @@ public interface IAuraType {
static IAuraType forLevel(Level level) { static IAuraType forLevel(Level level) {
IAuraType highestType = NaturesAuraAPI.TYPE_OTHER; IAuraType highestType = NaturesAuraAPI.TYPE_OTHER;
for (IAuraType type : NaturesAuraAPI.AURA_TYPES.values()) for (var type : NaturesAuraAPI.AURA_TYPES.values())
if (type.isPresentInLevel(level) && type.getPriority() > highestType.getPriority()) if (type.isPresentInLevel(level) && type.getPriority() > highestType.getPriority())
highestType = type; highestType = type;
return highestType; return highestType;

View file

@ -4,26 +4,26 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAncientLeaves; 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.client.color.block.BlockColor;
import net.minecraft.client.renderer.color.IBlockColor; import net.minecraft.client.color.item.ItemColor;
import net.minecraft.client.renderer.color.IItemColor; import net.minecraft.core.BlockPos;
import net.minecraft.level.IBlockReader; import net.minecraft.server.level.ServerLevel;
import net.minecraft.level.Level; import net.minecraft.world.level.Level;
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.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.LeavesBlock; import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor; 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;
import org.jetbrains.annotations.Nullable;
import javax.annotation.Nullable;
import java.util.Random; import java.util.Random;
public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorProvidingBlock, IColorProvidingItem, ICustomBlockState { public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorProvidingBlock, IColorProvidingItem, ICustomBlockState, EntityBlock {
public BlockAncientLeaves() { public BlockAncientLeaves() {
super(Block.Properties.of(Material.LEAVES, MaterialColor.COLOR_PINK).strength(0.2F).randomTicks().noOcclusion().sound(SoundType.GRASS)); super(Block.Properties.of(Material.LEAVES, MaterialColor.COLOR_PINK).strength(0.2F).randomTicks().noOcclusion().sound(SoundType.GRASS));
@ -36,26 +36,15 @@ public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorP
return "ancient_leaves"; return "ancient_leaves";
} }
@Nullable
@Override
public BlockEntity createBlockEntity(BlockState state, IBlockReader level) {
return new BlockEntityAncientLeaves();
}
@Override
public boolean hasBlockEntity(BlockState state) {
return true;
}
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public IBlockColor getBlockColor() { public BlockColor getBlockColor() {
return (state, levelIn, pos, tintIndex) -> 0xE55B97; return (state, levelIn, pos, tintIndex) -> 0xE55B97;
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public IItemColor getItemColor() { public ItemColor getItemColor() {
return (stack, tintIndex) -> 0xE55B97; return (stack, tintIndex) -> 0xE55B97;
} }
@ -63,8 +52,8 @@ public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorP
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) {
super.animateTick(stateIn, levelIn, pos, rand); super.animateTick(stateIn, levelIn, pos, rand);
if (rand.nextFloat() >= 0.95F && !levelIn.getBlockState(pos.down()).isOpaqueCube(levelIn, pos)) { if (rand.nextFloat() >= 0.95F && !levelIn.getBlockState(pos.below()).isCollisionShapeFullBlock(levelIn, pos)) {
BlockEntity tile = levelIn.getBlockEntity(pos); var tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityAncientLeaves) { if (tile instanceof BlockEntityAncientLeaves) {
if (((BlockEntityAncientLeaves) tile).getAuraContainer().getStoredAura() > 0) { if (((BlockEntityAncientLeaves) tile).getAuraContainer().getStoredAura() > 0) {
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
@ -83,17 +72,17 @@ public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorP
public void randomTick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) {
super.randomTick(state, levelIn, pos, random); super.randomTick(state, levelIn, pos, random);
if (!levelIn.isClientSide) { if (!levelIn.isClientSide) {
BlockEntity tile = levelIn.getBlockEntity(pos); var tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityAncientLeaves) { if (tile instanceof BlockEntityAncientLeaves) {
if (((BlockEntityAncientLeaves) tile).getAuraContainer().getStoredAura() <= 0) { if (((BlockEntityAncientLeaves) tile).getAuraContainer().getStoredAura() <= 0) {
levelIn.setBlockState(pos, ModBlocks.DECAYED_LEAVES.getDefaultState()); levelIn.setBlockAndUpdate(pos, ModBlocks.DECAYED_LEAVES.defaultBlockState());
} }
} }
} }
} }
@Override @Override
public boolean ticksRandomly(BlockState state) { public boolean isRandomlyTicking(BlockState state) {
return true; return true;
} }
@ -101,4 +90,10 @@ public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorP
public void generateCustomBlockState(BlockStateGenerator generator) { public void generateCustomBlockState(BlockStateGenerator generator) {
generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName()))); generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName())));
} }
@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new BlockEntityAncientLeaves(pos, state);
}
} }

View file

@ -4,17 +4,17 @@ import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.IModItem; import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.ModRegistry; import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.block.RotatedPillarBlock; import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.block.SoundType; import net.minecraft.world.level.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.world.level.material.Material;
import net.minecraft.block.material.MaterialColor; import net.minecraft.world.level.material.MaterialColor;
public class BlockAncientLog extends RotatedPillarBlock implements IModItem, ICustomBlockState { public class BlockAncientLog extends RotatedPillarBlock implements IModItem, ICustomBlockState {
private final String baseName; private final String baseName;
public BlockAncientLog(String baseName) { public BlockAncientLog(String baseName) {
super(Properties.create(Material.WOOD, MaterialColor.PURPLE).hardnessAndResistance(2.0F).sound(SoundType.WOOD)); super(Properties.of(Material.WOOD, MaterialColor.COLOR_PURPLE).strength(2.0F).sound(SoundType.WOOD));
this.baseName = baseName; this.baseName = baseName;
ModRegistry.add(this); ModRegistry.add(this);
} }

View file

@ -3,33 +3,34 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.data.ItemModelGenerator; import de.ellpeck.naturesaura.data.ItemModelGenerator;
import de.ellpeck.naturesaura.gen.ModFeatures; import de.ellpeck.naturesaura.gen.ModFeatures;
import de.ellpeck.naturesaura.gen.LevelGenAncientTree;
import de.ellpeck.naturesaura.reg.*; import de.ellpeck.naturesaura.reg.*;
import net.minecraft.block.*;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.state.StateContainer; import net.minecraft.core.BlockPos;
import net.minecraft.util.math.BlockPos; import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.world.level.BlockGetter;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.level.Level;
import net.minecraft.level.IBlockReader; import net.minecraft.world.level.block.*;
import net.minecraft.level.Level; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.level.server.ServerLevel; import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.event.ForgeEventFactory;
import java.util.Random; import java.util.Random;
import java.util.function.Supplier; import java.util.function.Supplier;
public class BlockAncientSapling extends BushBlock implements IGrowable, IModItem, ICustomBlockState, ICustomItemModel, ICustomRenderType { public class BlockAncientSapling extends BushBlock implements BonemealableBlock, IModItem, ICustomBlockState, ICustomItemModel, ICustomRenderType {
protected static final VoxelShape SHAPE = Block.makeCuboidShape(2.0D, 0.0D, 2.0D, 14.0D, 12.0D, 14.0D);
protected static final VoxelShape SHAPE = box(2.0D, 0.0D, 2.0D, 14.0D, 12.0D, 14.0D);
public BlockAncientSapling() { public BlockAncientSapling() {
super(Properties.create(Material.PLANTS).hardnessAndResistance(0.0F).sound(SoundType.PLANT)); super(Properties.of(Material.GRASS).strength(0.0F).sound(SoundType.GRASS));
ModRegistry.add(this); ModRegistry.add(this);
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPE; return SHAPE;
} }
@ -38,9 +39,8 @@ public class BlockAncientSapling extends BushBlock implements IGrowable, IModIte
if (!level.isClientSide) { if (!level.isClientSide) {
super.randomTick(state, level, pos, random); super.randomTick(state, level, pos, random);
if (level.getLight(pos.up()) >= 9 && random.nextInt(7) == 0) { if (level.getLightEmission(pos.above()) >= 9 && random.nextInt(7) == 0)
this.grow(level, random, pos, state); this.performBonemeal(level, random, pos, state);
}
} }
} }
@ -50,26 +50,26 @@ public class BlockAncientSapling extends BushBlock implements IGrowable, IModIte
} }
@Override @Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(SaplingBlock.STAGE); builder.add(SaplingBlock.STAGE);
} }
@Override @Override
public boolean canGrow(IBlockReader levelIn, BlockPos pos, BlockState state, boolean isClient) { public boolean isValidBonemealTarget(BlockGetter p_50897_, BlockPos p_50898_, BlockState p_50899_, boolean p_50900_) {
return true; return true;
} }
@Override @Override
public boolean canUseBonemeal(Level level, Random rand, BlockPos pos, BlockState state) { public boolean isBonemealSuccess(Level level, Random rand, BlockPos pos, BlockState state) {
return level.rand.nextFloat() < 0.45F; return level.random.nextFloat() < 0.45F;
} }
@Override @Override
public void grow(ServerLevel level, Random rand, BlockPos pos, BlockState state) { public void performBonemeal(ServerLevel level, Random rand, BlockPos pos, BlockState state) {
if (state.get(SaplingBlock.STAGE) == 0) { if (state.getValue(SaplingBlock.STAGE) == 0) {
level.setBlockState(pos, state.func_235896_a_(SaplingBlock.STAGE), 4); level.setBlock(pos, state.cycle(SaplingBlock.STAGE), 4);
} else if (ForgeEventFactory.saplingGrowTree(level, rand, pos)) { } else if (ForgeEventFactory.saplingGrowTree(level, rand, pos)) {
ModFeatures.ANCIENT_TREE.func_241855_a(level, level.getChunkProvider().getChunkGenerator(), rand, pos, LevelGenAncientTree.CONFIG); ModFeatures.Configured.ANCIENT_TREE.place(level, level.getChunkSource().getGenerator(), rand, pos);
} }
} }
@ -85,6 +85,6 @@ public class BlockAncientSapling extends BushBlock implements IGrowable, IModIte
@Override @Override
public Supplier<RenderType> getRenderType() { public Supplier<RenderType> getRenderType() {
return RenderType::getCutoutMipped; return RenderType::cutoutMipped;
} }
} }

View file

@ -4,24 +4,23 @@ import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAnimalContainer; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAnimalContainer;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.BlockState; import net.minecraft.core.BlockPos;
import net.minecraft.block.Blocks; import net.minecraft.world.level.BlockGetter;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.world.level.Level;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.level.block.Blocks;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.world.phys.AABB;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.level.IBlockReader; import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.level.Level;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
public class BlockAnimalContainer extends BlockContainerImpl implements IVisualizable, ICustomBlockState { public class BlockAnimalContainer extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
private static final VoxelShape SHAPE = makeCuboidShape(5, 0, 5, 11, 13, 11); private static final VoxelShape SHAPE = box(5, 0, 5, 11, 13, 11);
public BlockAnimalContainer() { public BlockAnimalContainer() {
super("animal_container", BlockEntityAnimalContainer::new, Properties.from(Blocks.STONE)); super("animal_container", BlockEntityAnimalContainer::new, Properties.copy(Blocks.STONE));
} }
@Override @Override
@ -30,18 +29,18 @@ public class BlockAnimalContainer extends BlockContainerImpl implements IVisuali
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPE; return SHAPE;
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AABB getVisualizationBounds(Level level, BlockPos pos) {
BlockEntity tile = level.getBlockEntity(pos); var tile = level.getBlockEntity(pos);
if (tile instanceof BlockEntityAnimalContainer) { if (tile instanceof BlockEntityAnimalContainer) {
int radius = ((BlockEntityAnimalContainer) tile).getRadius(); var radius = ((BlockEntityAnimalContainer) tile).getRadius();
if (radius > 0) if (radius > 0)
return new AxisAlignedBB(pos).grow(radius); return new AABB(pos).inflate(radius);
} }
return null; return null;
} }

View file

@ -8,17 +8,17 @@ import de.ellpeck.naturesaura.data.BlockStateGenerator;
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 de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.SoundType; import net.minecraft.core.BlockPos;
import net.minecraft.block.material.Material;
import net.minecraft.entity.INPC;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.Mth;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.util.math.Mth; import net.minecraft.world.entity.Mob;
import net.minecraft.level.Level; import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.npc.Npc;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.AABB;
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;
@ -29,53 +29,53 @@ import net.minecraftforge.event.entity.living.LivingExperienceDropEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
public class BlockAnimalGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState { public class BlockAnimalGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockAnimalGenerator() { public BlockAnimalGenerator() {
super("animal_generator", BlockEntityAnimalGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).sound(SoundType.STONE)); super("animal_generator", BlockEntityAnimalGenerator::new, Properties.of(Material.STONE).strength(3F).sound(SoundType.STONE));
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
} }
@SubscribeEvent @SubscribeEvent
public void onLivingUpdate(LivingEvent.LivingUpdateEvent event) { public void onLivingUpdate(LivingEvent.LivingUpdateEvent event) {
LivingEntity entity = event.getEntityLiving(); var entity = event.getEntityLiving();
if (entity.level.isClientSide || entity.level.getGameTime() % 40 != 0 || !(entity instanceof AnimalEntity) || entity instanceof IMob || entity instanceof INPC) if (entity.level.isClientSide || entity.level.getGameTime() % 40 != 0 || !(entity instanceof Animal) || entity instanceof Mob || entity instanceof Npc)
return; return;
CompoundTag data = entity.getPersistentData(); var data = entity.getPersistentData();
int timeAlive = data.getInt(NaturesAura.MOD_ID + ":time_alive"); var timeAlive = data.getInt(NaturesAura.MOD_ID + ":time_alive");
data.putInt(NaturesAura.MOD_ID + ":time_alive", timeAlive + 40); data.putInt(NaturesAura.MOD_ID + ":time_alive", timeAlive + 40);
} }
@SubscribeEvent @SubscribeEvent
public void onEntityDeath(LivingDeathEvent event) { public void onEntityDeath(LivingDeathEvent event) {
LivingEntity entity = event.getEntityLiving(); var entity = event.getEntityLiving();
if (entity.level.isClientSide || !(entity instanceof AnimalEntity) || entity instanceof IMob || entity instanceof INPC) if (entity.level.isClientSide || !(entity instanceof Animal) || entity instanceof Mob || entity instanceof Npc)
return; return;
BlockPos pos = entity.getPosition(); var pos = entity.blockPosition();
Helper.getBlockEntitiesInArea(entity.level, pos, 5, tile -> { Helper.getBlockEntitiesInArea(entity.level, pos, 5, tile -> {
if (!(tile instanceof BlockEntityAnimalGenerator)) if (!(tile instanceof BlockEntityAnimalGenerator gen))
return false; return false;
BlockEntityAnimalGenerator gen = (BlockEntityAnimalGenerator) tile;
CompoundTag data = entity.getPersistentData(); var data = entity.getPersistentData();
data.putBoolean(NaturesAura.MOD_ID + ":no_drops", true); data.putBoolean(NaturesAura.MOD_ID + ":no_drops", true);
if (gen.isBusy()) if (gen.isBusy())
return false; return false;
boolean child = entity.isChild(); var child = entity.isBaby();
float timeMod = child ? 0.5F : 1; var timeMod = child ? 0.5F : 1;
float amountMod = child ? 0.667F : 1; var amountMod = child ? 0.667F : 1;
int timeAlive = data.getInt(NaturesAura.MOD_ID + ":time_alive"); var timeAlive = data.getInt(NaturesAura.MOD_ID + ":time_alive");
int time = Math.min(Mth.floor((timeAlive - 15000) / 500F * timeMod), 200); var time = Math.min(Mth.floor((timeAlive - 15000) / 500F * timeMod), 200);
int amount = Math.min(Mth.floor((timeAlive - 8000) / 2F * amountMod), 25000); var amount = Math.min(Mth.floor((timeAlive - 8000) / 2F * amountMod), 25000);
if (time <= 0 || amount <= 0) if (time <= 0 || amount <= 0)
return false; return false;
gen.setGenerationValues(time, amount); gen.setGenerationValues(time, amount);
BlockPos genPos = gen.getPos(); var genPos = gen.getBlockPos();
PacketHandler.sendToAllAround(entity.level, pos, 32, new PacketParticles( PacketHandler.sendToAllAround(entity.level, pos, 32, new PacketParticles(
(float) entity.getPosX(), (float) entity.getPosY(), (float) entity.getPosZ(), PacketParticles.Type.ANIMAL_GEN_CONSUME, (float) entity.getX(), (float) entity.getY(), (float) entity.getZ(), PacketParticles.Type.ANIMAL_GEN_CONSUME,
child ? 1 : 0, child ? 1 : 0,
(int) (entity.getEyeHeight() * 10F), (int) (entity.getEyeHeight() * 10F),
genPos.getX(), genPos.getY(), genPos.getZ())); genPos.getX(), genPos.getY(), genPos.getZ()));
@ -86,22 +86,22 @@ public class BlockAnimalGenerator extends BlockContainerImpl implements IVisuali
@SubscribeEvent @SubscribeEvent
public void onEntityDrops(LivingDropsEvent event) { public void onEntityDrops(LivingDropsEvent event) {
LivingEntity entity = event.getEntityLiving(); var entity = event.getEntityLiving();
if (entity.getPersistentData().getBoolean(NaturesAura.MOD_ID + ":no_drops")) if (entity.getPersistentData().getBoolean(NaturesAura.MOD_ID + ":no_drops"))
event.setCanceled(true); event.setCanceled(true);
} }
@SubscribeEvent @SubscribeEvent
public void onEntityExp(LivingExperienceDropEvent event) { public void onEntityExp(LivingExperienceDropEvent event) {
LivingEntity entity = event.getEntityLiving(); var entity = event.getEntityLiving();
if (entity.getPersistentData().getBoolean(NaturesAura.MOD_ID + ":no_drops")) if (entity.getPersistentData().getBoolean(NaturesAura.MOD_ID + ":no_drops"))
event.setCanceled(true); event.setCanceled(true);
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AABB getVisualizationBounds(Level level, BlockPos pos) {
return new AxisAlignedBB(pos).grow(5); return new AABB(pos).inflate(5);
} }
@Override @Override

View file

@ -1,11 +1,12 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAnimalSpawner; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAnimalSpawner;
import net.minecraft.block.SoundType; import net.minecraft.world.level.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.world.level.material.Material;
public class BlockAnimalSpawner extends BlockContainerImpl { public class BlockAnimalSpawner extends BlockContainerImpl {
public BlockAnimalSpawner() { public BlockAnimalSpawner() {
super("animal_spawner", BlockEntityAnimalSpawner::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE)); super("animal_spawner", BlockEntityAnimalSpawner::new, Properties.of(Material.STONE).strength(2F).sound(SoundType.STONE));
} }
} }

View file

@ -40,7 +40,7 @@ public class BlockAuraBloom extends BushBlock implements IModItem, ICustomBlockS
@Override @Override
public boolean canSurvive(BlockState state, LevelReader levelIn, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader levelIn, BlockPos pos) {
BlockPos down = pos.below(); var down = pos.below();
return this.mayPlaceOn(levelIn.getBlockState(down), levelIn, down); return this.mayPlaceOn(levelIn.getBlockState(down), levelIn, down);
} }
@ -57,7 +57,7 @@ public class BlockAuraBloom extends BushBlock implements IModItem, ICustomBlockS
@Override @Override
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) { public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
Vec3 vec3d = state.getOffset(levelIn, pos); var vec3d = state.getOffset(levelIn, pos);
return SHAPE.move(vec3d.x, vec3d.y, vec3d.z); return SHAPE.move(vec3d.x, vec3d.y, vec3d.z);
} }
@ -84,6 +84,6 @@ public class BlockAuraBloom extends BushBlock implements IModItem, ICustomBlockS
@org.jetbrains.annotations.Nullable @org.jetbrains.annotations.Nullable
@Override @Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new BlockEntityAuraBloom(); return new BlockEntityAuraBloom(pos, state);
} }
} }

View file

@ -1,29 +1,29 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraDetector; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraDetector;
import net.minecraft.block.BlockState; import net.minecraft.core.BlockPos;
import net.minecraft.block.SoundType; import net.minecraft.world.level.Level;
import net.minecraft.block.material.Material; import net.minecraft.world.level.block.SoundType;
import net.minecraft.tileentity.BlockEntity; 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.level.Level; import net.minecraft.world.level.material.Material;
public class BlockAuraDetector extends BlockContainerImpl { public class BlockAuraDetector extends BlockContainerImpl {
public BlockAuraDetector() { public BlockAuraDetector() {
super("aura_detector", BlockEntityAuraDetector::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE)); super("aura_detector", BlockEntityAuraDetector::new, Properties.of(Material.STONE).strength(2F).sound(SoundType.STONE));
} }
@Override @Override
public boolean hasComparatorInputOverride(BlockState state) { public boolean hasAnalogOutputSignal(BlockState state) {
return true; return true;
} }
@Override @Override
public int getComparatorInputOverride(BlockState blockState, Level levelIn, BlockPos pos) { public int getAnalogOutputSignal(BlockState blockState, Level levelIn, BlockPos pos) {
BlockEntity tile = levelIn.getBlockEntity(pos); var tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityAuraDetector) if (tile instanceof BlockEntityAuraDetector detector)
return ((BlockEntityAuraDetector) tile).redstonePower; return detector.redstonePower;
else else
return 0; return 0;
} }

View file

@ -1,48 +1,42 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraTimer; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraTimer;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderAuraTimer; import de.ellpeck.naturesaura.blocks.tiles.render.RenderAuraTimer;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ICustomRenderType; import de.ellpeck.naturesaura.reg.ICustomRenderType;
import de.ellpeck.naturesaura.reg.ITESRProvider; import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher; import net.minecraft.core.BlockPos;
import net.minecraft.entity.player.Player; import net.minecraft.core.Direction;
import net.minecraft.state.StateContainer; import net.minecraft.server.level.ServerLevel;
import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.world.InteractionHand;
import net.minecraft.tileentity.BlockEntityType; import net.minecraft.world.InteractionResult;
import net.minecraft.util.InteractionResult; import net.minecraft.world.entity.player.Player;
import net.minecraft.util.Direction; import net.minecraft.world.level.BlockGetter;
import net.minecraft.util.Hand; import net.minecraft.world.level.Level;
import net.minecraft.util.Tuple; import net.minecraft.world.level.block.Block;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.Blocks;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.level.IBlockReader; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.level.Level; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.level.server.ServerLevel; import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import java.util.Random; import java.util.Random;
import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
public class BlockAuraTimer extends BlockContainerImpl implements ICustomBlockState, ITESRProvider<BlockEntityAuraTimer>, ICustomRenderType { public class BlockAuraTimer extends BlockContainerImpl implements ICustomBlockState, ITESRProvider<BlockEntityAuraTimer>, ICustomRenderType {
private static final VoxelShape SHAPE = makeCuboidShape(1, 0, 1, 15, 15, 15); private static final VoxelShape SHAPE = box(1, 0, 1, 15, 15, 15);
public BlockAuraTimer() { public BlockAuraTimer() {
super("aura_timer", BlockEntityAuraTimer::new, Properties.from(Blocks.SMOOTH_STONE)); super("aura_timer", BlockEntityAuraTimer::new, Properties.copy(Blocks.SMOOTH_STONE));
this.setDefaultState(this.getDefaultState().with(BlockStateProperties.POWERED, false)); this.registerDefaultState(this.defaultBlockState().setValue(BlockStateProperties.POWERED, false));
} }
@Override @Override
@ -51,46 +45,44 @@ public class BlockAuraTimer extends BlockContainerImpl implements ICustomBlockSt
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPE; return SHAPE;
} }
@Override
@OnlyIn(Dist.CLIENT)
public Tuple<BlockEntityType<BlockEntityAuraTimer>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityAuraTimer>>>> getTESR() {
return new Tuple<>(ModTileEntities.AURA_TIMER, () -> RenderAuraTimer::new);
}
@Override @Override
public Supplier<RenderType> getRenderType() { public Supplier<RenderType> getRenderType() {
return RenderType::getCutout; return RenderType::cutout;
} }
@Override @Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(BlockStateProperties.POWERED); builder.add(BlockStateProperties.POWERED);
} }
@Override @Override
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult p_225533_6_) { public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult p_225533_6_) {
return Helper.putStackOnTile(player, handIn, pos, 0, true); return Helper.putStackOnTile(player, handIn, pos, 0, true);
} }
@Override @Override
public boolean canProvidePower(BlockState state) { public boolean isSignalSource(BlockState state) {
return true; return true;
} }
@Override @Override
public int getWeakPower(BlockState state, IBlockReader level, BlockPos pos, Direction side) { public int getSignal(BlockState state, BlockGetter level, BlockPos pos, Direction side) {
return state.get(BlockStateProperties.POWERED) ? 15 : 0; return state.getValue(BlockStateProperties.POWERED) ? 15 : 0;
} }
@Override @Override
public void tick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) { public void tick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) {
super.tick(state, levelIn, pos, random); super.tick(state, levelIn, pos, random);
if (state.get(BlockStateProperties.POWERED)) if (state.getValue(BlockStateProperties.POWERED))
levelIn.setBlockState(pos, state.with(BlockStateProperties.POWERED, false)); levelIn.setBlockAndUpdate(pos, state.setValue(BlockStateProperties.POWERED, false));
} }
@Override
public void registerTESR() {
BlockEntityRenderers.register(ModTileEntities.AURA_TIMER, RenderAuraTimer::new);
}
} }

View file

@ -3,31 +3,32 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAutoCrafter; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAutoCrafter;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Block; import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.block.BlockState; import net.minecraft.world.level.block.Block;
import net.minecraft.block.SoundType; import net.minecraft.world.level.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.item.BlockItemUseContext; import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.state.DirectionProperty; import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.state.StateContainer; import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.world.level.material.Material;
public class BlockAutoCrafter extends BlockContainerImpl implements ICustomBlockState { public class BlockAutoCrafter extends BlockContainerImpl implements ICustomBlockState {
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
public BlockAutoCrafter() { public BlockAutoCrafter() {
super("auto_crafter", BlockEntityAutoCrafter::new, Properties.create(Material.WOOD).hardnessAndResistance(1.5F).sound(SoundType.WOOD)); super("auto_crafter", BlockEntityAutoCrafter::new, Properties.of(Material.WOOD).strength(1.5F).sound(SoundType.WOOD));
} }
@Override @Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder); super.createBlockStateDefinition(builder);
builder.add(FACING); builder.add(FACING);
} }
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockPlaceContext context) {
return super.getStateForPlacement(context).with(FACING, context.getPlayer().getHorizontalFacing()); return super.getStateForPlacement(context).setValue(FACING, context.getPlayer().getDirection());
} }
@Override @Override

View file

@ -3,25 +3,26 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityBlastFurnaceBooster; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityBlastFurnaceBooster;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Block; import net.minecraft.core.BlockPos;
import net.minecraft.block.BlockState; import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.block.Blocks; import net.minecraft.world.level.BlockGetter;
import net.minecraft.block.HorizontalBlock; import net.minecraft.world.level.block.Block;
import net.minecraft.item.BlockItemUseContext; import net.minecraft.world.level.block.Blocks;
import net.minecraft.state.DirectionProperty; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.state.StateContainer; import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.util.math.shapes.Shapes; import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.level.IBlockReader; import net.minecraft.world.phys.shapes.VoxelShape;
public class BlockBlastFurnaceBooster extends BlockContainerImpl implements ICustomBlockState { public class BlockBlastFurnaceBooster extends BlockContainerImpl implements ICustomBlockState {
public static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING;
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
private static final VoxelShape SHAPE = Shapes.create(1 / 16F, 0, 1 / 16F, 15 / 16F, 1, 15 / 16F); private static final VoxelShape SHAPE = Shapes.create(1 / 16F, 0, 1 / 16F, 15 / 16F, 1, 15 / 16F);
public BlockBlastFurnaceBooster() { public BlockBlastFurnaceBooster() {
super("blast_furnace_booster", BlockEntityBlastFurnaceBooster::new, Block.Properties.from(Blocks.BLAST_FURNACE).setLightLevel(s -> 0)); super("blast_furnace_booster", BlockEntityBlastFurnaceBooster::new, Block.Properties.copy(Blocks.BLAST_FURNACE).lightLevel(s -> 0));
} }
@Override @Override
@ -30,19 +31,19 @@ public class BlockBlastFurnaceBooster extends BlockContainerImpl implements ICus
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPE; return SHAPE;
} }
@Override @Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder); super.createBlockStateDefinition(builder);
builder.add(FACING); builder.add(FACING);
} }
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockPlaceContext context) {
return super.getStateForPlacement(context).with(FACING, context.getPlacementHorizontalFacing().getOpposite()); return super.getStateForPlacement(context).setValue(FACING, context.getHorizontalDirection().getOpposite());
} }
@Override @Override

View file

@ -4,29 +4,30 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Block; import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.block.BlockState; import net.minecraft.world.level.block.Block;
import net.minecraft.item.BlockItemUseContext; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.state.StateContainer; import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.BooleanProperty;
public class BlockCatalyst extends BlockImpl implements ICustomBlockState { public class BlockCatalyst extends BlockImpl implements ICustomBlockState {
public static final BooleanProperty NETHER = BlockNatureAltar.NETHER; public static final BooleanProperty NETHER = BlockNatureAltar.NETHER;
public BlockCatalyst(String baseName, Properties properties) { public BlockCatalyst(String baseName, Properties properties) {
super(baseName, properties); super(baseName, properties);
this.setDefaultState(this.getDefaultState().with(NETHER, false)); this.registerDefaultState(this.defaultBlockState().setValue(NETHER, false));
} }
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockPlaceContext context) {
boolean nether = IAuraType.forLevel(context.getLevel()).isSimilar(NaturesAuraAPI.TYPE_NETHER); var nether = IAuraType.forLevel(context.getLevel()).isSimilar(NaturesAuraAPI.TYPE_NETHER);
return super.getStateForPlacement(context).with(NETHER, nether); return super.getStateForPlacement(context).setValue(NETHER, nether);
} }
@Override @Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder); super.createBlockStateDefinition(builder);
builder.add(NETHER); builder.add(NETHER);
} }

View file

@ -3,11 +3,12 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityChorusGenerator; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityChorusGenerator;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Blocks; import net.minecraft.world.level.block.Blocks;
public class BlockChorusGenerator extends BlockContainerImpl implements ICustomBlockState { public class BlockChorusGenerator extends BlockContainerImpl implements ICustomBlockState {
public BlockChorusGenerator() { public BlockChorusGenerator() {
super("chorus_generator", BlockEntityChorusGenerator::new, Properties.from(Blocks.END_STONE)); super("chorus_generator", BlockEntityChorusGenerator::new, Properties.copy(Blocks.END_STONE));
} }
@Override @Override

View file

@ -7,33 +7,28 @@ import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityChunkLoader; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityChunkLoader;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.BlockState; import net.minecraft.core.BlockPos;
import net.minecraft.block.SoundType; import net.minecraft.util.Mth;
import net.minecraft.block.material.Material; import net.minecraft.world.level.BlockGetter;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.world.level.Level;
import net.minecraft.item.ItemStack; import net.minecraft.world.level.block.SoundType;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.material.Material;
import net.minecraft.util.math.Mth; import net.minecraft.world.phys.AABB;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.level.IBlockReader;
import net.minecraft.level.Level;
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 javax.annotation.Nullable;
import java.util.List;
import java.util.Random; import java.util.Random;
public class BlockChunkLoader extends BlockContainerImpl implements IVisualizable, ICustomBlockState { public class BlockChunkLoader extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
private static final VoxelShape SHAPE = makeCuboidShape(4, 4, 4, 12, 12, 12); private static final VoxelShape SHAPE = box(4, 4, 4, 12, 12, 12);
public BlockChunkLoader() { public BlockChunkLoader() {
super("chunk_loader", BlockEntityChunkLoader::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).sound(SoundType.STONE)); super("chunk_loader", BlockEntityChunkLoader::new, Properties.of(Material.STONE).strength(3F).sound(SoundType.STONE));
} }
@Override @Override
@ -43,12 +38,12 @@ public class BlockChunkLoader extends BlockContainerImpl implements IVisualizabl
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AABB getVisualizationBounds(Level level, BlockPos pos) {
BlockEntity tile = level.getBlockEntity(pos); var tile = level.getBlockEntity(pos);
if (tile instanceof BlockEntityChunkLoader) { if (tile instanceof BlockEntityChunkLoader) {
int range = ((BlockEntityChunkLoader) tile).range(); var range = ((BlockEntityChunkLoader) tile).range();
if (range > 0) { if (range > 0) {
return new AxisAlignedBB( return new AABB(
(pos.getX() - range) >> 4 << 4, (pos.getX() - range) >> 4 << 4,
0, 0,
(pos.getZ() - range) >> 4 << 4, (pos.getZ() - range) >> 4 << 4,
@ -65,13 +60,13 @@ public class BlockChunkLoader extends BlockContainerImpl implements IVisualizabl
public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) {
if (!ModConfig.instance.chunkLoader.get()) if (!ModConfig.instance.chunkLoader.get())
return; return;
BlockEntity tile = levelIn.getBlockEntity(pos); var tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityChunkLoader) { if (tile instanceof BlockEntityChunkLoader) {
int range = ((BlockEntityChunkLoader) tile).range(); var range = ((BlockEntityChunkLoader) tile).range();
for (int i = Mth.ceil(range / 8F); i > 0; i--) { for (var i = Mth.ceil(range / 8F); i > 0; i--) {
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
pos.getX() + levelIn.rand.nextFloat(), pos.getY() + levelIn.rand.nextFloat(), pos.getZ() + levelIn.rand.nextFloat(), pos.getX() + levelIn.random.nextFloat(), pos.getY() + levelIn.random.nextFloat(), pos.getZ() + levelIn.random.nextFloat(),
0, 0, 0, 0xa12dff, 1F + levelIn.rand.nextFloat(), 100, 0, false, true); 0, 0, 0, 0xa12dff, 1F + levelIn.random.nextFloat(), 100, 0, false, true);
} }
} }
} }
@ -83,18 +78,13 @@ public class BlockChunkLoader extends BlockContainerImpl implements IVisualizabl
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPE; return SHAPE;
} }
@Override @Override
public String getTranslationKey() { public String getDescriptionId() {
return ModConfig.instance.chunkLoader.get() ? super.getTranslationKey() : "block." + NaturesAura.MOD_ID + "." + this.getBaseName() + ".disabled"; return ModConfig.instance.chunkLoader.get() ? super.getDescriptionId() : "block." + NaturesAura.MOD_ID + "." + this.getBaseName() + ".disabled";
}
@Override
public void addInformation(ItemStack stack, @Nullable IBlockReader levelIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
super.addInformation(stack, levelIn, tooltip, flagIn);
} }
@Override @Override

View file

@ -76,7 +76,7 @@ public class BlockContainerImpl extends BaseEntityBlock implements IModItem {
@Nullable @Nullable
public BlockState getStateForPlacement(BlockPlaceContext context) { public BlockState getStateForPlacement(BlockPlaceContext context) {
if (this.hasWaterlogging()) { if (this.hasWaterlogging()) {
FluidState state = context.getLevel().getFluidState(context.getClickedPos()); var state = context.getLevel().getFluidState(context.getClickedPos());
return this.defaultBlockState().setValue(BlockStateProperties.WATERLOGGED, state.is(FluidTags.WATER) && state.getAmount() == 8); return this.defaultBlockState().setValue(BlockStateProperties.WATERLOGGED, state.is(FluidTags.WATER) && state.getAmount() == 8);
} }
return super.getStateForPlacement(context); return super.getStateForPlacement(context);
@ -100,11 +100,11 @@ public class BlockContainerImpl extends BaseEntityBlock implements IModItem {
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
List<ItemStack> drops = super.getDrops(state, builder); var drops = super.getDrops(state, builder);
BlockEntity tile = builder.getParameter(LootContextParams.BLOCK_ENTITY); var tile = builder.getParameter(LootContextParams.BLOCK_ENTITY);
if (tile instanceof BlockEntityImpl) { if (tile instanceof BlockEntityImpl) {
for (ItemStack stack : drops) { for (var stack : drops) {
if (stack.getItem() != this.asItem()) if (stack.getItem() != this.asItem())
continue; continue;
((BlockEntityImpl) tile).modifyDrop(stack); ((BlockEntityImpl) tile).modifyDrop(stack);
@ -117,7 +117,7 @@ public class BlockContainerImpl extends BaseEntityBlock implements IModItem {
@Override @Override
public void onPlace(BlockState state, Level levelIn, BlockPos pos, BlockState newState, boolean isMoving) { public void onPlace(BlockState state, Level levelIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (state.getBlock() != newState.getBlock()) { if (state.getBlock() != newState.getBlock()) {
BlockEntity tile = levelIn.getBlockEntity(pos); var tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityImpl) if (tile instanceof BlockEntityImpl)
((BlockEntityImpl) tile).dropInventory(); ((BlockEntityImpl) tile).dropInventory();
} }
@ -132,7 +132,7 @@ public class BlockContainerImpl extends BaseEntityBlock implements IModItem {
@Override @Override
public void setPlacedBy(Level levelIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { public void setPlacedBy(Level levelIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
BlockEntity tile = levelIn.getBlockEntity(pos); var tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityImpl) if (tile instanceof BlockEntityImpl)
((BlockEntityImpl) tile).loadDataOnPlace(stack); ((BlockEntityImpl) tile).loadDataOnPlace(stack);
} }
@ -144,9 +144,9 @@ public class BlockContainerImpl extends BaseEntityBlock implements IModItem {
private void updateRedstoneState(Level level, BlockPos pos) { private void updateRedstoneState(Level level, BlockPos pos) {
if (!level.isClientSide) { if (!level.isClientSide) {
BlockEntity tile = level.getBlockEntity(pos); var tile = level.getBlockEntity(pos);
if (tile instanceof BlockEntityImpl impl) { if (tile instanceof BlockEntityImpl impl) {
int newPower = level.getBestNeighborSignal(pos); var newPower = level.getBestNeighborSignal(pos);
if (impl.redstonePower != newPower) if (impl.redstonePower != newPower)
level.scheduleTick(pos, this, 4); level.scheduleTick(pos, this, 4);
} }
@ -156,9 +156,9 @@ public class BlockContainerImpl extends BaseEntityBlock implements IModItem {
@Override @Override
public void tick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) { public void tick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) {
if (!levelIn.isClientSide) { if (!levelIn.isClientSide) {
BlockEntity tile = levelIn.getBlockEntity(pos); var tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityImpl impl) { if (tile instanceof BlockEntityImpl impl) {
int newPower = levelIn.getBestNeighborSignal(pos); var newPower = levelIn.getBestNeighborSignal(pos);
if (impl.redstonePower != newPower) if (impl.redstonePower != newPower)
impl.onRedstonePowerChange(newPower); impl.onRedstonePowerChange(newPower);
} }

View file

@ -3,14 +3,13 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ICustomRenderType; import de.ellpeck.naturesaura.reg.ICustomRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.util.math.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.level.IBlockReader; import net.minecraft.server.level.ServerLevel;
import net.minecraft.level.server.ServerLevel; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import java.util.Random; import java.util.Random;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -18,13 +17,13 @@ import java.util.function.Supplier;
public class BlockDecayedLeaves extends BlockImpl implements ICustomBlockState, ICustomRenderType { public class BlockDecayedLeaves extends BlockImpl implements ICustomBlockState, ICustomRenderType {
public BlockDecayedLeaves() { public BlockDecayedLeaves() {
super("decayed_leaves", Properties.create(Material.LEAVES).hardnessAndResistance(0.2F).sound(SoundType.PLANT).notSolid().tickRandomly()); super("decayed_leaves", Properties.of(Material.LEAVES).strength(0.2F).sound(SoundType.GRASS).noOcclusion().randomTicks());
} }
@Override @Override
public void tick(BlockState state, ServerLevel level, BlockPos pos, Random random) { public void tick(BlockState state, ServerLevel level, BlockPos pos, Random random) {
if (!level.isClientSide) { if (!level.isClientSide) {
level.setBlockState(pos, Blocks.AIR.getDefaultState()); level.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
} }
} }
@ -33,13 +32,8 @@ public class BlockDecayedLeaves extends BlockImpl implements ICustomBlockState,
generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName()))); generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName())));
} }
@Override
public int getOpacity(BlockState state, IBlockReader levelIn, BlockPos pos) {
return 1;
}
@Override @Override
public Supplier<RenderType> getRenderType() { public Supplier<RenderType> getRenderType() {
return RenderType::getCutoutMipped; return RenderType::cutoutMipped;
} }
} }

View file

@ -4,26 +4,30 @@ import de.ellpeck.naturesaura.blocks.tiles.BlockEntityEndFlower;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.data.ItemModelGenerator; import de.ellpeck.naturesaura.data.ItemModelGenerator;
import de.ellpeck.naturesaura.reg.*; import de.ellpeck.naturesaura.reg.*;
import net.minecraft.block.*;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.entity.LivingEntity; import net.minecraft.core.BlockPos;
import net.minecraft.entity.boss.dragon.EnderDragonEntity; import net.minecraft.core.NonNullList;
import net.minecraft.entity.player.Player; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.fluid.FluidState; import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
import net.minecraft.item.ItemStack; import net.minecraft.world.entity.player.Player;
import net.minecraft.loot.LootContext; import net.minecraft.world.item.ItemStack;
import net.minecraft.loot.LootParameters; import net.minecraft.world.level.BlockGetter;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.world.level.Level;
import net.minecraft.util.NonNullList; import net.minecraft.world.level.LevelReader;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.Blocks;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.world.level.block.BushBlock;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.level.block.SoundType;
import net.minecraft.level.IBlockReader; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.level.ILevelReader; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.level.Level; import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.level.gen.Heightmap; import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Material;
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.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -32,52 +36,46 @@ import javax.annotation.Nullable;
import java.util.List; import java.util.List;
import java.util.function.Supplier; import java.util.function.Supplier;
public class BlockEndFlower extends BushBlock implements IModItem, ICustomBlockState, ICustomItemModel, ICustomRenderType { public class BlockEndFlower extends BushBlock implements IModItem, ICustomBlockState, ICustomItemModel, ICustomRenderType, EntityBlock {
protected static final VoxelShape SHAPE = Block.makeCuboidShape(5.0D, 0.0D, 5.0D, 11.0D, 10.0D, 11.0D); protected static final VoxelShape SHAPE = box(5.0D, 0.0D, 5.0D, 11.0D, 10.0D, 11.0D);
public BlockEndFlower() { public BlockEndFlower() {
super(Properties.create(Material.PLANTS).doesNotBlockMovement().hardnessAndResistance(0.5F).sound(SoundType.PLANT)); super(Properties.of(Material.GRASS).noCollission().strength(0.5F).sound(SoundType.GRASS));
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
ModRegistry.add(this); ModRegistry.add(this);
ModRegistry.add(new ModTileType<>(BlockEntityEndFlower::new, this)); ModRegistry.add(new ModTileType<>(BlockEntityEndFlower::new, this));
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
Vector3d vec3d = state.getOffset(levelIn, pos); var vec3d = state.getOffset(levelIn, pos);
return SHAPE.withOffset(vec3d.x, vec3d.y, vec3d.z); return SHAPE.move(vec3d.x, vec3d.y, vec3d.z);
} }
@SubscribeEvent @SubscribeEvent
public void onDragonTick(LivingUpdateEvent event) { public void onDragonTick(LivingUpdateEvent event) {
LivingEntity living = event.getEntityLiving(); var living = event.getEntityLiving();
if (living.level.isClientSide || !(living instanceof EnderDragonEntity)) if (living.level.isClientSide || !(living instanceof EnderDragon dragon))
return; return;
EnderDragonEntity dragon = (EnderDragonEntity) living; if (dragon.deathTime < 150 || dragon.deathTime % 10 != 0)
if (dragon.deathTicks < 150 || dragon.deathTicks % 10 != 0)
return; return;
for (int i = 0; i < 6; i++) { for (var i = 0; i < 6; i++) {
int x = dragon.level.rand.nextInt(256) - 128; var x = dragon.level.random.nextInt(256) - 128;
int z = dragon.level.rand.nextInt(256) - 128; var z = dragon.level.random.nextInt(256) - 128;
BlockPos pos = new BlockPos(x, dragon.level.getHeight(Heightmap.Type.WORLD_SURFACE, x, z), z); var pos = new BlockPos(x, dragon.level.getHeight(Heightmap.Types.WORLD_SURFACE, x, z), z);
if (!dragon.level.isBlockLoaded(pos)) if (!dragon.level.isLoaded(pos))
continue; continue;
if (dragon.level.getBlockState(pos.down()).getBlock() != Blocks.END_STONE) if (dragon.level.getBlockState(pos.below()).getBlock() != Blocks.END_STONE)
continue; continue;
dragon.level.setBlockState(pos, this.getDefaultState()); dragon.level.setBlockAndUpdate(pos, this.defaultBlockState());
} }
} }
@Override @Override
protected boolean isValidGround(BlockState state, IBlockReader levelIn, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader levelIn, BlockPos pos) {
return state.getBlock() == Blocks.END_STONE; return levelIn.getBlockState(pos.below()).getBlock() == Blocks.END_STONE;
}
@Override
public boolean isValidPosition(BlockState state, ILevelReader levelIn, BlockPos pos) {
return levelIn.getBlockState(pos.down()).getBlock() == Blocks.END_STONE;
} }
@Override @Override
@ -87,29 +85,24 @@ public class BlockEndFlower extends BushBlock implements IModItem, ICustomBlockS
@Nullable @Nullable
@Override @Override
public BlockEntity createBlockEntity(BlockState state, IBlockReader level) { public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new BlockEntityEndFlower(); return new BlockEntityEndFlower(pos, state);
} }
@Override @Override
public boolean hasBlockEntity(BlockState state) { public boolean onDestroyedByPlayer(BlockState state, Level level, BlockPos pos, Player player, boolean willHarvest, FluidState fluid) {
return true; return willHarvest || super.onDestroyedByPlayer(state, level, pos, player, willHarvest, fluid);
} }
@Override @Override
public boolean removedByPlayer(BlockState state, Level level, BlockPos pos, Player player, boolean willHarvest, FluidState fluid) { public void playerDestroy(Level levelIn, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity te, ItemStack stack) {
return willHarvest || super.removedByPlayer(state, level, pos, player, willHarvest, fluid); super.playerDestroy(levelIn, player, pos, state, te, stack);
} levelIn.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
@Override
public void harvestBlock(Level levelIn, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity te, ItemStack stack) {
super.harvestBlock(levelIn, player, pos, state, te, stack);
levelIn.setBlockState(pos, Blocks.AIR.getDefaultState());
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
BlockEntity tile = builder.get(LootParameters.BLOCK_ENTITY); var tile = builder.getParameter(LootContextParams.BLOCK_ENTITY);
if (tile instanceof BlockEntityEndFlower && ((BlockEntityEndFlower) tile).isDrainMode) if (tile instanceof BlockEntityEndFlower && ((BlockEntityEndFlower) tile).isDrainMode)
return NonNullList.create(); return NonNullList.create();
return super.getDrops(state, builder); return super.getDrops(state, builder);
@ -127,6 +120,6 @@ public class BlockEndFlower extends BushBlock implements IModItem, ICustomBlockS
@Override @Override
public Supplier<RenderType> getRenderType() { public Supplier<RenderType> getRenderType() {
return RenderType::getCutout; return RenderType::cutout;
} }
} }

View file

@ -10,15 +10,13 @@ import de.ellpeck.naturesaura.items.ModItems;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ITESRProvider; import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher; import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.resources.language.I18n; import net.minecraft.client.resources.language.I18n;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes; import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Tuple;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
@ -28,8 +26,6 @@ import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
@ -43,8 +39,6 @@ import net.minecraftforge.network.NetworkHooks;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.function.Function;
import java.util.function.Supplier;
public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider<BlockEntityEnderCrate>, ICustomBlockState { public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider<BlockEntityEnderCrate>, ICustomBlockState {
@ -62,7 +56,7 @@ public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public static void addEnderNameInfo(ItemStack stack, List<Component> tooltip) { public static void addEnderNameInfo(ItemStack stack, List<Component> tooltip) {
String name = getEnderName(stack); var name = getEnderName(stack);
if (name != null && !name.isEmpty()) { if (name != null && !name.isEmpty()) {
tooltip.add(new TextComponent(ChatFormatting.DARK_PURPLE + I18n.get("info." + NaturesAura.MOD_ID + ".ender_name", ChatFormatting.ITALIC + name + ChatFormatting.RESET))); tooltip.add(new TextComponent(ChatFormatting.DARK_PURPLE + I18n.get("info." + NaturesAura.MOD_ID + ".ender_name", ChatFormatting.ITALIC + name + ChatFormatting.RESET)));
} else { } else {
@ -75,18 +69,18 @@ public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider
var player = event.getPlayer(); var player = event.getPlayer();
if (player == null) if (player == null)
return; return;
ItemStack stack = event.getLeft(); var stack = event.getLeft();
if (stack.getItem() != this.asItem() && stack.getItem() != ModItems.ENDER_ACCESS) if (stack.getItem() != this.asItem() && stack.getItem() != ModItems.ENDER_ACCESS)
return; return;
ItemStack second = event.getRight(); var second = event.getRight();
if (second.getItem() != Items.ENDER_EYE || second.getCount() < stack.getCount()) if (second.getItem() != Items.ENDER_EYE || second.getCount() < stack.getCount())
return; return;
String name = event.getName(); var name = event.getName();
if (name == null || name.isEmpty()) if (name == null || name.isEmpty())
return; return;
if (ILevelData.getOverworldData(player.level).isEnderStorageLocked(name)) if (ILevelData.getOverworldData(player.level).isEnderStorageLocked(name))
return; return;
ItemStack output = stack.copy(); var output = stack.copy();
output.getOrCreateTag().putString(NaturesAura.MOD_ID + ":ender_name", name); output.getOrCreateTag().putString(NaturesAura.MOD_ID + ":ender_name", name);
event.setOutput(output); event.setOutput(output);
event.setMaterialCost(stack.getCount()); event.setMaterialCost(stack.getCount());
@ -96,7 +90,7 @@ public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider
@Override @Override
public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) { public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
if (!levelIn.isClientSide) { if (!levelIn.isClientSide) {
BlockEntity tile = levelIn.getBlockEntity(pos); var tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityEnderCrate crate && crate.canOpen()) { if (tile instanceof BlockEntityEnderCrate crate && crate.canOpen()) {
crate.drainAura(2500); crate.drainAura(2500);
NetworkHooks.openGui((ServerPlayer) player, crate, pos); NetworkHooks.openGui((ServerPlayer) player, crate, pos);
@ -114,24 +108,19 @@ public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) {
for (int i = 0; i < 3; ++i) { for (var i = 0; i < 3; ++i) {
int j = rand.nextInt(2) * 2 - 1; var j = rand.nextInt(2) * 2 - 1;
int k = rand.nextInt(2) * 2 - 1; var k = rand.nextInt(2) * 2 - 1;
double d0 = (double) pos.getX() + 0.5D + 0.25D * (double) j; var d0 = (double) pos.getX() + 0.5D + 0.25D * (double) j;
double d1 = (float) pos.getY() + rand.nextFloat(); double d1 = (float) pos.getY() + rand.nextFloat();
double d2 = (double) pos.getZ() + 0.5D + 0.25D * (double) k; var d2 = (double) pos.getZ() + 0.5D + 0.25D * (double) k;
double d3 = rand.nextFloat() * (float) j; double d3 = rand.nextFloat() * (float) j;
double d4 = ((double) rand.nextFloat() - 0.5D) * 0.125D; var d4 = ((double) rand.nextFloat() - 0.5D) * 0.125D;
double d5 = rand.nextFloat() * (float) k; double d5 = rand.nextFloat() * (float) k;
levelIn.addParticle(ParticleTypes.PORTAL, d0, d1, d2, d3, d4, d5); levelIn.addParticle(ParticleTypes.PORTAL, d0, d1, d2, d3, d4, d5);
} }
} }
@Override
public Tuple<BlockEntityType<BlockEntityEnderCrate>, Supplier<Function<? super BlockEntityRenderDispatcher, ? extends BlockEntityRenderer<? super BlockEntityEnderCrate>>>> getTESR() {
return new Tuple<>(ModTileEntities.ENDER_CRATE, () -> RenderEnderCrate::new);
}
@Override @Override
public void generateCustomBlockState(BlockStateGenerator generator) { public void generateCustomBlockState(BlockStateGenerator generator) {
generator.simpleBlock(this, generator.models().cubeBottomTop(this.getBaseName(), generator.simpleBlock(this, generator.models().cubeBottomTop(this.getBaseName(),
@ -139,4 +128,9 @@ public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider
generator.modLoc("block/" + this.getBaseName() + "_bottom"), generator.modLoc("block/" + this.getBaseName() + "_bottom"),
generator.modLoc("block/" + this.getBaseName() + "_top"))); generator.modLoc("block/" + this.getBaseName() + "_top")));
} }
@Override
public void registerTESR() {
BlockEntityRenderers.register(ModTileEntities.ENDER_CRATE, RenderEnderCrate::new);
}
} }

View file

@ -6,19 +6,19 @@ import de.ellpeck.naturesaura.blocks.tiles.BlockEntityFieldCreator;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ICustomRenderType; import de.ellpeck.naturesaura.reg.ICustomRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.entity.player.Player; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.util.InteractionResult; import net.minecraft.world.InteractionHand;
import net.minecraft.util.Hand; import net.minecraft.world.InteractionResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.entity.player.Player;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.world.level.Level;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.world.level.block.SoundType;
import net.minecraft.level.Level; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@ -26,44 +26,44 @@ import java.util.Random;
import java.util.function.Supplier; import java.util.function.Supplier;
public class BlockFieldCreator extends BlockContainerImpl implements ICustomBlockState, ICustomRenderType { public class BlockFieldCreator extends BlockContainerImpl implements ICustomBlockState, ICustomRenderType {
public BlockFieldCreator() { public BlockFieldCreator() {
super("field_creator", BlockEntityFieldCreator::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).notSolid().sound(SoundType.STONE)); super("field_creator", BlockEntityFieldCreator::new, Properties.of(Material.STONE).strength(2F).noCollission().sound(SoundType.STONE));
} }
@Override @Override
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult p_225533_6_) { public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult p_225533_6_) {
BlockEntity tile = levelIn.getBlockEntity(pos); var tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityFieldCreator) { if (tile instanceof BlockEntityFieldCreator) {
if (!levelIn.isClientSide) { if (!levelIn.isClientSide) {
String key = NaturesAura.MOD_ID + ":field_creator_pos"; var key = NaturesAura.MOD_ID + ":field_creator_pos";
CompoundTag compound = player.getPersistentData(); var compound = player.getPersistentData();
if (!player.isSneaking() && compound.contains(key)) { if (!player.isCrouching() && compound.contains(key)) {
BlockPos stored = BlockPos.fromLong(compound.getLong(key)); var stored = BlockPos.of(compound.getLong(key));
BlockEntityFieldCreator creator = (BlockEntityFieldCreator) tile; var creator = (BlockEntityFieldCreator) tile;
if (!pos.equals(stored)) { if (!pos.equals(stored)) {
if (creator.isCloseEnough(stored)) { if (creator.isCloseEnough(stored)) {
BlockEntity otherTile = levelIn.getBlockEntity(stored); var otherTile = levelIn.getBlockEntity(stored);
if (otherTile instanceof BlockEntityFieldCreator) { if (otherTile instanceof BlockEntityFieldCreator otherCreator) {
creator.connectionOffset = stored.subtract(pos); creator.connectionOffset = stored.subtract(pos);
creator.isMain = true; creator.isMain = true;
creator.sendToClients(); creator.sendToClients();
BlockEntityFieldCreator otherCreator = (BlockEntityFieldCreator) otherTile;
otherCreator.connectionOffset = pos.subtract(stored); otherCreator.connectionOffset = pos.subtract(stored);
otherCreator.isMain = false; otherCreator.isMain = false;
otherCreator.sendToClients(); otherCreator.sendToClients();
compound.remove(key); compound.remove(key);
player.sendStatusMessage(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".connected"), true); player.displayClientMessage(new TranslatableComponent("info." + NaturesAura.MOD_ID + ".connected"), true);
} else } else
player.sendStatusMessage(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".stored_pos_gone"), true); player.displayClientMessage(new TranslatableComponent("info." + NaturesAura.MOD_ID + ".stored_pos_gone"), true);
} else } else
player.sendStatusMessage(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".too_far"), true); player.displayClientMessage(new TranslatableComponent("info." + NaturesAura.MOD_ID + ".too_far"), true);
} else } else
player.sendStatusMessage(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".same_position"), true); player.displayClientMessage(new TranslatableComponent("info." + NaturesAura.MOD_ID + ".same_position"), true);
} else { } else {
compound.putLong(key, pos.toLong()); compound.putLong(key, pos.asLong());
player.sendStatusMessage(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".stored_pos"), true); player.displayClientMessage(new TranslatableComponent("info." + NaturesAura.MOD_ID + ".stored_pos"), true);
} }
} }
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
@ -74,22 +74,19 @@ public class BlockFieldCreator extends BlockContainerImpl implements ICustomBloc
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) {
BlockEntity tile = levelIn.getBlockEntity(pos); var tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityFieldCreator) { if (tile instanceof BlockEntityFieldCreator creator && creator.isCharged) {
BlockEntityFieldCreator creator = (BlockEntityFieldCreator) tile; var connected = creator.getConnectedPos();
if (creator.isCharged) { if (connected != null)
BlockPos connected = creator.getConnectedPos(); NaturesAuraAPI.instance().spawnParticleStream(
if (connected != null) pos.getX() + 0.25F + rand.nextFloat() * 0.5F,
NaturesAuraAPI.instance().spawnParticleStream( pos.getY() + 0.25F + rand.nextFloat() * 0.5F,
pos.getX() + 0.25F + rand.nextFloat() * 0.5F, pos.getZ() + 0.25F + rand.nextFloat() * 0.5F,
pos.getY() + 0.25F + rand.nextFloat() * 0.5F, connected.getX() + 0.25F + rand.nextFloat() * 0.5F,
pos.getZ() + 0.25F + rand.nextFloat() * 0.5F, connected.getY() + 0.25F + rand.nextFloat() * 0.5F,
connected.getX() + 0.25F + rand.nextFloat() * 0.5F, connected.getZ() + 0.25F + rand.nextFloat() * 0.5F,
connected.getY() + 0.25F + rand.nextFloat() * 0.5F, 0.65F, 0x4245f4, 1F
connected.getZ() + 0.25F + rand.nextFloat() * 0.5F, );
0.65F, 0x4245f4, 1F
);
}
} }
} }
@ -100,6 +97,6 @@ public class BlockFieldCreator extends BlockContainerImpl implements ICustomBloc
@Override @Override
public Supplier<RenderType> getRenderType() { public Supplier<RenderType> getRenderType() {
return RenderType::getCutoutMipped; return RenderType::cutoutMipped;
} }
} }

View file

@ -4,23 +4,24 @@ import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityFireworkGenerator; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityFireworkGenerator;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.SoundType; import net.minecraft.core.BlockPos;
import net.minecraft.block.material.Material; import net.minecraft.world.level.Level;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.level.block.SoundType;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.material.Material;
import net.minecraft.level.Level; import net.minecraft.world.phys.AABB;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
public class BlockFireworkGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState { public class BlockFireworkGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockFireworkGenerator() { public BlockFireworkGenerator() {
super("firework_generator", BlockEntityFireworkGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).sound(SoundType.STONE)); super("firework_generator", BlockEntityFireworkGenerator::new, Properties.of(Material.STONE).strength(3F).sound(SoundType.STONE));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AABB getVisualizationBounds(Level level, BlockPos pos) {
return new AxisAlignedBB(pos).grow(4); return new AABB(pos).inflate(4);
} }
@Override @Override

View file

@ -4,24 +4,24 @@ import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityFlowerGenerator; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityFlowerGenerator;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.SoundType; import net.minecraft.core.BlockPos;
import net.minecraft.block.material.Material; import net.minecraft.world.level.Level;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.level.block.SoundType;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.material.Material;
import net.minecraft.level.Level; import net.minecraft.world.phys.AABB;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
public class BlockFlowerGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState { public class BlockFlowerGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockFlowerGenerator() { public BlockFlowerGenerator() {
super("flower_generator", BlockEntityFlowerGenerator::new, Properties.create(Material.WOOD).sound(SoundType.WOOD).hardnessAndResistance(2F)); super("flower_generator", BlockEntityFlowerGenerator::new, Properties.of(Material.WOOD).sound(SoundType.WOOD).strength(2F));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AABB getVisualizationBounds(Level level, BlockPos pos) {
return new AxisAlignedBB(pos).grow(3, 1, 3); return new AABB(pos).inflate(3, 1, 3);
} }
@Override @Override

View file

@ -2,13 +2,14 @@ package de.ellpeck.naturesaura.blocks;
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.Block;
import net.minecraft.block.FlowerPotBlock;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.FlowerPotBlock;
import java.util.function.Supplier; import java.util.function.Supplier;
public class BlockFlowerPot extends FlowerPotBlock implements ICustomBlockState, IModItem, INoItemBlock, ICustomRenderType { public class BlockFlowerPot extends FlowerPotBlock implements ICustomBlockState, IModItem, INoItemBlock, ICustomRenderType {
public BlockFlowerPot(Supplier<FlowerPotBlock> emptyPot, Supplier<? extends Block> block, Properties props) { public BlockFlowerPot(Supplier<FlowerPotBlock> emptyPot, Supplier<? extends Block> block, Properties props) {
super(emptyPot, block, props); super(emptyPot, block, props);
ModRegistry.add(this); ModRegistry.add(this);
@ -18,16 +19,16 @@ public class BlockFlowerPot extends FlowerPotBlock implements ICustomBlockState,
public void generateCustomBlockState(BlockStateGenerator generator) { public void generateCustomBlockState(BlockStateGenerator generator) {
generator.simpleBlock(this, generator.models() generator.simpleBlock(this, generator.models()
.withExistingParent(this.getBaseName(), "block/flower_pot_cross") .withExistingParent(this.getBaseName(), "block/flower_pot_cross")
.texture("plant", "block/" + this.getFlower().getRegistryName().getPath())); .texture("plant", "block/" + this.getContent().getRegistryName().getPath()));
} }
@Override @Override
public String getBaseName() { public String getBaseName() {
return "potted_" + this.getFlower().getRegistryName().getPath(); return "potted_" + this.getContent().getRegistryName().getPath();
} }
@Override @Override
public Supplier<RenderType> getRenderType() { public Supplier<RenderType> getRenderType() {
return RenderType::getCutout; return RenderType::cutout;
} }
} }

View file

@ -4,41 +4,41 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityFurnaceHeater; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityFurnaceHeater;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Block; import net.minecraft.core.BlockPos;
import net.minecraft.block.BlockState; import net.minecraft.core.Direction;
import net.minecraft.block.material.Material; import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.item.BlockItemUseContext; import net.minecraft.world.level.BlockGetter;
import net.minecraft.state.DirectionProperty; import net.minecraft.world.level.Level;
import net.minecraft.state.StateContainer; import net.minecraft.world.level.block.Block;
import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.Direction; import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.level.material.Material;
import net.minecraft.level.IBlockReader; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.level.Level; import net.minecraft.world.phys.shapes.VoxelShape;
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.ToolType;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Random; import java.util.Random;
public class BlockFurnaceHeater extends BlockContainerImpl implements ICustomBlockState { public class BlockFurnaceHeater extends BlockContainerImpl implements ICustomBlockState {
public static final DirectionProperty FACING = BlockStateProperties.FACING; public static final DirectionProperty FACING = BlockStateProperties.FACING;
private static final VoxelShape[] SHAPES = new VoxelShape[]{ private static final VoxelShape[] SHAPES = new VoxelShape[]{
Block.makeCuboidShape(2, 12, 2, 14, 16, 14), // Down box(2, 12, 2, 14, 16, 14), // Down
Block.makeCuboidShape(2, 0, 2, 14, 4, 14), // Up box(2, 0, 2, 14, 4, 14), // Up
Block.makeCuboidShape(2, 2, 12, 14, 14, 16), // North box(2, 2, 12, 14, 14, 16), // North
Block.makeCuboidShape(2, 2, 0, 14, 14, 4), // South box(2, 2, 0, 14, 14, 4), // South
Block.makeCuboidShape(12, 2, 2, 16, 14, 14), // West box(12, 2, 2, 16, 14, 14), // West
Block.makeCuboidShape(0, 2, 2, 4, 14, 14) // East box(0, 2, 2, 4, 14, 14) // East
}; };
public BlockFurnaceHeater() { public BlockFurnaceHeater() {
super("furnace_heater", BlockEntityFurnaceHeater::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).harvestLevel(1).harvestTool(ToolType.PICKAXE)); super("furnace_heater", BlockEntityFurnaceHeater::new, Properties.of(Material.STONE).strength(3F));
} }
@Override @Override
@ -49,9 +49,9 @@ public class BlockFurnaceHeater extends BlockContainerImpl implements ICustomBlo
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) {
BlockEntity tile = levelIn.getBlockEntity(pos); var tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityFurnaceHeater && ((BlockEntityFurnaceHeater) tile).isActive) { if (tile instanceof BlockEntityFurnaceHeater heater && heater.isActive) {
Direction facing = stateIn.get(FACING); var facing = stateIn.getValue(FACING);
float x; float x;
float y; float y;
@ -65,35 +65,35 @@ public class BlockFurnaceHeater extends BlockContainerImpl implements ICustomBlo
y = 1F; y = 1F;
z = 0.35F + rand.nextFloat() * 0.3F; z = 0.35F + rand.nextFloat() * 0.3F;
} else { } else {
x = facing.getZOffset() != 0 ? (0.35F + rand.nextFloat() * 0.3F) : facing.getXOffset() < 0 ? 1 : 0; x = facing.getStepZ() != 0 ? (0.35F + rand.nextFloat() * 0.3F) : facing.getStepX() < 0 ? 1 : 0;
y = 0.35F + rand.nextFloat() * 0.3F; y = 0.35F + rand.nextFloat() * 0.3F;
z = facing.getXOffset() != 0 ? (0.35F + rand.nextFloat() * 0.3F) : facing.getZOffset() < 0 ? 1 : 0; z = facing.getStepX() != 0 ? (0.35F + rand.nextFloat() * 0.3F) : facing.getStepZ() < 0 ? 1 : 0;
} }
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
pos.getX() + x, pos.getY() + y, pos.getZ() + z, pos.getX() + x, pos.getY() + y, pos.getZ() + z,
(rand.nextFloat() * 0.016F + 0.01F) * facing.getXOffset(), (rand.nextFloat() * 0.016F + 0.01F) * facing.getStepX(),
(rand.nextFloat() * 0.016F + 0.01F) * facing.getYOffset(), (rand.nextFloat() * 0.016F + 0.01F) * facing.getStepY(),
(rand.nextFloat() * 0.016F + 0.01F) * facing.getZOffset(), (rand.nextFloat() * 0.016F + 0.01F) * facing.getStepZ(),
0xf46e42, rand.nextFloat() + 0.5F, 55, 0F, true, true); 0xf46e42, rand.nextFloat() + 0.5F, 55, 0F, true, true);
} }
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPES[state.get(FACING).getIndex()]; return SHAPES[state.getValue(FACING).ordinal()];
} }
@Override @Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder); super.createBlockStateDefinition(builder);
builder.add(FACING); builder.add(FACING);
} }
@Nullable @Nullable
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockPlaceContext context) {
return super.getStateForPlacement(context).with(FACING, context.getFace()); return super.getStateForPlacement(context).setValue(FACING, context.getClickedFace());
} }
@Override @Override

View file

@ -1,30 +1,19 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityGeneratorLimitRemover; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityGeneratorLimitRemover;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderGeneratorLimitRemover; import de.ellpeck.naturesaura.blocks.tiles.render.RenderGeneratorLimitRemover;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ITESRProvider; import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.block.SoundType; import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.block.material.Material; import net.minecraft.world.level.block.SoundType;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer; import net.minecraft.world.level.material.Material;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher;
import net.minecraft.tileentity.BlockEntityType;
import net.minecraft.util.Tuple;
import java.util.function.Function;
import java.util.function.Supplier;
public class BlockGeneratorLimitRemover extends BlockContainerImpl implements ITESRProvider<BlockEntityGeneratorLimitRemover>, ICustomBlockState { public class BlockGeneratorLimitRemover extends BlockContainerImpl implements ITESRProvider<BlockEntityGeneratorLimitRemover>, ICustomBlockState {
public BlockGeneratorLimitRemover() { public BlockGeneratorLimitRemover() {
super("generator_limit_remover", BlockEntityGeneratorLimitRemover::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE)); super("generator_limit_remover", BlockEntityGeneratorLimitRemover::new, Properties.of(Material.STONE).strength(2F).sound(SoundType.STONE));
}
@Override
public Tuple<BlockEntityType<BlockEntityGeneratorLimitRemover>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityGeneratorLimitRemover>>>> getTESR() {
return new Tuple<>(ModTileEntities.GENERATOR_LIMIT_REMOVER, () -> RenderGeneratorLimitRemover::new);
} }
@Override @Override
@ -34,4 +23,9 @@ public class BlockGeneratorLimitRemover extends BlockContainerImpl implements IT
generator.modLoc("block/" + this.getBaseName() + "_top"), generator.modLoc("block/" + this.getBaseName() + "_top"),
generator.modLoc("block/" + this.getBaseName() + "_top"))); generator.modLoc("block/" + this.getBaseName() + "_top")));
} }
@Override
public void registerTESR() {
BlockEntityRenderers.register(ModTileEntities.GENERATOR_LIMIT_REMOVER, RenderGeneratorLimitRemover::new);
}
} }

View file

@ -6,104 +6,104 @@ import de.ellpeck.naturesaura.reg.IColorProvidingBlock;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ICustomItemModel; import de.ellpeck.naturesaura.reg.ICustomItemModel;
import de.ellpeck.naturesaura.reg.ICustomRenderType; import de.ellpeck.naturesaura.reg.ICustomRenderType;
import net.minecraft.block.Block; import net.minecraft.client.color.block.BlockColor;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.RedstoneWireBlock;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.color.IBlockColor; import net.minecraft.core.BlockPos;
import net.minecraft.item.BlockItemUseContext; import net.minecraft.core.Direction;
import net.minecraft.state.EnumProperty; import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.state.StateContainer; import net.minecraft.world.level.BlockGetter;
import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.world.level.Level;
import net.minecraft.state.properties.RedstoneSide; import net.minecraft.world.level.LevelAccessor;
import net.minecraft.util.Direction; import net.minecraft.world.level.LevelReader;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.Block;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.world.level.block.Blocks;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.level.block.RedStoneWireBlock;
import net.minecraft.util.math.shapes.Shapes; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.level.IBlockReader; import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.level.ILevel; import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.level.ILevelReader; import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.level.Level; import net.minecraft.world.level.block.state.properties.RedstoneSide;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import java.util.function.Supplier; import java.util.function.Supplier;
public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock, ICustomBlockState, ICustomItemModel, ICustomRenderType { public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock, ICustomBlockState, ICustomItemModel, ICustomRenderType {
public static final EnumProperty<RedstoneSide> NORTH = BlockStateProperties.REDSTONE_NORTH; public static final EnumProperty<RedstoneSide> NORTH = BlockStateProperties.NORTH_REDSTONE;
public static final EnumProperty<RedstoneSide> EAST = BlockStateProperties.REDSTONE_EAST; public static final EnumProperty<RedstoneSide> EAST = BlockStateProperties.EAST_REDSTONE;
public static final EnumProperty<RedstoneSide> SOUTH = BlockStateProperties.REDSTONE_SOUTH; public static final EnumProperty<RedstoneSide> SOUTH = BlockStateProperties.SOUTH_REDSTONE;
public static final EnumProperty<RedstoneSide> WEST = BlockStateProperties.REDSTONE_WEST; public static final EnumProperty<RedstoneSide> WEST = BlockStateProperties.WEST_REDSTONE;
protected static final VoxelShape[] SHAPES = new VoxelShape[]{Block.makeCuboidShape(3.0D, 0.0D, 3.0D, 13.0D, 1.0D, 13.0D), Block.makeCuboidShape(3.0D, 0.0D, 3.0D, 13.0D, 1.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 3.0D, 13.0D, 1.0D, 13.0D), Block.makeCuboidShape(0.0D, 0.0D, 3.0D, 13.0D, 1.0D, 16.0D), Block.makeCuboidShape(3.0D, 0.0D, 0.0D, 13.0D, 1.0D, 13.0D), Block.makeCuboidShape(3.0D, 0.0D, 0.0D, 13.0D, 1.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 13.0D, 1.0D, 13.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 13.0D, 1.0D, 16.0D), Block.makeCuboidShape(3.0D, 0.0D, 3.0D, 16.0D, 1.0D, 13.0D), Block.makeCuboidShape(3.0D, 0.0D, 3.0D, 16.0D, 1.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 3.0D, 16.0D, 1.0D, 13.0D), Block.makeCuboidShape(0.0D, 0.0D, 3.0D, 16.0D, 1.0D, 16.0D), Block.makeCuboidShape(3.0D, 0.0D, 0.0D, 16.0D, 1.0D, 13.0D), Block.makeCuboidShape(3.0D, 0.0D, 0.0D, 16.0D, 1.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 1.0D, 13.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 1.0D, 16.0D)}; protected static final VoxelShape[] SHAPES = new VoxelShape[]{box(3.0D, 0.0D, 3.0D, 13.0D, 1.0D, 13.0D), box(3.0D, 0.0D, 3.0D, 13.0D, 1.0D, 16.0D), box(0.0D, 0.0D, 3.0D, 13.0D, 1.0D, 13.0D), box(0.0D, 0.0D, 3.0D, 13.0D, 1.0D, 16.0D), box(3.0D, 0.0D, 0.0D, 13.0D, 1.0D, 13.0D), box(3.0D, 0.0D, 0.0D, 13.0D, 1.0D, 16.0D), box(0.0D, 0.0D, 0.0D, 13.0D, 1.0D, 13.0D), box(0.0D, 0.0D, 0.0D, 13.0D, 1.0D, 16.0D), box(3.0D, 0.0D, 3.0D, 16.0D, 1.0D, 13.0D), box(3.0D, 0.0D, 3.0D, 16.0D, 1.0D, 16.0D), box(0.0D, 0.0D, 3.0D, 16.0D, 1.0D, 13.0D), box(0.0D, 0.0D, 3.0D, 16.0D, 1.0D, 16.0D), box(3.0D, 0.0D, 0.0D, 16.0D, 1.0D, 13.0D), box(3.0D, 0.0D, 0.0D, 16.0D, 1.0D, 16.0D), box(0.0D, 0.0D, 0.0D, 16.0D, 1.0D, 13.0D), box(0.0D, 0.0D, 0.0D, 16.0D, 1.0D, 16.0D)};
public BlockGoldPowder() { public BlockGoldPowder() {
super("gold_powder", Properties.from(Blocks.REDSTONE_WIRE)); super("gold_powder", Properties.copy(Blocks.REDSTONE_WIRE));
this.setDefaultState(this.stateContainer.getBaseState().with(NORTH, RedstoneSide.NONE).with(EAST, RedstoneSide.NONE).with(SOUTH, RedstoneSide.NONE).with(WEST, RedstoneSide.NONE)); this.registerDefaultState(this.defaultBlockState().setValue(NORTH, RedstoneSide.NONE).setValue(EAST, RedstoneSide.NONE).setValue(SOUTH, RedstoneSide.NONE).setValue(WEST, RedstoneSide.NONE));
} }
private static int getShapeIndex(BlockState state) { private static int getShapeIndex(BlockState state) {
int i = 0; var i = 0;
boolean n = state.get(NORTH) != RedstoneSide.NONE; var n = state.getValue(NORTH) != RedstoneSide.NONE;
boolean e = state.get(EAST) != RedstoneSide.NONE; var e = state.getValue(EAST) != RedstoneSide.NONE;
boolean s = state.get(SOUTH) != RedstoneSide.NONE; var s = state.getValue(SOUTH) != RedstoneSide.NONE;
boolean w = state.get(WEST) != RedstoneSide.NONE; var w = state.getValue(WEST) != RedstoneSide.NONE;
if (n || s && !n && !e && !w) { if (n || s && !n && !e && !w) {
i |= 1 << Direction.NORTH.getHorizontalIndex(); i |= 1 << Direction.NORTH.ordinal();
} }
if (e || w && !n && !e && !s) { if (e || w && !n && !e && !s) {
i |= 1 << Direction.EAST.getHorizontalIndex(); i |= 1 << Direction.EAST.ordinal();
} }
if (s || n && !e && !s && !w) { if (s || n && !e && !s && !w) {
i |= 1 << Direction.SOUTH.getHorizontalIndex(); i |= 1 << Direction.SOUTH.ordinal();
} }
if (w || e && !n && !s && !w) { if (w || e && !n && !s && !w) {
i |= 1 << Direction.WEST.getHorizontalIndex(); i |= 1 << Direction.WEST.ordinal();
} }
return i; return i;
} }
@Override @Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(NORTH, EAST, SOUTH, WEST); builder.add(NORTH, EAST, SOUTH, WEST);
} }
@Override @Override
public IBlockColor getBlockColor() { public BlockColor getBlockColor() {
return (state, levelIn, pos, tintIndex) -> 0xf4cb42; return (state, levelIn, pos, tintIndex) -> 0xf4cb42;
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPES[getShapeIndex(state)]; return SHAPES[getShapeIndex(state)];
} }
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockPlaceContext context) {
IBlockReader iblockreader = context.getLevel(); BlockGetter iblockreader = context.getLevel();
BlockPos blockpos = context.getPos(); var blockpos = context.getClickedPos();
return this.getDefaultState().with(WEST, this.getSide(iblockreader, blockpos, Direction.WEST)).with(EAST, this.getSide(iblockreader, blockpos, Direction.EAST)).with(NORTH, this.getSide(iblockreader, blockpos, Direction.NORTH)).with(SOUTH, this.getSide(iblockreader, blockpos, Direction.SOUTH)); return this.defaultBlockState().setValue(WEST, this.getSide(iblockreader, blockpos, Direction.WEST)).setValue(EAST, this.getSide(iblockreader, blockpos, Direction.EAST)).setValue(NORTH, this.getSide(iblockreader, blockpos, Direction.NORTH)).setValue(SOUTH, this.getSide(iblockreader, blockpos, Direction.SOUTH));
} }
@Override @Override
public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, ILevel levelIn, BlockPos currentPos, BlockPos facingPos) { public BlockState updateShape(BlockState stateIn, Direction facing, BlockState facingState, LevelAccessor levelIn, BlockPos currentPos, BlockPos facingPos) {
if (facing == Direction.DOWN) { if (facing == Direction.DOWN) {
return stateIn; return stateIn;
} else { } else {
return facing == Direction.UP ? stateIn.with(WEST, this.getSide(levelIn, currentPos, Direction.WEST)).with(EAST, this.getSide(levelIn, currentPos, Direction.EAST)).with(NORTH, this.getSide(levelIn, currentPos, Direction.NORTH)).with(SOUTH, this.getSide(levelIn, currentPos, Direction.SOUTH)) : stateIn.with(RedstoneWireBlock.FACING_PROPERTY_MAP.get(facing), this.getSide(levelIn, currentPos, facing)); return facing == Direction.UP ? stateIn.setValue(WEST, this.getSide(levelIn, currentPos, Direction.WEST)).setValue(EAST, this.getSide(levelIn, currentPos, Direction.EAST)).setValue(NORTH, this.getSide(levelIn, currentPos, Direction.NORTH)).setValue(SOUTH, this.getSide(levelIn, currentPos, Direction.SOUTH)) : stateIn.setValue(RedStoneWireBlock.PROPERTY_BY_DIRECTION.get(facing), this.getSide(levelIn, currentPos, facing));
} }
} }
private RedstoneSide getSide(IBlockReader levelIn, BlockPos pos, Direction face) { private RedstoneSide getSide(BlockGetter levelIn, BlockPos pos, Direction face) {
BlockPos blockpos = pos.offset(face); var blockpos = pos.relative(face);
BlockState blockstate = levelIn.getBlockState(blockpos); var blockstate = levelIn.getBlockState(blockpos);
BlockPos blockpos1 = pos.up(); var blockpos1 = pos.above();
BlockState blockstate1 = levelIn.getBlockState(blockpos1); var blockstate1 = levelIn.getBlockState(blockpos1);
if (!blockstate1.isNormalCube(levelIn, blockpos1)) { if (!blockstate1.isCollisionShapeFullBlock(levelIn, blockpos1)) {
boolean flag = blockstate.isSolidSide(levelIn, blockpos, Direction.UP) || blockstate.getBlock() == Blocks.HOPPER; var flag = blockstate.isFaceSturdy(levelIn, blockpos, Direction.UP) || blockstate.getBlock() == Blocks.HOPPER;
if (flag && this.canConnectTo(levelIn.getBlockState(blockpos.up()))) { if (flag && this.canConnectTo(levelIn.getBlockState(blockpos.above()))) {
if (blockstate.hasOpaqueCollisionShape(levelIn, blockpos)) { if (blockstate.isCollisionShapeFullBlock(levelIn, blockpos)) {
return RedstoneSide.UP; return RedstoneSide.UP;
} }
@ -111,41 +111,41 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
} }
} }
return !this.canConnectTo(blockstate) && (blockstate.isNormalCube(levelIn, blockpos) || !this.canConnectTo(levelIn.getBlockState(blockpos.down()))) ? RedstoneSide.NONE : RedstoneSide.SIDE; return !this.canConnectTo(blockstate) && (blockstate.isCollisionShapeFullBlock(levelIn, blockpos) || !this.canConnectTo(levelIn.getBlockState(blockpos.below()))) ? RedstoneSide.NONE : RedstoneSide.SIDE;
} }
protected boolean canConnectTo(BlockState blockState) { protected boolean canConnectTo(BlockState blockState) {
Block block = blockState.getBlock(); var block = blockState.getBlock();
return block == this; return block == this;
} }
@Override @Override
public boolean isValidPosition(BlockState state, ILevelReader levelIn, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader levelIn, BlockPos pos) {
BlockPos blockpos = pos.down(); var blockpos = pos.below();
BlockState blockstate = levelIn.getBlockState(blockpos); var blockstate = levelIn.getBlockState(blockpos);
return blockstate.isSolidSide(levelIn, blockpos, Direction.UP) || blockstate.getBlock() == Blocks.HOPPER; return blockstate.isFaceSturdy(levelIn, blockpos, Direction.UP) || blockstate.getBlock() == Blocks.HOPPER;
} }
@Override @Override
public VoxelShape getCollisionShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getCollisionShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return Shapes.empty(); return Shapes.empty();
} }
@Override @Override
public void onBlockAdded(BlockState state, Level levelIn, BlockPos pos, BlockState oldState, boolean isMoving) { public void onPlace(BlockState state, Level levelIn, BlockPos pos, BlockState oldState, boolean isMoving) {
if (oldState.getBlock() != state.getBlock() && !levelIn.isClientSide) { if (oldState.getBlock() != state.getBlock() && !levelIn.isClientSide) {
for (Direction direction : Direction.Plane.VERTICAL) { for (var direction : Direction.Plane.VERTICAL) {
levelIn.notifyNeighborsOfStateChange(pos.offset(direction), this); levelIn.updateNeighborsAt(pos.relative(direction), this);
} }
for (Direction direction1 : Direction.Plane.HORIZONTAL) { for (var direction1 : Direction.Plane.HORIZONTAL) {
this.notifyWireNeighborsOfStateChange(levelIn, pos.offset(direction1)); this.notifyWireNeighborsOfStateChange(levelIn, pos.relative(direction1));
} }
for (Direction direction2 : Direction.Plane.HORIZONTAL) { for (var direction2 : Direction.Plane.HORIZONTAL) {
BlockPos blockpos = pos.offset(direction2); var blockpos = pos.relative(direction2);
if (levelIn.getBlockState(blockpos).isNormalCube(levelIn, blockpos)) { if (levelIn.getBlockState(blockpos).isCollisionShapeFullBlock(levelIn, blockpos)) {
this.notifyWireNeighborsOfStateChange(levelIn, blockpos.up()); this.notifyWireNeighborsOfStateChange(levelIn, blockpos.above());
} else { } else {
this.notifyWireNeighborsOfStateChange(levelIn, blockpos.down()); this.notifyWireNeighborsOfStateChange(levelIn, blockpos.below());
} }
} }
@ -153,22 +153,22 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
} }
@Override @Override
public void onReplaced(BlockState state, Level levelIn, BlockPos pos, BlockState newState, boolean isMoving) { public void onRemove(BlockState state, Level levelIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (!isMoving && state.getBlock() != newState.getBlock()) { if (!isMoving && state.getBlock() != newState.getBlock()) {
super.onReplaced(state, levelIn, pos, newState, isMoving); super.onRemove(state, levelIn, pos, newState, isMoving);
if (!levelIn.isClientSide) { if (!levelIn.isClientSide) {
for (Direction direction : Direction.values()) { for (var direction : Direction.values()) {
levelIn.notifyNeighborsOfStateChange(pos.offset(direction), this); levelIn.updateNeighborsAt(pos.relative(direction), this);
} }
for (Direction direction1 : Direction.Plane.HORIZONTAL) { for (var direction1 : Direction.Plane.HORIZONTAL) {
this.notifyWireNeighborsOfStateChange(levelIn, pos.offset(direction1)); this.notifyWireNeighborsOfStateChange(levelIn, pos.relative(direction1));
} }
for (Direction direction2 : Direction.Plane.HORIZONTAL) { for (var direction2 : Direction.Plane.HORIZONTAL) {
BlockPos blockpos = pos.offset(direction2); var blockpos = pos.relative(direction2);
if (levelIn.getBlockState(blockpos).isNormalCube(levelIn, blockpos)) { if (levelIn.getBlockState(blockpos).isCollisionShapeFullBlock(levelIn, blockpos)) {
this.notifyWireNeighborsOfStateChange(levelIn, blockpos.up()); this.notifyWireNeighborsOfStateChange(levelIn, blockpos.above());
} else { } else {
this.notifyWireNeighborsOfStateChange(levelIn, blockpos.down()); this.notifyWireNeighborsOfStateChange(levelIn, blockpos.below());
} }
} }
@ -179,33 +179,33 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
@Override @Override
public void neighborChanged(BlockState state, Level levelIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) { public void neighborChanged(BlockState state, Level levelIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) {
if (!levelIn.isClientSide) { if (!levelIn.isClientSide) {
if (!state.isValidPosition(levelIn, pos)) { if (!state.canSurvive(levelIn, pos)) {
spawnDrops(state, levelIn, pos); dropResources(state, levelIn, pos);
levelIn.removeBlock(pos, false); levelIn.removeBlock(pos, false);
} }
} }
} }
@Override @Override
public void updateDiagonalNeighbors(BlockState state, ILevel levelIn, BlockPos pos, int flags, int recursionLeft) { public void updateIndirectNeighbourShapes(BlockState state, LevelAccessor levelIn, BlockPos pos, int flags, int recursionLeft) {
BlockPos.Mutable pool = new BlockPos.Mutable(); var pool = new BlockPos.MutableBlockPos();
for (Direction direction : Direction.Plane.HORIZONTAL) { for (var direction : Direction.Plane.HORIZONTAL) {
RedstoneSide redstoneside = state.get(RedstoneWireBlock.FACING_PROPERTY_MAP.get(direction)); var redstoneside = state.getValue(RedStoneWireBlock.PROPERTY_BY_DIRECTION.get(direction));
if (redstoneside != RedstoneSide.NONE && levelIn.getBlockState(pool.setPos(pos).move(direction)).getBlock() != this) { if (redstoneside != RedstoneSide.NONE && levelIn.getBlockState(pool.set(pos).move(direction)).getBlock() != this) {
pool.move(Direction.DOWN); pool.move(Direction.DOWN);
BlockState blockstate = levelIn.getBlockState(pool); var blockstate = levelIn.getBlockState(pool);
if (blockstate.getBlock() != Blocks.OBSERVER) { if (blockstate.getBlock() != Blocks.OBSERVER) {
BlockPos blockpos = pool.offset(direction.getOpposite()); var blockpos = pool.relative(direction.getOpposite());
BlockState blockstate1 = blockstate.updatePostPlacement(direction.getOpposite(), levelIn.getBlockState(blockpos), levelIn, pool, blockpos); var blockstate1 = blockstate.updateShape(direction.getOpposite(), levelIn.getBlockState(blockpos), levelIn, pool, blockpos);
replaceBlock(blockstate, blockstate1, levelIn, pool, flags); updateOrDestroy(blockstate, blockstate1, levelIn, pool, flags);
} }
pool.setPos(pos).move(direction).move(Direction.UP); pool.set(pos).move(direction).move(Direction.UP);
BlockState blockstate3 = levelIn.getBlockState(pool); var blockstate3 = levelIn.getBlockState(pool);
if (blockstate3.getBlock() != Blocks.OBSERVER) { if (blockstate3.getBlock() != Blocks.OBSERVER) {
BlockPos blockpos1 = pool.offset(direction.getOpposite()); var blockpos1 = pool.relative(direction.getOpposite());
BlockState blockstate2 = blockstate3.updatePostPlacement(direction.getOpposite(), levelIn.getBlockState(blockpos1), levelIn, pool, blockpos1); var blockstate2 = blockstate3.updateShape(direction.getOpposite(), levelIn.getBlockState(blockpos1), levelIn, pool, blockpos1);
replaceBlock(blockstate3, blockstate2, levelIn, pool, flags); updateOrDestroy(blockstate3, blockstate2, levelIn, pool, flags);
} }
} }
} }
@ -214,10 +214,10 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
private void notifyWireNeighborsOfStateChange(Level levelIn, BlockPos pos) { private void notifyWireNeighborsOfStateChange(Level levelIn, BlockPos pos) {
if (levelIn.getBlockState(pos).getBlock() == this) { if (levelIn.getBlockState(pos).getBlock() == this) {
levelIn.notifyNeighborsOfStateChange(pos, this); levelIn.updateNeighborsAt(pos, this);
for (Direction direction : Direction.values()) { for (var direction : Direction.values()) {
levelIn.notifyNeighborsOfStateChange(pos.offset(direction), this); levelIn.updateNeighborsAt(pos.relative(direction), this);
} }
} }
} }
@ -234,6 +234,6 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
@Override @Override
public Supplier<RenderType> getRenderType() { public Supplier<RenderType> getRenderType() {
return RenderType::getCutoutMipped; return RenderType::cutoutMipped;
} }
} }

View file

@ -4,21 +4,21 @@ import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
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.Block; import net.minecraft.client.color.block.BlockColor;
import net.minecraft.block.BlockState; import net.minecraft.client.color.item.ItemColor;
import net.minecraft.block.LeavesBlock; import net.minecraft.client.renderer.BiomeColors;
import net.minecraft.block.SoundType; import net.minecraft.core.BlockPos;
import net.minecraft.block.material.Material; import net.minecraft.core.Direction;
import net.minecraft.block.material.MaterialColor; import net.minecraft.server.level.ServerLevel;
import net.minecraft.client.renderer.color.IBlockColor; import net.minecraft.world.level.Level;
import net.minecraft.client.renderer.color.IItemColor; import net.minecraft.world.level.block.Block;
import net.minecraft.state.IntegerProperty; import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.state.StateContainer; import net.minecraft.world.level.block.SoundType;
import net.minecraft.util.Direction; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.level.Level; import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.level.biome.BiomeColors; import net.minecraft.world.level.material.Material;
import net.minecraft.level.server.ServerLevel; 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;
@ -30,17 +30,17 @@ public class BlockGoldenLeaves extends LeavesBlock implements IModItem, IColorPr
public static final IntegerProperty STAGE = IntegerProperty.create("stage", 0, HIGHEST_STAGE); public static final IntegerProperty STAGE = IntegerProperty.create("stage", 0, HIGHEST_STAGE);
public BlockGoldenLeaves() { public BlockGoldenLeaves() {
super(Properties.create(Material.LEAVES, MaterialColor.GOLD).hardnessAndResistance(0.2F).tickRandomly().notSolid().sound(SoundType.PLANT)); super(Properties.of(Material.LEAVES, MaterialColor.GOLD).strength(0.2F).randomTicks().noCollission().sound(SoundType.GRASS));
ModRegistry.add(this); ModRegistry.add(this);
} }
public static boolean convert(Level level, BlockPos pos) { public static boolean convert(Level level, BlockPos pos) {
BlockState state = level.getBlockState(pos); var state = level.getBlockState(pos);
if (state.getBlock() instanceof LeavesBlock && !(state.getBlock() instanceof BlockAncientLeaves || state.getBlock() instanceof BlockGoldenLeaves)) { if (state.getBlock() instanceof LeavesBlock && !(state.getBlock() instanceof BlockAncientLeaves || state.getBlock() instanceof BlockGoldenLeaves)) {
if (!level.isClientSide) { if (!level.isClientSide) {
level.setBlockState(pos, ModBlocks.GOLDEN_LEAVES.getDefaultState() level.setBlockAndUpdate(pos, ModBlocks.GOLDEN_LEAVES.defaultBlockState()
.with(DISTANCE, state.hasProperty(DISTANCE) ? state.get(DISTANCE) : 1) .setValue(DISTANCE, state.hasProperty(DISTANCE) ? state.getValue(DISTANCE) : 1)
.with(PERSISTENT, state.hasProperty(PERSISTENT) ? state.get(PERSISTENT) : false)); .setValue(PERSISTENT, state.hasProperty(PERSISTENT) ? state.getValue(PERSISTENT) : false));
} }
return true; return true;
} }
@ -55,7 +55,7 @@ public class BlockGoldenLeaves extends LeavesBlock implements IModItem, IColorPr
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) {
if (stateIn.get(STAGE) == HIGHEST_STAGE && rand.nextFloat() >= 0.75F) if (stateIn.getValue(STAGE) == HIGHEST_STAGE && rand.nextFloat() >= 0.75F)
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
pos.getX() + rand.nextFloat(), pos.getX() + rand.nextFloat(),
pos.getY() + rand.nextFloat(), pos.getY() + rand.nextFloat(),
@ -65,19 +65,19 @@ public class BlockGoldenLeaves extends LeavesBlock implements IModItem, IColorPr
} }
@Override @Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder); super.createBlockStateDefinition(builder);
builder.add(STAGE); builder.add(STAGE);
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public IBlockColor getBlockColor() { public BlockColor getBlockColor() {
return (state, levelIn, pos, tintIndex) -> { return (state, levelIn, pos, tintIndex) -> {
int color = 0xF2FF00; var color = 0xF2FF00;
if (state != null && levelIn != null && pos != null) { if (state != null && levelIn != null && pos != null) {
int foliage = BiomeColors.getFoliageColor(levelIn, pos); var foliage = BiomeColors.getAverageFoliageColor(levelIn, pos);
return Helper.blendColors(color, foliage, state.get(STAGE) / (float) HIGHEST_STAGE); return Helper.blendColors(color, foliage, state.getValue(STAGE) / (float) HIGHEST_STAGE);
} else { } else {
return color; return color;
} }
@ -86,7 +86,7 @@ public class BlockGoldenLeaves extends LeavesBlock implements IModItem, IColorPr
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public IItemColor getItemColor() { public ItemColor getItemColor() {
return (stack, tintIndex) -> 0xF2FF00; return (stack, tintIndex) -> 0xF2FF00;
} }
@ -94,21 +94,21 @@ public class BlockGoldenLeaves extends LeavesBlock implements IModItem, IColorPr
public void randomTick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) {
super.randomTick(state, levelIn, pos, random); super.randomTick(state, levelIn, pos, random);
if (!levelIn.isClientSide) { if (!levelIn.isClientSide) {
int stage = state.get(STAGE); int stage = state.getValue(STAGE);
if (stage < HIGHEST_STAGE) { if (stage < HIGHEST_STAGE) {
levelIn.setBlockState(pos, state.with(STAGE, stage + 1)); levelIn.setBlockAndUpdate(pos, state.setValue(STAGE, stage + 1));
} }
if (stage > 1) { if (stage > 1) {
BlockPos offset = pos.offset(Direction.func_239631_a_(random)); var offset = pos.relative(Direction.getRandom(random));
if (levelIn.isBlockLoaded(offset)) if (levelIn.isLoaded(offset))
convert(levelIn, offset); convert(levelIn, offset);
} }
} }
} }
@Override @Override
public boolean ticksRandomly(BlockState state) { public boolean isRandomlyTicking(BlockState p_54449_) {
return true; return true;
} }

View file

@ -5,27 +5,31 @@ import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.data.ItemModelGenerator; import de.ellpeck.naturesaura.data.ItemModelGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ICustomItemModel; import de.ellpeck.naturesaura.reg.ICustomItemModel;
import net.minecraft.block.*; import net.minecraft.core.BlockPos;
import net.minecraft.block.material.Material; import net.minecraft.core.Direction;
import net.minecraft.entity.player.Player; import net.minecraft.util.Mth;
import net.minecraft.item.BlockItemUseContext; import net.minecraft.world.InteractionHand;
import net.minecraft.item.ItemStack; import net.minecraft.world.InteractionResult;
import net.minecraft.state.DirectionProperty; import net.minecraft.world.entity.player.Player;
import net.minecraft.state.StateContainer; import net.minecraft.world.item.ItemStack;
import net.minecraft.tileentity.IHopper; import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.world.level.BlockGetter;
import net.minecraft.util.InteractionResult; import net.minecraft.world.level.Level;
import net.minecraft.util.Direction; import net.minecraft.world.level.block.Block;
import net.minecraft.util.Hand; import net.minecraft.world.level.block.HopperBlock;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.RenderShape;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.world.level.block.SoundType;
import net.minecraft.util.math.Mth; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.util.math.shapes.IBooleanFunction; import net.minecraft.world.level.block.entity.Hopper;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.util.math.shapes.Shapes; import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.level.IBlockReader; import net.minecraft.world.level.material.Material;
import net.minecraft.level.Level; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -33,23 +37,23 @@ import javax.annotation.Nullable;
public class BlockGratedChute extends BlockContainerImpl implements ICustomBlockState, ICustomItemModel { public class BlockGratedChute extends BlockContainerImpl implements ICustomBlockState, ICustomItemModel {
public static final DirectionProperty FACING = HopperBlock.FACING; public static final DirectionProperty FACING = HopperBlock.FACING;
private static final VoxelShape INPUT_SHAPE = Block.makeCuboidShape(0.0D, 10.0D, 0.0D, 16.0D, 16.0D, 16.0D); private static final VoxelShape INPUT_SHAPE = box(0.0D, 10.0D, 0.0D, 16.0D, 16.0D, 16.0D);
private static final VoxelShape MIDDLE_SHAPE = Block.makeCuboidShape(4.0D, 4.0D, 4.0D, 12.0D, 10.0D, 12.0D); private static final VoxelShape MIDDLE_SHAPE = box(4.0D, 4.0D, 4.0D, 12.0D, 10.0D, 12.0D);
private static final VoxelShape INPUT_MIDDLE_SHAPE = Shapes.or(MIDDLE_SHAPE, INPUT_SHAPE); private static final VoxelShape INPUT_MIDDLE_SHAPE = Shapes.or(MIDDLE_SHAPE, INPUT_SHAPE);
private static final VoxelShape COMBINED_SHAPE = Shapes.combineAndSimplify(INPUT_MIDDLE_SHAPE, IHopper.INSIDE_BOWL_SHAPE, IBooleanFunction.ONLY_FIRST); private static final VoxelShape COMBINED_SHAPE = Shapes.join(INPUT_MIDDLE_SHAPE, Hopper.INSIDE, BooleanOp.ONLY_FIRST);
private static final VoxelShape DOWN_SHAPE = Shapes.or(COMBINED_SHAPE, Block.makeCuboidShape(6.0D, 0.0D, 6.0D, 10.0D, 4.0D, 10.0D)); private static final VoxelShape DOWN_SHAPE = Shapes.or(COMBINED_SHAPE, box(6.0D, 0.0D, 6.0D, 10.0D, 4.0D, 10.0D));
private static final VoxelShape EAST_SHAPE = Shapes.or(COMBINED_SHAPE, Block.makeCuboidShape(12.0D, 4.0D, 6.0D, 16.0D, 8.0D, 10.0D)); private static final VoxelShape EAST_SHAPE = Shapes.or(COMBINED_SHAPE, box(12.0D, 4.0D, 6.0D, 16.0D, 8.0D, 10.0D));
private static final VoxelShape NORTH_SHAPE = Shapes.or(COMBINED_SHAPE, Block.makeCuboidShape(6.0D, 4.0D, 0.0D, 10.0D, 8.0D, 4.0D)); private static final VoxelShape NORTH_SHAPE = Shapes.or(COMBINED_SHAPE, box(6.0D, 4.0D, 0.0D, 10.0D, 8.0D, 4.0D));
private static final VoxelShape SOUTH_SHAPE = Shapes.or(COMBINED_SHAPE, Block.makeCuboidShape(6.0D, 4.0D, 12.0D, 10.0D, 8.0D, 16.0D)); private static final VoxelShape SOUTH_SHAPE = Shapes.or(COMBINED_SHAPE, box(6.0D, 4.0D, 12.0D, 10.0D, 8.0D, 16.0D));
private static final VoxelShape WEST_SHAPE = Shapes.or(COMBINED_SHAPE, Block.makeCuboidShape(0.0D, 4.0D, 6.0D, 4.0D, 8.0D, 10.0D)); private static final VoxelShape WEST_SHAPE = Shapes.or(COMBINED_SHAPE, box(0.0D, 4.0D, 6.0D, 4.0D, 8.0D, 10.0D));
private static final VoxelShape DOWN_RAYTRACE_SHAPE = IHopper.INSIDE_BOWL_SHAPE; private static final VoxelShape DOWN_RAYTRACE_SHAPE = Hopper.INSIDE;
private static final VoxelShape EAST_RAYTRACE_SHAPE = Shapes.or(IHopper.INSIDE_BOWL_SHAPE, Block.makeCuboidShape(12.0D, 8.0D, 6.0D, 16.0D, 10.0D, 10.0D)); private static final VoxelShape EAST_RAYTRACE_SHAPE = Shapes.or(Hopper.INSIDE, box(12.0D, 8.0D, 6.0D, 16.0D, 10.0D, 10.0D));
private static final VoxelShape NORTH_RAYTRACE_SHAPE = Shapes.or(IHopper.INSIDE_BOWL_SHAPE, Block.makeCuboidShape(6.0D, 8.0D, 0.0D, 10.0D, 10.0D, 4.0D)); private static final VoxelShape NORTH_RAYTRACE_SHAPE = Shapes.or(Hopper.INSIDE, box(6.0D, 8.0D, 0.0D, 10.0D, 10.0D, 4.0D));
private static final VoxelShape SOUTH_RAYTRACE_SHAPE = Shapes.or(IHopper.INSIDE_BOWL_SHAPE, Block.makeCuboidShape(6.0D, 8.0D, 12.0D, 10.0D, 10.0D, 16.0D)); private static final VoxelShape SOUTH_RAYTRACE_SHAPE = Shapes.or(Hopper.INSIDE, box(6.0D, 8.0D, 12.0D, 10.0D, 10.0D, 16.0D));
private static final VoxelShape WEST_RAYTRACE_SHAPE = Shapes.or(IHopper.INSIDE_BOWL_SHAPE, Block.makeCuboidShape(0.0D, 8.0D, 6.0D, 4.0D, 10.0D, 10.0D)); private static final VoxelShape WEST_RAYTRACE_SHAPE = Shapes.or(Hopper.INSIDE, box(0.0D, 8.0D, 6.0D, 4.0D, 10.0D, 10.0D));
public BlockGratedChute() { public BlockGratedChute() {
super("grated_chute", BlockEntityGratedChute::new, Properties.create(Material.IRON).hardnessAndResistance(3.0F, 8.0F).sound(SoundType.METAL)); super("grated_chute", BlockEntityGratedChute::new, Properties.of(Material.METAL).strength(3.0F, 8.0F).sound(SoundType.METAL));
} }
@Override @Override
@ -58,50 +62,37 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
switch (state.get(FACING)) { return switch (state.getValue(FACING)) {
case DOWN: case DOWN -> DOWN_SHAPE;
return DOWN_SHAPE; case NORTH -> NORTH_SHAPE;
case NORTH: case SOUTH -> SOUTH_SHAPE;
return NORTH_SHAPE; case WEST -> WEST_SHAPE;
case SOUTH: case EAST -> EAST_SHAPE;
return SOUTH_SHAPE; default -> COMBINED_SHAPE;
case WEST: };
return WEST_SHAPE;
case EAST:
return EAST_SHAPE;
default:
return COMBINED_SHAPE;
}
} }
@Override @Override
public VoxelShape getRaytraceShape(BlockState state, IBlockReader levelIn, BlockPos pos) { public VoxelShape getInteractionShape(BlockState state, BlockGetter levelIn, BlockPos pos) {
switch (state.get(FACING)) { return switch (state.getValue(FACING)) {
case DOWN: case DOWN -> DOWN_RAYTRACE_SHAPE;
return DOWN_RAYTRACE_SHAPE; case NORTH -> NORTH_RAYTRACE_SHAPE;
case NORTH: case SOUTH -> SOUTH_RAYTRACE_SHAPE;
return NORTH_RAYTRACE_SHAPE; case WEST -> WEST_RAYTRACE_SHAPE;
case SOUTH: case EAST -> EAST_RAYTRACE_SHAPE;
return SOUTH_RAYTRACE_SHAPE; default -> Hopper.INSIDE;
case WEST: };
return WEST_RAYTRACE_SHAPE;
case EAST:
return EAST_RAYTRACE_SHAPE;
default:
return IHopper.INSIDE_BOWL_SHAPE;
}
} }
@Override @Override
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult hit) { public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
if (!player.isSneaking()) if (!player.isCrouching())
return InteractionResult.FAIL; return InteractionResult.FAIL;
BlockEntity tile = levelIn.getBlockEntity(pos); var tile = levelIn.getBlockEntity(pos);
if (!(tile instanceof BlockEntityGratedChute)) if (!(tile instanceof BlockEntityGratedChute chute))
return InteractionResult.FAIL; return InteractionResult.FAIL;
if (!levelIn.isClientSide) { if (!levelIn.isClientSide) {
BlockEntityGratedChute chute = (BlockEntityGratedChute) tile;
chute.isBlacklist = !chute.isBlacklist; chute.isBlacklist = !chute.isBlacklist;
chute.sendToClients(); chute.sendToClients();
} }
@ -110,29 +101,29 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
@Nullable @Nullable
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockPlaceContext context) {
Direction newFacing = context.getFace().getOpposite(); var newFacing = context.getClickedFace().getOpposite();
if (newFacing == Direction.UP) if (newFacing == Direction.UP)
newFacing = Direction.DOWN; newFacing = Direction.DOWN;
return super.getStateForPlacement(context).with(FACING, newFacing); return super.getStateForPlacement(context).setValue(FACING, newFacing);
} }
@Override @Override
public BlockRenderType getRenderType(BlockState state) { public RenderShape getRenderShape(BlockState state) {
return BlockRenderType.MODEL; return RenderShape.MODEL;
} }
@Override @Override
public boolean hasComparatorInputOverride(BlockState state) { public boolean hasAnalogOutputSignal(BlockState p_60457_) {
return true; return true;
} }
@Override @Override
public int getComparatorInputOverride(BlockState blockState, Level levelIn, BlockPos pos) { public int getAnalogOutputSignal(BlockState blockState, Level levelIn, BlockPos pos) {
BlockEntity tile = levelIn.getBlockEntity(pos); var tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityGratedChute) { if (tile instanceof BlockEntityGratedChute) {
IItemHandler handler = ((BlockEntityGratedChute) tile).getItemHandler(); IItemHandler handler = ((BlockEntityGratedChute) tile).getItemHandler();
ItemStack stack = handler.getStackInSlot(0); var stack = handler.getStackInSlot(0);
if (stack.isEmpty()) if (stack.isEmpty())
return 0; return 0;
return Mth.ceil(stack.getCount() / (float) stack.getMaxStackSize() * 15); return Mth.ceil(stack.getCount() / (float) stack.getMaxStackSize() * 15);
@ -141,8 +132,8 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
} }
@Override @Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder); super.createBlockStateDefinition(builder);
builder.add(FACING); builder.add(FACING);
} }

View file

@ -2,23 +2,24 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.api.render.IVisualizable; import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityHopperUpgrade; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityHopperUpgrade;
import net.minecraft.block.SoundType; import net.minecraft.core.BlockPos;
import net.minecraft.block.material.Material; import net.minecraft.world.level.Level;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.level.block.SoundType;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.material.Material;
import net.minecraft.level.Level; import net.minecraft.world.phys.AABB;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
public class BlockHopperUpgrade extends BlockContainerImpl implements IVisualizable { public class BlockHopperUpgrade extends BlockContainerImpl implements IVisualizable {
public BlockHopperUpgrade() { public BlockHopperUpgrade() {
super("hopper_upgrade", BlockEntityHopperUpgrade::new, Properties.create(Material.IRON).hardnessAndResistance(2.5F).sound(SoundType.METAL)); super("hopper_upgrade", BlockEntityHopperUpgrade::new, Properties.of(Material.METAL).strength(2.5F).sound(SoundType.METAL));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AABB getVisualizationBounds(Level level, BlockPos pos) {
return new AxisAlignedBB(pos).grow(7); return new AABB(pos).inflate(7);
} }
@Override @Override

View file

@ -3,31 +3,31 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityItemDistributor; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityItemDistributor;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.BlockState; import net.minecraft.core.BlockPos;
import net.minecraft.block.Blocks; import net.minecraft.world.InteractionHand;
import net.minecraft.entity.player.Player; import net.minecraft.world.InteractionResult;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.world.entity.player.Player;
import net.minecraft.util.InteractionResult; import net.minecraft.world.level.Level;
import net.minecraft.util.Hand; import net.minecraft.world.level.block.Blocks;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.level.Level; import net.minecraft.world.phys.BlockHitResult;
public class BlockItemDistributor extends BlockContainerImpl implements ICustomBlockState { public class BlockItemDistributor extends BlockContainerImpl implements ICustomBlockState {
public BlockItemDistributor() { public BlockItemDistributor() {
super("item_distributor", BlockEntityItemDistributor::new, Properties.from(Blocks.STONE_BRICKS)); super("item_distributor", BlockEntityItemDistributor::new, Properties.copy(Blocks.STONE_BRICKS));
} }
@Override @Override
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult hit) { public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
if (!player.isSneaking()) if (!player.isCrouching())
return InteractionResult.FAIL; return InteractionResult.FAIL;
BlockEntity tile = levelIn.getBlockEntity(pos); var tile = levelIn.getBlockEntity(pos);
if (!(tile instanceof BlockEntityItemDistributor)) if (!(tile instanceof BlockEntityItemDistributor))
return InteractionResult.FAIL; return InteractionResult.FAIL;
if (!levelIn.isClientSide) { if (!levelIn.isClientSide) {
BlockEntityItemDistributor distributor = (BlockEntityItemDistributor) tile; var distributor = (BlockEntityItemDistributor) tile;
distributor.isRandomMode = !distributor.isRandomMode; distributor.isRandomMode = !distributor.isRandomMode;
distributor.sendToClients(); distributor.sendToClients();
} }

View file

@ -5,15 +5,15 @@ import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ICustomRenderType; import de.ellpeck.naturesaura.reg.ICustomRenderType;
import de.ellpeck.naturesaura.reg.INoItemBlock; import de.ellpeck.naturesaura.reg.INoItemBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.item.BlockItemUseContext; import net.minecraft.core.BlockPos;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.world.level.BlockGetter;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.level.Level;
import net.minecraft.level.IBlockReader; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.level.Level; import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@ -22,16 +22,16 @@ import java.util.function.Supplier;
public class BlockLight extends BlockImpl implements ICustomBlockState, INoItemBlock, ICustomRenderType { public class BlockLight extends BlockImpl implements ICustomBlockState, INoItemBlock, ICustomRenderType {
private static final VoxelShape SHAPE = makeCuboidShape(4, 4, 4, 12, 12, 12); private static final VoxelShape SHAPE = box(4, 4, 4, 12, 12, 12);
public BlockLight() { public BlockLight() {
super("light", Properties.create(Material.WOOL).doesNotBlockMovement().setLightLevel(s -> 15)); super("light", Properties.of(Material.WOOL).noCollission().lightLevel(s -> 15));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) {
for (int i = 0; i < 2; i++) for (var i = 0; i < 2; i++)
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F,
rand.nextGaussian() * 0.015F, 0, rand.nextGaussian() * 0.015F, rand.nextGaussian() * 0.015F, 0, rand.nextGaussian() * 0.015F,
@ -39,12 +39,12 @@ public class BlockLight extends BlockImpl implements ICustomBlockState, INoItemB
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPE; return SHAPE;
} }
@Override @Override
public boolean isReplaceable(BlockState state, BlockItemUseContext useContext) { public boolean canBeReplaced(BlockState state, BlockPlaceContext useContext) {
return true; return true;
} }
@ -56,6 +56,6 @@ public class BlockLight extends BlockImpl implements ICustomBlockState, INoItemB
@Override @Override
public Supplier<RenderType> getRenderType() { public Supplier<RenderType> getRenderType() {
return RenderType::getCutoutMipped; return RenderType::cutoutMipped;
} }
} }

View file

@ -2,23 +2,24 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.api.render.IVisualizable; import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityMossGenerator; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityMossGenerator;
import net.minecraft.block.SoundType; import net.minecraft.core.BlockPos;
import net.minecraft.block.material.Material; import net.minecraft.world.level.Level;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.level.block.SoundType;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.material.Material;
import net.minecraft.level.Level; import net.minecraft.world.phys.AABB;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
public class BlockMossGenerator extends BlockContainerImpl implements IVisualizable { public class BlockMossGenerator extends BlockContainerImpl implements IVisualizable {
public BlockMossGenerator() { public BlockMossGenerator() {
super("moss_generator", BlockEntityMossGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE)); super("moss_generator", BlockEntityMossGenerator::new, Properties.of(Material.STONE).strength(2.5F).sound(SoundType.STONE));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AABB getVisualizationBounds(Level level, BlockPos pos) {
return new AxisAlignedBB(pos).grow(2); return new AABB(pos).inflate(2);
} }
@Override @Override

View file

@ -9,32 +9,25 @@ import de.ellpeck.naturesaura.blocks.tiles.render.RenderNatureAltar;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ITESRProvider; import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.block.Block; import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.entity.player.Player; import net.minecraft.world.InteractionHand;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.StateContainer;
import net.minecraft.tileentity.BlockEntityType;
import net.minecraft.util.Hand;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.common.ToolType;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.function.Function;
import java.util.function.Supplier;
public class BlockNatureAltar extends BlockContainerImpl implements ITESRProvider<BlockEntityNatureAltar>, ICustomBlockState { public class BlockNatureAltar extends BlockContainerImpl implements ITESRProvider<BlockEntityNatureAltar>, ICustomBlockState {
@ -42,8 +35,8 @@ public class BlockNatureAltar extends BlockContainerImpl implements ITESRProvide
public static final BooleanProperty NETHER = BooleanProperty.create("nether"); public static final BooleanProperty NETHER = BooleanProperty.create("nether");
public BlockNatureAltar() { public BlockNatureAltar() {
super("nature_altar", BlockEntityNatureAltar::new, Block.Properties.create(Material.ROCK).hardnessAndResistance(4F).harvestLevel(1).harvestTool(ToolType.PICKAXE)); super("nature_altar", BlockEntityNatureAltar::new, Block.Properties.of(Material.STONE).strength(4F));
this.setDefaultState(this.getDefaultState().with(NETHER, false)); this.registerDefaultState(this.defaultBlockState().setValue(NETHER, false));
} }
@Override @Override
@ -58,30 +51,30 @@ public class BlockNatureAltar extends BlockContainerImpl implements ITESRProvide
@Override @Override
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult hit) { public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
return Helper.putStackOnTile(player, handIn, pos, 0, true); return Helper.putStackOnTile(player, handIn, pos, 0, true);
} }
@Override
public Tuple<BlockEntityType<BlockEntityNatureAltar>, Supplier<Function<? super BlockEntityRenderDispatcher, ? extends BlockEntityRenderer<? super BlockEntityNatureAltar>>>> getTESR() {
return new Tuple<>(ModTileEntities.NATURE_ALTAR, () -> RenderNatureAltar::new);
}
@Override @Override
public void generateCustomBlockState(BlockStateGenerator generator) { public void generateCustomBlockState(BlockStateGenerator generator) {
// noop // noop
} }
@Override @Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder); super.createBlockStateDefinition(builder);
builder.add(NETHER); builder.add(NETHER);
} }
@Nullable @Nullable
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockPlaceContext context) {
boolean nether = IAuraType.forLevel(context.getLevel()).isSimilar(NaturesAuraAPI.TYPE_NETHER); var nether = IAuraType.forLevel(context.getLevel()).isSimilar(NaturesAuraAPI.TYPE_NETHER);
return super.getStateForPlacement(context).with(NETHER, nether); return super.getStateForPlacement(context).setValue(NETHER, nether);
}
@Override
public void registerTESR() {
BlockEntityRenderers.register(ModTileEntities.NATURE_ALTAR, RenderNatureAltar::new);
} }
} }

View file

@ -2,29 +2,29 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.BlockState; import net.minecraft.core.BlockPos;
import net.minecraft.block.Blocks; import net.minecraft.core.Direction;
import net.minecraft.block.IGrowable; import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Direction; import net.minecraft.world.level.BlockGetter;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.Level;
import net.minecraft.level.IBlockReader; import net.minecraft.world.level.block.Blocks;
import net.minecraft.level.Level; import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.level.server.ServerLevel; import net.minecraft.world.level.block.state.BlockState;
import java.util.Random; import java.util.Random;
public class BlockNetherGrass extends BlockImpl implements ICustomBlockState, IGrowable { public class BlockNetherGrass extends BlockImpl implements ICustomBlockState, BonemealableBlock {
public BlockNetherGrass() { public BlockNetherGrass() {
super("nether_grass", Properties.from(Blocks.NETHERRACK).tickRandomly()); super("nether_grass", Properties.copy(Blocks.NETHERRACK).randomTicks());
} }
@Override @Override
public void randomTick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) {
BlockPos up = pos.up(); var up = pos.above();
BlockState upState = levelIn.getBlockState(up); var upState = levelIn.getBlockState(up);
if (upState.isSolidSide(levelIn, up, Direction.DOWN)) if (upState.isFaceSturdy(levelIn, up, Direction.DOWN))
levelIn.setBlockState(pos, Blocks.NETHERRACK.getDefaultState()); levelIn.setBlockAndUpdate(pos, Blocks.NETHERRACK.defaultBlockState());
} }
@Override @Override
@ -36,43 +36,43 @@ public class BlockNetherGrass extends BlockImpl implements ICustomBlockState, IG
} }
@Override @Override
public boolean canGrow(IBlockReader levelIn, BlockPos pos, BlockState state, boolean isClient) { public boolean isValidBonemealTarget(BlockGetter levelIn, BlockPos pos, BlockState state, boolean isClient) {
return levelIn.getBlockState(pos.up()).isAir(levelIn, pos.up()); return levelIn.getBlockState(pos.above()).isAir();
} }
@Override @Override
public boolean canUseBonemeal(Level levelIn, Random rand, BlockPos pos, BlockState state) { public boolean isBonemealSuccess(Level levelIn, Random rand, BlockPos pos, BlockState state) {
return true; return true;
} }
@Override @Override
public void grow(ServerLevel level, Random rand, BlockPos pos, BlockState state) { public void performBonemeal(ServerLevel level, Random rand, BlockPos pos, BlockState state) {
BlockPos blockpos = pos.up(); var blockpos = pos.above();
BlockState blockstate = Blocks.GRASS.getDefaultState(); var blockstate = Blocks.GRASS.defaultBlockState();
for (int i = 0; i < 128; ++i) { for (var i = 0; i < 128; ++i) {
BlockPos blockpos1 = blockpos; var blockpos1 = blockpos;
int j = 0; var j = 0;
while (true) { while (true) {
if (j >= i / 16) { if (j >= i / 16) {
BlockState blockstate2 = level.getBlockState(blockpos1); var blockstate2 = level.getBlockState(blockpos1);
if (blockstate2.getBlock() == blockstate.getBlock() && rand.nextInt(10) == 0) { if (blockstate2.getBlock() == blockstate.getBlock() && rand.nextInt(10) == 0) {
((IGrowable) blockstate.getBlock()).grow(level, rand, blockpos1, blockstate2); ((BonemealableBlock) blockstate.getBlock()).performBonemeal(level, rand, blockpos1, blockstate2);
} }
if (!blockstate2.isAir()) { if (!blockstate2.isAir()) {
break; break;
} }
if (blockstate.isValidPosition(level, blockpos1)) { if (blockstate.canSurvive(level, blockpos1)) {
level.setBlockState(blockpos1, blockstate, 3); level.setBlock(blockpos1, blockstate, 3);
} }
break; break;
} }
blockpos1 = blockpos1.add(rand.nextInt(3) - 1, (rand.nextInt(3) - 1) * rand.nextInt(3) / 2, rand.nextInt(3) - 1); blockpos1 = blockpos1.offset(rand.nextInt(3) - 1, (rand.nextInt(3) - 1) * rand.nextInt(3) / 2, rand.nextInt(3) - 1);
if (level.getBlockState(blockpos1.down()).getBlock() != this || level.getBlockState(blockpos1).hasOpaqueCollisionShape(level, blockpos1)) { if (level.getBlockState(blockpos1.below()).getBlock() != this || level.getBlockState(blockpos1).isCollisionShapeFullBlock(level, blockpos1)) {
break; break;
} }

View file

@ -7,17 +7,16 @@ import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityOakGenerator; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityOakGenerator;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.SaplingBlock; import net.minecraft.core.BlockPos;
import net.minecraft.block.SoundType; import net.minecraft.world.level.Level;
import net.minecraft.block.material.Material; import net.minecraft.world.level.block.SaplingBlock;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.level.block.SoundType;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.material.Material;
import net.minecraft.level.ILevel; import net.minecraft.world.phys.AABB;
import net.minecraft.level.Level;
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;
import net.minecraftforge.event.level.SaplingGrowTreeEvent; import net.minecraftforge.event.world.SaplingGrowTreeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import java.util.Random; import java.util.Random;
@ -25,22 +24,22 @@ import java.util.Random;
public class BlockOakGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState { public class BlockOakGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockOakGenerator() { public BlockOakGenerator() {
super("oak_generator", BlockEntityOakGenerator::new, Properties.create(Material.WOOD).hardnessAndResistance(2F).sound(SoundType.WOOD)); super("oak_generator", BlockEntityOakGenerator::new, Properties.of(Material.WOOD).strength(2F).sound(SoundType.WOOD));
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
} }
@SubscribeEvent @SubscribeEvent
public void onTreeGrow(SaplingGrowTreeEvent event) { public void onTreeGrow(SaplingGrowTreeEvent event) {
ILevel level = event.getLevel(); var level = event.getWorld();
BlockPos pos = event.getPos(); var pos = event.getPos();
if (level instanceof Level && !level.isClientSide() && IAuraType.forLevel(level).isSimilar(NaturesAuraAPI.TYPE_OVERWORLD) if (level instanceof Level && !level.isClientSide() && IAuraType.forLevel((Level) level).isSimilar(NaturesAuraAPI.TYPE_OVERWORLD)
&& level.getBlockState(pos).getBlock() instanceof SaplingBlock) { && level.getBlockState(pos).getBlock() instanceof SaplingBlock) {
Helper.getBlockEntitiesInArea(level, pos, 10, tile -> { Helper.getBlockEntitiesInArea(level, pos, 10, tile -> {
if (!(tile instanceof BlockEntityOakGenerator)) if (!(tile instanceof BlockEntityOakGenerator))
return false; return false;
Random rand = event.getRand(); var rand = event.getRand();
if (rand.nextInt(10) == 0) if (rand.nextInt(10) == 0)
((BlockEntityOakGenerator) tile).scheduledBigTrees.add(pos); ((BlockEntityOakGenerator) tile).scheduledBigTrees.add(pos);
@ -59,8 +58,8 @@ public class BlockOakGenerator extends BlockContainerImpl implements IVisualizab
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AABB getVisualizationBounds(Level level, BlockPos pos) {
return new AxisAlignedBB(pos).grow(10); return new AABB(pos).inflate(10);
} }
@Override @Override

View file

@ -1,39 +1,33 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityOfferingTable; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityOfferingTable;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderOfferingTable; import de.ellpeck.naturesaura.blocks.tiles.render.RenderOfferingTable;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ITESRProvider; import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.block.BlockState; import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.block.SoundType; import net.minecraft.core.BlockPos;
import net.minecraft.block.material.Material; import net.minecraft.world.InteractionHand;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer; import net.minecraft.world.InteractionResult;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher; import net.minecraft.world.entity.player.Player;
import net.minecraft.entity.player.Player; import net.minecraft.world.level.BlockGetter;
import net.minecraft.tileentity.BlockEntityType; import net.minecraft.world.level.Level;
import net.minecraft.util.InteractionResult; import net.minecraft.world.level.block.SoundType;
import net.minecraft.util.Hand; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.Tuple; import net.minecraft.world.level.material.Material;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.util.math.shapes.Shapes;
import net.minecraft.level.IBlockReader;
import net.minecraft.level.Level;
import java.util.function.Function;
import java.util.function.Supplier;
public class BlockOfferingTable extends BlockContainerImpl implements ITESRProvider<BlockEntityOfferingTable>, ICustomBlockState { public class BlockOfferingTable extends BlockContainerImpl implements ITESRProvider<BlockEntityOfferingTable>, ICustomBlockState {
private static final VoxelShape SHAPE = Shapes.create(2 / 16F, 0F, 2 / 16F, 14 / 16F, 1F, 14 / 16F); private static final VoxelShape SHAPE = Shapes.create(2 / 16F, 0F, 2 / 16F, 14 / 16F, 1F, 14 / 16F);
public BlockOfferingTable() { public BlockOfferingTable() {
super("offering_table", BlockEntityOfferingTable::new, Properties.create(Material.WOOD).hardnessAndResistance(2F).sound(SoundType.WOOD)); super("offering_table", BlockEntityOfferingTable::new, Properties.of(Material.WOOD).strength(2F).sound(SoundType.WOOD));
} }
@Override @Override
@ -42,22 +36,22 @@ public class BlockOfferingTable extends BlockContainerImpl implements ITESRProvi
} }
@Override @Override
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult hit) { public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
return Helper.putStackOnTile(player, handIn, pos, 0, true); return Helper.putStackOnTile(player, handIn, pos, 0, true);
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPE; return SHAPE;
} }
@Override
public Tuple<BlockEntityType<BlockEntityOfferingTable>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityOfferingTable>>>> getTESR() {
return new Tuple<>(ModTileEntities.OFFERING_TABLE, () -> RenderOfferingTable::new);
}
@Override @Override
public void generateCustomBlockState(BlockStateGenerator generator) { public void generateCustomBlockState(BlockStateGenerator generator) {
generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName()))); generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName())));
} }
@Override
public void registerTESR() {
BlockEntityRenderers.register(ModTileEntities.OFFERING_TABLE, RenderOfferingTable::new);
}
} }

View file

@ -7,14 +7,14 @@ import de.ellpeck.naturesaura.data.BlockStateGenerator;
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 de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.SoundType; import net.minecraft.core.BlockPos;
import net.minecraft.block.material.Material; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.world.entity.player.Player;
import net.minecraft.entity.player.Player; import net.minecraft.world.level.Level;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.world.level.block.SoundType;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.material.Material;
import net.minecraft.level.Level; import net.minecraft.world.phys.AABB;
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,34 +22,34 @@ import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
public class BlockPickupStopper extends BlockContainerImpl implements IVisualizable, ICustomBlockState { public class BlockPickupStopper extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockPickupStopper() { public BlockPickupStopper() {
super("pickup_stopper", BlockEntityPickupStopper::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE)); super("pickup_stopper", BlockEntityPickupStopper::new, Properties.of(Material.STONE).strength(2F).sound(SoundType.STONE));
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
} }
@SubscribeEvent @SubscribeEvent
public void onPickup(EntityItemPickupEvent event) { public void onPickup(EntityItemPickupEvent event) {
Player player = event.getPlayer(); var player = event.getPlayer();
if (player != null && !player.isSneaking()) { if (player != null && !player.isCrouching()) {
ItemEntity item = event.getItem(); var item = event.getItem();
BlockPos pos = item.getPosition(); var pos = item.blockPosition();
Helper.getBlockEntitiesInArea(item.level, pos, 8, tile -> { Helper.getBlockEntitiesInArea(item.level, pos, 8, tile -> {
if (!(tile instanceof BlockEntityPickupStopper)) if (!(tile instanceof BlockEntityPickupStopper stopper))
return false; return false;
BlockEntityPickupStopper stopper = (BlockEntityPickupStopper) tile; var radius = stopper.getRadius();
float radius = stopper.getRadius();
if (radius <= 0F) if (radius <= 0F)
return false; return false;
BlockPos stopperPos = stopper.getPos(); var stopperPos = stopper.getBlockPos();
if (!new AxisAlignedBB(stopperPos).grow(radius).intersects(item.getBoundingBox())) if (!new AABB(stopperPos).inflate(radius).intersects(item.getBoundingBox()))
return false; return false;
event.setCanceled(true); event.setCanceled(true);
if (item.level.getGameTime() % 3 == 0) if (item.level.getGameTime() % 3 == 0)
PacketHandler.sendToAllAround(item.level, pos, 32, PacketHandler.sendToAllAround(item.level, pos, 32,
new PacketParticles((float) item.getPosX(), (float) item.getPosY(), (float) item.getPosZ(), PacketParticles.Type.PICKUP_STOPPER)); new PacketParticles((float) item.getX(), (float) item.getY(), (float) item.getZ(), PacketParticles.Type.PICKUP_STOPPER));
return true; return true;
}); });
} }
@ -57,12 +57,12 @@ public class BlockPickupStopper extends BlockContainerImpl implements IVisualiza
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AABB getVisualizationBounds(Level level, BlockPos pos) {
BlockEntity tile = level.getBlockEntity(pos); var tile = level.getBlockEntity(pos);
if (tile instanceof BlockEntityPickupStopper) { if (tile instanceof BlockEntityPickupStopper) {
double radius = ((BlockEntityPickupStopper) tile).getRadius(); double radius = ((BlockEntityPickupStopper) tile).getRadius();
if (radius > 0) if (radius > 0)
return new AxisAlignedBB(pos).grow(radius); return new AABB(pos).inflate(radius);
} }
return null; return null;
} }

View file

@ -4,24 +4,24 @@ import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityPlacer; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityPlacer;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.SoundType; import net.minecraft.core.BlockPos;
import net.minecraft.block.material.Material; import net.minecraft.world.level.Level;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.level.block.SoundType;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.material.Material;
import net.minecraft.level.Level; import net.minecraft.world.phys.AABB;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
public class BlockPlacer extends BlockContainerImpl implements IVisualizable, ICustomBlockState { public class BlockPlacer extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockPlacer() { public BlockPlacer() {
super("placer", BlockEntityPlacer::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE)); super("placer", BlockEntityPlacer::new, Properties.of(Material.STONE).strength(2.5F).sound(SoundType.STONE));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AABB getVisualizationBounds(Level level, BlockPos pos) {
return new AxisAlignedBB(pos).grow(5); return new AABB(pos).inflate(5);
} }
@Override @Override

View file

@ -3,12 +3,12 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityPotionGenerator; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityPotionGenerator;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.material.Material; import net.minecraft.world.level.material.Material;
import net.minecraftforge.common.ToolType;
public class BlockPotionGenerator extends BlockContainerImpl implements ICustomBlockState { public class BlockPotionGenerator extends BlockContainerImpl implements ICustomBlockState {
public BlockPotionGenerator() { public BlockPotionGenerator() {
super("potion_generator", BlockEntityPotionGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(5F).harvestTool(ToolType.PICKAXE).harvestLevel(1)); super("potion_generator", BlockEntityPotionGenerator::new, Properties.of(Material.STONE).strength(5F));
} }
@Override @Override

View file

@ -3,21 +3,21 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityPowderPlacer; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityPowderPlacer;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.BlockState; import net.minecraft.core.BlockPos;
import net.minecraft.block.SoundType; import net.minecraft.world.level.BlockGetter;
import net.minecraft.block.material.Material; import net.minecraft.world.level.block.SoundType;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.world.level.material.Material;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.util.math.shapes.Shapes; import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.level.IBlockReader; import net.minecraft.world.phys.shapes.VoxelShape;
public class BlockPowderPlacer extends BlockContainerImpl implements ICustomBlockState { public class BlockPowderPlacer extends BlockContainerImpl implements ICustomBlockState {
private static final VoxelShape SHAPE = Shapes.create(0F, 0F, 0F, 1F, 4 / 16F, 1F); private static final VoxelShape SHAPE = Shapes.create(0F, 0F, 0F, 1F, 4 / 16F, 1F);
public BlockPowderPlacer() { public BlockPowderPlacer() {
super("powder_placer", BlockEntityPowderPlacer::new, Properties.create(Material.ROCK).hardnessAndResistance(2, 5F).sound(SoundType.STONE)); super("powder_placer", BlockEntityPowderPlacer::new, Properties.of(Material.STONE).strength(2, 5F).sound(SoundType.STONE));
} }
@Override @Override
@ -26,7 +26,7 @@ public class BlockPowderPlacer extends BlockContainerImpl implements ICustomBloc
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPE; return SHAPE;
} }

View file

@ -1,69 +1,62 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityProjectileGenerator; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityProjectileGenerator;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderProjectileGenerator; import de.ellpeck.naturesaura.blocks.tiles.render.RenderProjectileGenerator;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
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 de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ITESRProvider; import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.block.DispenserBlock; import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.block.SoundType; import net.minecraft.core.BlockPos;
import net.minecraft.block.material.Material; import net.minecraft.core.Position;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer; import net.minecraft.core.dispenser.AbstractProjectileDispenseBehavior;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher; import net.minecraft.sounds.SoundEvents;
import net.minecraft.dispenser.IPosition; import net.minecraft.sounds.SoundSource;
import net.minecraft.dispenser.ProjectileDispenseBehavior; import net.minecraft.world.entity.Entity;
import net.minecraft.entity.Entity; import net.minecraft.world.entity.EntityType;
import net.minecraft.entity.EntityType; import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.entity.item.EnderPearlEntity; import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.entity.projectile.AbstractArrowEntity; import net.minecraft.world.entity.projectile.ThrownEnderpearl;
import net.minecraft.entity.projectile.ProjectileEntity; import net.minecraft.world.entity.projectile.ThrownTrident;
import net.minecraft.entity.projectile.TridentEntity; import net.minecraft.world.item.ItemStack;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.Items;
import net.minecraft.item.Items; import net.minecraft.world.level.Level;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.world.level.block.DispenserBlock;
import net.minecraft.tileentity.BlockEntityType; import net.minecraft.world.level.block.SoundType;
import net.minecraft.util.SoundCategory; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.util.SoundEvents; import net.minecraft.world.level.material.Material;
import net.minecraft.util.Tuple; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.phys.HitResult;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.level.Level;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.ProjectileImpactEvent; import net.minecraftforge.event.entity.ProjectileImpactEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
import java.util.function.Function;
import java.util.function.Supplier;
public class BlockProjectileGenerator extends BlockContainerImpl implements ITESRProvider<BlockEntityProjectileGenerator>, ICustomBlockState { public class BlockProjectileGenerator extends BlockContainerImpl implements ITESRProvider<BlockEntityProjectileGenerator>, ICustomBlockState {
public BlockProjectileGenerator() { public BlockProjectileGenerator() {
super("projectile_generator", BlockEntityProjectileGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE)); super("projectile_generator", BlockEntityProjectileGenerator::new, Properties.of(Material.STONE).strength(2.5F).sound(SoundType.STONE));
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
DispenserBlock.registerDispenseBehavior(Items.ENDER_PEARL, new ProjectileDispenseBehavior() { DispenserBlock.registerBehavior(Items.ENDER_PEARL, new AbstractProjectileDispenseBehavior() {
@Override @Override
protected ProjectileEntity getProjectileEntity(Level levelIn, IPosition position, ItemStack stackIn) { protected Projectile getProjectile(Level levelIn, Position position, ItemStack stackIn) {
EnderPearlEntity ret = new EnderPearlEntity(EntityType.ENDER_PEARL, levelIn); var ret = new ThrownEnderpearl(EntityType.ENDER_PEARL, levelIn);
ret.setPosition(position.getX(), position.getY(), position.getZ()); ret.setPos(position.x(), position.y(), position.z());
return ret; return ret;
} }
}); });
DispenserBlock.registerDispenseBehavior(Items.TRIDENT, new ProjectileDispenseBehavior() { DispenserBlock.registerBehavior(Items.TRIDENT, new AbstractProjectileDispenseBehavior() {
@Override @Override
protected ProjectileEntity getProjectileEntity(Level levelIn, IPosition position, ItemStack stackIn) { protected Projectile getProjectile(Level levelIn, Position position, ItemStack stackIn) {
TridentEntity ret = new TridentEntity(EntityType.TRIDENT, levelIn); var ret = new ThrownTrident(EntityType.TRIDENT, levelIn);
ret.setPosition(position.getX(), position.getY(), position.getZ()); ret.setPos(position.x(), position.y(), position.z());
// set thrownStack ObfuscationReflectionHelper.setPrivateValue(ThrownTrident.class, ret, stackIn.copy(), "tridentItem");
ObfuscationReflectionHelper.setPrivateValue(TridentEntity.class, ret, stackIn.copy(), "field_203054_h"); ret.pickup = AbstractArrow.Pickup.ALLOWED;
ret.pickupStatus = AbstractArrowEntity.PickupStatus.ALLOWED;
return ret; return ret;
} }
}); });
@ -71,23 +64,21 @@ public class BlockProjectileGenerator extends BlockContainerImpl implements ITES
@SubscribeEvent @SubscribeEvent
public void onProjectileImpact(ProjectileImpactEvent event) { public void onProjectileImpact(ProjectileImpactEvent event) {
Entity entity = event.getEntity(); var entity = event.getEntity();
if (entity.level.isClientSide) if (entity.level.isClientSide)
return; return;
RayTraceResult ray = event.getRayTraceResult(); var ray = event.getRayTraceResult();
if (!(ray instanceof BlockRayTraceResult)) if (!(ray instanceof BlockHitResult blockRay))
return; return;
BlockRayTraceResult blockRay = (BlockRayTraceResult) ray; var pos = blockRay.getBlockPos();
BlockPos pos = blockRay.getPos();
if (pos == null) if (pos == null)
return; return;
BlockEntity tile = entity.level.getBlockEntity(pos); var tile = entity.level.getBlockEntity(pos);
if (!(tile instanceof BlockEntityProjectileGenerator)) if (!(tile instanceof BlockEntityProjectileGenerator generator))
return; return;
BlockEntityProjectileGenerator generator = (BlockEntityProjectileGenerator) tile; if (generator.nextSide != blockRay.getDirection())
if (generator.nextSide != blockRay.getFace())
return; return;
Integer amount = NaturesAuraAPI.PROJECTILE_GENERATIONS.get(entity.getType()); var amount = NaturesAuraAPI.PROJECTILE_GENERATIONS.get(entity.getType());
if (amount == null || amount <= 0) if (amount == null || amount <= 0)
return; return;
if (!generator.canGenerateRightNow(amount)) if (!generator.canGenerateRightNow(amount))
@ -95,21 +86,16 @@ public class BlockProjectileGenerator extends BlockContainerImpl implements ITES
generator.generateAura(amount); generator.generateAura(amount);
PacketHandler.sendToAllAround(entity.level, pos, 32, PacketHandler.sendToAllAround(entity.level, pos, 32,
new PacketParticles((float) entity.getPosX(), (float) entity.getPosY(), (float) entity.getPosZ(), PacketParticles.Type.PROJECTILE_GEN, pos.getX(), pos.getY(), pos.getZ())); new PacketParticles((float) entity.getX(), (float) entity.getY(), (float) entity.getZ(), PacketParticles.Type.PROJECTILE_GEN, pos.getX(), pos.getY(), pos.getZ()));
entity.level.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_ENDER_EYE_LAUNCH, SoundCategory.BLOCKS, 0.8F, 1F); entity.level.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENDER_EYE_LAUNCH, SoundSource.BLOCKS, 0.8F, 1F);
generator.nextSide = generator.nextSide.rotateY(); generator.nextSide = generator.nextSide.getClockWise();
generator.sendToClients(); generator.sendToClients();
entity.remove(); entity.kill();
event.setCanceled(true); event.setCanceled(true);
} }
@Override
public Tuple<BlockEntityType<BlockEntityProjectileGenerator>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityProjectileGenerator>>>> getTESR() {
return new Tuple<>(ModTileEntities.PROJECTILE_GENERATOR, () -> RenderProjectileGenerator::new);
}
@Override @Override
public void generateCustomBlockState(BlockStateGenerator generator) { public void generateCustomBlockState(BlockStateGenerator generator) {
generator.simpleBlock(this, generator.models().cubeBottomTop(this.getBaseName(), generator.simpleBlock(this, generator.models().cubeBottomTop(this.getBaseName(),
@ -117,4 +103,9 @@ public class BlockProjectileGenerator extends BlockContainerImpl implements ITES
generator.modLoc("block/" + this.getBaseName() + "_top"), generator.modLoc("block/" + this.getBaseName() + "_top"),
generator.modLoc("block/" + this.getBaseName() + "_top"))); generator.modLoc("block/" + this.getBaseName() + "_top")));
} }
@Override
public void registerTESR() {
BlockEntityRenderers.register(ModTileEntities.PROJECTILE_GENERATOR, RenderProjectileGenerator::new);
}
} }

View file

@ -3,17 +3,17 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.ModConfig; import de.ellpeck.naturesaura.ModConfig;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityRFConverter; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityRFConverter;
import net.minecraft.block.SoundType; import net.minecraft.world.level.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.world.level.material.Material;
public class BlockRFConverter extends BlockContainerImpl { public class BlockRFConverter extends BlockContainerImpl {
public BlockRFConverter() { public BlockRFConverter() {
super("rf_converter", BlockEntityRFConverter::new, Properties.create(Material.ROCK).sound(SoundType.STONE).hardnessAndResistance(3)); super("rf_converter", BlockEntityRFConverter::new, Properties.of(Material.STONE).sound(SoundType.STONE).strength(3));
} }
@Override @Override
public String getTranslationKey() { public String getDescriptionId() {
return ModConfig.instance.rfConverter.get() ? super.getTranslationKey() : "block." + NaturesAura.MOD_ID + "." + this.getBaseName() + ".disabled"; return ModConfig.instance.rfConverter.get() ? super.getDescriptionId() : "block." + NaturesAura.MOD_ID + "." + this.getBaseName() + ".disabled";
} }
} }

View file

@ -5,12 +5,12 @@ import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntitySlimeSplitGenerator; import de.ellpeck.naturesaura.blocks.tiles.BlockEntitySlimeSplitGenerator;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Blocks; import net.minecraft.core.BlockPos;
import net.minecraft.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.entity.monster.SlimeEntity; import net.minecraft.world.entity.monster.Slime;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.level.Level;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.Blocks;
import net.minecraft.level.Level; import net.minecraft.world.phys.AABB;
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;
@ -18,8 +18,9 @@ import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
public class BlockSlimeSplitGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState { public class BlockSlimeSplitGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockSlimeSplitGenerator() { public BlockSlimeSplitGenerator() {
super("slime_split_generator", BlockEntitySlimeSplitGenerator::new, Properties.from(Blocks.SLIME_BLOCK).hardnessAndResistance(2)); super("slime_split_generator", BlockEntitySlimeSplitGenerator::new, Properties.copy(Blocks.SLIME_BLOCK).strength(2));
MinecraftForge.EVENT_BUS.register(new Events()); MinecraftForge.EVENT_BUS.register(new Events());
} }
@ -33,8 +34,8 @@ public class BlockSlimeSplitGenerator extends BlockContainerImpl implements IVis
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AABB getVisualizationBounds(Level level, BlockPos pos) {
return new AxisAlignedBB(pos).grow(8); return new AABB(pos).inflate(8);
} }
@Override @Override
@ -47,17 +48,15 @@ public class BlockSlimeSplitGenerator extends BlockContainerImpl implements IVis
@SubscribeEvent @SubscribeEvent
public void onLivingDeath(LivingDeathEvent event) { public void onLivingDeath(LivingDeathEvent event) {
LivingEntity entity = event.getEntityLiving(); var entity = event.getEntityLiving();
if (!(entity instanceof SlimeEntity) || entity.level.isClientSide) if (!(entity instanceof Slime slime) || entity.level.isClientSide)
return; return;
SlimeEntity slime = (SlimeEntity) entity; var size = slime.getSize();
int size = slime.getSlimeSize();
if (size <= 1) if (size <= 1)
return; return;
Helper.getBlockEntitiesInArea(entity.level, entity.getPosition(), 8, tile -> { Helper.getBlockEntitiesInArea(entity.level, entity.blockPosition(), 8, tile -> {
if (!(tile instanceof BlockEntitySlimeSplitGenerator)) if (!(tile instanceof BlockEntitySlimeSplitGenerator gen))
return false; return false;
BlockEntitySlimeSplitGenerator gen = (BlockEntitySlimeSplitGenerator) tile;
if (gen.isBusy()) if (gen.isBusy())
return false; return false;
gen.startGenerating(slime); gen.startGenerating(slime);

View file

@ -4,27 +4,28 @@ import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntitySnowCreator; import de.ellpeck.naturesaura.blocks.tiles.BlockEntitySnowCreator;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Blocks; import net.minecraft.core.BlockPos;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.world.level.Level;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.level.block.Blocks;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.level.Level; import net.minecraft.world.phys.AABB;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
public class BlockSnowCreator extends BlockContainerImpl implements IVisualizable, ICustomBlockState { public class BlockSnowCreator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockSnowCreator() { public BlockSnowCreator() {
super("snow_creator", BlockEntitySnowCreator::new, Properties.from(Blocks.STONE_BRICKS)); super("snow_creator", BlockEntitySnowCreator::new, Properties.copy(Blocks.STONE_BRICKS));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AABB getVisualizationBounds(Level level, BlockPos pos) {
BlockEntity tile = level.getBlockEntity(pos); var tile = level.getBlockEntity(pos);
if (tile instanceof BlockEntitySnowCreator) { if (tile instanceof BlockEntitySnowCreator) {
int radius = ((BlockEntitySnowCreator) tile).getRange(); var radius = ((BlockEntitySnowCreator) tile).getRange();
if (radius > 0) if (radius > 0)
return new AxisAlignedBB(pos).grow(radius); return new AABB(pos).inflate(radius);
} }
return null; return null;
} }

View file

@ -10,22 +10,22 @@ import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ICustomRenderType; import de.ellpeck.naturesaura.reg.ICustomRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.entity.MobEntity; import net.minecraft.core.BlockPos;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.entity.Mob;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.BlockGetter;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.world.level.Level;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.level.LevelAccessor;
import net.minecraft.util.math.shapes.Shapes; import net.minecraft.world.level.block.SoundType;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.level.IBlockReader; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.level.ILevel; import net.minecraft.world.level.material.Material;
import net.minecraft.level.Level; import net.minecraft.world.phys.AABB;
import net.minecraft.level.server.ServerLevel; import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
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;
@ -40,7 +40,7 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable,
private static final VoxelShape SHAPE = Shapes.create(4 / 16F, 0F, 4 / 16F, 12 / 16F, 13 / 16F, 12 / 16F); private static final VoxelShape SHAPE = Shapes.create(4 / 16F, 0F, 4 / 16F, 12 / 16F, 13 / 16F, 12 / 16F);
public BlockSpawnLamp() { public BlockSpawnLamp() {
super("spawn_lamp", BlockEntitySpawnLamp::new, Properties.create(Material.IRON).hardnessAndResistance(3F).setLightLevel(s -> 15).sound(SoundType.METAL)); super("spawn_lamp", BlockEntitySpawnLamp::new, Properties.of(Material.METAL).strength(3F).lightLevel(s -> 15).sound(SoundType.METAL));
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
} }
@ -53,27 +53,27 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable,
public void onSpawn(LivingSpawnEvent.CheckSpawn event) { public void onSpawn(LivingSpawnEvent.CheckSpawn event) {
if (event.getSpawner() != null) if (event.getSpawner() != null)
return; return;
ILevel level = event.getLevel(); var level = event.getWorld();
BlockPos pos = new BlockPos(event.getX(), event.getY(), event.getZ()); var pos = new BlockPos(event.getX(), event.getY(), event.getZ());
if (!(level instanceof Level)) if (!(level instanceof Level))
return; return;
LevelData data = (LevelData) ILevelData.getLevelData((Level) level); var data = (LevelData) ILevelData.getLevelData((Level) level);
for (BlockEntitySpawnLamp lamp : data.spawnLamps) { for (var lamp : data.spawnLamps) {
if (lamp.isRemoved()) if (lamp.isRemoved())
continue; continue;
int range = lamp.getRadius(); var range = lamp.getRadius();
if (range <= 0) if (range <= 0)
continue; continue;
BlockPos lampPos = lamp.getPos(); var lampPos = lamp.getBlockPos();
if (!new AxisAlignedBB(lampPos).grow(range).contains(new Vector3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5))) if (!new AABB(lampPos).inflate(range).contains(new Vec3(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5)))
continue; continue;
MobEntity entity = (MobEntity) event.getEntityLiving(); var entity = (Mob) event.getEntityLiving();
if (entity.canSpawn(level, event.getSpawnReason()) && entity.isNotColliding(level)) { if (entity.checkSpawnRules(level, event.getSpawnReason()) && entity.checkSpawnObstruction(level)) {
BlockPos spot = IAuraChunk.getHighestSpot(level, lampPos, 32, lampPos); var spot = IAuraChunk.getHighestSpot((Level) level, lampPos, 32, lampPos);
IAuraChunk.getAuraChunk(level, spot).drainAura(spot, 200); IAuraChunk.getAuraChunk((Level) level, spot).drainAura(spot, 200);
PacketHandler.sendToAllAround((ServerLevel) level, lampPos, 32, PacketHandler.sendToAllAround((ServerLevel) level, lampPos, 32,
new PacketParticles(lampPos.getX(), lampPos.getY(), lampPos.getZ(), PacketParticles.Type.SPAWN_LAMP)); new PacketParticles(lampPos.getX(), lampPos.getY(), lampPos.getZ(), PacketParticles.Type.SPAWN_LAMP));
@ -85,18 +85,18 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable,
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPE; return SHAPE;
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AABB getVisualizationBounds(Level level, BlockPos pos) {
BlockEntity tile = level.getBlockEntity(pos); var tile = level.getBlockEntity(pos);
if (tile instanceof BlockEntitySpawnLamp) { if (tile instanceof BlockEntitySpawnLamp) {
int radius = ((BlockEntitySpawnLamp) tile).getRadius(); var radius = ((BlockEntitySpawnLamp) tile).getRadius();
if (radius > 0) if (radius > 0)
return new AxisAlignedBB(pos).grow(radius); return new AABB(pos).inflate(radius);
} }
return null; return null;
} }
@ -114,6 +114,6 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable,
@Override @Override
public Supplier<RenderType> getRenderType() { public Supplier<RenderType> getRenderType() {
return RenderType::getCutoutMipped; return RenderType::cutoutMipped;
} }
} }

View file

@ -6,46 +6,49 @@ import de.ellpeck.naturesaura.reg.IColorProvidingBlock;
import de.ellpeck.naturesaura.reg.IColorProvidingItem; import de.ellpeck.naturesaura.reg.IColorProvidingItem;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ICustomRenderType; import de.ellpeck.naturesaura.reg.ICustomRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.IBucketPickupHandler;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.color.block.BlockColor;
import net.minecraft.client.color.item.ItemColor;
import net.minecraft.client.renderer.BiomeColors;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.color.IBlockColor; import net.minecraft.core.BlockPos;
import net.minecraft.client.renderer.color.IItemColor; import net.minecraft.sounds.SoundEvent;
import net.minecraft.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.fluid.Fluid; import net.minecraft.world.item.ItemStack;
import net.minecraft.fluid.Fluids; import net.minecraft.world.item.Items;
import net.minecraft.item.ItemStack; import net.minecraft.world.level.LevelAccessor;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.world.level.block.Blocks;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.BucketPickup;
import net.minecraft.level.ILevel; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.level.biome.BiomeColors; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluids;
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.Optional;
import java.util.function.Supplier; import java.util.function.Supplier;
public class BlockSpring extends BlockContainerImpl implements ICustomBlockState, IColorProvidingBlock, IColorProvidingItem, IBucketPickupHandler, ICustomRenderType { public class BlockSpring extends BlockContainerImpl implements ICustomBlockState, IColorProvidingBlock, IColorProvidingItem, BucketPickup, ICustomRenderType {
public BlockSpring() { public BlockSpring() {
super("spring", BlockEntitySpring::new, Properties.from(Blocks.STONE_BRICKS)); super("spring", BlockEntitySpring::new, Properties.copy(Blocks.STONE_BRICKS));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public IBlockColor getBlockColor() { public BlockColor getBlockColor() {
return (state, level, pos, i) -> BiomeColors.getWaterColor(level, pos); return (state, level, pos, i) -> BiomeColors.getAverageWaterColor(level, pos);
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
@SuppressWarnings("Convert2Lambda") @SuppressWarnings("Convert2Lambda")
public IItemColor getItemColor() { public ItemColor getItemColor() {
return new IItemColor() { return new ItemColor() {
@Override @Override
public int getColor(ItemStack stack, int i) { public int getColor(ItemStack stack, int i) {
Player player = Minecraft.getInstance().player; Player player = Minecraft.getInstance().player;
return BiomeColors.getWaterColor(player.level, player.getPosition()); return BiomeColors.getAverageWaterColor(player.level, player.blockPosition());
} }
}; };
} }
@ -55,16 +58,21 @@ public class BlockSpring extends BlockContainerImpl implements ICustomBlockState
generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName()))); generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName())));
} }
@Override
public Fluid pickupFluid(ILevel levelIn, BlockPos pos, BlockState state) {
BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntitySpring)
((BlockEntitySpring) tile).consumeAura(2500);
return Fluids.WATER;
}
@Override @Override
public Supplier<RenderType> getRenderType() { public Supplier<RenderType> getRenderType() {
return RenderType::getTranslucent; return RenderType::translucent;
}
@Override
public ItemStack pickupBlock(LevelAccessor levelIn, BlockPos pos, BlockState state) {
var tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntitySpring)
((BlockEntitySpring) tile).consumeAura(2500);
return new ItemStack(Items.WATER_BUCKET); }
@Override
public Optional<SoundEvent> getPickupSound() {
return Fluids.WATER.getPickupSound();
} }
} }

View file

@ -4,19 +4,19 @@ import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.IModItem; import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.ModRegistry; import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.world.level.block.StairBlock;
import net.minecraft.block.StairsBlock; import net.minecraft.world.level.block.state.BlockState;
import java.util.function.Supplier; import java.util.function.Supplier;
public class BlockStairsNA extends StairsBlock implements IModItem, ICustomBlockState { public class BlockStairsNA extends StairBlock implements IModItem, ICustomBlockState {
public final String textureName; public final String textureName;
private final String baseName; private final String baseName;
public BlockStairsNA(String baseName, String textureName, Supplier<BlockState> modelState, Block.Properties properties) { public BlockStairsNA(String baseName, String textureName, Supplier<BlockState> modelState, Block.Properties properties) {
super(modelState, properties.variableOpacity()); super(modelState, properties.dynamicShape());
this.baseName = baseName; this.baseName = baseName;
this.textureName = textureName; this.textureName = textureName;
ModRegistry.add(this); ModRegistry.add(this);

View file

@ -3,12 +3,13 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityTimeChanger; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityTimeChanger;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.SoundType; import net.minecraft.world.level.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.world.level.material.Material;
public class BlockTimeChanger extends BlockContainerImpl implements ICustomBlockState { public class BlockTimeChanger extends BlockContainerImpl implements ICustomBlockState {
public BlockTimeChanger() { public BlockTimeChanger() {
super("time_changer", BlockEntityTimeChanger::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE)); super("time_changer", BlockEntityTimeChanger::new, Properties.of(Material.STONE).strength(2.5F).sound(SoundType.STONE));
} }
@Override @Override

View file

@ -3,11 +3,12 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityWeatherChanger; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityWeatherChanger;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Blocks; import net.minecraft.world.level.block.Blocks;
public class BlockWeatherChanger extends BlockContainerImpl implements ICustomBlockState { public class BlockWeatherChanger extends BlockContainerImpl implements ICustomBlockState {
public BlockWeatherChanger() { public BlockWeatherChanger() {
super("weather_changer", BlockEntityWeatherChanger::new, Properties.from(Blocks.STONE_BRICKS)); super("weather_changer", BlockEntityWeatherChanger::new, Properties.copy(Blocks.STONE_BRICKS));
} }
@Override @Override

View file

@ -2,53 +2,47 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.blocks.multi.Multiblocks; import de.ellpeck.naturesaura.blocks.multi.Multiblocks;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityWoodStand; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityWoodStand;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderWoodStand; import de.ellpeck.naturesaura.blocks.tiles.render.RenderWoodStand;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.recipes.ModRecipes; import de.ellpeck.naturesaura.recipes.ModRecipes;
import de.ellpeck.naturesaura.recipes.TreeRitualRecipe; import de.ellpeck.naturesaura.recipes.TreeRitualRecipe;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ITESRProvider; import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.block.BlockState; import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.block.SoundType; import net.minecraft.core.BlockPos;
import net.minecraft.block.material.Material; import net.minecraft.world.InteractionHand;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer; import net.minecraft.world.InteractionResult;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher; import net.minecraft.world.entity.player.Player;
import net.minecraft.entity.player.Player; import net.minecraft.world.item.ItemStack;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.item.crafting.Ingredient; import net.minecraft.world.level.BlockGetter;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.world.level.Level;
import net.minecraft.tileentity.BlockEntityType; import net.minecraft.world.level.LevelAccessor;
import net.minecraft.util.InteractionResult; import net.minecraft.world.level.block.SoundType;
import net.minecraft.util.Hand; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.util.Tuple; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.material.Material;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.util.math.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.level.IBlockReader;
import net.minecraft.level.ILevel;
import net.minecraft.level.Level;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.ToolType; import net.minecraftforge.event.world.SaplingGrowTreeEvent;
import net.minecraftforge.event.level.SaplingGrowTreeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import org.apache.commons.lang3.mutable.MutableObject; import org.apache.commons.lang3.mutable.MutableObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider<BlockEntityWoodStand>, ICustomBlockState { public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider<BlockEntityWoodStand>, ICustomBlockState {
private static final VoxelShape SHAPE = Shapes.create(3 / 16F, 0F, 3 / 16F, 13 / 16F, 13 / 16F, 13 / 16F); private static final VoxelShape SHAPE = Shapes.create(3 / 16F, 0F, 3 / 16F, 13 / 16F, 13 / 16F, 13 / 16F);
public BlockWoodStand() { public BlockWoodStand() {
super("wood_stand", BlockEntityWoodStand::new, Properties.create(Material.WOOD).hardnessAndResistance(1.5F).sound(SoundType.WOOD).harvestLevel(0).harvestTool(ToolType.AXE)); super("wood_stand", BlockEntityWoodStand::new, Properties.of(Material.WOOD).strength(1.5F).sound(SoundType.WOOD));
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
} }
@ -58,32 +52,31 @@ public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider<
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPE; return SHAPE;
} }
@SubscribeEvent @SubscribeEvent
public void onTreeGrow(SaplingGrowTreeEvent event) { public void onTreeGrow(SaplingGrowTreeEvent event) {
ILevel level = event.getLevel(); var level = event.getWorld();
BlockPos pos = event.getPos(); var pos = event.getPos();
if (!level.isClientSide() && level instanceof Level) { if (!level.isClientSide() && level instanceof Level) {
if (Multiblocks.TREE_RITUAL.isComplete((Level) level, pos)) { if (Multiblocks.TREE_RITUAL.isComplete((Level) level, pos)) {
BlockState sapling = level.getBlockState(pos); var sapling = level.getBlockState(pos);
ItemStack saplingStack = sapling.getBlock().getItem(level, pos, sapling); var saplingStack = sapling.getBlock().getCloneItemStack(level, pos, sapling);
if (!saplingStack.isEmpty()) { if (!saplingStack.isEmpty()) {
for (TreeRitualRecipe recipe : ((Level) level).getRecipeManager().getRecipes(ModRecipes.TREE_RITUAL_TYPE, null, null)) { for (var recipe : ((Level) level).getRecipeManager().getRecipesFor(ModRecipes.TREE_RITUAL_TYPE, null, null)) {
if (recipe.saplingType.test(saplingStack)) { if (recipe.saplingType.test(saplingStack)) {
List<Ingredient> required = new ArrayList<>(Arrays.asList(recipe.ingredients)); List<Ingredient> required = new ArrayList<>(Arrays.asList(recipe.ingredients));
MutableObject<BlockEntityWoodStand> toPick = new MutableObject<>(); var toPick = new MutableObject<BlockEntityWoodStand>();
boolean fine = Multiblocks.TREE_RITUAL.forEach(pos, 'W', (tilePos, matcher) -> { var fine = Multiblocks.TREE_RITUAL.forEach(pos, 'W', (tilePos, matcher) -> {
BlockEntity tile = level.getBlockEntity(tilePos); var tile = level.getBlockEntity(tilePos);
if (tile instanceof BlockEntityWoodStand) { if (tile instanceof BlockEntityWoodStand stand) {
BlockEntityWoodStand stand = (BlockEntityWoodStand) tile; var stack = stand.items.getStackInSlot(0);
ItemStack stack = stand.items.getStackInSlot(0);
if (!stack.isEmpty()) { if (!stack.isEmpty()) {
for (int i = required.size() - 1; i >= 0; i--) { for (var i = required.size() - 1; i >= 0; i--) {
Ingredient req = required.get(i); var req = required.get(i);
if (req.test(stack)) { if (req.test(stack)) {
required.remove(i); required.remove(i);
@ -111,17 +104,17 @@ public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider<
} }
@Override @Override
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult hit) { public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
return Helper.putStackOnTile(player, handIn, pos, 0, true); return Helper.putStackOnTile(player, handIn, pos, 0, true);
} }
@Override
public Tuple<BlockEntityType<BlockEntityWoodStand>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityWoodStand>>>> getTESR() {
return new Tuple<>(ModTileEntities.WOOD_STAND, () -> RenderWoodStand::new);
}
@Override @Override
public void generateCustomBlockState(BlockStateGenerator generator) { public void generateCustomBlockState(BlockStateGenerator generator) {
generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName()))); generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName())));
} }
@Override
public void registerTESR() {
BlockEntityRenderers.register(ModTileEntities.WOOD_STAND, RenderWoodStand::new);
}
} }

View file

@ -29,24 +29,24 @@ public class Multiblock implements IMultiblock {
public Multiblock(ResourceLocation name, String[][] pattern, Object... rawMatchers) { public Multiblock(ResourceLocation name, String[][] pattern, Object... rawMatchers) {
this.name = name; this.name = name;
int width = -1; var width = -1;
this.height = pattern.length; this.height = pattern.length;
int depth = -1; var depth = -1;
int xOff = 0; var xOff = 0;
int yOff = 0; var yOff = 0;
int zOff = 0; var zOff = 0;
char[][][] raw = null; char[][][] raw = null;
for (int i = 0; i < pattern.length; i++) { for (var i = 0; i < pattern.length; i++) {
String[] row = pattern[i]; var row = pattern[i];
if (width < 0) if (width < 0)
width = row.length; width = row.length;
else if (row.length != width) else if (row.length != width)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
for (int j = 0; j < row.length; j++) { for (var j = 0; j < row.length; j++) {
String column = row[j]; var column = row[j];
if (depth < 0) if (depth < 0)
depth = column.length(); depth = column.length();
else if (column.length() != depth) else if (column.length() != depth)
@ -54,8 +54,8 @@ public class Multiblock implements IMultiblock {
if (raw == null) if (raw == null)
raw = new char[width][this.height][depth]; raw = new char[width][this.height][depth];
for (int k = 0; k < column.length(); k++) { for (var k = 0; k < column.length(); k++) {
char c = column.charAt(k); var c = column.charAt(k);
raw[k][this.height - 1 - i][j] = c; raw[k][this.height - 1 - i][j] = c;
if (c == '0') { if (c == '0') {
@ -74,12 +74,12 @@ public class Multiblock implements IMultiblock {
this.rawPattern = raw; this.rawPattern = raw;
Map<Character, Matcher> matchers = new HashMap<>(); Map<Character, Matcher> matchers = new HashMap<>();
for (int i = 0; i < rawMatchers.length; i += 2) { for (var i = 0; i < rawMatchers.length; i += 2) {
char c = (char) rawMatchers[i]; var c = (char) rawMatchers[i];
if (matchers.containsKey(c)) if (matchers.containsKey(c))
continue; continue;
Object value = rawMatchers[i + 1]; var value = rawMatchers[i + 1];
if (value instanceof BlockState state) { if (value instanceof BlockState state) {
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));
@ -90,13 +90,13 @@ public class Multiblock implements IMultiblock {
matchers.put(c, (Matcher) value); matchers.put(c, (Matcher) value);
} }
for (int x = 0; x < this.width; x++) for (var x = 0; x < this.width; x++)
for (int y = 0; y < this.height; y++) for (var y = 0; y < this.height; y++)
for (int z = 0; z < this.depth; z++) { for (var z = 0; z < this.depth; z++) {
Matcher matcher = matchers.get(this.rawPattern[x][y][z]); var matcher = matchers.get(this.rawPattern[x][y][z]);
if (matcher == null) if (matcher == null)
throw new IllegalStateException(); throw new IllegalStateException();
if (matcher.getCheck() != null) if (matcher.check() != null)
this.matchers.put(new BlockPos(x, y, z), matcher); this.matchers.put(new BlockPos(x, y, z), matcher);
} }
@ -106,18 +106,18 @@ public class Multiblock implements IMultiblock {
@Override @Override
public boolean isComplete(Level level, BlockPos center) { public boolean isComplete(Level level, BlockPos center) {
BlockPos start = this.getStart(center); var start = this.getStart(center);
return this.forEach(center, (char) 0, (pos, matcher) -> { return this.forEach(center, (char) 0, (pos, matcher) -> {
BlockPos offset = pos.subtract(start); var offset = pos.subtract(start);
return matcher.getCheck().matches(level, start, offset, pos, level.getBlockState(pos), this.getChar(offset)); return matcher.check().matches(level, start, offset, pos, level.getBlockState(pos), this.getChar(offset));
}); });
} }
@Override @Override
public boolean forEach(BlockPos center, char c, BiFunction<BlockPos, Matcher, Boolean> function) { public boolean forEach(BlockPos center, char c, BiFunction<BlockPos, Matcher, Boolean> function) {
BlockPos start = this.getStart(center); var start = this.getStart(center);
for (Map.Entry<BlockPos, Matcher> entry : this.matchers.entrySet()) { for (var entry : this.matchers.entrySet()) {
BlockPos offset = entry.getKey(); var offset = entry.getKey();
if (c == 0 || this.getChar(offset) == c) if (c == 0 || this.getChar(offset) == c)
if (!function.apply(start.offset(offset), entry.getValue())) if (!function.apply(start.offset(offset), entry.getValue()))
return false; return false;

View file

@ -53,7 +53,7 @@ public final class Multiblocks {
return true; return true;
// try-catch to prevent blocks that need to have been placed crashing here // try-catch to prevent blocks that need to have been placed crashing here
try { try {
ItemStack stack = state.getBlock().getCloneItemStack(level, pos, state); var stack = state.getBlock().getCloneItemStack(level, pos, state);
return !stack.isEmpty() && level.getRecipeManager().getRecipesFor(ModRecipes.TREE_RITUAL_TYPE, null, null).stream().anyMatch(r -> r.saplingType.test(stack)); return !stack.isEmpty() && level.getRecipeManager().getRecipesFor(ModRecipes.TREE_RITUAL_TYPE, null, null).stream().anyMatch(r -> r.saplingType.test(stack));
} catch (Exception e) { } catch (Exception e) {
return false; return false;

View file

@ -17,7 +17,7 @@ public class BlockEntityAncientLeaves extends BlockEntityImpl {
@Override @Override
public int drainAura(int amountToDrain, boolean simulate) { public int drainAura(int amountToDrain, boolean simulate) {
int amount = super.drainAura(amountToDrain, simulate); var amount = super.drainAura(amountToDrain, simulate);
if (amount > 0 && !simulate) { if (amount > 0 && !simulate) {
BlockEntityAncientLeaves.this.sendToClients(); BlockEntityAncientLeaves.this.sendToClients();
} }

View file

@ -22,7 +22,7 @@ public class BlockEntityAnimalGenerator extends BlockEntityImpl implements ITick
if (this.timeRemaining <= 0) if (this.timeRemaining <= 0)
return; return;
int remain = this.amountToRelease; var remain = this.amountToRelease;
if (this.canGenerateRightNow(remain)) { if (this.canGenerateRightNow(remain)) {
this.generateAura(remain); this.generateAura(remain);
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,

View file

@ -51,13 +51,13 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
} }
if (this.currentRecipe != null) { if (this.currentRecipe != null) {
int drain = Mth.ceil(this.currentRecipe.aura / (float) this.currentRecipe.time * 10F); var drain = Mth.ceil(this.currentRecipe.aura / (float) this.currentRecipe.time * 10F);
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition); var spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition);
IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, drain); IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, drain);
this.time += 10; this.time += 10;
if (this.time >= this.currentRecipe.time) { if (this.time >= this.currentRecipe.time) {
Entity entity = this.currentRecipe.makeEntity(this.level, new BlockPos(this.spawnX, this.worldPosition.getY() + 1, this.spawnZ)); var entity = this.currentRecipe.makeEntity(this.level, new BlockPos(this.spawnX, this.worldPosition.getY() + 1, this.spawnZ));
this.level.addFreshEntity(entity); this.level.addFreshEntity(entity);
this.currentRecipe = null; this.currentRecipe = null;
@ -65,20 +65,20 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
this.sendToClients(); this.sendToClients();
} }
} else { } else {
List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class, var items = this.level.getEntitiesOfClass(ItemEntity.class,
new AABB(this.worldPosition).inflate(2)); new AABB(this.worldPosition).inflate(2));
for (AnimalSpawnerRecipe recipe : this.level.getRecipeManager().getRecipesFor(ModRecipes.ANIMAL_SPAWNER_TYPE, null, null)) { for (var recipe : this.level.getRecipeManager().getRecipesFor(ModRecipes.ANIMAL_SPAWNER_TYPE, null, null)) {
if (recipe.ingredients.length != items.size()) if (recipe.ingredients.length != items.size())
continue; continue;
List<Ingredient> required = new ArrayList<>(Arrays.asList(recipe.ingredients)); List<Ingredient> required = new ArrayList<>(Arrays.asList(recipe.ingredients));
for (ItemEntity item : items) { for (var item : items) {
if (!item.isAlive() || item.hasPickUpDelay()) if (!item.isAlive() || item.hasPickUpDelay())
break; break;
ItemStack stack = item.getItem(); var stack = item.getItem();
if (stack.isEmpty()) if (stack.isEmpty())
break; break;
for (Ingredient ingredient : required) { for (var ingredient : required) {
if (ingredient.test(stack) && Helper.getIngredientAmount(ingredient) == stack.getCount()) { if (ingredient.test(stack) && Helper.getIngredientAmount(ingredient) == stack.getCount()) {
required.remove(ingredient); required.remove(ingredient);
break; break;
@ -88,7 +88,7 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
if (!required.isEmpty()) if (!required.isEmpty())
continue; continue;
for (ItemEntity item : items) { for (var item : items) {
item.remove(Entity.RemovalReason.KILLED); item.remove(Entity.RemovalReason.KILLED);
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
new PacketParticles((float) item.getX(), (float) item.getY(), (float) item.getZ(), PacketParticles.Type.ANIMAL_SPAWNER)); new PacketParticles((float) item.getX(), (float) item.getY(), (float) item.getZ(), PacketParticles.Type.ANIMAL_SPAWNER));
@ -124,8 +124,8 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
this.entityClient = this.currentRecipe.makeEntity(this.level, BlockPos.ZERO); this.entityClient = this.currentRecipe.makeEntity(this.level, BlockPos.ZERO);
this.entityClient.setPos(this.spawnX, this.worldPosition.getY() + 1, this.spawnZ); this.entityClient.setPos(this.spawnX, this.worldPosition.getY() + 1, this.spawnZ);
} }
AABB bounds = this.entityClient.getBoundingBox(); var bounds = this.entityClient.getBoundingBox();
for (int i = this.level.random.nextInt(5) + 5; i >= 0; i--) for (var i = this.level.random.nextInt(5) + 5; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
bounds.minX + this.level.random.nextFloat() * (bounds.maxX - bounds.minX), bounds.minX + this.level.random.nextFloat() * (bounds.maxX - bounds.minX),
bounds.minY + this.level.random.nextFloat() * (bounds.maxY - bounds.minY), bounds.minY + this.level.random.nextFloat() * (bounds.maxY - bounds.minY),
@ -153,7 +153,7 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
if (type != SaveType.BLOCK) { if (type != SaveType.BLOCK) {
if (compound.contains("recipe")) { if (compound.contains("recipe")) {
if (this.hasLevel()) { if (this.hasLevel()) {
ResourceLocation name = new ResourceLocation(compound.getString("recipe")); var name = new ResourceLocation(compound.getString("recipe"));
this.currentRecipe = (AnimalSpawnerRecipe) this.level.getRecipeManager().byKey(name).orElse(null); this.currentRecipe = (AnimalSpawnerRecipe) this.level.getRecipeManager().byKey(name).orElse(null);
} }
this.spawnX = compound.getDouble("spawn_x"); this.spawnX = compound.getDouble("spawn_x");

View file

@ -16,8 +16,8 @@ public class BlockEntityAuraDetector extends BlockEntityImpl implements ITickabl
@Override @Override
public void tick() { public void tick() {
if (!this.level.isClientSide && this.level.getGameTime() % 20 == 0) { if (!this.level.isClientSide && this.level.getGameTime() % 20 == 0) {
int totalAmount = IAuraChunk.triangulateAuraInArea(this.level, this.worldPosition, 25); var totalAmount = IAuraChunk.triangulateAuraInArea(this.level, this.worldPosition, 25);
int power = Mth.clamp(Mth.ceil(totalAmount / (IAuraChunk.DEFAULT_AURA * 2F) * 15F), 0, 15); var power = Mth.clamp(Mth.ceil(totalAmount / (IAuraChunk.DEFAULT_AURA * 2F) * 15F), 0, 15);
if (this.redstonePower != power) { if (this.redstonePower != power) {
this.redstonePower = power; this.redstonePower = power;
this.level.updateNeighbourForOutputSignal(this.worldPosition, this.getBlockState().getBlock()); this.level.updateNeighbourForOutputSignal(this.worldPosition, this.getBlockState().getBlock());

View file

@ -38,7 +38,7 @@ public class BlockEntityAuraTimer extends BlockEntityImpl implements ITickableBl
public void onRedstonePowerChange(int newPower) { public void onRedstonePowerChange(int newPower) {
if (this.redstonePower <= 0 && newPower > 0) { if (this.redstonePower <= 0 && newPower > 0) {
this.timer = 0; this.timer = 0;
int color = ItemAuraBottle.getType(this.itemHandler.getStackInSlot(0)).getColor(); var color = ItemAuraBottle.getType(this.itemHandler.getStackInSlot(0)).getColor();
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.TIMER_RESET, color)); PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.TIMER_RESET, color));
this.sendToClients(); this.sendToClients();
} }
@ -47,7 +47,7 @@ public class BlockEntityAuraTimer extends BlockEntityImpl implements ITickableBl
@Override @Override
public void tick() { public void tick() {
int total = this.getTotalTime(); var total = this.getTotalTime();
if (total <= 0) { if (total <= 0) {
this.timer = 0; this.timer = 0;
return; return;
@ -55,7 +55,7 @@ public class BlockEntityAuraTimer extends BlockEntityImpl implements ITickableBl
if (this.level.isClientSide) { if (this.level.isClientSide) {
if (this.level.getGameTime() % 8 == 0) { if (this.level.getGameTime() % 8 == 0) {
int color = ItemAuraBottle.getType(this.itemHandler.getStackInSlot(0)).getColor(); var color = ItemAuraBottle.getType(this.itemHandler.getStackInSlot(0)).getColor();
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
this.worldPosition.getX() + 1 / 16F + this.level.random.nextFloat() * 14 / 16F, this.worldPosition.getX() + 1 / 16F + this.level.random.nextFloat() * 14 / 16F,
this.worldPosition.getY() + 1 / 16F + this.level.random.nextFloat() * 14 / 16F, this.worldPosition.getY() + 1 / 16F + this.level.random.nextFloat() * 14 / 16F,
@ -69,11 +69,11 @@ public class BlockEntityAuraTimer extends BlockEntityImpl implements ITickableBl
if (this.timer >= total) { if (this.timer >= total) {
this.timer = 0; this.timer = 0;
BlockState state = this.getBlockState(); var state = this.getBlockState();
this.level.setBlock(this.worldPosition, state.setValue(BlockStateProperties.POWERED, true), 1); this.level.setBlock(this.worldPosition, state.setValue(BlockStateProperties.POWERED, true), 1);
this.level.scheduleTick(this.worldPosition, state.getBlock(), 4); this.level.scheduleTick(this.worldPosition, state.getBlock(), 4);
int color = ItemAuraBottle.getType(this.itemHandler.getStackInSlot(0)).getColor(); var color = ItemAuraBottle.getType(this.itemHandler.getStackInSlot(0)).getColor();
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.TIMER_RESET, color)); PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.TIMER_RESET, color));
} }
if (this.timer % 2 == 0) if (this.timer % 2 == 0)
@ -81,10 +81,10 @@ public class BlockEntityAuraTimer extends BlockEntityImpl implements ITickableBl
} }
public int getTotalTime() { public int getTotalTime() {
ItemStack stack = this.itemHandler.getStackInSlot(0); var stack = this.itemHandler.getStackInSlot(0);
if (stack.isEmpty()) if (stack.isEmpty())
return 0; return 0;
Integer amount = TIMES.get(ItemAuraBottle.getType(stack)); var amount = TIMES.get(ItemAuraBottle.getType(stack));
if (amount == null) if (amount == null)
return 0; return 0;
return amount * stack.getCount(); return amount * stack.getCount();

View file

@ -38,7 +38,7 @@ public class BlockEntityAutoCrafter extends BlockEntityImpl implements ITickable
this.crafting.clearContent(); this.crafting.clearContent();
var state = this.level.getBlockState(this.worldPosition); var state = this.level.getBlockState(this.worldPosition);
Direction facing = state.getValue(BlockAutoCrafter.FACING); var facing = state.getValue(BlockAutoCrafter.FACING);
var middlePos = this.worldPosition.above(); var middlePos = this.worldPosition.above();
var topPos = middlePos.relative(facing, 2); var topPos = middlePos.relative(facing, 2);
var bottomPos = middlePos.relative(facing.getOpposite(), 2); var bottomPos = middlePos.relative(facing.getOpposite(), 2);

View file

@ -30,7 +30,7 @@ public class BlockEntityBlastFurnaceBooster extends BlockEntityImpl implements I
if (this.level.isClientSide) if (this.level.isClientSide)
return; return;
BlockEntity below = this.level.getBlockEntity(this.worldPosition.below()); var below = this.level.getBlockEntity(this.worldPosition.below());
if (!(below instanceof BlastFurnaceBlockEntity tile)) if (!(below instanceof BlastFurnaceBlockEntity tile))
return; return;
Recipe<?> recipe = this.level.getRecipeManager().getRecipeFor(BlockEntityFurnaceHeater.getRecipeType(tile), tile, this.level).orElse(null); Recipe<?> recipe = this.level.getRecipeManager().getRecipeFor(BlockEntityFurnaceHeater.getRecipeType(tile), tile, this.level).orElse(null);
@ -39,8 +39,8 @@ public class BlockEntityBlastFurnaceBooster extends BlockEntityImpl implements I
if (!this.isApplicable(recipe.getIngredients())) if (!this.isApplicable(recipe.getIngredients()))
return; return;
ContainerData data = BlockEntityFurnaceHeater.getFurnaceData(tile); var data = BlockEntityFurnaceHeater.getFurnaceData(tile);
int doneDiff = data.get(3) - data.get(2); var doneDiff = data.get(3) - data.get(2);
if (doneDiff > 1) if (doneDiff > 1)
return; return;
@ -50,18 +50,18 @@ public class BlockEntityBlastFurnaceBooster extends BlockEntityImpl implements I
return; return;
} }
ItemStack output = tile.getItem(2); var output = tile.getItem(2);
if (output.getCount() >= output.getMaxStackSize()) if (output.getCount() >= output.getMaxStackSize())
return; return;
if (output.isEmpty()) { if (output.isEmpty()) {
ItemStack result = recipe.getResultItem(); var result = recipe.getResultItem();
tile.setItem(2, result.copy()); tile.setItem(2, result.copy());
} else { } else {
output.grow(1); output.grow(1);
} }
BlockPos pos = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 30, this.worldPosition); var pos = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 30, this.worldPosition);
IAuraChunk.getAuraChunk(this.level, pos).drainAura(pos, 6500); IAuraChunk.getAuraChunk(this.level, pos).drainAura(pos, 6500);
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
@ -69,8 +69,8 @@ public class BlockEntityBlastFurnaceBooster extends BlockEntityImpl implements I
} }
private boolean isApplicable(List<Ingredient> ingredients) { private boolean isApplicable(List<Ingredient> ingredients) {
for (Ingredient ing : ingredients) { for (var ing : ingredients) {
for (ItemStack stack : ing.getItems()) { for (var stack : ing.getItems()) {
if (stack.getItem().getTags().stream().anyMatch(t -> t.getPath().startsWith("ores/"))) if (stack.getItem().getTags().stream().anyMatch(t -> t.getPath().startsWith("ores/")))
return true; return true;
} }
@ -80,10 +80,10 @@ public class BlockEntityBlastFurnaceBooster extends BlockEntityImpl implements I
@Override @Override
public IItemHandlerModifiable getItemHandler() { public IItemHandlerModifiable getItemHandler() {
BlockEntity below = this.level.getBlockEntity(this.worldPosition.below()); var below = this.level.getBlockEntity(this.worldPosition.below());
if (!(below instanceof BlastFurnaceBlockEntity)) if (!(below instanceof BlastFurnaceBlockEntity))
return null; return null;
IItemHandler handler = below.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.UP).orElse(null); var handler = below.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.UP).orElse(null);
if (handler == null) if (handler == null)
return null; return null;
return new IItemHandlerModifiable() { return new IItemHandlerModifiable() {

View file

@ -34,8 +34,8 @@ public class BlockEntityChorusGenerator extends BlockEntityImpl implements ITick
return; return;
if (this.currentlyBreaking.isEmpty()) if (this.currentlyBreaking.isEmpty())
return; return;
BlockPos pos = this.currentlyBreaking.removeLast(); var pos = this.currentlyBreaking.removeLast();
BlockState state = this.level.getBlockState(pos); var state = this.level.getBlockState(pos);
if (state.getBlock() != Blocks.CHORUS_PLANT && state.getBlock() != Blocks.CHORUS_FLOWER) { if (state.getBlock() != Blocks.CHORUS_PLANT && state.getBlock() != Blocks.CHORUS_FLOWER) {
this.currentlyBreaking.clear(); this.currentlyBreaking.clear();
return; return;
@ -50,16 +50,16 @@ public class BlockEntityChorusGenerator extends BlockEntityImpl implements ITick
@Override @Override
public void onRedstonePowerChange(int newPower) { public void onRedstonePowerChange(int newPower) {
if (this.redstonePower <= 0 && newPower > 0 && this.currentlyBreaking.isEmpty()) { if (this.redstonePower <= 0 && newPower > 0 && this.currentlyBreaking.isEmpty()) {
int range = 2; var range = 2;
xyz: xyz:
for (int x = -range; x <= range; x++) { for (var x = -range; x <= range; x++) {
for (int y = -range; y <= range; y++) { for (var y = -range; y <= range; y++) {
for (int z = -range; z <= range; z++) { for (var z = -range; z <= range; z++) {
BlockPos offset = this.worldPosition.offset(x, y, z); var offset = this.worldPosition.offset(x, y, z);
BlockState below = this.level.getBlockState(offset.below()); var below = this.level.getBlockState(offset.below());
if (below.getBlock() != Blocks.END_STONE) if (below.getBlock() != Blocks.END_STONE)
continue; continue;
BlockState state = this.level.getBlockState(offset); var state = this.level.getBlockState(offset);
if (state.getBlock() != Blocks.CHORUS_PLANT) if (state.getBlock() != Blocks.CHORUS_PLANT)
continue; continue;
@ -70,7 +70,7 @@ public class BlockEntityChorusGenerator extends BlockEntityImpl implements ITick
this.currentlyBreaking.addAll(plants); this.currentlyBreaking.addAll(plants);
this.currentlyBreaking.addFirst(offset); this.currentlyBreaking.addFirst(offset);
int aura = plants.size() * plants.size() * 300; var aura = plants.size() * plants.size() * 300;
this.auraPerBlock = aura / plants.size(); this.auraPerBlock = aura / plants.size();
break xyz; break xyz;
@ -82,13 +82,13 @@ public class BlockEntityChorusGenerator extends BlockEntityImpl implements ITick
} }
private void collectChorusPlant(BlockPos pos, List<BlockPos> blocks) { private void collectChorusPlant(BlockPos pos, List<BlockPos> blocks) {
for (Direction dir : Direction.values()) { for (var dir : Direction.values()) {
if (dir == Direction.DOWN) if (dir == Direction.DOWN)
continue; continue;
BlockPos offset = pos.relative(dir); var offset = pos.relative(dir);
if (blocks.contains(offset)) if (blocks.contains(offset))
continue; continue;
BlockState state = this.level.getBlockState(offset); var state = this.level.getBlockState(offset);
if (state.getBlock() != Blocks.CHORUS_PLANT && state.getBlock() != Blocks.CHORUS_FLOWER) if (state.getBlock() != Blocks.CHORUS_PLANT && state.getBlock() != Blocks.CHORUS_FLOWER)
continue; continue;
blocks.add(offset); blocks.add(offset);
@ -100,8 +100,8 @@ public class BlockEntityChorusGenerator extends BlockEntityImpl implements ITick
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.TILE) { if (type == SaveType.TILE) {
ListTag list = new ListTag(); var list = new ListTag();
for (BlockPos pos : this.currentlyBreaking) for (var pos : this.currentlyBreaking)
list.add(NbtUtils.writeBlockPos(pos)); list.add(NbtUtils.writeBlockPos(pos));
compound.put("breaking", list); compound.put("breaking", list);
compound.putInt("aura", this.auraPerBlock); compound.putInt("aura", this.auraPerBlock);
@ -113,8 +113,8 @@ public class BlockEntityChorusGenerator extends BlockEntityImpl implements ITick
super.readNBT(compound, type); super.readNBT(compound, type);
if (type == SaveType.TILE) { if (type == SaveType.TILE) {
this.currentlyBreaking.clear(); this.currentlyBreaking.clear();
ListTag list = compound.getList("breaking", 10); var list = compound.getList("breaking", 10);
for (int i = 0; i < list.size(); i++) for (var i = 0; i < list.size(); i++)
this.currentlyBreaking.add(NbtUtils.readBlockPos(list.getCompound(i))); this.currentlyBreaking.add(NbtUtils.readBlockPos(list.getCompound(i)));
this.auraPerBlock = compound.getInt("aura"); this.auraPerBlock = compound.getInt("aura");
} }

View file

@ -45,15 +45,15 @@ public class BlockEntityChunkLoader extends BlockEntityImpl implements ITickable
private void loadChunks(boolean unload) { private void loadChunks(boolean unload) {
if (this.level.isClientSide || !ModConfig.instance.chunkLoader.get()) if (this.level.isClientSide || !ModConfig.instance.chunkLoader.get())
return; return;
ServerLevel level = (ServerLevel) this.level; var level = (ServerLevel) this.level;
List<ChunkPos> shouldBeForced = new ArrayList<>(); List<ChunkPos> shouldBeForced = new ArrayList<>();
if (!unload) { if (!unload) {
int range = this.range(); var range = this.range();
if (range > 0) { if (range > 0) {
for (int x = (this.worldPosition.getX() - range) >> 4; x <= (this.worldPosition.getX() + range) >> 4; x++) { for (var x = (this.worldPosition.getX() - range) >> 4; x <= (this.worldPosition.getX() + range) >> 4; x++) {
for (int z = (this.worldPosition.getZ() - range) >> 4; z <= (this.worldPosition.getZ() + range) >> 4; z++) { for (var z = (this.worldPosition.getZ() - range) >> 4; z <= (this.worldPosition.getZ() + range) >> 4; z++) {
ChunkPos pos = new ChunkPos(x, z); var pos = new ChunkPos(x, z);
// Only force chunks that we're already forcing or that nobody else is forcing // Only force chunks that we're already forcing or that nobody else is forcing
if (this.forcedChunks.contains(pos) || !level.getForcedChunks().contains(pos.toLong())) if (this.forcedChunks.contains(pos) || !level.getForcedChunks().contains(pos.toLong()))
shouldBeForced.add(pos); shouldBeForced.add(pos);
@ -63,14 +63,14 @@ public class BlockEntityChunkLoader extends BlockEntityImpl implements ITickable
} }
// Unforce all the chunks that shouldn't be forced anymore // Unforce all the chunks that shouldn't be forced anymore
for (ChunkPos pos : this.forcedChunks) { for (var pos : this.forcedChunks) {
if (!shouldBeForced.contains(pos)) if (!shouldBeForced.contains(pos))
level.setChunkForced(pos.x, pos.z, false); level.setChunkForced(pos.x, pos.z, false);
} }
this.forcedChunks.clear(); this.forcedChunks.clear();
// Force all chunks that should be forced // Force all chunks that should be forced
for (ChunkPos pos : shouldBeForced) { for (var pos : shouldBeForced) {
level.setChunkForced(pos.x, pos.z, true); level.setChunkForced(pos.x, pos.z, true);
this.forcedChunks.add(pos); this.forcedChunks.add(pos);
} }
@ -88,9 +88,9 @@ public class BlockEntityChunkLoader extends BlockEntityImpl implements ITickable
if (this.level.getGameTime() % 20 != 0) if (this.level.getGameTime() % 20 != 0)
return; return;
int toUse = Mth.ceil(this.range() / 2F); var toUse = Mth.ceil(this.range() / 2F);
if (toUse > 0) { if (toUse > 0) {
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition); var spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition);
IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, toUse); IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, toUse);
} }
} }

View file

@ -31,7 +31,7 @@ public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBl
@Override @Override
public int drainAura(int amountToDrain, boolean simulate) { public int drainAura(int amountToDrain, boolean simulate) {
int amount = super.drainAura(amountToDrain, simulate); var amount = super.drainAura(amountToDrain, simulate);
if (amount > 0 && !simulate) if (amount > 0 && !simulate)
BlockEntityEndFlower.this.sendToClients(); BlockEntityEndFlower.this.sendToClients();
return amount; return amount;
@ -56,11 +56,11 @@ public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBl
return; return;
if (!this.isDrainMode) { if (!this.isDrainMode) {
List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class, new AABB(this.worldPosition).inflate(1), Entity::isAlive); var items = this.level.getEntitiesOfClass(ItemEntity.class, new AABB(this.worldPosition).inflate(1), Entity::isAlive);
for (ItemEntity item : items) { for (var item : items) {
if (item.hasPickUpDelay()) if (item.hasPickUpDelay())
continue; continue;
ItemStack stack = item.getItem(); var stack = item.getItem();
if (stack.getCount() != 1) if (stack.getCount() != 1)
continue; continue;
if (stack.getItem() != Items.ENDER_EYE) if (stack.getItem() != Items.ENDER_EYE)
@ -74,7 +74,7 @@ public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBl
break; break;
} }
} else { } else {
int toDrain = Math.min(5000, this.container.getStoredAura()); var toDrain = Math.min(5000, this.container.getStoredAura());
this.container.drainAura(toDrain, false); this.container.drainAura(toDrain, false);
this.generateAura(toDrain); this.generateAura(toDrain);

View file

@ -45,7 +45,7 @@ public class BlockEntityEnderCrate extends BlockEntityImpl implements MenuProvid
@Nonnull @Nonnull
@Override @Override
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
ItemStack remain = this.getStorage().insertItem(slot, stack, simulate); var remain = this.getStorage().insertItem(slot, stack, simulate);
if (!simulate) if (!simulate)
BlockEntityEnderCrate.this.drainAura((stack.getCount() - remain.getCount()) * 20); BlockEntityEnderCrate.this.drainAura((stack.getCount() - remain.getCount()) * 20);
return remain; return remain;
@ -54,7 +54,7 @@ public class BlockEntityEnderCrate extends BlockEntityImpl implements MenuProvid
@Nonnull @Nonnull
@Override @Override
public ItemStack extractItem(int slot, int amount, boolean simulate) { public ItemStack extractItem(int slot, int amount, boolean simulate) {
ItemStack extracted = this.getStorage().extractItem(slot, amount, simulate); var extracted = this.getStorage().extractItem(slot, amount, simulate);
if (!simulate) if (!simulate)
BlockEntityEnderCrate.this.drainAura(extracted.getCount() * 20); BlockEntityEnderCrate.this.drainAura(extracted.getCount() * 20);
return extracted; return extracted;
@ -107,7 +107,7 @@ public class BlockEntityEnderCrate extends BlockEntityImpl implements MenuProvid
public void loadDataOnPlace(ItemStack stack) { public void loadDataOnPlace(ItemStack stack) {
super.loadDataOnPlace(stack); super.loadDataOnPlace(stack);
if (!this.level.isClientSide) { if (!this.level.isClientSide) {
String name = BlockEnderCrate.getEnderName(stack); var name = BlockEnderCrate.getEnderName(stack);
if (name != null && !name.isEmpty()) if (name != null && !name.isEmpty())
this.name = name; this.name = name;
} }
@ -133,7 +133,7 @@ public class BlockEntityEnderCrate extends BlockEntityImpl implements MenuProvid
public void drainAura(int amount) { public void drainAura(int amount) {
if (amount > 0) { if (amount > 0) {
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition); var spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition);
IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, amount); IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, amount);
} }
} }

View file

@ -42,11 +42,11 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
if (this.level.isClientSide || this.level.getGameTime() % 10 != 0) if (this.level.isClientSide || this.level.getGameTime() % 10 != 0)
return; return;
BlockPos connectedPos = this.getConnectedPos(); var connectedPos = this.getConnectedPos();
if (connectedPos == null || !this.level.isLoaded(connectedPos)) if (connectedPos == null || !this.level.isLoaded(connectedPos))
return; return;
BlockEntity other = this.level.getBlockEntity(connectedPos); var other = this.level.getBlockEntity(connectedPos);
if (!this.isCloseEnough(connectedPos) if (!this.isCloseEnough(connectedPos)
|| !(other instanceof BlockEntityFieldCreator) || !(other instanceof BlockEntityFieldCreator)
|| !this.worldPosition.equals(((BlockEntityFieldCreator) other).getConnectedPos())) { || !this.worldPosition.equals(((BlockEntityFieldCreator) other).getConnectedPos())) {
@ -61,7 +61,7 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
if (!this.isMain) if (!this.isMain)
return; return;
BlockEntityFieldCreator creator = (BlockEntityFieldCreator) other; var creator = (BlockEntityFieldCreator) other;
if (this.redstonePower <= 0 && creator.redstonePower <= 0) { if (this.redstonePower <= 0 && creator.redstonePower <= 0) {
this.chargeTimer = 0; this.chargeTimer = 0;
if (this.isCharged) { if (this.isCharged) {
@ -73,8 +73,8 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
return; return;
} }
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 32, this.worldPosition); var spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 32, this.worldPosition);
IAuraChunk chunk = IAuraChunk.getAuraChunk(this.level, spot); var chunk = IAuraChunk.getAuraChunk(this.level, spot);
if (!this.isCharged) { if (!this.isCharged) {
this.chargeTimer += 10; this.chargeTimer += 10;
@ -93,17 +93,17 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
if (this.level.getGameTime() % 40 == 0) if (this.level.getGameTime() % 40 == 0)
chunk.drainAura(spot, 20); chunk.drainAura(spot, 20);
ItemStack tool = this.getToolUsed(creator); var tool = this.getToolUsed(creator);
Vec3 dist = new Vec3( var 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(); var length = dist.length();
Vec3 normal = new Vec3(dist.x / length, dist.y / length, dist.z / length); var 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) {
Vec3 scaled = normal.scale(i); var scaled = normal.scale(i);
BlockPos pos = connectedPos.offset( var 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));
@ -111,19 +111,19 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
if (pos.equals(this.worldPosition) || pos.equals(connectedPos)) if (pos.equals(this.worldPosition) || pos.equals(connectedPos))
continue; continue;
BlockState state = this.level.getBlockState(pos); var state = this.level.getBlockState(pos);
Block block = state.getBlock(); var block = state.getBlock();
if (!state.isAir() && state.getDestroySpeed(this.level, pos) >= 0F) { if (!state.isAir() && state.getDestroySpeed(this.level, pos) >= 0F) {
FakePlayer fake = FakePlayerFactory.getMinecraft((ServerLevel) this.level); var 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) var drops = state.getDrops(new LootContext.Builder((ServerLevel) this.level)
.withParameter(LootContextParams.THIS_ENTITY, fake) .withParameter(LootContextParams.THIS_ENTITY, fake)
.withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(pos)) .withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(pos))
.withParameter(LootContextParams.BLOCK_STATE, state) .withParameter(LootContextParams.BLOCK_STATE, state)
.withParameter(LootContextParams.TOOL, tool.isEmpty() ? new ItemStack(Items.DIAMOND_PICKAXE) : tool) .withParameter(LootContextParams.TOOL, tool.isEmpty() ? new ItemStack(Items.DIAMOND_PICKAXE) : tool)
.withOptionalParameter(LootContextParams.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 (var stack : drops)
Block.popResource(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();
@ -134,8 +134,8 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
} }
private ItemStack getToolUsed(BlockEntityFieldCreator other) { private ItemStack getToolUsed(BlockEntityFieldCreator other) {
ItemStack myTool = this.getMyTool(); var myTool = this.getMyTool();
ItemStack otherTool = other.getMyTool(); var otherTool = other.getMyTool();
if (!myTool.isEmpty()) { if (!myTool.isEmpty()) {
// if both have tools, choose randomly // if both have tools, choose randomly
if (!otherTool.isEmpty()) if (!otherTool.isEmpty())
@ -146,9 +146,9 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
} }
private ItemStack getMyTool() { private ItemStack getMyTool() {
List<ItemFrame> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition); var frames = Helper.getAttachedItemFrames(this.level, this.worldPosition);
for (ItemFrame frame : frames) { for (var frame : frames) {
ItemStack stack = frame.getItem(); var stack = frame.getItem();
if (!stack.isEmpty()) if (!stack.isEmpty())
return stack; return stack;
} }
@ -156,8 +156,8 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
} }
private void sendParticles() { private void sendParticles() {
for (int j = 0; j < 2; j++) { for (var j = 0; j < 2; j++) {
BlockPos p = j == 0 ? this.worldPosition : this.getConnectedPos(); var 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.random.nextGaussian() * 3F, p.getX() + (float) this.level.random.nextGaussian() * 3F,
p.getY() + 1 + this.level.random.nextFloat() * 3F, p.getY() + 1 + this.level.random.nextFloat() * 3F,
@ -171,7 +171,7 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
} }
public boolean isCloseEnough(BlockPos pos) { public boolean isCloseEnough(BlockPos pos) {
int range = ModConfig.instance.fieldCreatorRange.get() + 1; var range = ModConfig.instance.fieldCreatorRange.get() + 1;
return this.worldPosition.distSqr(pos) <= range * range; return this.worldPosition.distSqr(pos) <= range * range;
} }

View file

@ -36,15 +36,15 @@ public class BlockEntityFireworkGenerator extends BlockEntityImpl implements ITi
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.getEntitiesOfClass(ItemEntity.class, new AABB(this.worldPosition).inflate(4), Entity::isAlive); var items = this.level.getEntitiesOfClass(ItemEntity.class, new AABB(this.worldPosition).inflate(4), Entity::isAlive);
for (ItemEntity item : items) { for (var item : items) {
if (item.hasPickUpDelay()) if (item.hasPickUpDelay())
continue; continue;
ItemStack stack = item.getItem(); var 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.getX(), item.getY(), item.getZ(), stack); var 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.addFreshEntity(entity); this.level.addFreshEntity(entity);
@ -63,31 +63,31 @@ public class BlockEntityFireworkGenerator extends BlockEntityImpl implements ITi
float generateFactor = 0; float generateFactor = 0;
Set<Integer> usedColors = new HashSet<>(); Set<Integer> usedColors = new HashSet<>();
CompoundTag compound = this.trackedItem.getTag(); var compound = this.trackedItem.getTag();
CompoundTag fireworks = compound.getCompound("Fireworks"); var fireworks = compound.getCompound("Fireworks");
int flightTime = fireworks.getInt("Flight"); var flightTime = fireworks.getInt("Flight");
ListTag explosions = fireworks.getList("Explosions", 10); var explosions = fireworks.getList("Explosions", 10);
if (!explosions.isEmpty()) { if (!explosions.isEmpty()) {
generateFactor += flightTime; generateFactor += flightTime;
for (Tag base : explosions) { for (var base : explosions) {
CompoundTag explosion = (CompoundTag) base; var explosion = (CompoundTag) base;
generateFactor += 1.5F; generateFactor += 1.5F;
boolean flicker = explosion.getBoolean("Flicker"); var flicker = explosion.getBoolean("Flicker");
if (flicker) if (flicker)
generateFactor += 1; generateFactor += 1;
boolean trail = explosion.getBoolean("Trail"); var trail = explosion.getBoolean("Trail");
if (trail) if (trail)
generateFactor += 8; generateFactor += 8;
byte type = explosion.getByte("Type"); var type = explosion.getByte("Type");
generateFactor += new float[]{0, 1, 0.5F, 20, 0.5F}[type]; generateFactor += new float[]{0, 1, 0.5F, 20, 0.5F}[type];
Set<Integer> colors = new HashSet<>(); Set<Integer> colors = new HashSet<>();
for (int color : explosion.getIntArray("Colors")) { for (var color : explosion.getIntArray("Colors")) {
usedColors.add(color); usedColors.add(color);
colors.add(color); colors.add(color);
} }
@ -96,7 +96,7 @@ public class BlockEntityFireworkGenerator extends BlockEntityImpl implements ITi
} }
if (generateFactor > 0) { if (generateFactor > 0) {
int toAdd = Mth.ceil(generateFactor * 10000F); var toAdd = Mth.ceil(generateFactor * 10000F);
if (this.canGenerateRightNow(toAdd)) { if (this.canGenerateRightNow(toAdd)) {
this.toRelease = toAdd; this.toRelease = toAdd;
this.releaseTimer = 15 * flightTime + 40; this.releaseTimer = 15 * flightTime + 40;

View file

@ -34,12 +34,12 @@ public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITick
public void tick() { public void tick() {
if (!this.level.isClientSide && this.level.getGameTime() % 10 == 0) { if (!this.level.isClientSide && this.level.getGameTime() % 10 == 0) {
List<BlockPos> possible = new ArrayList<>(); List<BlockPos> possible = new ArrayList<>();
int range = 3; var range = 3;
for (int x = -range; x <= range; x++) { for (var x = -range; x <= range; x++) {
for (int y = -1; y <= 1; y++) { for (var y = -1; y <= 1; y++) {
for (int z = -range; z <= range; z++) { for (var z = -range; z <= range; z++) {
BlockPos offset = this.worldPosition.offset(x, y, z); var offset = this.worldPosition.offset(x, y, z);
BlockState state = this.level.getBlockState(offset); var 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);
} }
@ -49,12 +49,12 @@ public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITick
if (possible.isEmpty()) if (possible.isEmpty())
return; return;
BlockPos pos = possible.get(this.level.random.nextInt(possible.size())); var pos = possible.get(this.level.random.nextInt(possible.size()));
BlockState state = this.level.getBlockState(pos); var state = this.level.getBlockState(pos);
MutableInt curr = this.consumedRecently.computeIfAbsent(state, s -> new MutableInt()); var curr = this.consumedRecently.computeIfAbsent(state, s -> new MutableInt());
int addAmount = 25000; var addAmount = 25000;
int toAdd = Math.max(0, addAmount - curr.getValue() * 100); var toAdd = Math.max(0, addAmount - curr.getValue() * 100);
if (toAdd > 0) { if (toAdd > 0) {
if (IAuraType.forLevel(this.level).isSimilar(NaturesAuraAPI.TYPE_OVERWORLD) && this.canGenerateRightNow(toAdd)) { if (IAuraType.forLevel(this.level).isSimilar(NaturesAuraAPI.TYPE_OVERWORLD) && this.canGenerateRightNow(toAdd)) {
this.generateAura(toAdd); this.generateAura(toAdd);
@ -63,9 +63,9 @@ public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITick
} }
} }
for (Map.Entry<BlockState, MutableInt> entry : this.consumedRecently.entrySet()) { for (var entry : this.consumedRecently.entrySet()) {
if (entry.getKey() != state) { if (entry.getKey() != state) {
MutableInt val = entry.getValue(); var val = entry.getValue();
if (val.getValue() > 0) if (val.getValue() > 0)
val.subtract(1); val.subtract(1);
} }
@ -74,9 +74,9 @@ public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITick
this.level.removeBlock(pos, false); this.level.removeBlock(pos, false);
int color = Helper.blendColors(0x5ccc30, 0xe53c16, toAdd / (float) addAmount); var color = Helper.blendColors(0x5ccc30, 0xe53c16, toAdd / (float) addAmount);
if (toAdd > 0) { if (toAdd > 0) {
for (int i = this.level.random.nextInt(5) + 5; i >= 0; i--) for (var 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.random.nextFloat() * 0.5F, pos.getX() + 0.25F + this.level.random.nextFloat() * 0.5F,
pos.getY() + 0.25F + this.level.random.nextFloat() * 0.5F, pos.getY() + 0.25F + this.level.random.nextFloat() * 0.5F,
@ -102,12 +102,12 @@ 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()) {
ListTag list = new ListTag(); var list = new ListTag();
for (Map.Entry<BlockState, MutableInt> entry : this.consumedRecently.entrySet()) { for (var entry : this.consumedRecently.entrySet()) {
BlockState state = entry.getKey(); var state = entry.getKey();
Block block = state.getBlock(); var block = state.getBlock();
CompoundTag tag = new CompoundTag(); var tag = new CompoundTag();
tag.putString("block", block.getRegistryName().toString()); tag.putString("block", block.getRegistryName().toString());
tag.putInt("amount", entry.getValue().intValue()); tag.putInt("amount", entry.getValue().intValue());
list.add(tag); list.add(tag);
@ -121,10 +121,10 @@ 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();
ListTag list = compound.getList("consumed_recently", 10); var list = compound.getList("consumed_recently", 10);
for (Tag base : list) { for (var base : list) {
CompoundTag tag = (CompoundTag) base; var tag = (CompoundTag) base;
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(tag.getString("block"))); var block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(tag.getString("block")));
if (block != null) if (block != null)
this.consumedRecently.put(block.defaultBlockState(), new MutableInt(tag.getInt("amount"))); this.consumedRecently.put(block.defaultBlockState(), new MutableInt(tag.getInt("amount")));
} }

View file

@ -56,14 +56,14 @@ public class BlockEntityFurnaceHeater extends BlockEntityImpl implements ITickab
@Override @Override
public void tick() { public void tick() {
if (!this.level.isClientSide && this.level.getGameTime() % 5 == 0) { if (!this.level.isClientSide && this.level.getGameTime() % 5 == 0) {
boolean did = false; var did = false;
Direction facing = this.level.getBlockState(this.worldPosition).getValue(BlockFurnaceHeater.FACING); var facing = this.level.getBlockState(this.worldPosition).getValue(BlockFurnaceHeater.FACING);
BlockPos tilePos = this.worldPosition.relative(facing.getOpposite()); var tilePos = this.worldPosition.relative(facing.getOpposite());
BlockEntity tile = this.level.getBlockEntity(tilePos); var tile = this.level.getBlockEntity(tilePos);
if (tile instanceof AbstractFurnaceBlockEntity furnace && this.isReady(furnace)) { if (tile instanceof AbstractFurnaceBlockEntity furnace && this.isReady(furnace)) {
ContainerData data = getFurnaceData(furnace); var data = getFurnaceData(furnace);
int burnTime = data.get(0); var burnTime = data.get(0);
if (burnTime <= 0) if (burnTime <= 0)
this.level.setBlockAndUpdate(tilePos, this.level.getBlockState(tilePos).setValue(AbstractFurnaceBlock.LIT, true)); this.level.setBlockAndUpdate(tilePos, this.level.getBlockState(tilePos).setValue(AbstractFurnaceBlock.LIT, true));
@ -71,8 +71,8 @@ public class BlockEntityFurnaceHeater extends BlockEntityImpl implements ITickab
//if set higher than 199, it'll never finish because the furnace does ++ and then == //if set higher than 199, it'll never finish because the furnace does ++ and then ==
data.set(2, Math.min(data.get(3) - 1, data.get(2) + 5)); data.set(2, Math.min(data.get(3) - 1, data.get(2) + 5));
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 20, this.worldPosition); var spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 20, this.worldPosition);
IAuraChunk chunk = IAuraChunk.getAuraChunk(this.level, spot); var chunk = IAuraChunk.getAuraChunk(this.level, spot);
chunk.drainAura(spot, Mth.ceil((200 - burnTime) * 16.6F)); chunk.drainAura(spot, Mth.ceil((200 - burnTime) * 16.6F));
did = true; did = true;
@ -100,13 +100,13 @@ public class BlockEntityFurnaceHeater extends BlockEntityImpl implements ITickab
if (!furnace.getItem(1).isEmpty()) if (!furnace.getItem(1).isEmpty())
return false; return false;
ItemStack input = furnace.getItem(0); var input = furnace.getItem(0);
if (!input.isEmpty()) { if (!input.isEmpty()) {
AbstractCookingRecipe recipe = this.level.getRecipeManager().getRecipeFor(getRecipeType(furnace), furnace, this.level).orElse(null); var recipe = this.level.getRecipeManager().getRecipeFor(getRecipeType(furnace), furnace, this.level).orElse(null);
if (recipe == null) if (recipe == null)
return false; return false;
ItemStack output = recipe.getResultItem(); var output = recipe.getResultItem();
ItemStack currOutput = furnace.getItem(2); var currOutput = furnace.getItem(2);
return currOutput.isEmpty() || Helper.areItemsEqual(currOutput, output, true) && currOutput.getCount() + output.getCount() <= output.getMaxStackSize(); return currOutput.isEmpty() || Helper.areItemsEqual(currOutput, output, true) && currOutput.getCount() + output.getCount() <= output.getMaxStackSize();
} else } else
return false; return false;

View file

@ -45,22 +45,22 @@ public class BlockEntityGratedChute extends BlockEntityImpl implements ITickable
if (this.redstonePower > 0) if (this.redstonePower > 0)
return; return;
ItemStack curr = this.items.getStackInSlot(0); var curr = this.items.getStackInSlot(0);
push: push:
if (!curr.isEmpty()) { if (!curr.isEmpty()) {
BlockState state = this.level.getBlockState(this.worldPosition); var state = this.level.getBlockState(this.worldPosition);
Direction facing = state.getValue(BlockGratedChute.FACING); var facing = state.getValue(BlockGratedChute.FACING);
BlockEntity tile = this.level.getBlockEntity(this.worldPosition.relative(facing)); var 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, var handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY,
facing.getOpposite()).orElse(null); facing.getOpposite()).orElse(null);
if (handler == null) if (handler == null)
break push; break push;
for (int i = 0; i < handler.getSlots(); i++) { for (var i = 0; i < handler.getSlots(); i++) {
ItemStack theoreticalDrain = this.items.extractItem(0, 1, true); var theoreticalDrain = this.items.extractItem(0, 1, true);
if (!theoreticalDrain.isEmpty()) { if (!theoreticalDrain.isEmpty()) {
ItemStack left = handler.insertItem(i, theoreticalDrain, false); var left = handler.insertItem(i, theoreticalDrain, false);
if (left.isEmpty()) { if (left.isEmpty()) {
this.items.extractItem(0, 1, false); this.items.extractItem(0, 1, false);
break push; break push;
@ -70,16 +70,16 @@ 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.getEntitiesOfClass(ItemEntity.class, new AABB( var 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 (var item : items) {
if (!item.isAlive()) if (!item.isAlive())
continue; continue;
ItemStack stack = item.getItem(); var stack = item.getItem();
if (stack.isEmpty()) if (stack.isEmpty())
continue; continue;
ItemStack left = this.items.insertItem(0, stack, false); var left = this.items.insertItem(0, stack, false);
if (!ItemStack.isSame(stack, left)) { if (!ItemStack.isSame(stack, left)) {
if (left.isEmpty()) { if (left.isEmpty()) {
item.kill(); item.kill();
@ -90,16 +90,16 @@ public class BlockEntityGratedChute extends BlockEntityImpl implements ITickable
} }
} }
BlockEntity tileUp = this.level.getBlockEntity(this.worldPosition.above()); var 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); var handlerUp = tileUp.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.DOWN).orElse(null);
if (handlerUp == null) if (handlerUp == null)
break pull; break pull;
for (int i = 0; i < handlerUp.getSlots(); i++) { for (var i = 0; i < handlerUp.getSlots(); i++) {
ItemStack theoreticalDrain = handlerUp.extractItem(i, 1, true); var theoreticalDrain = handlerUp.extractItem(i, 1, true);
if (!theoreticalDrain.isEmpty()) { if (!theoreticalDrain.isEmpty()) {
ItemStack left = this.items.insertItem(0, theoreticalDrain, false); var left = this.items.insertItem(0, theoreticalDrain, false);
if (left.isEmpty()) { if (left.isEmpty()) {
handlerUp.extractItem(i, 1, false); handlerUp.extractItem(i, 1, false);
break pull; break pull;
@ -113,11 +113,11 @@ public class BlockEntityGratedChute extends BlockEntityImpl implements ITickable
} }
private boolean isItemInFrame(ItemStack stack) { private boolean isItemInFrame(ItemStack stack) {
List<ItemFrame> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition); var frames = Helper.getAttachedItemFrames(this.level, this.worldPosition);
if (frames.isEmpty()) if (frames.isEmpty())
return false; return false;
for (ItemFrame frame : frames) { for (var frame : frames) {
ItemStack frameStack = frame.getItem(); var frameStack = frame.getItem();
if (Helper.areItemsEqual(stack, frameStack, true)) { if (Helper.areItemsEqual(stack, frameStack, true)) {
return true; return true;
} }

View file

@ -36,26 +36,26 @@ 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.below()); var 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); var handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.UP).orElse(null);
if (handler == null) if (handler == null)
return; return;
List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class, new AABB(this.worldPosition).inflate(7)); var items = this.level.getEntitiesOfClass(ItemEntity.class, new AABB(this.worldPosition).inflate(7));
if (items.isEmpty()) if (items.isEmpty())
return; return;
for (ItemEntity item : items) { for (var item : items) {
if (!item.isAlive() || item.hasPickUpDelay()) if (!item.isAlive() || item.hasPickUpDelay())
continue; continue;
ItemStack stack = item.getItem(); var stack = item.getItem();
if (stack.isEmpty()) if (stack.isEmpty())
continue; continue;
ItemStack copy = stack.copy(); var copy = stack.copy();
for (int i = 0; i < handler.getSlots(); i++) { for (var i = 0; i < handler.getSlots(); i++) {
copy = handler.insertItem(i, copy, false); copy = handler.insertItem(i, copy, false);
if (copy.isEmpty()) { if (copy.isEmpty()) {
break; break;
@ -67,7 +67,7 @@ public class BlockEntityHopperUpgrade extends BlockEntityImpl implements ITickab
if (copy.isEmpty()) if (copy.isEmpty())
item.kill(); item.kill();
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 25, this.worldPosition); var 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,

View file

@ -65,7 +65,7 @@ public class BlockEntityImpl extends BlockEntity {
@Override @Override
public final ClientboundBlockEntityDataPacket getUpdatePacket() { public final ClientboundBlockEntityDataPacket getUpdatePacket() {
return ClientboundBlockEntityDataPacket.create(this, e -> { return ClientboundBlockEntityDataPacket.create(this, e -> {
CompoundTag compound = new CompoundTag(); var compound = new CompoundTag();
this.writeNBT(compound, SaveType.SYNC); this.writeNBT(compound, SaveType.SYNC);
return compound; return compound;
}); });
@ -73,7 +73,7 @@ public class BlockEntityImpl extends BlockEntity {
@Override @Override
public final CompoundTag getUpdateTag() { public final CompoundTag getUpdateTag() {
CompoundTag compound = new CompoundTag(); var compound = new CompoundTag();
this.writeNBT(compound, SaveType.SYNC); this.writeNBT(compound, SaveType.SYNC);
return compound; return compound;
} }
@ -92,7 +92,7 @@ public class BlockEntityImpl extends BlockEntity {
public void sendToClients() { public void sendToClients() {
var world = (ServerLevel) this.getLevel(); var world = (ServerLevel) this.getLevel();
var entities = world.getChunkSource().chunkMap.getPlayers(new ChunkPos(this.getBlockPos()), false); var entities = world.getChunkSource().chunkMap.getPlayers(new ChunkPos(this.getBlockPos()), false);
ClientboundBlockEntityDataPacket packet = this.getUpdatePacket(); var packet = this.getUpdatePacket();
for (var e : entities) for (var e : entities)
e.connection.send(packet); e.connection.send(packet);
} }
@ -116,7 +116,7 @@ public class BlockEntityImpl extends BlockEntity {
return this.itemHandler.cast(); return this.itemHandler.cast();
} else if (capability == NaturesAuraAPI.capAuraContainer) { } else if (capability == NaturesAuraAPI.capAuraContainer) {
if (this.auraContainer == null) { if (this.auraContainer == null) {
IAuraContainer container = this.getAuraContainer(); var container = this.getAuraContainer();
this.auraContainer = container == null ? LazyOptional.empty() : LazyOptional.of(() -> container); this.auraContainer = container == null ? LazyOptional.empty() : LazyOptional.of(() -> container);
} }
return this.auraContainer.cast(); return this.auraContainer.cast();
@ -137,10 +137,10 @@ public class BlockEntityImpl extends BlockEntity {
public void dropInventory() { public void dropInventory() {
IItemHandler handler = this.getItemHandler(); IItemHandler handler = this.getItemHandler();
if (handler != null) { if (handler != null) {
for (int i = 0; i < handler.getSlots(); i++) { for (var i = 0; i < handler.getSlots(); i++) {
ItemStack stack = handler.getStackInSlot(i); var stack = handler.getStackInSlot(i);
if (!stack.isEmpty()) { if (!stack.isEmpty()) {
ItemEntity item = new ItemEntity(this.level, this.worldPosition.getX() + 0.5, this.worldPosition.getY() + 0.5, this.worldPosition.getZ() + 0.5, stack); var item = new ItemEntity(this.level, this.worldPosition.getX() + 0.5, this.worldPosition.getY() + 0.5, this.worldPosition.getZ() + 0.5, stack);
this.level.addFreshEntity(item); this.level.addFreshEntity(item);
} }
} }
@ -148,7 +148,7 @@ public class BlockEntityImpl extends BlockEntity {
} }
public void modifyDrop(ItemStack regularItem) { public void modifyDrop(ItemStack regularItem) {
CompoundTag compound = new CompoundTag(); var compound = new CompoundTag();
this.writeNBT(compound, SaveType.BLOCK); this.writeNBT(compound, SaveType.BLOCK);
if (!compound.isEmpty()) { if (!compound.isEmpty()) {
if (!regularItem.hasTag()) regularItem.setTag(new CompoundTag()); if (!regularItem.hasTag()) regularItem.setTag(new CompoundTag());
@ -158,18 +158,18 @@ public class BlockEntityImpl extends BlockEntity {
public void loadDataOnPlace(ItemStack stack) { public void loadDataOnPlace(ItemStack stack) {
if (stack.hasTag()) { if (stack.hasTag()) {
CompoundTag compound = stack.getTag().getCompound("data"); var compound = stack.getTag().getCompound("data");
if (compound != null) this.readNBT(compound, SaveType.BLOCK); if (compound != null) this.readNBT(compound, SaveType.BLOCK);
} }
} }
public boolean canGenerateRightNow(int toAdd) { public boolean canGenerateRightNow(int toAdd) {
if (this.wantsLimitRemover()) { if (this.wantsLimitRemover()) {
BlockState below = this.level.getBlockState(this.worldPosition.below()); var below = this.level.getBlockState(this.worldPosition.below());
if (below.getBlock() == ModBlocks.GENERATOR_LIMIT_REMOVER) if (below.getBlock() == ModBlocks.GENERATOR_LIMIT_REMOVER)
return true; return true;
} }
int aura = IAuraChunk.getAuraInArea(this.level, this.worldPosition, 35); var aura = IAuraChunk.getAuraInArea(this.level, this.worldPosition, 35);
return aura + toAdd <= IAuraChunk.DEFAULT_AURA * 2; return aura + toAdd <= IAuraChunk.DEFAULT_AURA * 2;
} }
@ -179,7 +179,7 @@ public class BlockEntityImpl extends BlockEntity {
public void generateAura(int amount) { public void generateAura(int amount) {
while (amount > 0) { while (amount > 0) {
BlockPos spot = IAuraChunk.getLowestSpot(this.level, this.worldPosition, 35, this.worldPosition); var spot = IAuraChunk.getLowestSpot(this.level, this.worldPosition, 35, this.worldPosition);
amount -= IAuraChunk.getAuraChunk(this.level, spot).storeAura(spot, amount); amount -= IAuraChunk.getAuraChunk(this.level, spot).storeAura(spot, amount);
} }
} }

View file

@ -32,18 +32,18 @@ public class BlockEntityItemDistributor extends BlockEntityImpl implements ITick
} }
this.cooldown = 1; this.cooldown = 1;
IItemHandler above = this.getHandler(Direction.UP); var above = this.getHandler(Direction.UP);
if (above == null) if (above == null)
return; return;
IItemHandler dest = this.getNextSide(); var dest = this.getNextSide();
if (dest == null) if (dest == null)
return; return;
for (int i = 0; i < above.getSlots(); i++) { for (var i = 0; i < above.getSlots(); i++) {
ItemStack stack = above.extractItem(i, 1, true); var stack = above.extractItem(i, 1, true);
if (stack.isEmpty()) if (stack.isEmpty())
continue; continue;
for (int j = 0; j < dest.getSlots(); j++) { for (var j = 0; j < dest.getSlots(); j++) {
ItemStack remain = dest.insertItem(j, stack, false); var remain = dest.insertItem(j, stack, false);
if (!ItemStack.isSame(remain, stack)) { if (!ItemStack.isSame(remain, stack)) {
above.extractItem(i, 1, false); above.extractItem(i, 1, false);
this.cooldown = 3; this.cooldown = 3;
@ -54,8 +54,8 @@ public class BlockEntityItemDistributor extends BlockEntityImpl implements ITick
} }
private IItemHandler getHandler(Direction direction) { private IItemHandler getHandler(Direction direction) {
BlockPos offset = this.worldPosition.relative(direction); var offset = this.worldPosition.relative(direction);
BlockEntity tile = this.level.getBlockEntity(offset); var tile = this.level.getBlockEntity(offset);
if (tile == null) if (tile == null)
return null; return null;
return tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, direction.getOpposite()).orElse(null); return tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, direction.getOpposite()).orElse(null);
@ -64,8 +64,8 @@ public class BlockEntityItemDistributor extends BlockEntityImpl implements ITick
private IItemHandler getNextSide() { private IItemHandler getNextSide() {
if (this.isRandomMode) { if (this.isRandomMode) {
List<IItemHandler> handlers = new ArrayList<>(); List<IItemHandler> handlers = new ArrayList<>();
for (int i = 0; i < 4; i++) { for (var i = 0; i < 4; i++) {
IItemHandler handler = this.getHandler(Direction.values()[i]); var handler = this.getHandler(Direction.values()[i]);
if (handler != null) if (handler != null)
handlers.add(handler); handlers.add(handler);
} }
@ -73,9 +73,9 @@ public class BlockEntityItemDistributor extends BlockEntityImpl implements ITick
return null; return null;
return handlers.get(this.level.random.nextInt(handlers.size())); return handlers.get(this.level.random.nextInt(handlers.size()));
} else { } else {
for (int i = 0; i < 4; i++) { for (var i = 0; i < 4; i++) {
this.currentSide = this.currentSide.getClockWise(); this.currentSide = this.currentSide.getClockWise();
IItemHandler handler = this.getHandler(this.currentSide); var handler = this.getHandler(this.currentSide);
if (handler != null) if (handler != null)
return handler; return handler;
} }

View file

@ -23,16 +23,16 @@ public class BlockEntityMossGenerator extends BlockEntityImpl implements ITickab
if (!this.level.isClientSide) { if (!this.level.isClientSide) {
if (this.level.getGameTime() % 20 != 0) if (this.level.getGameTime() % 20 != 0)
return; return;
LevelData data = (LevelData) ILevelData.getLevelData(this.level); var data = (LevelData) ILevelData.getLevelData(this.level);
List<BlockPos> possibleOffsets = new ArrayList<>(); List<BlockPos> possibleOffsets = new ArrayList<>();
int range = 2; var range = 2;
for (int x = -range; x <= range; x++) for (var x = -range; x <= range; x++)
for (int y = -range; y <= range; y++) for (var y = -range; y <= range; y++)
for (int z = -range; z <= range; z++) { for (var z = -range; z <= range; z++) {
BlockPos offset = this.worldPosition.offset(x, y, z); var offset = this.worldPosition.offset(x, y, z);
boolean isRecent = data.recentlyConvertedMossStones.contains(offset); var isRecent = data.recentlyConvertedMossStones.contains(offset);
BlockState state = this.level.getBlockState(offset); var state = this.level.getBlockState(offset);
if (NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.inverse().containsKey(state)) { if (NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.inverse().containsKey(state)) {
if (isRecent) if (isRecent)
continue; continue;
@ -44,11 +44,11 @@ public class BlockEntityMossGenerator extends BlockEntityImpl implements ITickab
if (possibleOffsets.isEmpty()) if (possibleOffsets.isEmpty())
return; return;
BlockPos offset = possibleOffsets.get(this.level.random.nextInt(possibleOffsets.size())); var offset = possibleOffsets.get(this.level.random.nextInt(possibleOffsets.size()));
BlockState state = this.level.getBlockState(offset); var state = this.level.getBlockState(offset);
BlockState result = NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.inverse().get(state); var result = NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.inverse().get(state);
int toAdd = 7000; var toAdd = 7000;
if (this.canGenerateRightNow(toAdd)) { if (this.canGenerateRightNow(toAdd)) {
this.generateAura(toAdd); this.generateAura(toAdd);
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,

View file

@ -25,8 +25,6 @@ import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.ItemStackHandler;
import java.util.Random;
public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickableBlockEntity { public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickableBlockEntity {
private final BasicAuraContainer container = new BasicAuraContainer(null, 500000) { private final BasicAuraContainer container = new BasicAuraContainer(null, 500000) {
@ -49,7 +47,7 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
@Override @Override
protected boolean canExtract(ItemStack stack, int slot, int amount) { protected boolean canExtract(ItemStack stack, int slot, int amount) {
IAuraContainer cap = stack.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null); var cap = stack.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null);
if (cap != null) if (cap != null)
return cap.storeAura(1, true) <= 0; return cap.storeAura(1, true) <= 0;
else else
@ -72,14 +70,14 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
@Override @Override
public void tick() { public void tick() {
Random rand = this.level.random; var rand = this.level.random;
if (this.level.getGameTime() % 40 == 0) { if (this.level.getGameTime() % 40 == 0) {
int index = 0; var index = 0;
for (int x = -2; x <= 2; x += 4) { for (var x = -2; x <= 2; x += 4) {
for (int z = -2; z <= 2; z += 4) { for (var z = -2; z <= 2; z += 4) {
BlockPos offset = this.worldPosition.offset(x, 1, z); var offset = this.worldPosition.offset(x, 1, z);
BlockState state = this.level.getBlockState(offset); var state = this.level.getBlockState(offset);
this.catalysts[index] = state.getBlock().getCloneItemStack(this.level, offset, state); this.catalysts[index] = state.getBlock().getCloneItemStack(this.level, offset, state);
index++; index++;
} }
@ -88,7 +86,7 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
if (!this.level.isClientSide) { if (!this.level.isClientSide) {
if (this.level.getGameTime() % 40 == 0 || this.firstTick) { if (this.level.getGameTime() % 40 == 0 || this.firstTick) {
StructureState newState = this.getNewState(); var newState = this.getNewState();
if (newState != this.structureState) { if (newState != this.structureState) {
this.structureState = newState; this.structureState = newState;
this.sendToClients(); this.sendToClients();
@ -97,13 +95,13 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
} }
if (this.structureState != StructureState.INVALID) { if (this.structureState != StructureState.INVALID) {
int space = this.container.storeAura(300, true); var space = this.container.storeAura(300, true);
IAuraType expectedType = this.structureState == StructureState.NETHER ? NaturesAuraAPI.TYPE_NETHER : NaturesAuraAPI.TYPE_OVERWORLD; IAuraType expectedType = this.structureState == StructureState.NETHER ? NaturesAuraAPI.TYPE_NETHER : NaturesAuraAPI.TYPE_OVERWORLD;
if (space > 0 && IAuraType.forLevel(this.level).isSimilar(expectedType)) { if (space > 0 && IAuraType.forLevel(this.level).isSimilar(expectedType)) {
int toStore = Math.min(IAuraChunk.getAuraInArea(this.level, this.worldPosition, 20), space); var toStore = Math.min(IAuraChunk.getAuraInArea(this.level, this.worldPosition, 20), space);
if (toStore > 0) { if (toStore > 0) {
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 20, this.worldPosition); var spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 20, this.worldPosition);
IAuraChunk chunk = IAuraChunk.getAuraChunk(this.level, spot); var chunk = IAuraChunk.getAuraChunk(this.level, spot);
chunk.drainAura(spot, toStore); chunk.drainAura(spot, toStore);
this.container.storeAura(toStore, false); this.container.storeAura(toStore, false);
@ -114,17 +112,17 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
this.worldPosition.getY() + rand.nextFloat() * 10F, this.worldPosition.getY() + rand.nextFloat() * 10F,
this.worldPosition.getZ() + (float) rand.nextGaussian() * 10F, this.worldPosition.getZ() + (float) rand.nextGaussian() * 10F,
this.worldPosition.getX() + 0.5F, this.worldPosition.getY() + 0.5F, this.worldPosition.getZ() + 0.5F, this.worldPosition.getX() + 0.5F, this.worldPosition.getY() + 0.5F, this.worldPosition.getZ() + 0.5F,
rand.nextFloat() * 0.1F + 0.1F, this.container.getAuraColor(), rand.nextFloat() * 1F + 1F rand.nextFloat() * 0.1F + 0.1F, this.container.getAuraColor(), rand.nextFloat() + 1F
)); ));
} }
} }
ItemStack stack = this.items.getStackInSlot(0); var stack = this.items.getStackInSlot(0);
IAuraContainer container = stack.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null); var container = stack.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null);
if (!stack.isEmpty() && container != null) { if (!stack.isEmpty() && container != null) {
int theoreticalDrain = this.container.drainAura(1000, true); var theoreticalDrain = this.container.drainAura(1000, true);
if (theoreticalDrain > 0) { if (theoreticalDrain > 0) {
int stored = container.storeAura(theoreticalDrain, false); var stored = container.storeAura(theoreticalDrain, false);
if (stored > 0) { if (stored > 0) {
this.container.drainAura(stored, false); this.container.drainAura(stored, false);
@ -142,7 +140,7 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
this.currentRecipe = null; this.currentRecipe = null;
this.timer = 0; this.timer = 0;
} else { } else {
int req = Mth.ceil(this.currentRecipe.aura / (double) this.currentRecipe.time); var req = Mth.ceil(this.currentRecipe.aura / (double) this.currentRecipe.time);
if (this.container.getStoredAura() >= req) { if (this.container.getStoredAura() >= req) {
this.container.drainAura(req, false); this.container.drainAura(req, false);
@ -170,7 +168,7 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
} else { } else {
if (this.structureState != StructureState.INVALID) { if (this.structureState != StructureState.INVALID) {
if (rand.nextFloat() >= 0.7F) { if (rand.nextFloat() >= 0.7F) {
int fourths = this.container.getMaxAura() / 4; var fourths = this.container.getMaxAura() / 4;
if (this.container.getStoredAura() > 0) { if (this.container.getStoredAura() > 0) {
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
this.worldPosition.getX() - 4F + rand.nextFloat(), this.worldPosition.getY() + 3F, this.worldPosition.getZ() + rand.nextFloat(), this.worldPosition.getX() - 4F + rand.nextFloat(), this.worldPosition.getY() + 3F, this.worldPosition.getZ() + rand.nextFloat(),
@ -200,12 +198,12 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
} }
private AltarRecipe getRecipeForInput(ItemStack input) { private AltarRecipe getRecipeForInput(ItemStack input) {
IAuraType type = IAuraType.forLevel(this.level); var type = IAuraType.forLevel(this.level);
for (AltarRecipe recipe : this.level.getRecipeManager().getRecipesFor(ModRecipes.ALTAR_TYPE, null, null)) { for (var 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;
for (ItemStack stack : this.catalysts) for (var stack : this.catalysts)
if (recipe.catalyst.test(stack)) if (recipe.catalyst.test(stack))
return recipe; return recipe;
} }

View file

@ -21,10 +21,10 @@ public class BlockEntityOakGenerator extends BlockEntityImpl implements ITickabl
public void tick() { public void tick() {
if (!this.level.isClientSide) if (!this.level.isClientSide)
while (!this.scheduledBigTrees.isEmpty()) { while (!this.scheduledBigTrees.isEmpty()) {
BlockPos pos = this.scheduledBigTrees.remove(); var pos = this.scheduledBigTrees.remove();
if (this.level.getBlockState(pos).getBlock().getTags().contains(BlockTags.LOGS.getName())) { if (this.level.getBlockState(pos).getBlock().getTags().contains(BlockTags.LOGS.getName())) {
int toAdd = 100000; var toAdd = 100000;
boolean canGen = this.canGenerateRightNow(toAdd); var canGen = this.canGenerateRightNow(toAdd);
if (canGen) if (canGen)
this.generateAura(toAdd); this.generateAura(toAdd);

View file

@ -41,7 +41,7 @@ public class BlockEntityOfferingTable extends BlockEntityImpl implements ITickab
} }
private OfferingRecipe getRecipe(ItemStack input) { private OfferingRecipe getRecipe(ItemStack input) {
for (OfferingRecipe recipe : this.level.getRecipeManager().getRecipesFor(ModRecipes.OFFERING_TYPE, null, null)) for (var 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;
@ -54,44 +54,44 @@ public class BlockEntityOfferingTable extends BlockEntityImpl implements ITickab
if (!Multiblocks.OFFERING_TABLE.isComplete(this.level, this.worldPosition)) if (!Multiblocks.OFFERING_TABLE.isComplete(this.level, this.worldPosition))
return; return;
ItemStack stack = this.items.getStackInSlot(0); var stack = this.items.getStackInSlot(0);
if (stack.isEmpty()) if (stack.isEmpty())
return; return;
List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class, new AABB(this.worldPosition).inflate(1)); var items = this.level.getEntitiesOfClass(ItemEntity.class, new AABB(this.worldPosition).inflate(1));
if (items.isEmpty()) if (items.isEmpty())
return; return;
OfferingRecipe recipe = this.getRecipe(stack); var recipe = this.getRecipe(stack);
if (recipe == null) if (recipe == null)
return; return;
for (ItemEntity item : items) { for (var item : items) {
if (!item.isAlive() || item.hasPickUpDelay()) if (!item.isAlive() || item.hasPickUpDelay())
continue; continue;
ItemStack itemStack = item.getItem(); var itemStack = item.getItem();
if (itemStack.isEmpty() || itemStack.getCount() != 1) if (itemStack.isEmpty() || itemStack.getCount() != 1)
continue; continue;
if (!recipe.startItem.test(itemStack)) if (!recipe.startItem.test(itemStack))
continue; continue;
int amount = Helper.getIngredientAmount(recipe.input); var amount = Helper.getIngredientAmount(recipe.input);
int recipeCount = stack.getCount() / amount; var recipeCount = stack.getCount() / amount;
stack.shrink(recipeCount * amount); stack.shrink(recipeCount * amount);
item.kill(); item.kill();
this.sendToClients(); this.sendToClients();
for (int i = 0; i < recipeCount; i++) for (var 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.random.nextInt(5) + 3; i >= 0; i--) for (var 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));
} }
LightningBolt lightningboltentity = EntityType.LIGHTNING_BOLT.create(this.level); var lightningboltentity = EntityType.LIGHTNING_BOLT.create(this.level);
lightningboltentity.setVisualOnly(true); lightningboltentity.setVisualOnly(true);
lightningboltentity.moveTo(Vec3.atCenterOf(this.worldPosition)); lightningboltentity.moveTo(Vec3.atCenterOf(this.worldPosition));
this.level.addFreshEntity(lightningboltentity); this.level.addFreshEntity(lightningboltentity);
@ -115,8 +115,8 @@ 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) {
ListTag list = new ListTag(); var list = new ListTag();
for (ItemStack stack : this.itemsToSpawn) for (var stack : this.itemsToSpawn)
list.add(stack.serializeNBT()); list.add(stack.serializeNBT());
compound.put("items_to_spawn", list); compound.put("items_to_spawn", list);
} }
@ -131,8 +131,8 @@ public class BlockEntityOfferingTable extends BlockEntityImpl implements ITickab
if (type != SaveType.SYNC) { if (type != SaveType.SYNC) {
this.itemsToSpawn.clear(); this.itemsToSpawn.clear();
ListTag list = compound.getList("items_to_spawn", 10); var list = compound.getList("items_to_spawn", 10);
for (Tag base : list) for (var base : list)
this.itemsToSpawn.add(ItemStack.of((CompoundTag) base)); this.itemsToSpawn.add(ItemStack.of((CompoundTag) base));
} }
} }

View file

@ -37,45 +37,45 @@ 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.above()); var 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); var handler = tileUp.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.DOWN).orElse(null);
if (handler == null) if (handler == null)
return; return;
List<ItemFrame> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition); var frames = Helper.getAttachedItemFrames(this.level, this.worldPosition);
if (frames.isEmpty()) if (frames.isEmpty())
return; return;
List<BlockPos> validPositions = new ArrayList<>(); List<BlockPos> validPositions = new ArrayList<>();
int range = 5; var range = 5;
for (int x = -range; x <= range; x++) for (var x = -range; x <= range; x++)
for (int y = -range; y <= range; y++) for (var y = -range; y <= range; y++)
for (int z = -range; z <= range; z++) { for (var z = -range; z <= range; z++) {
BlockPos pos = this.worldPosition.offset(x, y, z); var 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.above(); var up = pos.above();
BlockState state = this.level.getBlockState(up); var state = this.level.getBlockState(up);
if (state.getMaterial().isReplaceable()) if (state.getMaterial().isReplaceable())
validPositions.add(up); validPositions.add(up);
} }
if (validPositions.isEmpty()) if (validPositions.isEmpty())
return; return;
for (int i = 0; i < handler.getSlots(); i++) { for (var i = 0; i < handler.getSlots(); i++) {
ItemStack stack = handler.extractItem(i, 1, true); var stack = handler.extractItem(i, 1, true);
if (stack.isEmpty()) if (stack.isEmpty())
continue; continue;
BlockPos pos = validPositions.get(this.level.random.nextInt(validPositions.size())); var pos = validPositions.get(this.level.random.nextInt(validPositions.size()));
ItemStack left = this.tryPlace(stack.copy(), pos); var left = this.tryPlace(stack.copy(), pos);
if (ItemStack.isSame(stack, left)) if (ItemStack.isSame(stack, left))
continue; continue;
handler.extractItem(i, 1, false); handler.extractItem(i, 1, false);
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 10, this.worldPosition); var spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 10, this.worldPosition);
IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, 1000); IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, 1000);
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(pos.getX(), pos.getY(), pos.getZ(), PacketParticles.Type.PLACER_PLACING)); PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(pos.getX(), pos.getY(), pos.getZ(), PacketParticles.Type.PLACER_PLACING));
@ -86,12 +86,12 @@ public class BlockEntityPlacer extends BlockEntityImpl implements ITickableBlock
} }
private boolean framesContain(List<ItemFrame> frames, BlockPos pos, BlockState state) { private boolean framesContain(List<ItemFrame> frames, BlockPos pos, BlockState state) {
ItemStack stack = state.getBlock().getCloneItemStack(this.level, pos, state); var stack = state.getBlock().getCloneItemStack(this.level, pos, state);
if (stack.isEmpty()) if (stack.isEmpty())
return false; return false;
for (ItemFrame frame : frames) { for (var frame : frames) {
ItemStack frameStack = frame.getItem(); var frameStack = frame.getItem();
if (frameStack.isEmpty()) if (frameStack.isEmpty())
continue; continue;
if (Helper.areItemsEqual(stack, frameStack, false)) if (Helper.areItemsEqual(stack, frameStack, false))
@ -106,9 +106,9 @@ public class BlockEntityPlacer extends BlockEntityImpl implements ITickableBlock
private ItemStack tryPlace(ItemStack stack, BlockPos pos) { private ItemStack tryPlace(ItemStack stack, BlockPos pos) {
if (!(this.level instanceof ServerLevel)) if (!(this.level instanceof ServerLevel))
return stack; return stack;
FakePlayer fake = FakePlayerFactory.getMinecraft((ServerLevel) this.level); var fake = FakePlayerFactory.getMinecraft((ServerLevel) this.level);
fake.getInventory().items.set(fake.getInventory().selected, stack); fake.getInventory().items.set(fake.getInventory().selected, stack);
BlockHitResult ray = new BlockHitResult(Vec3.atCenterOf(pos), Direction.UP, pos, false); var ray = new BlockHitResult(Vec3.atCenterOf(pos), Direction.UP, pos, false);
ForgeHooks.onPlaceItemIntoWorld(new UseOnContext(fake, InteractionHand.MAIN_HAND, ray)); ForgeHooks.onPlaceItemIntoWorld(new UseOnContext(fake, InteractionHand.MAIN_HAND, ray));
return fake.getMainHandItem().copy(); return fake.getMainHandItem().copy();
} }

View file

@ -24,26 +24,26 @@ public class BlockEntityPotionGenerator extends BlockEntityImpl implements ITick
public void tick() { public void tick() {
if (!this.level.isClientSide && this.level.getGameTime() % 10 == 0) { if (!this.level.isClientSide && this.level.getGameTime() % 10 == 0) {
if (Multiblocks.POTION_GENERATOR.isComplete(this.level, this.worldPosition)) { if (Multiblocks.POTION_GENERATOR.isComplete(this.level, this.worldPosition)) {
boolean addedOne = false; var addedOne = false;
List<AreaEffectCloud> clouds = this.level.getEntitiesOfClass(AreaEffectCloud.class, new AABB(this.worldPosition).inflate(2)); var clouds = this.level.getEntitiesOfClass(AreaEffectCloud.class, new AABB(this.worldPosition).inflate(2));
for (AreaEffectCloud cloud : clouds) { for (var cloud : clouds) {
if (!cloud.isAlive()) if (!cloud.isAlive())
continue; continue;
if (!addedOne) { if (!addedOne) {
Potion type = cloud.getPotion(); var type = cloud.getPotion();
if (type == null) if (type == null)
continue; continue;
for (MobEffectInstance effect : type.getEffects()) { for (var effect : type.getEffects()) {
MobEffect potion = effect.getEffect(); var potion = effect.getEffect();
if (!potion.isBeneficial() || potion.isInstantenous()) { if (!potion.isBeneficial() || potion.isInstantenous()) {
continue; continue;
} }
int toAdd = (effect.getAmplifier() * 7 + 1) * (effect.getDuration() / 25) * 100; var toAdd = (effect.getAmplifier() * 7 + 1) * (effect.getDuration() / 25) * 100;
boolean canGen = this.canGenerateRightNow(toAdd); var canGen = this.canGenerateRightNow(toAdd);
if (canGen) if (canGen)
this.generateAura(toAdd); this.generateAura(toAdd);
@ -56,7 +56,7 @@ public class BlockEntityPotionGenerator extends BlockEntityImpl implements ITick
} }
} }
float newRadius = cloud.getRadius() - 0.25F; var newRadius = cloud.getRadius() - 0.25F;
if (newRadius < 0.5F) { if (newRadius < 0.5F) {
cloud.kill(); cloud.kill();
} else { } else {

View file

@ -23,22 +23,22 @@ public class BlockEntityPowderPlacer extends BlockEntityImpl {
@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.getEntitiesOfClass(EntityEffectInhibitor.class, new AABB(this.worldPosition, this.worldPosition.offset(1, 2, 1)), Entity::isAlive); var powders = this.level.getEntitiesOfClass(EntityEffectInhibitor.class, new AABB(this.worldPosition, this.worldPosition.offset(1, 2, 1)), Entity::isAlive);
for (Direction facing : Direction.values()) { for (var facing : Direction.values()) {
if (!facing.getAxis().isHorizontal()) if (!facing.getAxis().isHorizontal())
continue; continue;
BlockEntity tile = this.level.getBlockEntity(this.worldPosition.relative(facing)); var 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); var handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite()).orElse(null);
if (handler == null) if (handler == null)
continue; continue;
if (!powders.isEmpty()) { if (!powders.isEmpty()) {
for (EntityEffectInhibitor powder : powders) { for (var powder : powders) {
ItemStack drop = powder.getDrop(); var drop = powder.getDrop();
for (int i = 0; i < handler.getSlots(); i++) { for (var i = 0; i < handler.getSlots(); i++) {
ItemStack remain = handler.insertItem(i, drop, false); var remain = handler.insertItem(i, drop, false);
if (remain.isEmpty()) { if (remain.isEmpty()) {
powder.kill(); powder.kill();
break; break;
@ -48,8 +48,8 @@ public class BlockEntityPowderPlacer extends BlockEntityImpl {
} }
} }
} else { } else {
for (int i = 0; i < handler.getSlots(); i++) { for (var i = 0; i < handler.getSlots(); i++) {
ItemStack stack = handler.extractItem(i, Integer.MAX_VALUE, true); var stack = handler.extractItem(i, Integer.MAX_VALUE, true);
if (stack.isEmpty() || stack.getItem() != ModItems.EFFECT_POWDER) if (stack.isEmpty() || stack.getItem() != ModItems.EFFECT_POWDER)
continue; continue;
EntityEffectInhibitor.place(this.level, stack, this.worldPosition.getX() + 0.5, this.worldPosition.getY() + 1, this.worldPosition.getZ() + 0.5); EntityEffectInhibitor.place(this.level, stack, this.worldPosition.getX() + 0.5, this.worldPosition.getY() + 1, this.worldPosition.getZ() + 0.5);

View file

@ -49,24 +49,24 @@ public class BlockEntityRFConverter extends BlockEntityImpl implements ITickable
this.lastEnergy = this.storage.getEnergyStored(); this.lastEnergy = this.storage.getEnergyStored();
} }
for (Direction facing : Direction.values()) { for (var facing : Direction.values()) {
BlockEntity tile = this.level.getBlockEntity(this.worldPosition.relative(facing)); var 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); var storage = tile.getCapability(CapabilityEnergy.ENERGY, facing.getOpposite()).orElse(null);
if (storage == null) if (storage == null)
continue; continue;
int canStore = storage.receiveEnergy(Integer.MAX_VALUE, true); var canStore = storage.receiveEnergy(Integer.MAX_VALUE, true);
if (canStore <= 0) if (canStore <= 0)
continue; continue;
int extracted = this.storage.extractEnergy(canStore, false); var extracted = this.storage.extractEnergy(canStore, false);
if (extracted <= 0) if (extracted <= 0)
continue; continue;
storage.receiveEnergy(extracted, false); storage.receiveEnergy(extracted, false);
break; break;
} }
int emptyPart = this.storage.getMaxEnergyStored() - this.storage.getEnergyStored(); var emptyPart = this.storage.getMaxEnergyStored() - this.storage.getEnergyStored();
if (emptyPart <= 0) if (emptyPart <= 0)
return; return;
if (this.level.getGameTime() % 20 != 0) if (this.level.getGameTime() % 20 != 0)
@ -74,14 +74,14 @@ public class BlockEntityRFConverter extends BlockEntityImpl implements ITickable
if (!Multiblocks.RF_CONVERTER.isComplete(this.level, this.worldPosition)) if (!Multiblocks.RF_CONVERTER.isComplete(this.level, this.worldPosition))
return; return;
int aura = IAuraChunk.getAuraInArea(this.level, this.worldPosition, 45); var aura = IAuraChunk.getAuraInArea(this.level, this.worldPosition, 45);
if (aura <= IAuraChunk.DEFAULT_AURA) if (aura <= IAuraChunk.DEFAULT_AURA)
return; return;
int amountToGen = Math.min(Math.min(10000, aura / 1000), emptyPart); var amountToGen = Math.min(Math.min(10000, aura / 1000), emptyPart);
int amountToUse = Mth.ceil(amountToGen / ModConfig.instance.auraToRFRatio.get()); var amountToUse = Mth.ceil(amountToGen / ModConfig.instance.auraToRFRatio.get());
this.storage.setEnergy(this.storage.getEnergyStored() + amountToGen); this.storage.setEnergy(this.storage.getEnergyStored() + amountToGen);
BlockPos pos = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 45, this.worldPosition); var pos = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 45, this.worldPosition);
IAuraChunk.getAuraChunk(this.level, pos).drainAura(pos, amountToUse); IAuraChunk.getAuraChunk(this.level, pos).drainAura(pos, amountToUse);
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,

View file

@ -23,7 +23,7 @@ public class BlockEntitySlimeSplitGenerator extends BlockEntityImpl implements I
if (this.level.isClientSide || this.level.getGameTime() % 10 != 0) if (this.level.isClientSide || this.level.getGameTime() % 10 != 0)
return; return;
if (this.generationTimer > 0) { if (this.generationTimer > 0) {
int amount = this.amountToRelease * 10; var amount = this.amountToRelease * 10;
if (this.canGenerateRightNow(amount)) { if (this.canGenerateRightNow(amount)) {
this.generateAura(amount); this.generateAura(amount);
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.SLIME_SPLIT_GEN_CREATE, this.color)); PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.SLIME_SPLIT_GEN_CREATE, this.color));
@ -42,7 +42,7 @@ public class BlockEntitySlimeSplitGenerator extends BlockEntityImpl implements I
} }
public void startGenerating(Slime slime) { public void startGenerating(Slime slime) {
int size = slime.getSize(); var 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);

View file

@ -36,7 +36,7 @@ public class BlockEntitySnowCreator extends BlockEntityImpl implements ITickable
@Override @Override
public void tick() { public void tick() {
int range = this.getRange(); var range = this.getRange();
if (range <= 0) if (range <= 0)
return; return;
@ -44,13 +44,13 @@ public class BlockEntitySnowCreator extends BlockEntityImpl implements ITickable
if (this.level.getGameTime() % 10 != 0) if (this.level.getGameTime() % 10 != 0)
return; return;
for (int i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
double angle = this.level.random.nextFloat() * Math.PI * 2; var angle = this.level.random.nextFloat() * Math.PI * 2;
BlockPos pos = this.worldPosition.offset(Math.cos(angle) * range * this.level.random.nextFloat(), 0, Math.sin(angle) * range * this.level.random.nextFloat()); var pos = this.worldPosition.offset(Math.cos(angle) * range * this.level.random.nextFloat(), 0, Math.sin(angle) * range * this.level.random.nextFloat());
pos = this.level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, pos); pos = this.level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, pos);
BlockPos down = pos.below(); var down = pos.below();
Fluid fluid = this.level.getFluidState(down).getType(); var 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.setBlockAndUpdate(down, Blocks.ICE.defaultBlockState()); this.level.setBlockAndUpdate(down, Blocks.ICE.defaultBlockState());
@ -67,7 +67,7 @@ public class BlockEntitySnowCreator extends BlockEntityImpl implements ITickable
continue; continue;
} }
BlockPos auraPos = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 30, this.worldPosition); var auraPos = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 30, this.worldPosition);
IAuraChunk.getAuraChunk(this.level, auraPos).drainAura(auraPos, 300); IAuraChunk.getAuraChunk(this.level, auraPos).drainAura(auraPos, 300);
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
@ -77,9 +77,9 @@ public class BlockEntitySnowCreator extends BlockEntityImpl implements ITickable
} else { } else {
if (this.level.getGameTime() % 30 != 0) if (this.level.getGameTime() % 30 != 0)
return; return;
for (int i = range * 4; i >= 0; i--) { for (var i = range * 4; i >= 0; i--) {
double angle = this.level.random.nextFloat() * Math.PI * 2; var angle = this.level.random.nextFloat() * Math.PI * 2;
BlockPos pos = this.worldPosition.offset( var pos = this.worldPosition.offset(
Math.cos(angle) * range * this.level.random.nextFloat(), Math.cos(angle) * range * this.level.random.nextFloat(),
Mth.nextInt(this.level.random, range / 2, range), Mth.nextInt(this.level.random, range / 2, range),
Math.sin(angle) * range * this.level.random.nextFloat()); Math.sin(angle) * range * this.level.random.nextFloat());

View file

@ -19,7 +19,7 @@ public class BlockEntitySpawnLamp extends BlockEntityImpl {
public void onLoad() { public void onLoad() {
super.onLoad(); super.onLoad();
if (!this.level.isClientSide) { if (!this.level.isClientSide) {
LevelData data = (LevelData) ILevelData.getLevelData(this.level); var data = (LevelData) ILevelData.getLevelData(this.level);
data.spawnLamps.add(this); data.spawnLamps.add(this);
} }
} }
@ -28,7 +28,7 @@ public class BlockEntitySpawnLamp extends BlockEntityImpl {
public void setRemoved() { public void setRemoved() {
super.setRemoved(); super.setRemoved();
if (!this.level.isClientSide) { if (!this.level.isClientSide) {
LevelData data = (LevelData) ILevelData.getLevelData(this.level); var data = (LevelData) ILevelData.getLevelData(this.level);
data.spawnLamps.remove(this); data.spawnLamps.remove(this);
} }
} }

View file

@ -38,7 +38,7 @@ public class BlockEntitySpring extends BlockEntityImpl implements ITickableBlock
super.onLoad(); super.onLoad();
if (!this.level.isClientSide) { if (!this.level.isClientSide) {
// add a ticket to water crops // add a ticket to water crops
AABB area = new AABB(this.worldPosition).inflate(5, 1, 5); var area = new AABB(this.worldPosition).inflate(5, 1, 5);
this.waterTicket = FarmlandWaterManager.addAABBTicket(this.level, area); this.waterTicket = FarmlandWaterManager.addAABBTicket(this.level, area);
} }
} }
@ -59,8 +59,8 @@ public class BlockEntitySpring extends BlockEntityImpl implements ITickableBlock
return; return;
// fill cauldrons // fill cauldrons
BlockPos up = this.worldPosition.above(); var up = this.worldPosition.above();
BlockState upState = this.level.getBlockState(up); var upState = this.level.getBlockState(up);
if (upState.hasProperty(BlockStateProperties.LEVEL_CAULDRON)) { if (upState.hasProperty(BlockStateProperties.LEVEL_CAULDRON)) {
int level = upState.getValue(BlockStateProperties.LEVEL_CAULDRON); int level = upState.getValue(BlockStateProperties.LEVEL_CAULDRON);
if (level < 3) { if (level < 3) {
@ -72,12 +72,12 @@ public class BlockEntitySpring extends BlockEntityImpl implements ITickableBlock
} }
// wet sponges // wet sponges
int spongeRadius = 2; var spongeRadius = 2;
for (int x = -spongeRadius; x <= spongeRadius; x++) { for (var x = -spongeRadius; x <= spongeRadius; x++) {
for (int y = -spongeRadius; y <= spongeRadius; y++) { for (var y = -spongeRadius; y <= spongeRadius; y++) {
for (int z = -spongeRadius; z <= spongeRadius; z++) { for (var z = -spongeRadius; z <= spongeRadius; z++) {
BlockPos pos = this.worldPosition.offset(x, y, z); var pos = this.worldPosition.offset(x, y, z);
BlockState state = this.level.getBlockState(pos); var state = this.level.getBlockState(pos);
if (state.getBlock() == Blocks.SPONGE) { if (state.getBlock() == Blocks.SPONGE) {
this.level.setBlock(pos, Blocks.WET_SPONGE.defaultBlockState(), 2); this.level.setBlock(pos, Blocks.WET_SPONGE.defaultBlockState(), 2);
this.level.levelEvent(2001, pos, Block.getId(Blocks.WATER.defaultBlockState())); this.level.levelEvent(2001, pos, Block.getId(Blocks.WATER.defaultBlockState()));
@ -89,8 +89,8 @@ public class BlockEntitySpring extends BlockEntityImpl implements ITickableBlock
} }
// generate obsidian // generate obsidian
for (Direction dir : Direction.Plane.HORIZONTAL) { for (var dir : Direction.Plane.HORIZONTAL) {
BlockPos side = this.worldPosition.relative(dir); var side = this.worldPosition.relative(dir);
if (this.isLava(side, true)) { if (this.isLava(side, true)) {
this.level.setBlockAndUpdate(side, ForgeEventFactory.fireFluidPlaceBlockEvent(this.level, side, side, Blocks.OBSIDIAN.defaultBlockState())); this.level.setBlockAndUpdate(side, ForgeEventFactory.fireFluidPlaceBlockEvent(this.level, side, side, Blocks.OBSIDIAN.defaultBlockState()));
this.level.levelEvent(1501, side, 0); this.level.levelEvent(1501, side, 0);
@ -100,7 +100,7 @@ public class BlockEntitySpring extends BlockEntityImpl implements ITickableBlock
} }
// generate stone // generate stone
BlockPos twoUp = this.worldPosition.above(2); var twoUp = this.worldPosition.above(2);
if (this.isLava(twoUp, false) && (this.level.getBlockState(up).isAir() || this.isLava(up, false))) { if (this.isLava(twoUp, false) && (this.level.getBlockState(up).isAir() || this.isLava(up, false))) {
this.level.setBlockAndUpdate(up, ForgeEventFactory.fireFluidPlaceBlockEvent(this.level, up, twoUp, Blocks.STONE.defaultBlockState())); this.level.setBlockAndUpdate(up, ForgeEventFactory.fireFluidPlaceBlockEvent(this.level, up, twoUp, Blocks.STONE.defaultBlockState()));
this.level.levelEvent(1501, up, 0); this.level.levelEvent(1501, up, 0);
@ -109,9 +109,9 @@ public class BlockEntitySpring extends BlockEntityImpl implements ITickableBlock
} }
// generate cobblestone // generate cobblestone
for (Direction dir : Direction.Plane.HORIZONTAL) { for (var dir : Direction.Plane.HORIZONTAL) {
BlockPos twoSide = this.worldPosition.relative(dir, 2); var twoSide = this.worldPosition.relative(dir, 2);
BlockPos side = this.worldPosition.relative(dir); var side = this.worldPosition.relative(dir);
if (this.isLava(twoSide, false) && (this.level.getBlockState(side).isAir() || this.isLava(side, false))) { if (this.isLava(twoSide, false) && (this.level.getBlockState(side).isAir() || this.isLava(side, false))) {
this.level.setBlockAndUpdate(side, ForgeEventFactory.fireFluidPlaceBlockEvent(this.level, side, twoSide, Blocks.COBBLESTONE.defaultBlockState())); this.level.setBlockAndUpdate(side, ForgeEventFactory.fireFluidPlaceBlockEvent(this.level, side, twoSide, Blocks.COBBLESTONE.defaultBlockState()));
this.level.levelEvent(1501, side, 0); this.level.levelEvent(1501, side, 0);
@ -130,13 +130,13 @@ public class BlockEntitySpring extends BlockEntityImpl implements ITickableBlock
public void consumeAura(int amount) { public void consumeAura(int amount) {
while (amount > 0) { while (amount > 0) {
BlockPos pos = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition); var pos = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition);
amount -= IAuraChunk.getAuraChunk(this.level, pos).drainAura(pos, amount); amount -= IAuraChunk.getAuraChunk(this.level, pos).drainAura(pos, amount);
} }
} }
private boolean isLava(BlockPos offset, boolean source) { private boolean isLava(BlockPos offset, boolean source) {
FluidState state = this.level.getFluidState(offset); var state = this.level.getFluidState(offset);
return (!source || state.isSource()) && state.getType().is(FluidTags.LAVA); return (!source || state.isSource()) && state.getType().is(FluidTags.LAVA);
} }
@ -169,7 +169,7 @@ public class BlockEntitySpring extends BlockEntityImpl implements ITickableBlock
@Override @Override
public FluidStack drain(int maxDrain, IFluidHandler.FluidAction action) { public FluidStack drain(int maxDrain, IFluidHandler.FluidAction action) {
int drain = Math.min(maxDrain, 1000); var drain = Math.min(maxDrain, 1000);
if (action.execute()) if (action.execute())
BlockEntitySpring.this.consumeAura(Mth.ceil(drain / 2F)); BlockEntitySpring.this.consumeAura(Mth.ceil(drain / 2F));
return new FluidStack(Fluids.WATER, drain); return new FluidStack(Fluids.WATER, drain);

View file

@ -34,15 +34,15 @@ public class BlockEntityTimeChanger extends BlockEntityImpl implements ITickable
@Override @Override
public void tick() { public void tick() {
if (!this.level.isClientSide) { if (!this.level.isClientSide) {
List<ItemFrame> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition); var frames = Helper.getAttachedItemFrames(this.level, this.worldPosition);
for (ItemFrame frame : frames) { for (var frame : frames) {
ItemStack frameStack = frame.getItem(); var frameStack = frame.getItem();
if (frameStack.isEmpty() || frameStack.getItem() != ModItems.CLOCK_HAND) if (frameStack.isEmpty() || frameStack.getItem() != ModItems.CLOCK_HAND)
continue; continue;
if (this.goalTime > 0) { if (this.goalTime > 0) {
long current = this.level.getDayTime(); var current = this.level.getDayTime();
long toAdd = Math.min(75, this.goalTime - current); var toAdd = Math.min(75, this.goalTime - current);
if (toAdd <= 0) { if (toAdd <= 0) {
this.goalTime = 0; this.goalTime = 0;
this.sendToClients(); this.sendToClients();
@ -50,11 +50,11 @@ public class BlockEntityTimeChanger extends BlockEntityImpl implements ITickable
} }
((ServerLevelData) this.level.getLevelData()).setDayTime(current + toAdd); ((ServerLevelData) this.level.getLevelData()).setDayTime(current + toAdd);
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition); var 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(); var list = this.level.getServer().getPlayerList();
list.broadcastAll(new ClientboundSetTimePacket( list.broadcastAll(new ClientboundSetTimePacket(
this.level.getGameTime(), this.level.getDayTime(), this.level.getGameTime(), this.level.getDayTime(),
this.level.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT))); this.level.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT)));
@ -65,17 +65,17 @@ 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.getEntitiesOfClass(ItemEntity.class, new AABB(this.worldPosition).inflate(1), Entity::isAlive); var items = this.level.getEntitiesOfClass(ItemEntity.class, new AABB(this.worldPosition).inflate(1), Entity::isAlive);
for (ItemEntity item : items) { for (var item : items) {
if (item.hasPickUpDelay()) if (item.hasPickUpDelay())
continue; continue;
ItemStack stack = item.getItem(); var stack = item.getItem();
if (stack.isEmpty() || stack.getItem() != Items.CLOCK) if (stack.isEmpty() || stack.getItem() != Items.CLOCK)
continue; continue;
int dayGoal = Mth.floor((frame.getRotation() / 8F) * 24000F) + 18000; var dayGoal = Mth.floor((frame.getRotation() / 8F) * 24000F) + 18000;
long current = this.level.getDayTime(); var current = this.level.getDayTime();
long toMove = (24000 - current % 24000 + dayGoal) % 24000; var toMove = (24000 - current % 24000 + dayGoal) % 24000;
this.goalTime = current + toMove; this.goalTime = current + toMove;
this.sendToClients(); this.sendToClients();
@ -93,10 +93,10 @@ public class BlockEntityTimeChanger extends BlockEntityImpl implements ITickable
this.sendToClients(); this.sendToClients();
} }
} else if (this.goalTime > 0 && this.level.random.nextFloat() >= 0.25F) { } else if (this.goalTime > 0 && this.level.random.nextFloat() >= 0.25F) {
double angle = Math.toRadians(this.level.getDayTime() * 5F % 360); var angle = Math.toRadians(this.level.getDayTime() * 5F % 360);
double x = this.worldPosition.getX() + 0.5 + Math.sin(angle) * 3F; var x = this.worldPosition.getX() + 0.5 + Math.sin(angle) * 3F;
double z = this.worldPosition.getZ() + 0.5 + Math.cos(angle) * 3F; var z = this.worldPosition.getZ() + 0.5 + Math.cos(angle) * 3F;
int color = this.goalTime % 24000 > 12000 ? 0xe2e2e2 : 0xffe926; var color = this.goalTime % 24000 > 12000 ? 0xe2e2e2 : 0xffe926;
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,

View file

@ -34,11 +34,11 @@ public class BlockEntityWeatherChanger extends BlockEntityImpl implements ITicka
return; return;
if (this.processTime <= 0) if (this.processTime <= 0)
return; return;
int color = this.type == WeatherType.SUN ? 0xf5d742 : this.type == WeatherType.RAIN ? 0x4d5ae3 : 0x373247; var color = this.type == WeatherType.SUN ? 0xf5d742 : this.type == WeatherType.RAIN ? 0x4d5ae3 : 0x373247;
for (int r = 0; r < 360; r += 20) { for (var r = 0; r < 360; r += 20) {
double xOff = Math.cos(Math.toRadians(r)) * 3F; var xOff = Math.cos(Math.toRadians(r)) * 3F;
double zOff = Math.sin(Math.toRadians(r)) * 3F; var zOff = Math.sin(Math.toRadians(r)) * 3F;
for (int i = this.level.random.nextInt(3); i > 0; i--) { for (var 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(),
@ -54,15 +54,15 @@ public class BlockEntityWeatherChanger extends BlockEntityImpl implements ITicka
if (this.processTime > 0) { if (this.processTime > 0) {
if (this.processTime % 20 == 0) { if (this.processTime % 20 == 0) {
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition); var spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition);
IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, 30000 * this.itemAmount); IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, 30000 * this.itemAmount);
} }
this.processTime--; this.processTime--;
if (this.processTime <= 0) { if (this.processTime <= 0) {
this.sendToClients(); this.sendToClients();
int time = 6000 * this.itemAmount; var time = 6000 * this.itemAmount;
ServerLevel server = (ServerLevel) this.level; var server = (ServerLevel) this.level;
switch (this.type) { switch (this.type) {
case SUN -> server.setWeatherParameters(time, 0, false, false); case SUN -> server.setWeatherParameters(time, 0, false, false);
case RAIN -> server.setWeatherParameters(0, time, true, false); case RAIN -> server.setWeatherParameters(0, time, true, false);
@ -72,7 +72,7 @@ public class BlockEntityWeatherChanger extends BlockEntityImpl implements ITicka
} else { } else {
if (this.level.getGameTime() % 20 != 0) if (this.level.getGameTime() % 20 != 0)
return; return;
Pair<WeatherType, Integer> type = this.getNextWeatherType(); var type = this.getNextWeatherType();
if (type == null) if (type == null)
return; return;
this.type = type.getLeft(); this.type = type.getLeft();
@ -104,13 +104,13 @@ public class BlockEntityWeatherChanger extends BlockEntityImpl implements ITicka
} }
private Pair<WeatherType, Integer> getNextWeatherType() { private Pair<WeatherType, Integer> getNextWeatherType() {
AABB area = new AABB(this.worldPosition).inflate(2); var area = new AABB(this.worldPosition).inflate(2);
List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class, area, Entity::isAlive); var items = this.level.getEntitiesOfClass(ItemEntity.class, area, Entity::isAlive);
for (ItemEntity entity : items) { for (var entity : items) {
if (entity.hasPickUpDelay()) if (entity.hasPickUpDelay())
continue; continue;
ItemStack stack = entity.getItem(); var stack = entity.getItem();
for (Map.Entry<ItemStack, WeatherType> entry : NaturesAuraAPI.WEATHER_CHANGER_CONVERSIONS.entrySet()) { for (var 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);

View file

@ -54,13 +54,13 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
if (this.ritualPos != null && this.recipe != null) { if (this.ritualPos != null && this.recipe != null) {
if (this.level.getGameTime() % 5 == 0) { if (this.level.getGameTime() % 5 == 0) {
if (this.isRitualOkay()) { if (this.isRitualOkay()) {
boolean wasOverHalf = this.timer >= this.recipe.time / 2; var wasOverHalf = this.timer >= this.recipe.time / 2;
this.timer += 5; this.timer += 5;
boolean isOverHalf = this.timer >= this.recipe.time / 2; var isOverHalf = this.timer >= this.recipe.time / 2;
if (!isOverHalf) if (!isOverHalf)
Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'W', (pos, matcher) -> { Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'W', (pos, matcher) -> {
BlockEntity tile = this.level.getBlockEntity(pos); var tile = this.level.getBlockEntity(pos);
if (tile instanceof BlockEntityWoodStand && !((BlockEntityWoodStand) tile).items.getStackInSlot(0).isEmpty()) { if (tile instanceof BlockEntityWoodStand && !((BlockEntityWoodStand) tile).items.getStackInSlot(0).isEmpty()) {
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticleStream( PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticleStream(
(float) pos.getX() + 0.2F + this.level.random.nextFloat() * 0.6F, (float) pos.getX() + 0.2F + this.level.random.nextFloat() * 0.6F,
@ -83,7 +83,7 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
}); });
recurseTreeDestruction(this.level, this.ritualPos, this.ritualPos, true, false); recurseTreeDestruction(this.level, this.ritualPos, this.ritualPos, true, false);
ItemEntity item = new ItemEntity(this.level, var item = new ItemEntity(this.level,
this.ritualPos.getX() + 0.5, this.ritualPos.getY() + 4.5, this.ritualPos.getZ() + 0.5, this.ritualPos.getX() + 0.5, this.ritualPos.getY() + 4.5, this.ritualPos.getZ() + 0.5,
this.recipe.result.copy()); this.recipe.result.copy());
this.level.addFreshEntity(item); this.level.addFreshEntity(item);
@ -98,7 +98,7 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
this.timer = 0; this.timer = 0;
} else if (isOverHalf && !wasOverHalf) { } else if (isOverHalf && !wasOverHalf) {
Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'W', (pos, matcher) -> { Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'W', (pos, matcher) -> {
BlockEntity tile = this.level.getBlockEntity(pos); var tile = this.level.getBlockEntity(pos);
if (tile instanceof BlockEntityWoodStand stand && !stand.items.getStackInSlot(0).isEmpty()) { if (tile instanceof BlockEntityWoodStand stand && !stand.items.getStackInSlot(0).isEmpty()) {
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
new PacketParticles(stand.worldPosition.getX(), stand.worldPosition.getY(), stand.worldPosition.getZ(), PacketParticles.Type.TR_CONSUME_ITEM)); new PacketParticles(stand.worldPosition.getX(), stand.worldPosition.getY(), stand.worldPosition.getZ(), PacketParticles.Type.TR_CONSUME_ITEM));
@ -129,11 +129,11 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
return; return;
} }
for (int x = -1; x <= 1; x++) { for (var x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) { for (var y = -1; y <= 1; y++) {
for (int z = -1; z <= 1; z++) { for (var z = -1; z <= 1; z++) {
BlockPos offset = pos.offset(x, y, z); var offset = pos.offset(x, y, z);
BlockState state = level.getBlockState(offset); var state = level.getBlockState(offset);
if (state.getBlock().getTags().contains(BlockTags.LOGS.getName()) || includeLeaves && state.getBlock() instanceof LeavesBlock) { if (state.getBlock().getTags().contains(BlockTags.LOGS.getName()) || includeLeaves && state.getBlock() instanceof LeavesBlock) {
if (drop) { if (drop) {
level.destroyBlock(offset, true); level.destroyBlock(offset, true);
@ -153,20 +153,20 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
if (!Multiblocks.TREE_RITUAL.isComplete(this.level, this.ritualPos)) { if (!Multiblocks.TREE_RITUAL.isComplete(this.level, this.ritualPos)) {
return false; return false;
} }
for (int i = 0; i < 2; i++) { for (var i = 0; i < 2; i++) {
BlockState state = this.level.getBlockState(this.ritualPos.above(i)); var state = this.level.getBlockState(this.ritualPos.above(i));
if (!(state.getBlock().getTags().contains(BlockTags.LOGS.getName()))) if (!(state.getBlock().getTags().contains(BlockTags.LOGS.getName())))
return false; return false;
} }
if (this.timer < this.recipe.time / 2) { if (this.timer < this.recipe.time / 2) {
List<Ingredient> required = new ArrayList<>(Arrays.asList(this.recipe.ingredients)); List<Ingredient> required = new ArrayList<>(Arrays.asList(this.recipe.ingredients));
boolean fine = Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'W', (pos, matcher) -> { var fine = Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'W', (pos, matcher) -> {
BlockEntity tile = this.level.getBlockEntity(pos); var tile = this.level.getBlockEntity(pos);
if (tile instanceof BlockEntityWoodStand) { if (tile instanceof BlockEntityWoodStand) {
ItemStack stack = ((BlockEntityWoodStand) tile).items.getStackInSlot(0); var stack = ((BlockEntityWoodStand) tile).items.getStackInSlot(0);
if (!stack.isEmpty()) { if (!stack.isEmpty()) {
for (int i = required.size() - 1; i >= 0; i--) { for (var i = required.size() - 1; i >= 0; i--) {
Ingredient req = required.get(i); var req = required.get(i);
if (req.test(stack)) { if (req.test(stack)) {
required.remove(i); required.remove(i);
return true; return true;

View file

@ -1,48 +1,47 @@
package de.ellpeck.naturesaura.blocks.tiles.render; package de.ellpeck.naturesaura.blocks.tiles.render;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraTimer; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraTimer;
import de.ellpeck.naturesaura.items.ItemAuraBottle; import de.ellpeck.naturesaura.items.ItemAuraBottle;
import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.model.Model; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.model.ModelRenderer; import net.minecraft.resources.ResourceLocation;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer; import net.minecraft.world.item.ItemStack;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher;
import net.minecraft.item.ItemStack; public class RenderAuraTimer implements BlockEntityRenderer<BlockEntityAuraTimer> {
import net.minecraft.util.ResourceLocation;
public class RenderAuraTimer extends BlockEntityRenderer<BlockEntityAuraTimer> {
private static final ResourceLocation RES = new ResourceLocation(NaturesAura.MOD_ID, "textures/models/aura_timer_aura.png"); private static final ResourceLocation RES = new ResourceLocation(NaturesAura.MOD_ID, "textures/models/aura_timer_aura.png");
private final AuraModel model = new AuraModel(); // private final AuraModel model = new AuraModel();
public RenderAuraTimer(BlockEntityRendererProvider.Context context) {
public RenderAuraTimer(BlockEntityRendererDispatcher disp) {
super(disp);
} }
@Override @Override
public void render(BlockEntityAuraTimer tile, float partialTicks, MatrixStack stack, IRenderTypeBuffer buffer, int combinedLightIn, int combinedOverlayIn) { public void render(BlockEntityAuraTimer tile, float partialTicks, PoseStack stack, MultiBufferSource buffer, int combinedLightIn, int combinedOverlayIn) {
ItemStack bottle = tile.getItemHandler().getStackInSlot(0); var bottle = tile.getItemHandler().getStackInSlot(0);
if (bottle.isEmpty()) if (bottle.isEmpty())
return; return;
stack.push(); stack.pushPose();
stack.translate(4 / 16F, 2.001F / 16, 4 / 16F); stack.translate(4 / 16F, 2.001F / 16, 4 / 16F);
float percentage = 1 - tile.getTimerPercentage(); var percentage = 1 - tile.getTimerPercentage();
stack.scale(8 / 16F, 6.5F / 16 * percentage, 8 / 16F); stack.scale(8 / 16F, 6.5F / 16 * percentage, 8 / 16F);
IAuraType type = ItemAuraBottle.getType(bottle); var type = ItemAuraBottle.getType(bottle);
float r = (type.getColor() >> 16 & 255) / 255F; var r = (type.getColor() >> 16 & 255) / 255F;
float g = (type.getColor() >> 8 & 255) / 255F; var g = (type.getColor() >> 8 & 255) / 255F;
float b = (type.getColor() & 255) / 255F; var b = (type.getColor() & 255) / 255F;
this.model.render(stack, buffer.getBuffer(this.model.getRenderType(RES)), combinedLightIn, combinedOverlayIn, r, g, b, 0.75F); //this.model.render(stack, buffer.getBuffer(this.model.getRenderType(RES)), combinedLightIn, combinedOverlayIn, r, g, b, 0.75F);
stack.pop(); stack.popPose();
} }
private static class AuraModel extends Model { // TODO model rendering
/* private static class AuraModel extends Model {
private final ModelRenderer box; private final ModelRenderer box;
@ -57,5 +56,5 @@ public class RenderAuraTimer extends BlockEntityRenderer<BlockEntityAuraTimer> {
public void render(MatrixStack matrixStackIn, IVertexBuilder bufferIn, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) { public void render(MatrixStack matrixStackIn, IVertexBuilder bufferIn, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) {
this.box.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn, red, green, blue, alpha); this.box.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn, red, green, blue, alpha);
} }
} }*/
} }

View file

@ -7,16 +7,21 @@ import de.ellpeck.naturesaura.blocks.tiles.BlockEntityEnderCrate;
import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
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 RenderEnderCrate implements BlockEntityRenderer<BlockEntityEnderCrate> { public class RenderEnderCrate implements BlockEntityRenderer<BlockEntityEnderCrate> {
public RenderEnderCrate(BlockEntityRendererProvider.Context context) {
}
@Override @Override
public void render(BlockEntityEnderCrate tileEntityIn, float partialTicks, PoseStack matrixStackIn, MultiBufferSource bufferIn, int combinedLightIn, int combinedOverlayIn) { public void render(BlockEntityEnderCrate tileEntityIn, float partialTicks, PoseStack matrixStackIn, MultiBufferSource bufferIn, int combinedLightIn, int combinedOverlayIn) {
Matrix4f matrix4f = matrixStackIn.last().pose(); var matrix4f = matrixStackIn.last().pose();
float f1 = RenderEnderCrate.getOffsetUp(); var f1 = RenderEnderCrate.getOffsetUp();
RenderEnderCrate.renderFace(matrix4f, bufferIn.getBuffer(RenderEnderCrate.renderType()), f1, f1); RenderEnderCrate.renderFace(matrix4f, bufferIn.getBuffer(RenderEnderCrate.renderType()), f1, f1);
} }

View file

@ -1,52 +1,50 @@
package de.ellpeck.naturesaura.blocks.tiles.render; package de.ellpeck.naturesaura.blocks.tiles.render;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.IVertexBuilder; import com.mojang.math.Vector3f;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityGeneratorLimitRemover; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityGeneratorLimitRemover;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityImpl; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityImpl;
import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.model.Model; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.model.ModelRenderer; import net.minecraft.resources.ResourceLocation;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.ResourceLocation;
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;
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public class RenderGeneratorLimitRemover extends BlockEntityRenderer<BlockEntityGeneratorLimitRemover> { public class RenderGeneratorLimitRemover implements BlockEntityRenderer<BlockEntityGeneratorLimitRemover> {
private static final ResourceLocation RES = new ResourceLocation(NaturesAura.MOD_ID, "textures/models/generator_limit_remover_glint.png");
private final ModelLimitRemoverGlint model = new ModelLimitRemoverGlint(); private static final ResourceLocation RES = new ResourceLocation(NaturesAura.MOD_ID, "textures/models/generator_limit_remover_glint.png");
//private final ModelLimitRemoverGlint model = new ModelLimitRemoverGlint();
public RenderGeneratorLimitRemover(BlockEntityRendererProvider.Context context) {
public RenderGeneratorLimitRemover(BlockEntityRendererDispatcher disp) {
super(disp);
} }
@Override @Override
public void render(BlockEntityGeneratorLimitRemover te, float v, MatrixStack matrixStack, IRenderTypeBuffer iRenderTypeBuffer, int combinedLightIn, int combinedOverlayIn) { public void render(BlockEntityGeneratorLimitRemover te, float v, PoseStack matrixStack, MultiBufferSource iRenderTypeBuffer, int combinedLightIn, int combinedOverlayIn) {
BlockEntity above = te.getLevel().getBlockEntity(te.getPos().up()); var above = te.getLevel().getBlockEntity(te.getBlockPos().above());
if (above instanceof BlockEntityImpl && ((BlockEntityImpl) above).wantsLimitRemover()) { if (above instanceof BlockEntityImpl && ((BlockEntityImpl) above).wantsLimitRemover()) {
this.renderGlint(matrixStack, iRenderTypeBuffer, 1, combinedOverlayIn); this.renderGlint(matrixStack, iRenderTypeBuffer, 1, combinedOverlayIn);
this.renderGlint(matrixStack, iRenderTypeBuffer, 0, combinedOverlayIn); this.renderGlint(matrixStack, iRenderTypeBuffer, 0, combinedOverlayIn);
} }
} }
private void renderGlint(MatrixStack stack, IRenderTypeBuffer buffer, double yOff, int combinedOverlayIn) { private void renderGlint(PoseStack stack, MultiBufferSource buffer, double yOff, int combinedOverlayIn) {
stack.push(); stack.pushPose();
int brightness = 15 << 20 | 15 << 4; var brightness = 15 << 20 | 15 << 4;
float alpha = ((float) Math.sin(System.currentTimeMillis() / 800D) + 1F) / 2F; var alpha = ((float) Math.sin(System.currentTimeMillis() / 800D) + 1F) / 2F;
stack.translate(-0.001F, yOff + 1 + 0.001F, 1 + 0.001F); stack.translate(-0.001F, yOff + 1 + 0.001F, 1 + 0.001F);
stack.rotate(Vector3f.XP.rotationDegrees(180F)); stack.mulPose(Vector3f.XP.rotationDegrees(180F));
stack.scale(1.002F, 1.002F, 1.002F); stack.scale(1.002F, 1.002F, 1.002F);
this.model.render(stack, buffer.getBuffer(this.model.getRenderType(RES)), brightness, combinedOverlayIn, 1, 1, 1, alpha); //this.model.render(stack, buffer.getBuffer(this.model.getRenderType(RES)), brightness, combinedOverlayIn, 1, 1, 1, alpha);
stack.pop(); stack.popPose();
} }
private static class ModelLimitRemoverGlint extends Model { // TODO model rendering
/* private static class ModelLimitRemoverGlint extends Model {
private final ModelRenderer box; private final ModelRenderer box;
@ -61,5 +59,5 @@ public class RenderGeneratorLimitRemover extends BlockEntityRenderer<BlockEntity
public void render(MatrixStack matrixStack, IVertexBuilder iVertexBuilder, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) { public void render(MatrixStack matrixStack, IVertexBuilder iVertexBuilder, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) {
this.box.render(matrixStack, iVertexBuilder, packedLightIn, packedOverlayIn, red, green, blue, alpha); this.box.render(matrixStack, iVertexBuilder, packedLightIn, packedOverlayIn, red, green, blue, alpha);
} }
} }*/
} }

View file

@ -1,31 +1,32 @@
package de.ellpeck.naturesaura.blocks.tiles.render; package de.ellpeck.naturesaura.blocks.tiles.render;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityNatureAltar; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityNatureAltar;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.model.ItemCameraTransforms; import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.math.vector.Vector3f;
public class RenderNatureAltar implements BlockEntityRenderer<BlockEntityNatureAltar> {
public RenderNatureAltar(BlockEntityRendererProvider.Context context) {
public class RenderNatureAltar extends BlockEntityRenderer<BlockEntityNatureAltar> {
public RenderNatureAltar(BlockEntityRendererDispatcher rendererDispatcherIn) {
super(rendererDispatcherIn);
} }
@Override @Override
public void render(BlockEntityNatureAltar tileEntityIn, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) { public void render(BlockEntityNatureAltar tileEntityIn, float partialTicks, PoseStack matrixStackIn, MultiBufferSource bufferIn, int combinedLightIn, int combinedOverlayIn) {
ItemStack stack = tileEntityIn.items.getStackInSlot(0); var stack = tileEntityIn.items.getStackInSlot(0);
if (!stack.isEmpty()) { if (!stack.isEmpty()) {
matrixStackIn.push(); matrixStackIn.pushPose();
float time = tileEntityIn.bobTimer + partialTicks; var time = tileEntityIn.bobTimer + partialTicks;
float bob = (float) Math.sin(time / 10F) * 0.1F; var bob = (float) Math.sin(time / 10F) * 0.1F;
matrixStackIn.translate(0.5F, 1.2F + bob, 0.5F); matrixStackIn.translate(0.5F, 1.2F + bob, 0.5F);
matrixStackIn.rotate(Vector3f.YP.rotationDegrees(time * 3 % 360)); matrixStackIn.mulPose(Vector3f.YP.rotationDegrees(time * 3 % 360));
Minecraft.getInstance().getItemRenderer().renderItem(stack, ItemCameraTransforms.TransformType.GROUND, combinedLightIn, combinedOverlayIn, matrixStackIn, bufferIn); Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemTransforms.TransformType.GROUND, combinedLightIn, combinedOverlayIn, matrixStackIn, bufferIn, 0);
matrixStackIn.pop(); matrixStackIn.popPose();
} }
} }
} }

View file

@ -1,38 +1,38 @@
package de.ellpeck.naturesaura.blocks.tiles.render; package de.ellpeck.naturesaura.blocks.tiles.render;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityOfferingTable; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityOfferingTable;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.model.ItemCameraTransforms; import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.item.BlockItem; import net.minecraft.util.Mth;
import net.minecraft.item.Item; import net.minecraft.world.item.BlockItem;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.Item;
import net.minecraft.util.math.Mth; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.math.vector.Vector3f;
import java.util.Random; import java.util.Random;
public class RenderOfferingTable extends BlockEntityRenderer<BlockEntityOfferingTable> { public class RenderOfferingTable implements BlockEntityRenderer<BlockEntityOfferingTable> {
private final Random rand = new Random(); private final Random rand = new Random();
public RenderOfferingTable(BlockEntityRendererDispatcher disp) { public RenderOfferingTable(BlockEntityRendererProvider.Context context) {
super(disp);
} }
@Override @Override
public void render(BlockEntityOfferingTable tileEntityOfferingTable, float v, MatrixStack matrixStack, IRenderTypeBuffer iRenderTypeBuffer, int combinedLightIn, int combinedOverlayIn) { public void render(BlockEntityOfferingTable tileEntityOfferingTable, float v, PoseStack matrixStack, MultiBufferSource iRenderTypeBuffer, int combinedLightIn, int combinedOverlayIn) {
ItemStack stack = tileEntityOfferingTable.items.getStackInSlot(0); var stack = tileEntityOfferingTable.items.getStackInSlot(0);
if (!stack.isEmpty()) { if (!stack.isEmpty()) {
this.rand.setSeed(Item.getIdFromItem(stack.getItem()) + stack.getDamage()); this.rand.setSeed(Item.getId(stack.getItem()) + stack.getDamageValue());
int amount = Mth.ceil(stack.getCount() / 2F); var amount = Mth.ceil(stack.getCount() / 2F);
for (int i = 0; i < amount; i++) { for (var i = 0; i < amount; i++) {
matrixStack.push(); matrixStack.pushPose();
Item item = stack.getItem(); var item = stack.getItem();
float scale; float scale;
float yOff; float yOff;
@ -48,12 +48,12 @@ public class RenderOfferingTable extends BlockEntityRenderer<BlockEntityOffering
0.35F + this.rand.nextFloat() * 0.3F, 0.35F + this.rand.nextFloat() * 0.3F,
0.9F + yOff + i * 0.001F, 0.9F + yOff + i * 0.001F,
0.35F + this.rand.nextFloat() * 0.3F); 0.35F + this.rand.nextFloat() * 0.3F);
matrixStack.rotate(Vector3f.YP.rotationDegrees(this.rand.nextFloat() * 360)); matrixStack.mulPose(Vector3f.YP.rotationDegrees(this.rand.nextFloat() * 360));
matrixStack.rotate(Vector3f.XP.rotationDegrees(90F)); matrixStack.mulPose(Vector3f.XP.rotationDegrees(90F));
matrixStack.scale(scale, scale, scale); matrixStack.scale(scale, scale, scale);
Minecraft.getInstance().getItemRenderer().renderItem(stack, ItemCameraTransforms.TransformType.GROUND, combinedLightIn, combinedOverlayIn, matrixStack, iRenderTypeBuffer); Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemTransforms.TransformType.GROUND, combinedLightIn, combinedOverlayIn, matrixStack, iRenderTypeBuffer, 0);
matrixStack.pop(); matrixStack.popPose();
} }
} }
} }

View file

@ -1,64 +1,62 @@
package de.ellpeck.naturesaura.blocks.tiles.render; package de.ellpeck.naturesaura.blocks.tiles.render;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.IVertexBuilder; import com.mojang.math.Vector3f;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityProjectileGenerator; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityProjectileGenerator;
import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.model.Model; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.model.ModelRenderer; import net.minecraft.core.Direction;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer; import net.minecraft.resources.ResourceLocation;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
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;
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public class RenderProjectileGenerator extends BlockEntityRenderer<BlockEntityProjectileGenerator> { public class RenderProjectileGenerator implements BlockEntityRenderer<BlockEntityProjectileGenerator> {
private static final ResourceLocation RES = new ResourceLocation(NaturesAura.MOD_ID, "textures/models/projectile_generator_overlay.png");
private final ModelOverlay model = new ModelOverlay(); private static final ResourceLocation RES = new ResourceLocation(NaturesAura.MOD_ID, "textures/models/projectile_generator_overlay.png");
//private final ModelOverlay model = new ModelOverlay();
public RenderProjectileGenerator(BlockEntityRendererProvider.Context context) {
public RenderProjectileGenerator(BlockEntityRendererDispatcher rendererDispatcherIn) {
super(rendererDispatcherIn);
} }
@Override @Override
public void render(BlockEntityProjectileGenerator te, float partialTicks, MatrixStack stack, IRenderTypeBuffer buffer, int combinedLightIn, int combinedOverlayIn) { public void render(BlockEntityProjectileGenerator te, float partialTicks, PoseStack stack, MultiBufferSource buffer, int combinedLightIn, int combinedOverlayIn) {
stack.push(); stack.pushPose();
if (te.nextSide == Direction.NORTH) { if (te.nextSide == Direction.NORTH) {
stack.rotate(Vector3f.YP.rotationDegrees(270)); stack.mulPose(Vector3f.YP.rotationDegrees(270));
stack.translate(-0.002F, 0, -1); stack.translate(-0.002F, 0, -1);
} else if (te.nextSide == Direction.EAST) { } else if (te.nextSide == Direction.EAST) {
stack.rotate(Vector3f.YP.rotationDegrees(180)); stack.mulPose(Vector3f.YP.rotationDegrees(180));
stack.translate(-1.002F, 0, -1); stack.translate(-1.002F, 0, -1);
} else if (te.nextSide == Direction.SOUTH) { } else if (te.nextSide == Direction.SOUTH) {
stack.rotate(Vector3f.YP.rotationDegrees(90)); stack.mulPose(Vector3f.YP.rotationDegrees(90));
stack.translate(-1.002F, 0, 0); stack.translate(-1.002F, 0, 0);
} else { } else {
stack.translate(-0.002F, 0, 0); stack.translate(-0.002F, 0, 0);
} }
int brightness = 15 << 20 | 15 << 4; var brightness = 15 << 20 | 15 << 4;
this.model.render(stack, buffer.getBuffer(this.model.getRenderType(RES)), brightness, combinedOverlayIn, 1, 1, 1, 1); //this.model.render(stack, buffer.getBuffer(this.model.getRenderType(RES)), brightness, combinedOverlayIn, 1, 1, 1, 1);
stack.pop(); stack.popPose();
} }
private static class ModelOverlay extends Model { // TODO model rendering
/* private static class ModelOverlay extends Model {
private final ModelRenderer box; private final ModelPart box;
public ModelOverlay() { public ModelOverlay() {
super(RenderType::getEntityTranslucent); super(RenderType::entityTranslucent);
this.box = new ModelRenderer(this, 0, 0); this.box = new ModelPart(this, 0, 0);
this.box.setTextureSize(64, 64); this.box.setTextureSize(64, 64);
this.box.addBox(0, 0, 0, 16, 16, 16); this.box.(0, 0, 0, 16, 16, 16);
} }
@Override @Override
public void render(MatrixStack matrixStackIn, IVertexBuilder bufferIn, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) { public void render(MatrixStack matrixStackIn, IVertexBuilder bufferIn, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) {
this.box.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn, red, green, blue, alpha); this.box.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn, red, green, blue, alpha);
} }
} }*/
} }

Some files were not shown because too many files have changed in this diff Show more