This commit is contained in:
Ell 2021-12-15 16:30:22 +01:00
parent 24cf4ae186
commit 65cce7fae5
144 changed files with 1112 additions and 1114 deletions

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

@ -45,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());
} }

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

@ -53,7 +53,7 @@ public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorP
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.below()).isCollisionShapeFullBlock(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(
@ -72,7 +72,7 @@ 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.setBlockAndUpdate(pos, ModBlocks.DECAYED_LEAVES.defaultBlockState()); levelIn.setBlockAndUpdate(pos, ModBlocks.DECAYED_LEAVES.defaultBlockState());

View file

@ -8,7 +8,6 @@ import net.minecraft.core.BlockPos;
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.Blocks; import net.minecraft.world.level.block.Blocks;
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.phys.AABB; import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
@ -37,9 +36,9 @@ public class BlockAnimalContainer extends BlockContainerImpl implements IVisuali
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AABB 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 AABB(pos).inflate(radius); return new AABB(pos).inflate(radius);
} }

View file

@ -38,42 +38,42 @@ public class BlockAnimalGenerator extends BlockContainerImpl implements IVisuali
@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 Animal) || entity instanceof Mob || entity instanceof Npc) 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 Animal) || entity instanceof Mob || entity instanceof Npc) if (entity.level.isClientSide || !(entity instanceof Animal) || entity instanceof Mob || entity instanceof Npc)
return; return;
BlockPos pos = entity.blockPosition(); var pos = entity.blockPosition();
Helper.getBlockEntitiesInArea(entity.level, pos, 5, tile -> { Helper.getBlockEntitiesInArea(entity.level, pos, 5, tile -> {
if (!(tile instanceof BlockEntityAnimalGenerator gen)) if (!(tile instanceof BlockEntityAnimalGenerator gen))
return false; return false;
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.isBaby(); 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.getBlockPos(); var genPos = gen.getBlockPos();
PacketHandler.sendToAllAround(entity.level, pos, 32, new PacketParticles( PacketHandler.sendToAllAround(entity.level, pos, 32, new PacketParticles(
(float) entity.getX(), (float) entity.getY(), (float) entity.getZ(), 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,
@ -86,14 +86,14 @@ 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);
} }

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);
} }

View file

@ -21,7 +21,7 @@ public class BlockAuraDetector extends BlockContainerImpl {
@Override @Override
public int getAnalogOutputSignal(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 detector) if (tile instanceof BlockEntityAuraDetector detector)
return detector.redstonePower; return detector.redstonePower;
else else

View file

@ -21,7 +21,7 @@ public class BlockCatalyst extends BlockImpl implements ICustomBlockState {
@Override @Override
public BlockState getStateForPlacement(BlockPlaceContext 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).setValue(NETHER, nether); return super.getStateForPlacement(context).setValue(NETHER, nether);
} }

View file

@ -39,9 +39,9 @@ public class BlockChunkLoader extends BlockContainerImpl implements IVisualizabl
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AABB 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 AABB( return new AABB(
(pos.getX() - range) >> 4 << 4, (pos.getX() - range) >> 4 << 4,
@ -60,10 +60,10 @@ 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.random.nextFloat(), pos.getY() + levelIn.random.nextFloat(), pos.getZ() + levelIn.random.nextFloat(), pos.getX() + levelIn.random.nextFloat(), pos.getY() + levelIn.random.nextFloat(), pos.getZ() + levelIn.random.nextFloat(),
0, 0, 0, 0xa12dff, 1F + levelIn.random.nextFloat(), 100, 0, false, true); 0, 0, 0, 0xa12dff, 1F + levelIn.random.nextFloat(), 100, 0, false, true);

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

@ -49,22 +49,22 @@ public class BlockEndFlower 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);
} }
@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 EnderDragon dragon)) if (living.level.isClientSide || !(living instanceof EnderDragon dragon))
return; return;
if (dragon.deathTime < 150 || dragon.deathTime % 10 != 0) if (dragon.deathTime < 150 || dragon.deathTime % 10 != 0)
return; return;
for (int i = 0; i < 6; i++) { for (var i = 0; i < 6; i++) {
int x = dragon.level.random.nextInt(256) - 128; var x = dragon.level.random.nextInt(256) - 128;
int z = dragon.level.random.nextInt(256) - 128; var z = dragon.level.random.nextInt(256) - 128;
BlockPos pos = new BlockPos(x, dragon.level.getHeight(Heightmap.Types.WORLD_SURFACE, x, z), z); var pos = new BlockPos(x, dragon.level.getHeight(Heightmap.Types.WORLD_SURFACE, x, z), z);
if (!dragon.level.isLoaded(pos)) if (!dragon.level.isLoaded(pos))
continue; continue;
if (dragon.level.getBlockState(pos.below()).getBlock() != Blocks.END_STONE) if (dragon.level.getBlockState(pos.below()).getBlock() != Blocks.END_STONE)
@ -102,7 +102,7 @@ public class BlockEndFlower extends BushBlock implements IModItem, ICustomBlockS
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
BlockEntity tile = builder.getParameter(LootContextParams.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);

View file

@ -26,7 +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.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;
@ -57,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 {
@ -70,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());
@ -91,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);
@ -109,14 +108,14 @@ 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);
} }

View file

@ -33,17 +33,17 @@ public class BlockFieldCreator extends BlockContainerImpl implements ICustomBloc
@Override @Override
public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult 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.isCrouching() && compound.contains(key)) { if (!player.isCrouching() && compound.contains(key)) {
BlockPos stored = BlockPos.of(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 otherCreator) { if (otherTile instanceof BlockEntityFieldCreator otherCreator) {
creator.connectionOffset = stored.subtract(pos); creator.connectionOffset = stored.subtract(pos);
creator.isMain = true; creator.isMain = true;
@ -74,9 +74,9 @@ 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 creator && creator.isCharged) { if (tile instanceof BlockEntityFieldCreator creator && creator.isCharged) {
BlockPos connected = creator.getConnectedPos(); var connected = creator.getConnectedPos();
if (connected != null) if (connected != null)
NaturesAuraAPI.instance().spawnParticleStream( NaturesAuraAPI.instance().spawnParticleStream(
pos.getX() + 0.25F + rand.nextFloat() * 0.5F, pos.getX() + 0.25F + rand.nextFloat() * 0.5F,

View file

@ -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 heater && heater.isActive) { if (tile instanceof BlockEntityFurnaceHeater heater && heater.isActive) {
Direction facing = stateIn.getValue(FACING); var facing = stateIn.getValue(FACING);
float x; float x;
float y; float y;

View file

@ -43,11 +43,11 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
} }
private static int getShapeIndex(BlockState state) { private static int getShapeIndex(BlockState state) {
int i = 0; var i = 0;
boolean n = state.getValue(NORTH) != RedstoneSide.NONE; var n = state.getValue(NORTH) != RedstoneSide.NONE;
boolean e = state.getValue(EAST) != RedstoneSide.NONE; var e = state.getValue(EAST) != RedstoneSide.NONE;
boolean s = state.getValue(SOUTH) != RedstoneSide.NONE; var s = state.getValue(SOUTH) != RedstoneSide.NONE;
boolean w = state.getValue(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.ordinal(); i |= 1 << Direction.NORTH.ordinal();
@ -82,7 +82,7 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
@Override @Override
public BlockState getStateForPlacement(BlockPlaceContext context) { public BlockState getStateForPlacement(BlockPlaceContext context) {
BlockGetter iblockreader = context.getLevel(); BlockGetter iblockreader = context.getLevel();
BlockPos blockpos = context.getClickedPos(); var blockpos = context.getClickedPos();
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)); 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));
} }
@ -96,12 +96,12 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
} }
private RedstoneSide getSide(BlockGetter levelIn, BlockPos pos, Direction face) { private RedstoneSide getSide(BlockGetter levelIn, BlockPos pos, Direction face) {
BlockPos blockpos = pos.relative(face); var blockpos = pos.relative(face);
BlockState blockstate = levelIn.getBlockState(blockpos); var blockstate = levelIn.getBlockState(blockpos);
BlockPos blockpos1 = pos.above(); var blockpos1 = pos.above();
BlockState blockstate1 = levelIn.getBlockState(blockpos1); var blockstate1 = levelIn.getBlockState(blockpos1);
if (!blockstate1.isCollisionShapeFullBlock(levelIn, blockpos1)) { if (!blockstate1.isCollisionShapeFullBlock(levelIn, blockpos1)) {
boolean flag = blockstate.isFaceSturdy(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.above()))) { if (flag && this.canConnectTo(levelIn.getBlockState(blockpos.above()))) {
if (blockstate.isCollisionShapeFullBlock(levelIn, blockpos)) { if (blockstate.isCollisionShapeFullBlock(levelIn, blockpos)) {
return RedstoneSide.UP; return RedstoneSide.UP;
@ -115,14 +115,14 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
} }
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 canSurvive(BlockState state, LevelReader levelIn, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader levelIn, BlockPos pos) {
BlockPos blockpos = pos.below(); var blockpos = pos.below();
BlockState blockstate = levelIn.getBlockState(blockpos); var blockstate = levelIn.getBlockState(blockpos);
return blockstate.isFaceSturdy(levelIn, blockpos, Direction.UP) || blockstate.getBlock() == Blocks.HOPPER; return blockstate.isFaceSturdy(levelIn, blockpos, Direction.UP) || blockstate.getBlock() == Blocks.HOPPER;
} }
@ -134,14 +134,14 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
@Override @Override
public void onPlace(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.updateNeighborsAt(pos.relative(direction), this); levelIn.updateNeighborsAt(pos.relative(direction), this);
} }
for (Direction direction1 : Direction.Plane.HORIZONTAL) { for (var direction1 : Direction.Plane.HORIZONTAL) {
this.notifyWireNeighborsOfStateChange(levelIn, pos.relative(direction1)); this.notifyWireNeighborsOfStateChange(levelIn, pos.relative(direction1));
} }
for (Direction direction2 : Direction.Plane.HORIZONTAL) { for (var direction2 : Direction.Plane.HORIZONTAL) {
BlockPos blockpos = pos.relative(direction2); var blockpos = pos.relative(direction2);
if (levelIn.getBlockState(blockpos).isCollisionShapeFullBlock(levelIn, blockpos)) { if (levelIn.getBlockState(blockpos).isCollisionShapeFullBlock(levelIn, blockpos)) {
this.notifyWireNeighborsOfStateChange(levelIn, blockpos.above()); this.notifyWireNeighborsOfStateChange(levelIn, blockpos.above());
} else { } else {
@ -157,14 +157,14 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
if (!isMoving && state.getBlock() != newState.getBlock()) { if (!isMoving && state.getBlock() != newState.getBlock()) {
super.onRemove(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.updateNeighborsAt(pos.relative(direction), this); levelIn.updateNeighborsAt(pos.relative(direction), this);
} }
for (Direction direction1 : Direction.Plane.HORIZONTAL) { for (var direction1 : Direction.Plane.HORIZONTAL) {
this.notifyWireNeighborsOfStateChange(levelIn, pos.relative(direction1)); this.notifyWireNeighborsOfStateChange(levelIn, pos.relative(direction1));
} }
for (Direction direction2 : Direction.Plane.HORIZONTAL) { for (var direction2 : Direction.Plane.HORIZONTAL) {
BlockPos blockpos = pos.relative(direction2); var blockpos = pos.relative(direction2);
if (levelIn.getBlockState(blockpos).isCollisionShapeFullBlock(levelIn, blockpos)) { if (levelIn.getBlockState(blockpos).isCollisionShapeFullBlock(levelIn, blockpos)) {
this.notifyWireNeighborsOfStateChange(levelIn, blockpos.above()); this.notifyWireNeighborsOfStateChange(levelIn, blockpos.above());
} else { } else {
@ -188,23 +188,23 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
@Override @Override
public void updateIndirectNeighbourShapes(BlockState state, LevelAccessor levelIn, BlockPos pos, int flags, int recursionLeft) { public void updateIndirectNeighbourShapes(BlockState state, LevelAccessor levelIn, BlockPos pos, int flags, int recursionLeft) {
BlockPos.MutableBlockPos pool = new BlockPos.MutableBlockPos(); var pool = new BlockPos.MutableBlockPos();
for (Direction direction : Direction.Plane.HORIZONTAL) { for (var direction : Direction.Plane.HORIZONTAL) {
RedstoneSide redstoneside = state.getValue(RedStoneWireBlock.PROPERTY_BY_DIRECTION.get(direction)); var redstoneside = state.getValue(RedStoneWireBlock.PROPERTY_BY_DIRECTION.get(direction));
if (redstoneside != RedstoneSide.NONE && levelIn.getBlockState(pool.set(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.relative(direction.getOpposite()); var blockpos = pool.relative(direction.getOpposite());
BlockState blockstate1 = blockstate.updateShape(direction.getOpposite(), levelIn.getBlockState(blockpos), levelIn, pool, blockpos); var blockstate1 = blockstate.updateShape(direction.getOpposite(), levelIn.getBlockState(blockpos), levelIn, pool, blockpos);
updateOrDestroy(blockstate, blockstate1, levelIn, pool, flags); updateOrDestroy(blockstate, blockstate1, levelIn, pool, flags);
} }
pool.set(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.relative(direction.getOpposite()); var blockpos1 = pool.relative(direction.getOpposite());
BlockState blockstate2 = blockstate3.updateShape(direction.getOpposite(), levelIn.getBlockState(blockpos1), levelIn, pool, blockpos1); var blockstate2 = blockstate3.updateShape(direction.getOpposite(), levelIn.getBlockState(blockpos1), levelIn, pool, blockpos1);
updateOrDestroy(blockstate3, blockstate2, levelIn, pool, flags); updateOrDestroy(blockstate3, blockstate2, levelIn, pool, flags);
} }
} }
@ -216,7 +216,7 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
if (levelIn.getBlockState(pos).getBlock() == this) { if (levelIn.getBlockState(pos).getBlock() == this) {
levelIn.updateNeighborsAt(pos, this); levelIn.updateNeighborsAt(pos, this);
for (Direction direction : Direction.values()) { for (var direction : Direction.values()) {
levelIn.updateNeighborsAt(pos.relative(direction), this); levelIn.updateNeighborsAt(pos.relative(direction), this);
} }
} }

View file

@ -35,7 +35,7 @@ public class BlockGoldenLeaves extends LeavesBlock implements IModItem, IColorPr
} }
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.setBlockAndUpdate(pos, ModBlocks.GOLDEN_LEAVES.defaultBlockState() level.setBlockAndUpdate(pos, ModBlocks.GOLDEN_LEAVES.defaultBlockState()
@ -74,9 +74,9 @@ public class BlockGoldenLeaves extends LeavesBlock implements IModItem, IColorPr
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public BlockColor 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.getAverageFoliageColor(levelIn, pos); var foliage = BiomeColors.getAverageFoliageColor(levelIn, pos);
return Helper.blendColors(color, foliage, state.getValue(STAGE) / (float) HIGHEST_STAGE); return Helper.blendColors(color, foliage, state.getValue(STAGE) / (float) HIGHEST_STAGE);
} else { } else {
return color; return color;
@ -100,7 +100,7 @@ public class BlockGoldenLeaves extends LeavesBlock implements IModItem, IColorPr
} }
if (stage > 1) { if (stage > 1) {
BlockPos offset = pos.relative(Direction.getRandom(random)); var offset = pos.relative(Direction.getRandom(random));
if (levelIn.isLoaded(offset)) if (levelIn.isLoaded(offset))
convert(levelIn, offset); convert(levelIn, offset);
} }

View file

@ -89,7 +89,7 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
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 (!player.isCrouching()) if (!player.isCrouching())
return InteractionResult.FAIL; return InteractionResult.FAIL;
BlockEntity tile = levelIn.getBlockEntity(pos); var tile = levelIn.getBlockEntity(pos);
if (!(tile instanceof BlockEntityGratedChute chute)) if (!(tile instanceof BlockEntityGratedChute chute))
return InteractionResult.FAIL; return InteractionResult.FAIL;
if (!levelIn.isClientSide) { if (!levelIn.isClientSide) {
@ -102,7 +102,7 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
@Nullable @Nullable
@Override @Override
public BlockState getStateForPlacement(BlockPlaceContext context) { public BlockState getStateForPlacement(BlockPlaceContext context) {
Direction newFacing = context.getClickedFace().getOpposite(); var newFacing = context.getClickedFace().getOpposite();
if (newFacing == Direction.UP) if (newFacing == Direction.UP)
newFacing = Direction.DOWN; newFacing = Direction.DOWN;
return super.getStateForPlacement(context).setValue(FACING, newFacing); return super.getStateForPlacement(context).setValue(FACING, newFacing);
@ -120,10 +120,10 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
@Override @Override
public int getAnalogOutputSignal(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);

View file

@ -23,11 +23,11 @@ public class BlockItemDistributor extends BlockContainerImpl implements ICustomB
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 (!player.isCrouching()) 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

@ -31,7 +31,7 @@ public class BlockLight extends BlockImpl implements ICustomBlockState, INoItemB
@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,

View file

@ -69,7 +69,7 @@ public class BlockNatureAltar extends BlockContainerImpl implements ITESRProvide
@Nullable @Nullable
@Override @Override
public BlockState getStateForPlacement(BlockPlaceContext 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).setValue(NETHER, nether); return super.getStateForPlacement(context).setValue(NETHER, nether);
} }

View file

@ -21,8 +21,8 @@ public class BlockNetherGrass extends BlockImpl implements ICustomBlockState, Bo
@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.above(); var up = pos.above();
BlockState upState = levelIn.getBlockState(up); var upState = levelIn.getBlockState(up);
if (upState.isFaceSturdy(levelIn, up, Direction.DOWN)) if (upState.isFaceSturdy(levelIn, up, Direction.DOWN))
levelIn.setBlockAndUpdate(pos, Blocks.NETHERRACK.defaultBlockState()); levelIn.setBlockAndUpdate(pos, Blocks.NETHERRACK.defaultBlockState());
} }
@ -47,16 +47,16 @@ public class BlockNetherGrass extends BlockImpl implements ICustomBlockState, Bo
@Override @Override
public void performBonemeal(ServerLevel level, Random rand, BlockPos pos, BlockState state) { public void performBonemeal(ServerLevel level, Random rand, BlockPos pos, BlockState state) {
BlockPos blockpos = pos.above(); var blockpos = pos.above();
BlockState blockstate = Blocks.GRASS.defaultBlockState(); 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) {
((BonemealableBlock) blockstate.getBlock()).performBonemeal(level, rand, blockpos1, blockstate2); ((BonemealableBlock) blockstate.getBlock()).performBonemeal(level, rand, blockpos1, blockstate2);
} }

View file

@ -32,14 +32,14 @@ public class BlockOakGenerator extends BlockContainerImpl implements IVisualizab
@SubscribeEvent @SubscribeEvent
public void onTreeGrow(SaplingGrowTreeEvent event) { public void onTreeGrow(SaplingGrowTreeEvent event) {
var level = event.getWorld(); var level = event.getWorld();
BlockPos pos = event.getPos(); var pos = event.getPos();
if (level instanceof Level && !level.isClientSide() && IAuraType.forLevel((Level) 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);

View file

@ -31,17 +31,17 @@ public class BlockPickupStopper extends BlockContainerImpl implements IVisualiza
@SubscribeEvent @SubscribeEvent
public void onPickup(EntityItemPickupEvent event) { public void onPickup(EntityItemPickupEvent event) {
Player player = event.getPlayer(); var player = event.getPlayer();
if (player != null && !player.isCrouching()) { if (player != null && !player.isCrouching()) {
ItemEntity item = event.getItem(); var item = event.getItem();
BlockPos pos = item.blockPosition(); var pos = item.blockPosition();
Helper.getBlockEntitiesInArea(item.level, pos, 8, tile -> { Helper.getBlockEntitiesInArea(item.level, pos, 8, tile -> {
if (!(tile instanceof BlockEntityPickupStopper stopper)) if (!(tile instanceof BlockEntityPickupStopper stopper))
return false; return false;
float radius = stopper.getRadius(); var radius = stopper.getRadius();
if (radius <= 0F) if (radius <= 0F)
return false; return false;
BlockPos stopperPos = stopper.getBlockPos(); var stopperPos = stopper.getBlockPos();
if (!new AABB(stopperPos).inflate(radius).intersects(item.getBoundingBox())) if (!new AABB(stopperPos).inflate(radius).intersects(item.getBoundingBox()))
return false; return false;
@ -58,7 +58,7 @@ public class BlockPickupStopper extends BlockContainerImpl implements IVisualiza
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AABB 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)

View file

@ -45,7 +45,7 @@ public class BlockProjectileGenerator extends BlockContainerImpl implements ITES
@Override @Override
protected Projectile getProjectile(Level levelIn, Position position, ItemStack stackIn) { protected Projectile getProjectile(Level levelIn, Position position, ItemStack stackIn) {
ThrownEnderpearl ret = new ThrownEnderpearl(EntityType.ENDER_PEARL, levelIn); var ret = new ThrownEnderpearl(EntityType.ENDER_PEARL, levelIn);
ret.setPos(position.x(), position.y(), position.z()); ret.setPos(position.x(), position.y(), position.z());
return ret; return ret;
} }
@ -53,7 +53,7 @@ public class BlockProjectileGenerator extends BlockContainerImpl implements ITES
DispenserBlock.registerBehavior(Items.TRIDENT, new AbstractProjectileDispenseBehavior() { DispenserBlock.registerBehavior(Items.TRIDENT, new AbstractProjectileDispenseBehavior() {
@Override @Override
protected Projectile getProjectile(Level levelIn, Position position, ItemStack stackIn) { protected Projectile getProjectile(Level levelIn, Position position, ItemStack stackIn) {
ThrownTrident ret = new ThrownTrident(EntityType.TRIDENT, levelIn); var ret = new ThrownTrident(EntityType.TRIDENT, levelIn);
ret.setPos(position.x(), position.y(), position.z()); ret.setPos(position.x(), position.y(), position.z());
ObfuscationReflectionHelper.setPrivateValue(ThrownTrident.class, ret, stackIn.copy(), "tridentItem"); ObfuscationReflectionHelper.setPrivateValue(ThrownTrident.class, ret, stackIn.copy(), "tridentItem");
ret.pickup = AbstractArrow.Pickup.ALLOWED; ret.pickup = AbstractArrow.Pickup.ALLOWED;
@ -64,21 +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;
HitResult ray = event.getRayTraceResult(); var ray = event.getRayTraceResult();
if (!(ray instanceof BlockHitResult blockRay)) if (!(ray instanceof BlockHitResult blockRay))
return; return;
BlockPos pos = blockRay.getBlockPos(); var pos = blockRay.getBlockPos();
if (pos == null) if (pos == null)
return; return;
BlockEntity tile = entity.level.getBlockEntity(pos); var tile = entity.level.getBlockEntity(pos);
if (!(tile instanceof BlockEntityProjectileGenerator generator)) if (!(tile instanceof BlockEntityProjectileGenerator generator))
return; return;
if (generator.nextSide != blockRay.getDirection()) if (generator.nextSide != blockRay.getDirection())
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))

View file

@ -48,10 +48,10 @@ 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 Slime slime) || entity.level.isClientSide) if (!(entity instanceof Slime slime) || entity.level.isClientSide)
return; return;
int size = slime.getSize(); var size = slime.getSize();
if (size <= 1) if (size <= 1)
return; return;
Helper.getBlockEntitiesInArea(entity.level, entity.blockPosition(), 8, tile -> { Helper.getBlockEntitiesInArea(entity.level, entity.blockPosition(), 8, tile -> {

View file

@ -21,9 +21,9 @@ public class BlockSnowCreator extends BlockContainerImpl implements IVisualizabl
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AABB 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 AABB(pos).inflate(radius); return new AABB(pos).inflate(radius);
} }

View file

@ -53,26 +53,26 @@ 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;
LevelAccessor level = event.getWorld(); 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.getBlockPos(); var lampPos = lamp.getBlockPos();
if (!new AABB(lampPos).inflate(range).contains(new Vec3(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;
Mob entity = (Mob) event.getEntityLiving(); var entity = (Mob) event.getEntityLiving();
if (entity.checkSpawnRules(level, event.getSpawnReason()) && entity.checkSpawnObstruction(level)) { if (entity.checkSpawnRules(level, event.getSpawnReason()) && entity.checkSpawnObstruction(level)) {
BlockPos spot = IAuraChunk.getHighestSpot((Level) level, lampPos, 32, lampPos); var spot = IAuraChunk.getHighestSpot((Level) level, lampPos, 32, lampPos);
IAuraChunk.getAuraChunk((Level) 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,
@ -92,9 +92,9 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable,
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AABB 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 AABB(pos).inflate(radius); return new AABB(pos).inflate(radius);
} }

View file

@ -66,7 +66,7 @@ public class BlockSpring extends BlockContainerImpl implements ICustomBlockState
@Override @Override
public ItemStack pickupBlock(LevelAccessor levelIn, BlockPos pos, BlockState state) { public ItemStack pickupBlock(LevelAccessor levelIn, BlockPos pos, BlockState state) {
BlockEntity tile = levelIn.getBlockEntity(pos); var tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntitySpring) if (tile instanceof BlockEntitySpring)
((BlockEntitySpring) tile).consumeAura(2500); ((BlockEntitySpring) tile).consumeAura(2500);
return new ItemStack(Items.WATER_BUCKET); } return new ItemStack(Items.WATER_BUCKET); }

View file

@ -58,25 +58,25 @@ public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider<
@SubscribeEvent @SubscribeEvent
public void onTreeGrow(SaplingGrowTreeEvent event) { public void onTreeGrow(SaplingGrowTreeEvent event) {
LevelAccessor level = event.getWorld(); 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().getCloneItemStack(level, pos, sapling); var saplingStack = sapling.getBlock().getCloneItemStack(level, pos, sapling);
if (!saplingStack.isEmpty()) { if (!saplingStack.isEmpty()) {
for (TreeRitualRecipe recipe : ((Level) level).getRecipeManager().getRecipesFor(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 stand) { if (tile instanceof BlockEntityWoodStand stand) {
ItemStack stack = stand.items.getStackInSlot(0); var 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);

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,10 +90,10 @@ 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.check() != null) if (matcher.check() != null)
@ -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.check().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

@ -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

@ -22,19 +22,19 @@ public class RenderAuraTimer implements BlockEntityRenderer<BlockEntityAuraTimer
@Override @Override
public void render(BlockEntityAuraTimer tile, float partialTicks, PoseStack stack, MultiBufferSource 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.pushPose(); 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.popPose(); stack.popPose();

View file

@ -20,8 +20,8 @@ public class RenderEnderCrate implements BlockEntityRenderer<BlockEntityEnderCra
@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

@ -25,7 +25,7 @@ public class RenderGeneratorLimitRemover implements BlockEntityRenderer<BlockEnt
@Override @Override
public void render(BlockEntityGeneratorLimitRemover te, float v, PoseStack matrixStack, MultiBufferSource 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.getBlockPos().above()); 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);
@ -34,8 +34,8 @@ public class RenderGeneratorLimitRemover implements BlockEntityRenderer<BlockEnt
private void renderGlint(PoseStack stack, MultiBufferSource buffer, double yOff, int combinedOverlayIn) { private void renderGlint(PoseStack stack, MultiBufferSource buffer, double yOff, int combinedOverlayIn) {
stack.pushPose(); 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.mulPose(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);

View file

@ -18,11 +18,11 @@ public class RenderNatureAltar implements BlockEntityRenderer<BlockEntityNatureA
@Override @Override
public void render(BlockEntityNatureAltar tileEntityIn, float partialTicks, PoseStack matrixStackIn, MultiBufferSource 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.pushPose(); 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.mulPose(Vector3f.YP.rotationDegrees(time * 3 % 360)); matrixStackIn.mulPose(Vector3f.YP.rotationDegrees(time * 3 % 360));
Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemTransforms.TransformType.GROUND, combinedLightIn, combinedOverlayIn, matrixStackIn, bufferIn, 0); Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemTransforms.TransformType.GROUND, combinedLightIn, combinedOverlayIn, matrixStackIn, bufferIn, 0);

View file

@ -25,14 +25,14 @@ public class RenderOfferingTable implements BlockEntityRenderer<BlockEntityOffer
@Override @Override
public void render(BlockEntityOfferingTable tileEntityOfferingTable, float v, PoseStack matrixStack, MultiBufferSource 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.getId(stack.getItem()) + stack.getDamageValue()); 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.pushPose(); matrixStack.pushPose();
Item item = stack.getItem(); var item = stack.getItem();
float scale; float scale;
float yOff; float yOff;

View file

@ -37,7 +37,7 @@ public class RenderProjectileGenerator implements BlockEntityRenderer<BlockEntit
} 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.popPose(); stack.popPose();
} }

View file

@ -20,17 +20,17 @@ public class RenderWoodStand implements BlockEntityRenderer<BlockEntityWoodStand
@Override @Override
public void render(BlockEntityWoodStand tileEntityWoodStand, float v, PoseStack matrixStack, MultiBufferSource iRenderTypeBuffer, int i, int i1) { public void render(BlockEntityWoodStand tileEntityWoodStand, float v, PoseStack matrixStack, MultiBufferSource iRenderTypeBuffer, int i, int i1) {
ItemStack stack = tileEntityWoodStand.items.getStackInSlot(0); var stack = tileEntityWoodStand.items.getStackInSlot(0);
if (!stack.isEmpty()) { if (!stack.isEmpty()) {
matrixStack.pushPose(); matrixStack.pushPose();
Item item = stack.getItem(); var item = stack.getItem();
if (item instanceof BlockItem blockItem && blockItem.getBlock().defaultBlockState().getMaterial().isSolid()) { if (item instanceof BlockItem blockItem && blockItem.getBlock().defaultBlockState().getMaterial().isSolid()) {
matrixStack.translate(0.5F, 0.755F, 0.5F); matrixStack.translate(0.5F, 0.755F, 0.5F);
float scale = 0.95F; var scale = 0.95F;
matrixStack.scale(scale, scale, scale); matrixStack.scale(scale, scale, scale);
} else { } else {
matrixStack.translate(0.5F, 0.825F, 0.4F); matrixStack.translate(0.5F, 0.825F, 0.4F);
float scale = 0.75F; var scale = 0.75F;
matrixStack.scale(scale, scale, scale); matrixStack.scale(scale, scale, scale);
matrixStack.mulPose(Vector3f.XP.rotationDegrees(90)); matrixStack.mulPose(Vector3f.XP.rotationDegrees(90));
} }

View file

@ -27,10 +27,10 @@ public class AngerEffect implements IDrainSpotEffect {
private boolean calcValues(Level level, BlockPos pos, Integer spot) { private boolean calcValues(Level level, BlockPos pos, Integer spot) {
if (spot >= 0) if (spot >= 0)
return false; return false;
int aura = IAuraChunk.getAuraInArea(level, pos, 50); var aura = IAuraChunk.getAuraInArea(level, pos, 50);
if (aura > 0) if (aura > 0)
return false; return false;
int dist = Math.min(Math.abs(aura) / 50000, 75); var dist = Math.min(Math.abs(aura) / 50000, 75);
if (dist < 10) if (dist < 10)
return false; return false;
this.bb = new AABB(pos).inflate(dist); this.bb = new AABB(pos).inflate(dist);
@ -58,11 +58,11 @@ public class AngerEffect implements IDrainSpotEffect {
return; return;
if (!this.calcValues(level, pos, spot)) if (!this.calcValues(level, pos, spot))
return; return;
List<LivingEntity> entities = level.getEntitiesOfClass(LivingEntity.class, this.bb); var entities = level.getEntitiesOfClass(LivingEntity.class, this.bb);
for (LivingEntity entity : entities) { for (var entity : entities) {
if (!(entity instanceof NeutralMob)) if (!(entity instanceof NeutralMob))
continue; continue;
Player player = level.getNearestPlayer(entity, 25); var player = level.getNearestPlayer(entity, 25);
if (player == null) if (player == null)
continue; continue;
((NeutralMob) entity).setTarget(player); ((NeutralMob) entity).setTarget(player);

View file

@ -37,14 +37,14 @@ public class AnimalEffect implements IDrainSpotEffect {
private boolean calcValues(Level level, BlockPos pos, Integer spot) { private boolean calcValues(Level level, BlockPos pos, Integer spot) {
if (spot <= 0) if (spot <= 0)
return false; return false;
Pair<Integer, Integer> auraAndSpots = IAuraChunk.getAuraAndSpotAmountInArea(level, pos, 30); var auraAndSpots = IAuraChunk.getAuraAndSpotAmountInArea(level, pos, 30);
int aura = auraAndSpots.getLeft(); int aura = auraAndSpots.getLeft();
if (aura < 1500000) if (aura < 1500000)
return false; return false;
this.chance = Math.min(50, Mth.ceil(Math.abs(aura) / 500000F / auraAndSpots.getRight())); this.chance = Math.min(50, Mth.ceil(Math.abs(aura) / 500000F / auraAndSpots.getRight()));
if (this.chance <= 0) if (this.chance <= 0)
return false; return false;
int dist = Mth.clamp(Math.abs(aura) / 150000, 5, 35); var dist = Mth.clamp(Math.abs(aura) / 150000, 5, 35);
this.bb = new AABB(pos).inflate(dist); this.bb = new AABB(pos).inflate(dist);
return true; return true;
} }
@ -72,18 +72,18 @@ public class AnimalEffect implements IDrainSpotEffect {
if (!this.calcValues(level, pos, spot)) if (!this.calcValues(level, pos, spot))
return; return;
List<Animal> animals = level.getEntitiesOfClass(Animal.class, this.bb); var animals = level.getEntitiesOfClass(Animal.class, this.bb);
if (animals.size() >= ModConfig.instance.maxAnimalsAroundPowder.get()) if (animals.size() >= ModConfig.instance.maxAnimalsAroundPowder.get())
return; return;
List<ItemEntity> items = level.getEntitiesOfClass(ItemEntity.class, this.bb); var items = level.getEntitiesOfClass(ItemEntity.class, this.bb);
for (ItemEntity item : items) { for (var item : items) {
if (!item.isAlive()) if (!item.isAlive())
continue; continue;
if (!NaturesAuraAPI.instance().isEffectPowderActive(level, item.blockPosition(), NAME)) if (!NaturesAuraAPI.instance().isEffectPowderActive(level, item.blockPosition(), NAME))
continue; continue;
ItemStack stack = item.getItem(); var stack = item.getItem();
if (!(stack.getItem() instanceof EggItem)) if (!(stack.getItem() instanceof EggItem))
continue; continue;
if (item.getAge() < item.lifespan / 2) if (item.getAge() < item.lifespan / 2)
@ -96,44 +96,44 @@ public class AnimalEffect implements IDrainSpotEffect {
item.setItem(stack); item.setItem(stack);
} }
Chicken chicken = new Chicken(EntityType.CHICKEN, level); var chicken = new Chicken(EntityType.CHICKEN, level);
chicken.setAge(-24000); chicken.setAge(-24000);
chicken.setPos(item.getX(), item.getY(), item.getZ()); chicken.setPos(item.getX(), item.getY(), item.getZ());
level.addFreshEntity(chicken); level.addFreshEntity(chicken);
BlockPos closestSpot = IAuraChunk.getHighestSpot(level, item.blockPosition(), 35, pos); var closestSpot = IAuraChunk.getHighestSpot(level, item.blockPosition(), 35, pos);
IAuraChunk.getAuraChunk(level, closestSpot).drainAura(closestSpot, 2000); IAuraChunk.getAuraChunk(level, closestSpot).drainAura(closestSpot, 2000);
} }
if (level.random.nextInt(20) <= this.chance) { if (level.random.nextInt(20) <= this.chance) {
if (animals.size() < 2) if (animals.size() < 2)
return; return;
Animal first = animals.get(level.random.nextInt(animals.size())); var first = animals.get(level.random.nextInt(animals.size()));
if (first.isBaby() || first.isInLove()) if (first.isBaby() || first.isInLove())
return; return;
if (!NaturesAuraAPI.instance().isEffectPowderActive(level, first.blockPosition(), NAME)) if (!NaturesAuraAPI.instance().isEffectPowderActive(level, first.blockPosition(), NAME))
return; return;
Optional<Animal> secondOptional = animals.stream() var secondOptional = animals.stream()
.filter(e -> e != first && !e.isInLove() && !e.isBaby()) .filter(e -> e != first && !e.isInLove() && !e.isBaby())
.min(Comparator.comparingDouble(e -> e.distanceToSqr(first))); .min(Comparator.comparingDouble(e -> e.distanceToSqr(first)));
if (secondOptional.isEmpty()) if (secondOptional.isEmpty())
return; return;
Animal second = secondOptional.get(); var second = secondOptional.get();
if (second.distanceToSqr(first) > 5 * 5) if (second.distanceToSqr(first) > 5 * 5)
return; return;
this.setInLove(first); this.setInLove(first);
this.setInLove(second); this.setInLove(second);
BlockPos closestSpot = IAuraChunk.getHighestSpot(level, first.blockPosition(), 35, pos); var closestSpot = IAuraChunk.getHighestSpot(level, first.blockPosition(), 35, pos);
IAuraChunk.getAuraChunk(level, closestSpot).drainAura(closestSpot, 3500); IAuraChunk.getAuraChunk(level, closestSpot).drainAura(closestSpot, 3500);
} }
} }
private void setInLove(Animal animal) { private void setInLove(Animal animal) {
animal.setInLove(null); animal.setInLove(null);
for (int j = 0; j < 7; j++) for (var j = 0; j < 7; j++)
animal.level.addParticle(ParticleTypes.HEART, animal.level.addParticle(ParticleTypes.HEART,
animal.getX() + (double) (animal.level.random.nextFloat() * animal.getBbWidth() * 2.0F) - animal.getBbWidth(), animal.getX() + (double) (animal.level.random.nextFloat() * animal.getBbWidth() * 2.0F) - animal.getBbWidth(),
animal.getY() + 0.5D + (double) (animal.level.random.nextFloat() * animal.getBbHeight()), animal.getY() + 0.5D + (double) (animal.level.random.nextFloat() * animal.getBbHeight()),

View file

@ -20,17 +20,17 @@ public class BalanceEffect implements IDrainSpotEffect {
return; return;
if (level.getGameTime() % 200 != 0) if (level.getGameTime() % 200 != 0)
return; return;
int searchRadius = Math.min(45, spot / 10000); var searchRadius = Math.min(45, spot / 10000);
MutableInt positiveAura = new MutableInt(); var positiveAura = new MutableInt();
IAuraChunk.getSpotsInArea(level, pos, searchRadius, (otherPos, otherSpot) -> { IAuraChunk.getSpotsInArea(level, pos, searchRadius, (otherPos, otherSpot) -> {
if (otherSpot > 0) if (otherSpot > 0)
positiveAura.add(otherSpot); positiveAura.add(otherSpot);
}); });
int radius = Math.min(80, positiveAura.intValue() / 5000); var radius = Math.min(80, positiveAura.intValue() / 5000);
BlockPos lowestPos = IAuraChunk.getLowestSpot(level, pos, radius, null); var lowestPos = IAuraChunk.getLowestSpot(level, pos, radius, null);
if (lowestPos == null) if (lowestPos == null)
return; return;
int stored = IAuraChunk.getAuraChunk(level, lowestPos).storeAura(lowestPos, spot / 50); var stored = IAuraChunk.getAuraChunk(level, lowestPos).storeAura(lowestPos, spot / 50);
auraChunk.drainAura(pos, stored); auraChunk.drainAura(pos, stored);
} }

View file

@ -30,10 +30,10 @@ public class BreathlessEffect implements IDrainSpotEffect {
private boolean calcValues(Level level, BlockPos pos, Integer spot) { private boolean calcValues(Level level, BlockPos pos, Integer spot) {
if (spot >= 0) if (spot >= 0)
return false; return false;
int aura = IAuraChunk.getAuraInArea(level, pos, 50); var aura = IAuraChunk.getAuraInArea(level, pos, 50);
if (aura > 0) if (aura > 0)
return false; return false;
int dist = Math.min(Math.abs(aura) / 50000, 75); var dist = Math.min(Math.abs(aura) / 50000, 75);
if (dist < 10) if (dist < 10)
return false; return false;
this.amp = Math.min(Mth.floor(Math.abs(aura) / 2500000F), 3); this.amp = Math.min(Mth.floor(Math.abs(aura) / 2500000F), 3);
@ -61,8 +61,8 @@ public class BreathlessEffect implements IDrainSpotEffect {
return; return;
if (!this.calcValues(level, pos, spot)) if (!this.calcValues(level, pos, spot))
return; return;
List<LivingEntity> entities = level.getEntitiesOfClass(LivingEntity.class, this.bb); var entities = level.getEntitiesOfClass(LivingEntity.class, this.bb);
for (LivingEntity entity : entities) for (var entity : entities)
entity.addEffect(new MobEffectInstance(ModPotions.BREATHLESS, 300, this.amp)); entity.addEffect(new MobEffectInstance(ModPotions.BREATHLESS, 300, this.amp));
} }

View file

@ -29,11 +29,11 @@ public class CacheRechargeEffect implements IDrainSpotEffect {
private boolean calcValues(Level level, BlockPos pos, Integer spot) { private boolean calcValues(Level level, BlockPos pos, Integer spot) {
if (spot < 100000) if (spot < 100000)
return false; return false;
Pair<Integer, Integer> auraAndSpots = IAuraChunk.getAuraAndSpotAmountInArea(level, pos, 20); var auraAndSpots = IAuraChunk.getAuraAndSpotAmountInArea(level, pos, 20);
int aura = auraAndSpots.getLeft(); int aura = auraAndSpots.getLeft();
if (aura < 1500000) if (aura < 1500000)
return false; return false;
int dist = Mth.clamp(aura / 3500, 3, 15); var dist = Mth.clamp(aura / 3500, 3, 15);
this.bb = new AABB(pos).inflate(dist); this.bb = new AABB(pos).inflate(dist);
this.amount = Mth.ceil(aura / 250F / auraAndSpots.getRight()); this.amount = Mth.ceil(aura / 250F / auraAndSpots.getRight());
return true; return true;
@ -59,8 +59,8 @@ public class CacheRechargeEffect implements IDrainSpotEffect {
public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) { public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (!this.calcValues(level, pos, spot)) if (!this.calcValues(level, pos, spot))
return; return;
List<Player> players = level.getEntitiesOfClass(Player.class, this.bb); var players = level.getEntitiesOfClass(Player.class, this.bb);
for (Player player : players) { for (var player : players) {
if (NaturesAuraAPI.instance().isEffectPowderActive(level, player.blockPosition(), NAME)) if (NaturesAuraAPI.instance().isEffectPowderActive(level, player.blockPosition(), NAME))
continue; continue;
if (NaturesAuraAPI.instance().insertAuraIntoPlayer(player, this.amount, true)) { if (NaturesAuraAPI.instance().insertAuraIntoPlayer(player, this.amount, true)) {

View file

@ -26,10 +26,10 @@ public class ExplosionEffect implements IDrainSpotEffect {
private boolean calcValues(Level level, BlockPos pos, Integer spot) { private boolean calcValues(Level level, BlockPos pos, Integer spot) {
if (spot >= 0) if (spot >= 0)
return false; return false;
int aura = IAuraChunk.getAuraInArea(level, pos, 85); var aura = IAuraChunk.getAuraInArea(level, pos, 85);
if (aura > -5000000) if (aura > -5000000)
return false; return false;
int chance = 140 - Math.abs(aura) / 200000; var chance = 140 - Math.abs(aura) / 200000;
if (chance > 1 && level.random.nextInt(chance) != 0) if (chance > 1 && level.random.nextInt(chance) != 0)
return false; return false;
this.strength = Math.min(Math.abs(aura) / 5000000F, 5F); this.strength = Math.min(Math.abs(aura) / 5000000F, 5F);
@ -60,9 +60,9 @@ public class ExplosionEffect implements IDrainSpotEffect {
if (!this.calcValues(level, pos, spot)) if (!this.calcValues(level, pos, spot))
return; return;
int x = Mth.floor(pos.getX() + level.random.nextGaussian() * this.dist); var x = Mth.floor(pos.getX() + level.random.nextGaussian() * this.dist);
int z = Mth.floor(pos.getZ() + level.random.nextGaussian() * this.dist); var z = Mth.floor(pos.getZ() + level.random.nextGaussian() * this.dist);
BlockPos chosenPos = new BlockPos(x, level.getHeight(Heightmap.Types.WORLD_SURFACE, x, z), z); var chosenPos = new BlockPos(x, level.getHeight(Heightmap.Types.WORLD_SURFACE, x, z), z);
if (chosenPos.distSqr(pos) <= this.dist * this.dist && level.isLoaded(chosenPos)) { if (chosenPos.distSqr(pos) <= this.dist * this.dist && level.isLoaded(chosenPos)) {
level.explode(null, level.explode(null,
chosenPos.getX() + 0.5, chosenPos.getY() + 0.5, chosenPos.getZ() + 0.5, chosenPos.getX() + 0.5, chosenPos.getY() + 0.5, chosenPos.getZ() + 0.5,

View file

@ -27,7 +27,7 @@ public class GrassDieEffect implements IDrainSpotEffect {
private boolean calcValues(Level level, BlockPos pos, Integer spot) { private boolean calcValues(Level level, BlockPos pos, Integer spot) {
if (spot < 0) { if (spot < 0) {
Pair<Integer, Integer> auraAndSpots = IAuraChunk.getAuraAndSpotAmountInArea(level, pos, 50); var auraAndSpots = IAuraChunk.getAuraAndSpotAmountInArea(level, pos, 50);
int aura = auraAndSpots.getLeft(); int aura = auraAndSpots.getLeft();
if (aura < 0) { if (aura < 0) {
this.amount = Math.min(300, Mth.ceil(Math.abs(aura) / 100000F / auraAndSpots.getRight())); this.amount = Math.min(300, Mth.ceil(Math.abs(aura) / 100000F / auraAndSpots.getRight()));
@ -58,15 +58,15 @@ public class GrassDieEffect implements IDrainSpotEffect {
public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) { public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (!this.calcValues(level, pos, spot)) if (!this.calcValues(level, pos, spot))
return; return;
for (int i = this.amount / 2 + level.random.nextInt(this.amount / 2); i >= 0; i--) { for (var i = this.amount / 2 + level.random.nextInt(this.amount / 2); i >= 0; i--) {
BlockPos grassPos = new BlockPos( var grassPos = new BlockPos(
pos.getX() + level.random.nextGaussian() * this.dist, pos.getX() + level.random.nextGaussian() * this.dist,
pos.getY() + level.random.nextGaussian() * this.dist, pos.getY() + level.random.nextGaussian() * this.dist,
pos.getZ() + level.random.nextGaussian() * this.dist pos.getZ() + level.random.nextGaussian() * this.dist
); );
if (grassPos.distSqr(pos) <= this.dist * this.dist && level.isLoaded(grassPos)) { if (grassPos.distSqr(pos) <= this.dist * this.dist && level.isLoaded(grassPos)) {
BlockState state = level.getBlockState(grassPos); var state = level.getBlockState(grassPos);
Block block = state.getBlock(); var block = state.getBlock();
BlockState newState = null; BlockState newState = null;
if (block instanceof LeavesBlock) { if (block instanceof LeavesBlock) {

View file

@ -32,7 +32,7 @@ public class NetherDecayEffect implements IDrainSpotEffect {
private boolean calcValues(Level level, BlockPos pos, Integer spot) { private boolean calcValues(Level level, BlockPos pos, Integer spot) {
if (spot >= 0) if (spot >= 0)
return false; return false;
Pair<Integer, Integer> auraAndSpots = IAuraChunk.getAuraAndSpotAmountInArea(level, pos, 50); var auraAndSpots = IAuraChunk.getAuraAndSpotAmountInArea(level, pos, 50);
int aura = auraAndSpots.getLeft(); int aura = auraAndSpots.getLeft();
if (aura >= 0) if (aura >= 0)
return false; return false;
@ -61,8 +61,8 @@ public class NetherDecayEffect implements IDrainSpotEffect {
public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) { public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (!this.calcValues(level, pos, spot)) if (!this.calcValues(level, pos, spot))
return; return;
for (int i = this.amount / 2 + level.random.nextInt(this.amount / 2); i >= 0; i--) { for (var i = this.amount / 2 + level.random.nextInt(this.amount / 2); i >= 0; i--) {
BlockPos offset = new BlockPos( var offset = new BlockPos(
pos.getX() + level.random.nextGaussian() * this.dist, pos.getX() + level.random.nextGaussian() * this.dist,
pos.getY() + level.random.nextGaussian() * this.dist, pos.getY() + level.random.nextGaussian() * this.dist,
pos.getZ() + level.random.nextGaussian() * this.dist); pos.getZ() + level.random.nextGaussian() * this.dist);
@ -71,7 +71,7 @@ public class NetherDecayEffect implements IDrainSpotEffect {
// degrade blocks // degrade blocks
Block degraded = null; Block degraded = null;
BlockState state = level.getBlockState(offset); var state = level.getBlockState(offset);
if (state.getBlock() == Blocks.GLOWSTONE) { if (state.getBlock() == Blocks.GLOWSTONE) {
degraded = Blocks.NETHERRACK; degraded = Blocks.NETHERRACK;
} else if (state.is(BlockTags.NYLIUM) || state.getBlock() == Blocks.NETHERRACK) { } else if (state.is(BlockTags.NYLIUM) || state.getBlock() == Blocks.NETHERRACK) {
@ -86,7 +86,7 @@ public class NetherDecayEffect implements IDrainSpotEffect {
// ignite blocks // ignite blocks
if (BaseFireBlock.canBePlacedAt(level, offset, Direction.NORTH)) { if (BaseFireBlock.canBePlacedAt(level, offset, Direction.NORTH)) {
BlockState fire = BaseFireBlock.getState(level, offset); var fire = BaseFireBlock.getState(level, offset);
level.setBlockAndUpdate(offset, fire); level.setBlockAndUpdate(offset, fire);
level.levelEvent(1009, offset, 0); level.levelEvent(1009, offset, 0);
} }

View file

@ -32,7 +32,7 @@ public class NetherGrassEffect implements IDrainSpotEffect {
private boolean calcValues(Level level, BlockPos pos, Integer spot) { private boolean calcValues(Level level, BlockPos pos, Integer spot) {
if (spot <= 0) if (spot <= 0)
return false; return false;
Pair<Integer, Integer> auraAndSpots = IAuraChunk.getAuraAndSpotAmountInArea(level, pos, 30); var auraAndSpots = IAuraChunk.getAuraAndSpotAmountInArea(level, pos, 30);
int aura = auraAndSpots.getLeft(); int aura = auraAndSpots.getLeft();
if (aura < 1500000) if (aura < 1500000)
return false; return false;
@ -65,26 +65,26 @@ public class NetherGrassEffect implements IDrainSpotEffect {
return; return;
if (!this.calcValues(level, pos, spot)) if (!this.calcValues(level, pos, spot))
return; return;
for (int i = this.amount / 2 + level.random.nextInt(this.amount / 2); i >= 0; i--) { for (var i = this.amount / 2 + level.random.nextInt(this.amount / 2); i >= 0; i--) {
int x = Mth.floor(pos.getX() + level.random.nextGaussian() * this.dist); var x = Mth.floor(pos.getX() + level.random.nextGaussian() * this.dist);
int y = Mth.floor(pos.getY() + level.random.nextGaussian() * this.dist); var y = Mth.floor(pos.getY() + level.random.nextGaussian() * this.dist);
int z = Mth.floor(pos.getZ() + level.random.nextGaussian() * this.dist); var z = Mth.floor(pos.getZ() + level.random.nextGaussian() * this.dist);
for (int yOff = -5; yOff <= 5; yOff++) { for (var yOff = -5; yOff <= 5; yOff++) {
BlockPos goalPos = new BlockPos(x, y + yOff, z); var goalPos = new BlockPos(x, y + yOff, z);
if (goalPos.distSqr(pos) <= this.dist * this.dist && level.isLoaded(goalPos)) { if (goalPos.distSqr(pos) <= this.dist * this.dist && level.isLoaded(goalPos)) {
if (NaturesAuraAPI.instance().isEffectPowderActive(level, goalPos, NAME)) if (NaturesAuraAPI.instance().isEffectPowderActive(level, goalPos, NAME))
continue; continue;
BlockPos up = goalPos.above(); var up = goalPos.above();
if (level.getBlockState(up).isFaceSturdy(level, up, Direction.DOWN)) if (level.getBlockState(up).isFaceSturdy(level, up, Direction.DOWN))
continue; continue;
BlockState state = level.getBlockState(goalPos); var state = level.getBlockState(goalPos);
Block block = state.getBlock(); var block = state.getBlock();
if (Tags.Blocks.NETHERRACK.contains(block)) { if (Tags.Blocks.NETHERRACK.contains(block)) {
level.setBlockAndUpdate(goalPos, ModBlocks.NETHER_GRASS.defaultBlockState()); level.setBlockAndUpdate(goalPos, ModBlocks.NETHER_GRASS.defaultBlockState());
BlockPos closestSpot = IAuraChunk.getHighestSpot(level, goalPos, 25, pos); var closestSpot = IAuraChunk.getHighestSpot(level, goalPos, 25, pos);
IAuraChunk.getAuraChunk(level, closestSpot).drainAura(closestSpot, 500); IAuraChunk.getAuraChunk(level, closestSpot).drainAura(closestSpot, 500);
PacketHandler.sendToAllAround(level, goalPos, 32, PacketHandler.sendToAllAround(level, goalPos, 32,

View file

@ -48,7 +48,7 @@ public class OreSpawnEffect implements IDrainSpotEffect {
private boolean calcValues(Level level, BlockPos pos, Integer spot) { private boolean calcValues(Level level, BlockPos pos, Integer spot) {
if (spot <= 0) if (spot <= 0)
return false; return false;
Pair<Integer, Integer> auraAndSpots = IAuraChunk.getAuraAndSpotAmountInArea(level, pos, 30); var auraAndSpots = IAuraChunk.getAuraAndSpotAmountInArea(level, pos, 30);
int aura = auraAndSpots.getLeft(); int aura = auraAndSpots.getLeft();
if (aura <= 2000000) if (aura <= 2000000)
return false; return false;
@ -81,7 +81,7 @@ public class OreSpawnEffect implements IDrainSpotEffect {
return; return;
if (!this.calcValues(level, pos, spot)) if (!this.calcValues(level, pos, spot))
return; return;
IAuraType type = auraChunk.getType(); var type = auraChunk.getType();
Block requiredBlock; Block requiredBlock;
List<WeightedOre> ores; List<WeightedOre> ores;
if (type.isSimilar(NaturesAuraAPI.TYPE_OVERWORLD)) { if (type.isSimilar(NaturesAuraAPI.TYPE_OVERWORLD)) {
@ -91,51 +91,51 @@ public class OreSpawnEffect implements IDrainSpotEffect {
requiredBlock = Blocks.NETHERRACK; requiredBlock = Blocks.NETHERRACK;
ores = NaturesAuraAPI.NETHER_ORES; ores = NaturesAuraAPI.NETHER_ORES;
} }
int totalWeight = WeightedRandom.getTotalWeight(ores); var totalWeight = WeightedRandom.getTotalWeight(ores);
List<Tuple<Vec3, Integer>> powders = NaturesAuraAPI.instance().getActiveEffectPowders(level, var powders = NaturesAuraAPI.instance().getActiveEffectPowders(level,
new AABB(pos).inflate(this.dist), NAME); new AABB(pos).inflate(this.dist), NAME);
if (powders.isEmpty()) if (powders.isEmpty())
return; return;
for (int i = 0; i < this.amount; i++) { for (var i = 0; i < this.amount; i++) {
Tuple<Vec3, Integer> powder = powders.get(i % powders.size()); var powder = powders.get(i % powders.size());
Vec3 powderPos = powder.getA(); var powderPos = powder.getA();
int range = powder.getB(); int range = powder.getB();
int x = Mth.floor(powderPos.x + level.random.nextGaussian() * range); var x = Mth.floor(powderPos.x + level.random.nextGaussian() * range);
int y = Mth.floor(powderPos.y + level.random.nextGaussian() * range); var y = Mth.floor(powderPos.y + level.random.nextGaussian() * range);
int z = Mth.floor(powderPos.z + level.random.nextGaussian() * range); var z = Mth.floor(powderPos.z + level.random.nextGaussian() * range);
BlockPos orePos = new BlockPos(x, y, z); var orePos = new BlockPos(x, y, z);
if (orePos.distSqr(powderPos.x, powderPos.y, powderPos.z, true) <= range * range if (orePos.distSqr(powderPos.x, powderPos.y, powderPos.z, true) <= range * range
&& orePos.distSqr(pos) <= this.dist * this.dist && level.isLoaded(orePos)) { && orePos.distSqr(pos) <= this.dist * this.dist && level.isLoaded(orePos)) {
BlockState state = level.getBlockState(orePos); var state = level.getBlockState(orePos);
if (state.getBlock() != requiredBlock) if (state.getBlock() != requiredBlock)
continue; continue;
outer: outer:
while (true) { while (true) {
WeightedOre ore = WeightedRandom.getRandomItem(level.random, ores, totalWeight).orElse(null); var ore = WeightedRandom.getRandomItem(level.random, ores, totalWeight).orElse(null);
if (ore == null) if (ore == null)
continue; continue;
Tag<Block> tag = level.getTagManager().getOrEmpty(Registry.BLOCK_REGISTRY).getTag(ore.tag); var tag = level.getTagManager().getOrEmpty(Registry.BLOCK_REGISTRY).getTag(ore.tag);
if (tag == null) if (tag == null)
continue; continue;
for (Block toPlace : tag.getValues()) { for (var toPlace : tag.getValues()) {
if (toPlace == null || toPlace == Blocks.AIR) if (toPlace == null || toPlace == Blocks.AIR)
continue; continue;
FakePlayer player = FakePlayerFactory.getMinecraft((ServerLevel) level); var player = FakePlayerFactory.getMinecraft((ServerLevel) level);
player.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY); player.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY);
BlockHitResult ray = new BlockHitResult(Vec3.atCenterOf(pos), Direction.UP, pos, false); var ray = new BlockHitResult(Vec3.atCenterOf(pos), Direction.UP, pos, false);
BlockPlaceContext context = new BlockPlaceContext(new UseOnContext(player, InteractionHand.MAIN_HAND, ray)); var context = new BlockPlaceContext(new UseOnContext(player, InteractionHand.MAIN_HAND, ray));
BlockState stateToPlace = toPlace.getStateForPlacement(context); var stateToPlace = toPlace.getStateForPlacement(context);
if (SPAWN_EXCEPTIONS.contains(stateToPlace)) if (SPAWN_EXCEPTIONS.contains(stateToPlace))
continue; continue;
level.setBlockAndUpdate(orePos, stateToPlace); level.setBlockAndUpdate(orePos, stateToPlace);
level.levelEvent(2001, orePos, Block.getId(stateToPlace)); level.levelEvent(2001, orePos, Block.getId(stateToPlace));
int toDrain = (20000 - ore.getWeight().asInt() * 2) * 2; var toDrain = (20000 - ore.getWeight().asInt() * 2) * 2;
BlockPos highestSpot = IAuraChunk.getHighestSpot(level, orePos, 30, pos); var highestSpot = IAuraChunk.getHighestSpot(level, orePos, 30, pos);
IAuraChunk.getAuraChunk(level, highestSpot).drainAura(highestSpot, toDrain); IAuraChunk.getAuraChunk(level, highestSpot).drainAura(highestSpot, toDrain);
break outer; break outer;
} }

View file

@ -32,7 +32,7 @@ public class PlantBoostEffect implements IDrainSpotEffect {
private boolean calcValues(Level level, BlockPos pos, Integer spot) { private boolean calcValues(Level level, BlockPos pos, Integer spot) {
if (spot <= 0) if (spot <= 0)
return false; return false;
Pair<Integer, Integer> auraAndSpots = IAuraChunk.getAuraAndSpotAmountInArea(level, pos, 30); var auraAndSpots = IAuraChunk.getAuraAndSpotAmountInArea(level, pos, 30);
int aura = auraAndSpots.getLeft(); int aura = auraAndSpots.getLeft();
if (aura < 1500000) if (aura < 1500000)
return false; return false;
@ -63,16 +63,16 @@ public class PlantBoostEffect implements IDrainSpotEffect {
public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) { public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (!this.calcValues(level, pos, spot)) if (!this.calcValues(level, pos, spot))
return; return;
for (int i = this.amount / 2 + level.random.nextInt(this.amount / 2); i >= 0; i--) { for (var i = this.amount / 2 + level.random.nextInt(this.amount / 2); i >= 0; i--) {
int x = Mth.floor(pos.getX() + (2 * level.random.nextFloat() - 1) * this.dist); var x = Mth.floor(pos.getX() + (2 * level.random.nextFloat() - 1) * this.dist);
int z = Mth.floor(pos.getZ() + (2 * level.random.nextFloat() - 1) * this.dist); var z = Mth.floor(pos.getZ() + (2 * level.random.nextFloat() - 1) * this.dist);
BlockPos plantPos = new BlockPos(x, level.getHeight(Heightmap.Types.WORLD_SURFACE, x, z), z).below(); var plantPos = new BlockPos(x, level.getHeight(Heightmap.Types.WORLD_SURFACE, x, z), z).below();
if (plantPos.distSqr(pos) <= this.dist * this.dist && level.isLoaded(plantPos)) { if (plantPos.distSqr(pos) <= this.dist * this.dist && level.isLoaded(plantPos)) {
if (NaturesAuraAPI.instance().isEffectPowderActive(level, plantPos, NAME)) if (NaturesAuraAPI.instance().isEffectPowderActive(level, plantPos, NAME))
continue; continue;
BlockState state = level.getBlockState(plantPos); var state = level.getBlockState(plantPos);
Block block = state.getBlock(); var block = state.getBlock();
if (block instanceof BonemealableBlock growable && !(block instanceof DoublePlantBlock) && !(block instanceof TallGrassBlock) && block != Blocks.GRASS_BLOCK) { if (block instanceof BonemealableBlock growable && !(block instanceof DoublePlantBlock) && !(block instanceof TallGrassBlock) && block != Blocks.GRASS_BLOCK) {
if (growable.isValidBonemealTarget(level, plantPos, state, false)) { if (growable.isValidBonemealTarget(level, plantPos, state, false)) {
try { try {
@ -81,7 +81,7 @@ public class PlantBoostEffect implements IDrainSpotEffect {
// a lot of stuff throws here (double plants where generation only caused half of it to exist, bamboo at level height...) // a lot of stuff throws here (double plants where generation only caused half of it to exist, bamboo at level height...)
// so just catch all, bleh // so just catch all, bleh
} }
BlockPos closestSpot = IAuraChunk.getHighestSpot(level, plantPos, 25, pos); var closestSpot = IAuraChunk.getHighestSpot(level, plantPos, 25, pos);
IAuraChunk.getAuraChunk(level, closestSpot).drainAura(closestSpot, 3500); IAuraChunk.getAuraChunk(level, closestSpot).drainAura(closestSpot, 3500);
PacketHandler.sendToAllAround(level, plantPos, 32, PacketHandler.sendToAllAround(level, plantPos, 32,

View file

@ -25,18 +25,18 @@ public class ReplenishingEffect implements IDrainSpotEffect {
if (spot < 0) { if (spot < 0) {
List<ISpotDrainable> tiles = new ArrayList<>(); List<ISpotDrainable> tiles = new ArrayList<>();
Helper.getBlockEntitiesInArea(level, pos, 25, tile -> { Helper.getBlockEntitiesInArea(level, pos, 25, tile -> {
IAuraContainer container = tile.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null); var container = tile.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null);
if (container instanceof ISpotDrainable) if (container instanceof ISpotDrainable)
tiles.add((ISpotDrainable) container); tiles.add((ISpotDrainable) container);
return false; return false;
}); });
if (!tiles.isEmpty()) { if (!tiles.isEmpty()) {
IAuraType type = IAuraType.forLevel(level); var type = IAuraType.forLevel(level);
for (int i = level.random.nextInt(6); i >= 0; i--) { for (var i = level.random.nextInt(6); i >= 0; i--) {
ISpotDrainable tile = tiles.get(level.random.nextInt(tiles.size())); var tile = tiles.get(level.random.nextInt(tiles.size()));
if (!tile.isAcceptableType(type)) if (!tile.isAcceptableType(type))
continue; continue;
int drained = tile.drainAuraPassively(-spot, false); var drained = tile.drainAuraPassively(-spot, false);
if (drained <= 0) if (drained <= 0)
continue; continue;
auraChunk.storeAura(pos, drained); auraChunk.storeAura(pos, drained);

View file

@ -19,16 +19,16 @@ public class SpreadEffect implements IDrainSpotEffect {
public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) { public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (Math.abs(spot) < 500000 || Math.abs(IAuraChunk.getAuraInArea(level, pos, 25)) < 2000000) if (Math.abs(spot) < 500000 || Math.abs(IAuraChunk.getAuraInArea(level, pos, 25)) < 2000000)
return; return;
boolean drain = spot > 0; var drain = spot > 0;
int toMove = Mth.ceil(Math.abs(spot) * 0.72F); var toMove = Mth.ceil(Math.abs(spot) * 0.72F);
int perSide = toMove / 6; var perSide = toMove / 6;
while (toMove > 0) { while (toMove > 0) {
BlockPos bestOffset = null; BlockPos bestOffset = null;
int bestAmount = drain ? Integer.MAX_VALUE : Integer.MIN_VALUE; var bestAmount = drain ? Integer.MAX_VALUE : Integer.MIN_VALUE;
for (Direction facing : Direction.values()) { for (var facing : Direction.values()) {
BlockPos offset = pos.relative(facing, 15); var offset = pos.relative(facing, 15);
if (level.isLoaded(offset) && offset.getY() >= 0 && offset.getY() <= level.getHeight()) { if (level.isLoaded(offset) && offset.getY() >= 0 && offset.getY() <= level.getHeight()) {
int amount = IAuraChunk.getAuraInArea(level, offset, 14); var amount = IAuraChunk.getAuraInArea(level, offset, 14);
if (drain ? amount < bestAmount : amount > bestAmount) { if (drain ? amount < bestAmount : amount > bestAmount) {
bestAmount = amount; bestAmount = amount;
bestOffset = offset; bestOffset = offset;
@ -38,9 +38,9 @@ public class SpreadEffect implements IDrainSpotEffect {
if (bestOffset == null) if (bestOffset == null)
break; break;
BlockPos bestPos = drain ? IAuraChunk.getLowestSpot(level, bestOffset, 14, bestOffset) var bestPos = drain ? IAuraChunk.getLowestSpot(level, bestOffset, 14, bestOffset)
: IAuraChunk.getHighestSpot(level, bestOffset, 14, bestOffset); : IAuraChunk.getHighestSpot(level, bestOffset, 14, bestOffset);
IAuraChunk bestChunk = IAuraChunk.getAuraChunk(level, bestPos); var bestChunk = IAuraChunk.getAuraChunk(level, bestPos);
int moved; int moved;
if (drain) { if (drain) {

View file

@ -13,32 +13,32 @@ public final class CommandAura {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) { public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(Commands.literal("naaura").requires(s -> s.hasPermission(2)) dispatcher.register(Commands.literal("naaura").requires(s -> s.hasPermission(2))
.then(Commands.literal("add").then(Commands.argument("amount", IntegerArgumentType.integer(1)).executes(context -> { .then(Commands.literal("add").then(Commands.argument("amount", IntegerArgumentType.integer(1)).executes(context -> {
int amount = IntegerArgumentType.getInteger(context, "amount"); var amount = IntegerArgumentType.getInteger(context, "amount");
CommandSourceStack source = context.getSource(); var source = context.getSource();
BlockPos pos = new BlockPos(source.getPosition()); var pos = new BlockPos(source.getPosition());
while (amount > 0) { while (amount > 0) {
BlockPos spot = IAuraChunk.getLowestSpot(source.getLevel(), pos, 35, pos); var spot = IAuraChunk.getLowestSpot(source.getLevel(), pos, 35, pos);
amount -= IAuraChunk.getAuraChunk(source.getLevel(), spot).storeAura(spot, amount); amount -= IAuraChunk.getAuraChunk(source.getLevel(), spot).storeAura(spot, amount);
} }
source.sendSuccess(new TextComponent("Added aura to area"), true); source.sendSuccess(new TextComponent("Added aura to area"), true);
return 0; return 0;
}))) })))
.then(Commands.literal("remove").then(Commands.argument("amount", IntegerArgumentType.integer(1)).executes(context -> { .then(Commands.literal("remove").then(Commands.argument("amount", IntegerArgumentType.integer(1)).executes(context -> {
int amount = IntegerArgumentType.getInteger(context, "amount"); var amount = IntegerArgumentType.getInteger(context, "amount");
CommandSourceStack source = context.getSource(); var source = context.getSource();
BlockPos pos = new BlockPos(source.getPosition()); var pos = new BlockPos(source.getPosition());
while (amount > 0) { while (amount > 0) {
BlockPos spot = IAuraChunk.getHighestSpot(source.getLevel(), pos, 35, pos); var spot = IAuraChunk.getHighestSpot(source.getLevel(), pos, 35, pos);
amount -= IAuraChunk.getAuraChunk(source.getLevel(), spot).drainAura(spot, amount); amount -= IAuraChunk.getAuraChunk(source.getLevel(), spot).drainAura(spot, amount);
} }
source.sendSuccess(new TextComponent("Removed aura from area"), true); source.sendSuccess(new TextComponent("Removed aura from area"), true);
return 0; return 0;
}))) })))
.then(Commands.literal("reset").executes(context -> { .then(Commands.literal("reset").executes(context -> {
CommandSourceStack source = context.getSource(); var source = context.getSource();
BlockPos pos = new BlockPos(source.getPosition()); var pos = new BlockPos(source.getPosition());
IAuraChunk.getSpotsInArea(source.getLevel(), pos, 35, (spot, amount) -> { IAuraChunk.getSpotsInArea(source.getLevel(), pos, 35, (spot, amount) -> {
IAuraChunk chunk = IAuraChunk.getAuraChunk(source.getLevel(), spot); var chunk = IAuraChunk.getAuraChunk(source.getLevel(), spot);
if (amount > 0) if (amount > 0)
chunk.drainAura(spot, amount); chunk.drainAura(spot, amount);
else else

View file

@ -41,8 +41,8 @@ public final class Compat {
} }
private static void populateModules(Predicate<String> isLoaded) { private static void populateModules(Predicate<String> isLoaded) {
for (Map.Entry<String, Supplier<ICompat>> entry : MODULE_TYPES.entrySet()) { for (var entry : MODULE_TYPES.entrySet()) {
String id = entry.getKey(); var id = entry.getKey();
if (isLoaded.test(id)) { if (isLoaded.test(id)) {
MODULES.put(id, entry.getValue().get()); MODULES.put(id, entry.getValue().get());
NaturesAura.LOGGER.info("Loading compat module for mod " + id); NaturesAura.LOGGER.info("Loading compat module for mod " + id);

View file

@ -35,9 +35,9 @@ public class PatchouliCompat implements ICompat {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T extends Recipe<?>> T getRecipe(String type, String name) { public static <T extends Recipe<?>> T getRecipe(String type, String name) {
RecipeManager manager = Minecraft.getInstance().level.getRecipeManager(); var manager = Minecraft.getInstance().level.getRecipeManager();
ResourceLocation res = new ResourceLocation(name); var res = new ResourceLocation(name);
ResourceLocation pre = new ResourceLocation(res.getNamespace(), type + "/" + res.getPath()); var pre = new ResourceLocation(res.getNamespace(), type + "/" + res.getPath());
return (T) manager.byKey(pre).orElse(null); return (T) manager.byKey(pre).orElse(null);
} }

View file

@ -48,7 +48,7 @@ public class BlockLootProvider implements DataProvider {
public BlockLootProvider(DataGenerator generator) { public BlockLootProvider(DataGenerator generator) {
this.generator = generator; this.generator = generator;
for (IModItem item : ModRegistry.ALL_ITEMS) { for (var item : ModRegistry.ALL_ITEMS) {
if (!(item instanceof Block block)) if (!(item instanceof Block block))
continue; continue;
if (block instanceof Slab) { if (block instanceof Slab) {
@ -73,11 +73,11 @@ public class BlockLootProvider implements DataProvider {
@Override @Override
public void run(HashCache cache) throws IOException { public void run(HashCache cache) throws IOException {
for (Map.Entry<Block, Function<Block, LootTable.Builder>> function : this.lootFunctions.entrySet()) { for (var function : this.lootFunctions.entrySet()) {
Block block = function.getKey(); var block = function.getKey();
Function<Block, LootTable.Builder> func = function.getValue(); var func = function.getValue();
LootTable table = func.apply(block).setParamSet(LootContextParamSets.BLOCK).build(); var table = func.apply(block).setParamSet(LootContextParamSets.BLOCK).build();
Path path = getPath(this.generator.getOutputFolder(), block.getRegistryName()); var path = getPath(this.generator.getOutputFolder(), block.getRegistryName());
DataProvider.save(GSON, cache, LootTables.serialize(table), path); DataProvider.save(GSON, cache, LootTables.serialize(table), path);
} }
} }

View file

@ -17,7 +17,7 @@ public class BlockStateGenerator extends BlockStateProvider {
@Override @Override
protected void registerStatesAndModels() { protected void registerStatesAndModels() {
for (IModItem item : ModRegistry.ALL_ITEMS) { for (var item : ModRegistry.ALL_ITEMS) {
if (!(item instanceof Block block)) if (!(item instanceof Block block))
continue; continue;
if (block instanceof ICustomBlockState custom) { if (block instanceof ICustomBlockState custom) {

View file

@ -19,8 +19,8 @@ public class ItemModelGenerator extends ItemModelProvider {
@Override @Override
protected void registerModels() { protected void registerModels() {
for (IModItem modItem : ModRegistry.ALL_ITEMS) { for (var modItem : ModRegistry.ALL_ITEMS) {
String name = modItem.getBaseName(); var name = modItem.getBaseName();
if (modItem instanceof ICustomItemModel) { if (modItem instanceof ICustomItemModel) {
((ICustomItemModel) modItem).generateCustomItemModel(this); ((ICustomItemModel) modItem).generateCustomItemModel(this);
} else if (modItem instanceof Item) { } else if (modItem instanceof Item) {

View file

@ -11,9 +11,9 @@ public final class ModData {
@SubscribeEvent @SubscribeEvent
public static void gatherData(GatherDataEvent event) { public static void gatherData(GatherDataEvent event) {
DataGenerator generator = event.getGenerator(); var generator = event.getGenerator();
ExistingFileHelper ex = event.getExistingFileHelper(); var ex = event.getExistingFileHelper();
BlockTagProvider blockTags = new BlockTagProvider(generator); var blockTags = new BlockTagProvider(generator);
generator.addProvider(blockTags); generator.addProvider(blockTags);
generator.addProvider(new ItemTagProvider(generator, blockTags, ex)); generator.addProvider(new ItemTagProvider(generator, blockTags, ex));
generator.addProvider(new BlockLootProvider(generator)); generator.addProvider(new BlockLootProvider(generator));

View file

@ -47,8 +47,8 @@ public class EntityLightProjectile extends ThrowableProjectile {
protected void onHit(HitResult result) { protected void onHit(HitResult result) {
if (!this.level.isClientSide) { if (!this.level.isClientSide) {
if (result instanceof BlockHitResult res) { if (result instanceof BlockHitResult res) {
BlockPos pos = res.getBlockPos().relative(res.getDirection()); var pos = res.getBlockPos().relative(res.getDirection());
BlockState state = this.level.getBlockState(pos); var state = this.level.getBlockState(pos);
if (state.getMaterial().isReplaceable()) if (state.getMaterial().isReplaceable())
this.level.setBlockAndUpdate(pos, ModBlocks.LIGHT.defaultBlockState()); this.level.setBlockAndUpdate(pos, ModBlocks.LIGHT.defaultBlockState());
} else if (result instanceof EntityHitResult entity) { } else if (result instanceof EntityHitResult entity) {

View file

@ -49,7 +49,7 @@ public class EntityMoverMinecart extends AbstractMinecart {
super.moveMinecartOnRail(railPos); super.moveMinecartOnRail(railPos);
if (!this.isActive) if (!this.isActive)
return; return;
BlockPos pos = this.blockPosition(); var pos = this.blockPosition();
if (!this.spotOffsets.isEmpty() && this.level.getGameTime() % 10 == 0) if (!this.spotOffsets.isEmpty() && this.level.getGameTime() % 10 == 0)
PacketHandler.sendToAllAround(this.level, pos, 32, new PacketParticles( PacketHandler.sendToAllAround(this.level, pos, 32, new PacketParticles(
@ -64,18 +64,18 @@ public class EntityMoverMinecart extends AbstractMinecart {
} }
private void moveAura(Level oldLevel, BlockPos oldPos, Level newLevel, BlockPos newPos) { private void moveAura(Level oldLevel, BlockPos oldPos, Level newLevel, BlockPos newPos) {
for (BlockPos offset : this.spotOffsets) { for (var offset : this.spotOffsets) {
BlockPos spot = oldPos.offset(offset); var spot = oldPos.offset(offset);
IAuraChunk chunk = IAuraChunk.getAuraChunk(oldLevel, spot); var chunk = IAuraChunk.getAuraChunk(oldLevel, spot);
int amount = chunk.getDrainSpot(spot); var amount = chunk.getDrainSpot(spot);
if (amount <= 0) if (amount <= 0)
continue; continue;
int toMove = Math.min(amount, 300000); var toMove = Math.min(amount, 300000);
int drained = chunk.drainAura(spot, toMove, false, false); var drained = chunk.drainAura(spot, toMove, false, false);
if (drained <= 0) if (drained <= 0)
continue; continue;
int toLose = Mth.ceil(drained / 250F); var toLose = Mth.ceil(drained / 250F);
BlockPos newSpot = newPos.offset(offset); var newSpot = newPos.offset(offset);
IAuraChunk.getAuraChunk(newLevel, newSpot).storeAura(newSpot, drained - toLose, false, false); IAuraChunk.getAuraChunk(newLevel, newSpot).storeAura(newSpot, drained - toLose, false, false);
} }
} }
@ -85,7 +85,7 @@ public class EntityMoverMinecart extends AbstractMinecart {
if (this.isActive != receivingPower) { if (this.isActive != receivingPower) {
this.isActive = receivingPower; this.isActive = receivingPower;
BlockPos pos = this.blockPosition(); var pos = this.blockPosition();
if (!this.isActive) { if (!this.isActive) {
this.moveAura(this.level, this.lastPosition, this.level, pos); this.moveAura(this.level, this.lastPosition, this.level, pos);
this.spotOffsets.clear(); this.spotOffsets.clear();
@ -110,12 +110,12 @@ public class EntityMoverMinecart extends AbstractMinecart {
@Override @Override
public CompoundTag serializeNBT() { public CompoundTag serializeNBT() {
CompoundTag compound = super.serializeNBT(); var compound = super.serializeNBT();
compound.putBoolean("active", this.isActive); compound.putBoolean("active", this.isActive);
compound.putLong("last_pos", this.lastPosition.asLong()); compound.putLong("last_pos", this.lastPosition.asLong());
ListTag list = new ListTag(); var list = new ListTag();
for (BlockPos offset : this.spotOffsets) for (var offset : this.spotOffsets)
list.add(LongTag.valueOf(offset.asLong())); list.add(LongTag.valueOf(offset.asLong()));
compound.put("offsets", list); compound.put("offsets", list);
return compound; return compound;
@ -128,17 +128,17 @@ public class EntityMoverMinecart extends AbstractMinecart {
this.lastPosition = BlockPos.of(compound.getLong("last_pos")); this.lastPosition = BlockPos.of(compound.getLong("last_pos"));
this.spotOffsets.clear(); this.spotOffsets.clear();
ListTag list = compound.getList("offsets", Tag.TAG_LONG); var list = compound.getList("offsets", Tag.TAG_LONG);
for (Tag base : list) for (var base : list)
this.spotOffsets.add(BlockPos.of(((LongTag) base).getAsLong())); this.spotOffsets.add(BlockPos.of(((LongTag) base).getAsLong()));
} }
@Nullable @Nullable
@Override @Override
public Entity changeDimension(ServerLevel destination, ITeleporter teleporter) { public Entity changeDimension(ServerLevel destination, ITeleporter teleporter) {
Entity entity = super.changeDimension(destination, teleporter); var entity = super.changeDimension(destination, teleporter);
if (entity instanceof EntityMoverMinecart) { if (entity instanceof EntityMoverMinecart) {
BlockPos pos = entity.blockPosition(); var pos = entity.blockPosition();
this.moveAura(this.level, this.lastPosition, entity.level, pos); this.moveAura(this.level, this.lastPosition, entity.level, pos);
((EntityMoverMinecart) entity).lastPosition = pos; ((EntityMoverMinecart) entity).lastPosition = pos;
} }
@ -172,7 +172,7 @@ public class EntityMoverMinecart extends AbstractMinecart {
@Override @Override
protected void applyNaturalSlowdown() { protected void applyNaturalSlowdown() {
Vec3 motion = this.getDeltaMovement(); var motion = this.getDeltaMovement();
this.setDeltaMovement(motion.x * 0.99F, 0, motion.z * 0.99F); this.setDeltaMovement(motion.x * 0.99F, 0, motion.z * 0.99F);
} }

View file

@ -52,10 +52,10 @@ public class EntityStructureFinder extends EyeOfEnder {
@Override @Override
public void signalTo(BlockPos pos) { public void signalTo(BlockPos pos) {
double d0 = pos.getX(); double d0 = pos.getX();
int i = pos.getY(); var i = pos.getY();
double d1 = pos.getZ(); double d1 = pos.getZ();
double d2 = d0 - this.getX(); var d2 = d0 - this.getX();
double d3 = d1 - this.getZ(); var d3 = d1 - this.getZ();
var f = Math.sqrt(d2 * d2 + d3 * d3); var f = Math.sqrt(d2 * d2 + d3 * d3);
if (f > 12.0F) { if (f > 12.0F) {
this.targetX = this.getX() + d2 / (double) f * 12.0D; this.targetX = this.getX() + d2 / (double) f * 12.0D;
@ -75,10 +75,10 @@ public class EntityStructureFinder extends EyeOfEnder {
public void tick() { public void tick() {
this.baseTick(); this.baseTick();
Vec3 vec3d = this.getDeltaMovement(); var vec3d = this.getDeltaMovement();
double d0 = this.getX() + vec3d.x; var d0 = this.getX() + vec3d.x;
double d1 = this.getY() + vec3d.y; var d1 = this.getY() + vec3d.y;
double d2 = this.getZ() + vec3d.z; var d2 = this.getZ() + vec3d.z;
var f = Math.sqrt(vec3d.horizontalDistance()); var f = Math.sqrt(vec3d.horizontalDistance());
this.setYRot((float) (Mth.atan2(vec3d.x, vec3d.z) * (double) (180F / (float) Math.PI))); this.setYRot((float) (Mth.atan2(vec3d.x, vec3d.z) * (double) (180F / (float) Math.PI)));
this.setXRot((float) (Mth.atan2(vec3d.y, f) * (double) (180F / (float) Math.PI))); this.setXRot((float) (Mth.atan2(vec3d.y, f) * (double) (180F / (float) Math.PI)));
@ -93,24 +93,24 @@ public class EntityStructureFinder extends EyeOfEnder {
this.setXRot(Mth.lerp(0.2F, this.xRotO, this.getXRot())); this.setXRot(Mth.lerp(0.2F, this.xRotO, this.getXRot()));
this.setYRot(Mth.lerp(0.2F, this.yRotO, this.getYRot())); this.setYRot(Mth.lerp(0.2F, this.yRotO, this.getYRot()));
if (!this.level.isClientSide) { if (!this.level.isClientSide) {
double d3 = this.targetX - d0; var d3 = this.targetX - d0;
double d4 = this.targetZ - d2; var d4 = this.targetZ - d2;
float f1 = (float) Math.sqrt(d3 * d3 + d4 * d4); var f1 = (float) Math.sqrt(d3 * d3 + d4 * d4);
float f2 = (float) Mth.atan2(d4, d3); var f2 = (float) Mth.atan2(d4, d3);
double d5 = Mth.lerp(0.0025D, f, f1); var d5 = Mth.lerp(0.0025D, f, f1);
double d6 = vec3d.y; var d6 = vec3d.y;
if (f1 < 1.0F) { if (f1 < 1.0F) {
d5 *= 0.8D; d5 *= 0.8D;
d6 *= 0.8D; d6 *= 0.8D;
} }
int j = this.getY() < this.targetY ? 1 : -1; var j = this.getY() < this.targetY ? 1 : -1;
vec3d = new Vec3(Math.cos(f2) * d5, d6 + ((double) j - d6) * (double) 0.015F, Math.sin(f2) * d5); vec3d = new Vec3(Math.cos(f2) * d5, d6 + ((double) j - d6) * (double) 0.015F, Math.sin(f2) * d5);
this.setDeltaMovement(vec3d); this.setDeltaMovement(vec3d);
} }
if (this.isInWater()) { if (this.isInWater()) {
for (int i = 0; i < 4; ++i) for (var i = 0; i < 4; ++i)
this.level.addParticle(ParticleTypes.BUBBLE, d0 - vec3d.x * 0.25D, d1 - vec3d.y * 0.25D, d2 - vec3d.z * 0.25D, vec3d.x, vec3d.y, vec3d.z); this.level.addParticle(ParticleTypes.BUBBLE, d0 - vec3d.x * 0.25D, d1 - vec3d.y * 0.25D, d2 - vec3d.z * 0.25D, vec3d.x, vec3d.y, vec3d.z);
} else if (this.level.isClientSide) { } else if (this.level.isClientSide) {
NaturesAuraAPI.instance().spawnMagicParticle(d0 - vec3d.x * 0.25D + this.random.nextDouble() * 0.6D - 0.3D, d1 - vec3d.y * 0.25D - 0.5D, d2 - vec3d.z * 0.25D + this.random.nextDouble() * 0.6D - 0.3D, vec3d.x * 0.25F, vec3d.y * 0.25F, vec3d.z * 0.25F, this.entityData.get(COLOR), 1, 50, 0, false, true); NaturesAuraAPI.instance().spawnMagicParticle(d0 - vec3d.x * 0.25D + this.random.nextDouble() * 0.6D - 0.3D, d1 - vec3d.y * 0.25D - 0.5D, d2 - vec3d.z * 0.25D + this.random.nextDouble() * 0.6D - 0.3D, vec3d.x * 0.25F, vec3d.y * 0.25F, vec3d.z * 0.25F, this.entityData.get(COLOR), 1, 50, 0, false, true);

View file

@ -37,12 +37,12 @@ public class RenderEffectInhibitor extends EntityRenderer<EntityEffectInhibitor>
@Override @Override
public void render(EntityEffectInhibitor entity, float entityYaw, float partialTicks, PoseStack matrixStackIn, MultiBufferSource bufferIn, int packedLightIn) { public void render(EntityEffectInhibitor entity, float entityYaw, float partialTicks, PoseStack matrixStackIn, MultiBufferSource bufferIn, int packedLightIn) {
matrixStackIn.pushPose(); matrixStackIn.pushPose();
float time = entity.renderTicks + entity.getId() + partialTicks; var time = entity.renderTicks + entity.getId() + partialTicks;
float bob = (float) Math.sin(time / 10F) * 0.05F; var bob = (float) Math.sin(time / 10F) * 0.05F;
matrixStackIn.translate(0, 0.15F + bob, 0); matrixStackIn.translate(0, 0.15F + bob, 0);
matrixStackIn.mulPose(Vector3f.YP.rotationDegrees(time * 3 % 360)); matrixStackIn.mulPose(Vector3f.YP.rotationDegrees(time * 3 % 360));
ResourceLocation effect = entity.getInhibitedEffect(); var effect = entity.getInhibitedEffect();
ItemStack stack = this.items.computeIfAbsent(effect, var stack = this.items.computeIfAbsent(effect,
res -> ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER), effect)); res -> ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER), effect));
Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemTransforms.TransformType.GROUND, packedLightIn, OverlayTexture.NO_OVERLAY, matrixStackIn, bufferIn, 0); Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemTransforms.TransformType.GROUND, packedLightIn, OverlayTexture.NO_OVERLAY, matrixStackIn, bufferIn, 0);
matrixStackIn.popPose(); matrixStackIn.popPose();

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