From c08877c802fb8fcaa8059c9d638586780c803eb2 Mon Sep 17 00:00:00 2001 From: Albazavr Date: Wed, 24 Jun 2026 15:48:56 +0300 Subject: [PATCH 1/8] Entities port --- .../twilightforest/entity/CharmEffect.java | 34 +++++---- .../entity/EnforcedHomePoint.java | 38 +++++----- .../twilightforest/entity/MagicPainting.java | 73 +++++++++++-------- .../twilightforest/entity/ProtectionBox.java | 20 +++-- .../twilightforest/entity/SlideBlock.java | 33 ++++++--- .../twilightforest/entity/SpikeBlock.java | 20 ++--- .../entity/monster/LoyalZombie.java | 23 +++--- .../twilightforest/entity/monster/Troll.java | 4 +- .../twilightforest/entity/passive/Boar.java | 2 +- .../twilightforest/entity/passive/Deer.java | 3 +- .../entity/passive/DwarfRabbit.java | 3 +- .../entity/passive/Penguin.java | 3 +- .../entity/passive/QuestRam.java | 3 +- .../twilightforest/entity/passive/Raven.java | 3 +- .../entity/passive/Squirrel.java | 3 +- .../entity/passive/TinyBird.java | 3 +- .../passive/quest/ram/QuestingRamContext.java | 17 ++++- .../entity/projectile/TFArrow.java | 10 +-- .../entity/projectile/TFThrowable.java | 9 ++- .../entity/projectile/ThrownBlock.java | 19 +++-- .../entity/projectile/ThrownWep.java | 20 +++-- 21 files changed, 198 insertions(+), 145 deletions(-) diff --git a/src/main/java/twilightforest/entity/CharmEffect.java b/src/main/java/twilightforest/entity/CharmEffect.java index d4ddeb60c0..ba4c1d6c57 100644 --- a/src/main/java/twilightforest/entity/CharmEffect.java +++ b/src/main/java/twilightforest/entity/CharmEffect.java @@ -2,9 +2,10 @@ import net.minecraft.core.particles.ItemParticleOption; import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.nbt.CompoundTag; import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.level.ServerLevel; import net.minecraft.util.Mth; +import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; @@ -12,11 +13,12 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; +import net.minecraft.world.level.storage.ValueInput; +import net.minecraft.world.level.storage.ValueOutput; import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import javax.annotation.Nonnull; - public class CharmEffect extends Entity implements ItemSupplier { private static final double DISTANCE = 0.75D; private double interpTargetX; @@ -32,17 +34,18 @@ public class CharmEffect extends Entity implements ItemSupplier { private LivingEntity orbiter; private ItemStack displayItem = new ItemStack(Items.BARRIER); - public CharmEffect(EntityType type, Level level) { + public CharmEffect(EntityType type, Level level) { super(type, level); } @SuppressWarnings("this-escape") - public CharmEffect(EntityType type, Level level, LivingEntity owner, ItemStack item) { + public CharmEffect(EntityType type, Level level, LivingEntity owner, ItemStack item) { this(type, level); this.orbiter = owner; this.displayItem = item; - this.moveTo(owner.getX(), owner.getY() + owner.getEyeHeight(), owner.getZ(), owner.getYRot(), owner.getXRot()); + this.setPos(owner.getX(), owner.getY() + owner.getEyeHeight(), owner.getZ()); + this.setRot(owner.getYRot(), owner.getXRot()); Vec3 look = new Vec3(DISTANCE, 0, 0); double x = getX() + (look.x() * DISTANCE); @@ -73,7 +76,8 @@ public void tick() { if (this.orbiter != null) { float rotation = this.tickCount / 10.0F + this.offset; Vec3 look = new Vec3(DISTANCE, 0, 0).yRot(rotation); - this.moveTo(this.orbiter.getX() + look.x(), this.orbiter.getY() + this.orbiter.getEyeHeight(), this.orbiter.getZ() + look.z(), this.orbiter.getYRot(), this.orbiter.getXRot()); + this.setPos(this.orbiter.getX() + look.x(), this.orbiter.getY() + this.orbiter.getEyeHeight(), this.orbiter.getZ() + look.z()); + this.setRot(this.orbiter.getYRot(), this.orbiter.getXRot()); } if (!this.displayItem.isEmpty()) { @@ -81,7 +85,7 @@ public void tick() { double dy = getY() + 0.25 * (this.random.nextDouble() - this.random.nextDouble()); double dz = getZ() + 0.25 * (this.random.nextDouble() - this.random.nextDouble()); - this.level().addParticle(new ItemParticleOption(ParticleTypes.ITEM, this.displayItem), dx, dy, dz, 0, 0.2, 0); + this.level().addParticle(new ItemParticleOption(ParticleTypes.ITEM, this.displayItem.getItem()), dx, dy, dz, 0, 0.2, 0); } if (this.tickCount > 200 || (this.orbiter != null && (!this.orbiter.isAlive() || this.orbiter.isInvisible()))) { @@ -90,7 +94,7 @@ public void tick() { } @Override - public void lerpTo(double x, double y, double z, float yaw, float pitch, int posRotationIncrements) { + public void lerpPositionAndRotationStep(int posRotationIncrements, double x, double y, double z, double yaw, double pitch) { this.interpTargetX = x; this.interpTargetY = y; this.interpTargetZ = z; @@ -100,19 +104,19 @@ public void lerpTo(double x, double y, double z, float yaw, float pitch, int pos } @Override - protected void defineSynchedData(SynchedEntityData.Builder builder) { + protected void defineSynchedData(SynchedEntityData.Builder builder) {} - } + @Override + protected void readAdditionalSaveData(ValueInput valueInput) {} @Override - protected void readAdditionalSaveData(CompoundTag cmp) { - } + protected void addAdditionalSaveData(ValueOutput valueOutput) {} @Override - protected void addAdditionalSaveData(CompoundTag cmp) { + public boolean hurtServer(ServerLevel serverLevel, DamageSource damageSource, float v) { + return false; } - @Nonnull @Override public ItemStack getItem() { return this.displayItem; diff --git a/src/main/java/twilightforest/entity/EnforcedHomePoint.java b/src/main/java/twilightforest/entity/EnforcedHomePoint.java index c47c016716..f1768b679f 100644 --- a/src/main/java/twilightforest/entity/EnforcedHomePoint.java +++ b/src/main/java/twilightforest/entity/EnforcedHomePoint.java @@ -1,10 +1,8 @@ package twilightforest.entity; +import com.mojang.serialization.Codec; import net.minecraft.core.BlockPos; import net.minecraft.core.GlobalPos; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.NbtOps; import net.minecraft.resources.ResourceKey; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.PathfinderMob; @@ -12,44 +10,50 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.storage.ValueInput; import net.minecraft.world.level.storage.ValueOutput; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import twilightforest.TwilightForestMod; import twilightforest.entity.ai.goal.AttemptToGoHomeGoal; import twilightforest.init.TFDimension; public interface EnforcedHomePoint { - default void addRestrictionGoals(T entity, GoalSelector selector) { selector.addGoal(5, new AttemptToGoHomeGoal<>(entity, 1.25D)); } default void saveHomePointToNbt(ValueOutput tag) { if (this.getRestrictionPoint() != null) { - GlobalPos.CODEC.encodeStart(NbtOps.INSTANCE, this.getRestrictionPoint()).resultOrPartial(TwilightForestMod.LOGGER::error).ifPresent(tag1 -> tag.put("HomePos", tag1)); + tag.store("HomePos", GlobalPos.CODEC, this.getRestrictionPoint()); } } default void loadHomePointFromNbt(ValueInput tag) { - //properly load old home points, just assume theyre set in TF - if (tag.contains("Home", 9)) { - ListTag nbttaglist = tag.getList("Home", 6); - double hx = nbttaglist.getDouble(0); - double hy = nbttaglist.getDouble(1); - double hz = nbttaglist.getDouble(2); - this.setRestrictionPoint(GlobalPos.of(TFDimension.DIMENSION_KEY, BlockPos.containing(hx, hy, hz))); + var modernPos = tag.read("HomePos", GlobalPos.CODEC); + + if (modernPos.isPresent()) { + this.setRestrictionPoint(modernPos.get()); } else { - if (tag.contains("HomePos")) { - this.setRestrictionPoint(GlobalPos.CODEC.parse(NbtOps.INSTANCE, tag.get("HomePos")).resultOrPartial(TwilightForestMod.LOGGER::error).orElse(null)); - } + tag.read("Home", Codec.DOUBLE.listOf()).ifPresent(doubleList -> { + if (doubleList.size() >= 3) { + double hx = doubleList.get(0); + double hy = doubleList.get(1); + double hz = doubleList.get(2); + + this.setRestrictionPoint(GlobalPos.of( + TFDimension.DIMENSION_KEY, + BlockPos.containing(hx, hy, hz) + )); + } + }); } } + default boolean isMobWithinHomeArea(Entity entity) { if (!this.isRestrictionPointValid(entity.level().dimension())) return true; return this.getRestrictionPoint().pos().distSqr(entity.blockPosition()) < (double) (this.getHomeRadius() * this.getHomeRadius()); } - default boolean isRestrictionPointValid(ResourceKey currentMobLevel) { + default boolean isRestrictionPointValid(ResourceKey<@NotNull Level> currentMobLevel) { return this.getRestrictionPoint() != null && this.getRestrictionPoint().dimension().equals(currentMobLevel); } diff --git a/src/main/java/twilightforest/entity/MagicPainting.java b/src/main/java/twilightforest/entity/MagicPainting.java index b8253ccdad..5c72e12d7c 100644 --- a/src/main/java/twilightforest/entity/MagicPainting.java +++ b/src/main/java/twilightforest/entity/MagicPainting.java @@ -1,11 +1,11 @@ package twilightforest.entity; +import net.minecraft.server.level.ServerLevel; import net.minecraft.util.Util; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Holder; import net.minecraft.core.Registry; -import net.minecraft.nbt.CompoundTag; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; @@ -16,11 +16,14 @@ import net.minecraft.sounds.SoundEvents; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.MoverType; import net.minecraft.world.entity.decoration.HangingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.GameRules; import net.minecraft.world.level.Level; +import net.minecraft.world.level.gamerules.GameRules; +import net.minecraft.world.level.storage.ValueInput; +import net.minecraft.world.level.storage.ValueOutput; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; @@ -37,9 +40,11 @@ import java.util.Optional; public class MagicPainting extends HangingEntity { - private static final EntityDataAccessor> MAGIC_PAINTING_VARIANT = SynchedEntityData.defineId(MagicPainting.class, TFDataSerializers.MAGIC_PAINTING_VARIANT.value()); + private static final EntityDataAccessor<@NotNull Holder<@NotNull MagicPaintingVariant>> MAGIC_PAINTING_VARIANT = SynchedEntityData.defineId(MagicPainting.class, TFDataSerializers.MAGIC_PAINTING_VARIANT.value()); - public MagicPainting(EntityType entityType, Level level) { + private Direction direction; + + public MagicPainting(EntityType entityType, Level level) { super(entityType, level); } @@ -49,7 +54,7 @@ private MagicPainting(Level level, BlockPos pos) { @Override protected void defineSynchedData(SynchedEntityData.Builder builder) { - builder.define(MAGIC_PAINTING_VARIANT, this.getReg().getHolderOrThrow(MagicPaintingVariants.DEFAULT)); + builder.define(MAGIC_PAINTING_VARIANT, this.getReg().getOrThrow(MagicPaintingVariants.DEFAULT)); } @Override @@ -59,18 +64,18 @@ public void onSyncedDataUpdated(EntityDataAccessor pKey) { } } - public void setVariant(Holder variant) { + public void setVariant(Holder<@NotNull MagicPaintingVariant> variant) { this.getEntityData().set(MAGIC_PAINTING_VARIANT, variant); } - public Holder getVariant() { + public Holder<@NotNull MagicPaintingVariant> getVariant() { return this.getEntityData().get(MAGIC_PAINTING_VARIANT); } public static Optional create(Level level, BlockPos pos, Direction direction) { MagicPainting magicPainting = new MagicPainting(level, pos); - List> list = new ArrayList<>(); - level.registryAccess().registryOrThrow(TFRegistries.Keys.MAGIC_PAINTINGS).holders().forEach(list::add); + List> list = new ArrayList<>(); + level.registryAccess().lookupOrThrow(TFRegistries.Keys.MAGIC_PAINTINGS).listElements().forEach(list::add); if (list.isEmpty()) { return Optional.empty(); } else { @@ -83,8 +88,8 @@ public static Optional create(Level level, BlockPos pos, Directio return Optional.empty(); } else { int biggestPossibleArea = list.stream().mapToInt(MagicPainting::variantArea).max().orElse(0); - list.removeIf((variantArea) -> variantArea(variantArea) < biggestPossibleArea); - Optional> optional = Util.getRandomSafe(list, magicPainting.random); + list.removeIf((variant) -> variantArea(variant) < biggestPossibleArea); + Optional> optional = Util.getRandomSafe(list, magicPainting.random); if (optional.isEmpty()) { return Optional.empty(); } else { @@ -96,7 +101,7 @@ public static Optional create(Level level, BlockPos pos, Directio } } - private static int variantArea(Holder variant) { + private static int variantArea(Holder<@NotNull MagicPaintingVariant> variant) { return variantArea(variant.value()); } @@ -105,29 +110,29 @@ private static int variantArea(MagicPaintingVariant variant) { } @Override - public void addAdditionalSaveData(CompoundTag tag) { + protected void addAdditionalSaveData(ValueOutput output) { Identifier location = this.getReg().getKey(this.getVariant().value()); - if (location != null) tag.putString("variant", location.toString()); - tag.putByte("facing", (byte) this.direction.get2DDataValue()); - super.addAdditionalSaveData(tag); + if (location != null) output.putString("variant", location.toString()); + output.putByte("facing", (byte) this.direction.get2DDataValue()); + super.addAdditionalSaveData(output); } @Override - public void readAdditionalSaveData(CompoundTag tag) { - if (tag.contains("variant")) { - Identifier location = Identifier.tryParse(tag.getString("variant")); + public void readAdditionalSaveData(ValueInput input) { + if (!input.getStringOr("variant", "-1").equals("-1")) { + Identifier location = Identifier.tryParse(input.getString("variant").get()); if (location != null) { - this.setVariant(this.getReg().getHolder(location).orElse(this.getReg().getHolderOrThrow(MagicPaintingVariants.DEFAULT))); + this.setVariant(this.getReg().get(location).orElse(this.getReg().getOrThrow(MagicPaintingVariants.DEFAULT))); } } - this.direction = Direction.from2DDataValue(tag.getByte("facing")); - super.readAdditionalSaveData(tag); + this.direction = Direction.from2DDataValue(input.getByteOr("facing", (byte) 0)); + super.readAdditionalSaveData(input); this.setDirection(this.direction); } - protected Registry getReg() { - return this.registryAccess().registryOrThrow(TFRegistries.Keys.MAGIC_PAINTINGS); + protected Registry<@NotNull MagicPaintingVariant> getReg() { + return this.registryAccess().lookupOrThrow(TFRegistries.Keys.MAGIC_PAINTINGS); } @Override @@ -150,8 +155,8 @@ private double offsetForPaintingSize(int size) { } @Override - public void dropItem(@Nullable Entity entity) { - if (this.level().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) { + public void dropItem(ServerLevel serverLevel, @Nullable Entity entity) { + if (serverLevel.getGameRules().get(GameRules.ENTITY_DROPS)) { this.playSound(SoundEvents.PAINTING_BREAK, 1.0F, 1.0F); if (entity instanceof Player player) { if (player.getAbilities().instabuild) { @@ -159,7 +164,7 @@ public void dropItem(@Nullable Entity entity) { } } - this.spawnAtLocation(this.getPickResult()); + this.spawnAtLocation(serverLevel, this.getPickResult()); } } @@ -169,22 +174,27 @@ public void playPlacementSound() { } @Override - public void moveTo(double x, double y, double z, float yaw, float pitch) { - this.setPos(x, y, z); + public void move(MoverType moverType, Vec3 delta) { + this.setPos(delta.x, delta.y, delta.z); } @Override - public void lerpTo(double x, double y, double z, float yaw, float pitch, int posRotationIncrements) { + public void moveTowardsClosestSpace(double x, double y, double z) { this.setPos(x, y, z); } + @Override + protected void lerpPositionAndRotationStep(int stepsToTarget, double targetX, double targetY, double targetZ, double targetYRot, double targetXRot) { + this.setPos(targetX, targetY, targetZ); + } + @Override public Vec3 trackingPosition() { return Vec3.atLowerCornerOf(this.pos); } @Override - public Packet getAddEntityPacket(ServerEntity entity) { + public Packet<@NotNull ClientGamePacketListener> getAddEntityPacket(ServerEntity entity) { return new ClientboundAddEntityPacket(this, this.direction.get3DDataValue(), this.getPos()); } @@ -195,7 +205,6 @@ public void recreateFromPacket(ClientboundAddEntityPacket packet) { } @Override - @NotNull public ItemStack getPickResult() { ItemStack itemStack = new ItemStack(TFItems.MAGIC_PAINTING.get()); itemStack.set(TFDataComponents.MAGIC_PAINTING_VARIANT, this.getVariant()); diff --git a/src/main/java/twilightforest/entity/ProtectionBox.java b/src/main/java/twilightforest/entity/ProtectionBox.java index d872f8e893..d078138b08 100644 --- a/src/main/java/twilightforest/entity/ProtectionBox.java +++ b/src/main/java/twilightforest/entity/ProtectionBox.java @@ -1,12 +1,15 @@ package twilightforest.entity; -import net.minecraft.nbt.CompoundTag; import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityDimensions; import net.minecraft.world.entity.EntityType; import net.minecraft.world.level.Level; import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.storage.ValueInput; +import net.minecraft.world.level.storage.ValueOutput; import twilightforest.init.TFEntities; public class ProtectionBox extends Entity { @@ -31,7 +34,8 @@ public ProtectionBox(Level world, BoundingBox sbb) { this.sbb = sbb; - this.moveTo(sbb.minX(), sbb.minY(), sbb.minZ(), 0.0F, 0.0F); + this.setPos(sbb.minX(), sbb.minY(), sbb.minZ()); + this.setRot(0.0F, 0.0F); this.sizeX = sbb.getXSpan(); this.sizeY = sbb.getYSpan(); @@ -63,15 +67,17 @@ public void resetLifetime() { } @Override - protected void defineSynchedData(SynchedEntityData.Builder builder) { - } + protected void defineSynchedData(SynchedEntityData.Builder builder) {} @Override - protected void readAdditionalSaveData(CompoundTag compound) { - } + protected void readAdditionalSaveData(ValueInput compound) {} @Override - protected void addAdditionalSaveData(CompoundTag compound) { + protected void addAdditionalSaveData(ValueOutput compound) {} + + @Override + public boolean hurtServer(ServerLevel serverLevel, DamageSource damageSource, float v) { + return false; } @Override diff --git a/src/main/java/twilightforest/entity/SlideBlock.java b/src/main/java/twilightforest/entity/SlideBlock.java index c60d983264..fc22a85658 100644 --- a/src/main/java/twilightforest/entity/SlideBlock.java +++ b/src/main/java/twilightforest/entity/SlideBlock.java @@ -8,6 +8,8 @@ import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; @@ -16,8 +18,11 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.RotatedPillarBlock; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.ValueInput; +import net.minecraft.world.level.storage.ValueOutput; import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.shapes.CollisionContext; +import org.jetbrains.annotations.NotNull; import twilightforest.init.TFBlocks; import twilightforest.init.TFDamageTypes; import twilightforest.init.TFSounds; @@ -26,21 +31,20 @@ import java.util.List; public class SlideBlock extends Entity { - private static final int WARMUP_TIME = 20; - private static final EntityDataAccessor MOVE_DIRECTION = SynchedEntityData.defineId(SlideBlock.class, EntityDataSerializers.DIRECTION); + private static final EntityDataAccessor<@NotNull Direction> MOVE_DIRECTION = SynchedEntityData.defineId(SlideBlock.class, EntityDataSerializers.DIRECTION); private BlockState myState; private int slideTime; - public SlideBlock(EntityType type, Level world) { + public SlideBlock(EntityType type, Level world) { super(type, world); this.blocksBuilding = true; this.myState = TFBlocks.SLIDER.get().defaultBlockState(); } @SuppressWarnings("this-escape") - public SlideBlock(EntityType type, Level world, double x, double y, double z, BlockState state) { + public SlideBlock(EntityType type, Level world, double x, double y, double z, BlockState state) { super(type, world); this.myState = state; @@ -145,10 +149,10 @@ public void tick() { if (this.level().isUnobstructed(this.myState, pos, CollisionContext.empty())) { this.level().setBlockAndUpdate(pos, this.myState); } else { - this.spawnAtLocation(new ItemStack(this.myState.getBlock()), 0.0F); + this.spawnAtLocation((ServerLevel) level(), new ItemStack(this.myState.getBlock()), 0.0F); } } else if (this.slideTime > 100 && (pos.getY() < this.level().getMinY() + 1 || pos.getY() > this.level().getMaxY()) || this.slideTime > 600) { - this.spawnAtLocation(new ItemStack(this.myState.getBlock()), 0.0F); + this.spawnAtLocation((ServerLevel) level(), new ItemStack(this.myState.getBlock()), 0.0F); this.discard(); } @@ -177,17 +181,22 @@ public boolean displayFireAnimation() { } @Override - protected void readAdditionalSaveData(@Nonnull CompoundTag compound) { - this.slideTime = compound.getInt("Time"); - this.getEntityData().set(MOVE_DIRECTION, Direction.from3DDataValue(compound.getByte("Direction"))); - this.myState = NbtUtils.readBlockState(this.level().holderLookup(Registries.BLOCK), compound.getCompound("BlockState")); + protected void readAdditionalSaveData(@Nonnull ValueInput compound) { + this.slideTime = compound.getInt("Time").get(); + this.getEntityData().set(MOVE_DIRECTION, Direction.from3DDataValue(compound.getByteOr("Direction", (byte) 0))); + this.myState = NbtUtils.readBlockState(this.level().holderLookup(Registries.BLOCK), new CompoundTag()); } @Override - protected void addAdditionalSaveData(@Nonnull CompoundTag compound) { + protected void addAdditionalSaveData(@Nonnull ValueOutput compound) { compound.putInt("Time", this.slideTime); compound.putByte("Direction", (byte) this.getEntityData().get(MOVE_DIRECTION).get3DDataValue()); - compound.put("BlockState", NbtUtils.writeBlockState(this.myState)); + compound.store("BlockState", BlockState.CODEC, this.myState); + } + + @Override + public boolean hurtServer(ServerLevel serverLevel, DamageSource damageSource, float v) { + return false; } @Override diff --git a/src/main/java/twilightforest/entity/SpikeBlock.java b/src/main/java/twilightforest/entity/SpikeBlock.java index 7366602890..19acb5fa18 100644 --- a/src/main/java/twilightforest/entity/SpikeBlock.java +++ b/src/main/java/twilightforest/entity/SpikeBlock.java @@ -1,15 +1,14 @@ package twilightforest.entity; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.network.syncher.SynchedEntityData; -import net.minecraft.server.level.ServerEntity; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityDimensions; import net.minecraft.world.entity.MoverType; import net.minecraft.world.level.gameevent.GameEvent; +import net.minecraft.world.level.storage.ValueInput; +import net.minecraft.world.level.storage.ValueOutput; import twilightforest.entity.monster.BlockChainGoblin; import twilightforest.init.TFSounds; @@ -44,7 +43,7 @@ public void doFall() { } @Override - public boolean hurt(DamageSource source, float amount) { + public boolean hurtServer(ServerLevel serverLevel, DamageSource damageSource, float v) { return false; } @@ -63,11 +62,6 @@ public boolean is(Entity entity) { return this == entity || this.getParent() == entity; } - @Override - public Packet getAddEntityPacket(ServerEntity entity) { - throw new UnsupportedOperationException(); - } - @Override protected void defineSynchedData(SynchedEntityData.Builder builder) { } @@ -78,10 +72,8 @@ protected boolean canRide(Entity entity) { } @Override - protected void readAdditionalSaveData(CompoundTag compound) { - } + protected void readAdditionalSaveData(ValueInput compound) {} @Override - protected void addAdditionalSaveData(CompoundTag compound) { - } + protected void addAdditionalSaveData(ValueOutput compound) {} } diff --git a/src/main/java/twilightforest/entity/monster/LoyalZombie.java b/src/main/java/twilightforest/entity/monster/LoyalZombie.java index 757e2e7794..3217872c03 100644 --- a/src/main/java/twilightforest/entity/monster/LoyalZombie.java +++ b/src/main/java/twilightforest/entity/monster/LoyalZombie.java @@ -37,19 +37,19 @@ import net.minecraft.world.level.storage.ValueInput; import net.minecraft.world.level.storage.ValueOutput; import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import twilightforest.init.TFDamageTypes; import twilightforest.init.TFEntities; import twilightforest.init.TFSounds; public class LoyalZombie extends TamableAnimal { - - private static final EntityDataAccessor DATA_BABY_ID = SynchedEntityData.defineId(LoyalZombie.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor<@NotNull Boolean> DATA_BABY_ID = SynchedEntityData.defineId(LoyalZombie.class, EntityDataSerializers.BOOLEAN); private static final Identifier SPEED_MODIFIER_BABY_ID = Identifier.withDefaultNamespace("baby"); private static final AttributeModifier SPEED_MODIFIER_BABY = new AttributeModifier(SPEED_MODIFIER_BABY_ID, 0.5, AttributeModifier.Operation.ADD_MULTIPLIED_BASE); private static final EntityDimensions BABY_DIMENSIONS = TFEntities.LOYAL_ZOMBIE.get().getDimensions().scale(0.5F).withEyeHeight(0.93F); - public LoyalZombie(EntityType type, Level level) { + public LoyalZombie(EntityType type, Level level) { super(type, level); } @@ -130,15 +130,12 @@ public InteractionResult interact(Player player, InteractionHand hand, Vec3 vec3 @Override public boolean wantsToAttack(LivingEntity target, LivingEntity owner) { if (!(target instanceof Creeper) && !(target instanceof Ghast)) { - if (target instanceof LoyalZombie zombie) { - return !zombie.isTame() || zombie.getOwner() != owner; - } else if (target instanceof Player pTarget && owner instanceof Player pOwner && !pOwner.canHarmPlayer(pTarget)) { - return false; - } else if (target instanceof AbstractHorse horse && horse.isTamed()) { - return false; - } else { - return !(target instanceof TamableAnimal animal) || !animal.isTame(); - } + return switch (target) { + case LoyalZombie zombie -> !zombie.isTame() || zombie.getOwner() != owner; + case Player pTarget when owner instanceof Player pOwner && !pOwner.canHarmPlayer(pTarget) -> false; + case AbstractHorse horse when horse.isTamed() -> false; + default -> !(target instanceof TamableAnimal animal) || !animal.isTame(); + }; } else { return false; } @@ -208,7 +205,7 @@ public boolean isBaby() { @Override public void setBaby(boolean baby) { this.getEntityData().set(DATA_BABY_ID, baby); - if (this.level() != null && !this.level().isClientSide()) { + if (!this.level().isClientSide()) { AttributeInstance attributeinstance = this.getAttribute(Attributes.MOVEMENT_SPEED); attributeinstance.removeModifier(SPEED_MODIFIER_BABY_ID); if (baby) { diff --git a/src/main/java/twilightforest/entity/monster/Troll.java b/src/main/java/twilightforest/entity/monster/Troll.java index 632accbf98..7788298cd2 100644 --- a/src/main/java/twilightforest/entity/monster/Troll.java +++ b/src/main/java/twilightforest/entity/monster/Troll.java @@ -115,7 +115,7 @@ public void tick() { if (this.rock != null) { this.setHasRock(true); this.playSound(TFSounds.TROLL_GRABS_ROCK.get()); - ThrownBlock block = new ThrownBlock(level, this, this.rock); + ThrownBlock block = new ThrownBlock(level, this.rock); block.startRiding(this); level.addFreshEntity(block); } @@ -235,7 +235,7 @@ private void ripenBer(int offset, BlockPos pos) { @Override public void performRangedAttack(LivingEntity target, float distanceFactor) { if (this.hasRock()) { - ThrownBlock blocc = new ThrownBlock(this.level(), this, this.rock); + ThrownBlock blocc = new ThrownBlock(this.level(), this.rock); double d0 = target.getX() - this.getX(); double d1 = target.getBoundingBox().minY + target.getBbHeight() / 3.0F - blocc.getY(); diff --git a/src/main/java/twilightforest/entity/passive/Boar.java b/src/main/java/twilightforest/entity/passive/Boar.java index d55a70acab..01853943cb 100644 --- a/src/main/java/twilightforest/entity/passive/Boar.java +++ b/src/main/java/twilightforest/entity/passive/Boar.java @@ -43,7 +43,7 @@ protected void registerGoals() { } public static AttributeSupplier.Builder registerAttributes() { - return Mob.createMobAttributes().add(Attributes.MAX_HEALTH, 10.0D).add(Attributes.MOVEMENT_SPEED, 0.25D); + return Mob.createMobAttributes().add(Attributes.MAX_HEALTH, 10.0D).add(Attributes.MOVEMENT_SPEED, 0.25D).add(Attributes.TEMPT_RANGE, 16.0D); } @Override diff --git a/src/main/java/twilightforest/entity/passive/Deer.java b/src/main/java/twilightforest/entity/passive/Deer.java index 14e47f71fc..b3592f0e98 100644 --- a/src/main/java/twilightforest/entity/passive/Deer.java +++ b/src/main/java/twilightforest/entity/passive/Deer.java @@ -45,7 +45,8 @@ protected void registerGoals() { public static AttributeSupplier.Builder registerAttributes() { return Mob.createMobAttributes() .add(Attributes.MAX_HEALTH, 10.0) - .add(Attributes.MOVEMENT_SPEED, 0.2); + .add(Attributes.MOVEMENT_SPEED, 0.2) + .add(Attributes.TEMPT_RANGE, 16.0D); } @Override diff --git a/src/main/java/twilightforest/entity/passive/DwarfRabbit.java b/src/main/java/twilightforest/entity/passive/DwarfRabbit.java index 13689c9dc4..9cd01e8ec7 100644 --- a/src/main/java/twilightforest/entity/passive/DwarfRabbit.java +++ b/src/main/java/twilightforest/entity/passive/DwarfRabbit.java @@ -69,7 +69,8 @@ public static AttributeSupplier.Builder registerAttributes() { return Mob.createMobAttributes() .add(Attributes.MAX_HEALTH, 3.0D) .add(Attributes.MOVEMENT_SPEED, 0.3D) - .add(Attributes.STEP_HEIGHT, 1.0D); + .add(Attributes.STEP_HEIGHT, 1.0D) + .add(Attributes.TEMPT_RANGE, 16.0D); } @Nullable diff --git a/src/main/java/twilightforest/entity/passive/Penguin.java b/src/main/java/twilightforest/entity/passive/Penguin.java index 8fbea40ce6..19b4865b5d 100644 --- a/src/main/java/twilightforest/entity/passive/Penguin.java +++ b/src/main/java/twilightforest/entity/passive/Penguin.java @@ -70,7 +70,8 @@ protected SoundEvent getDeathSound() { public static AttributeSupplier.Builder registerAttributes() { return Mob.createMobAttributes() .add(Attributes.MAX_HEALTH, 10.0D) - .add(Attributes.MOVEMENT_SPEED, 0.2D); + .add(Attributes.MOVEMENT_SPEED, 0.2D) + .add(Attributes.TEMPT_RANGE, 16.0D); } @Override diff --git a/src/main/java/twilightforest/entity/passive/QuestRam.java b/src/main/java/twilightforest/entity/passive/QuestRam.java index ca7a6d4320..56ff813168 100644 --- a/src/main/java/twilightforest/entity/passive/QuestRam.java +++ b/src/main/java/twilightforest/entity/passive/QuestRam.java @@ -100,7 +100,8 @@ public Animal getBreedOffspring(ServerLevel level, AgeableMob mate) { public static AttributeSupplier.Builder registerAttributes() { return Mob.createMobAttributes() .add(Attributes.MAX_HEALTH, 70.0D) - .add(Attributes.MOVEMENT_SPEED, 0.23D); + .add(Attributes.MOVEMENT_SPEED, 0.23D) + .add(Attributes.TEMPT_RANGE, 16.0D); } @Override diff --git a/src/main/java/twilightforest/entity/passive/Raven.java b/src/main/java/twilightforest/entity/passive/Raven.java index 3600f2ac17..a28b6e283d 100644 --- a/src/main/java/twilightforest/entity/passive/Raven.java +++ b/src/main/java/twilightforest/entity/passive/Raven.java @@ -21,7 +21,8 @@ public static AttributeSupplier.Builder registerAttributes() { return FlyingBird.createMobAttributes() .add(Attributes.MAX_HEALTH, 10.0D) .add(Attributes.MOVEMENT_SPEED, 0.2D) - .add(Attributes.STEP_HEIGHT, 1.0D); + .add(Attributes.STEP_HEIGHT, 1.0D) + .add(Attributes.TEMPT_RANGE, 16.0D); } @Override diff --git a/src/main/java/twilightforest/entity/passive/Squirrel.java b/src/main/java/twilightforest/entity/passive/Squirrel.java index c812edf27a..3a1c4a6462 100644 --- a/src/main/java/twilightforest/entity/passive/Squirrel.java +++ b/src/main/java/twilightforest/entity/passive/Squirrel.java @@ -50,7 +50,8 @@ public static AttributeSupplier.Builder registerAttributes() { return Mob.createMobAttributes() .add(Attributes.MAX_HEALTH, 6.0D) .add(Attributes.MOVEMENT_SPEED, 0.3D) - .add(Attributes.STEP_HEIGHT, 1.0D); + .add(Attributes.STEP_HEIGHT, 1.0D) + .add(Attributes.TEMPT_RANGE, 16.0D); } @Override diff --git a/src/main/java/twilightforest/entity/passive/TinyBird.java b/src/main/java/twilightforest/entity/passive/TinyBird.java index ebc66d5510..b700f4458d 100644 --- a/src/main/java/twilightforest/entity/passive/TinyBird.java +++ b/src/main/java/twilightforest/entity/passive/TinyBird.java @@ -54,7 +54,8 @@ public static AttributeSupplier.Builder registerAttributes() { return FlyingBird.createMobAttributes() .add(Attributes.MAX_HEALTH, 4.0D) .add(Attributes.MOVEMENT_SPEED, 0.2D) - .add(Attributes.STEP_HEIGHT, 1.0D); + .add(Attributes.STEP_HEIGHT, 1.0D) + .add(Attributes.TEMPT_RANGE, 16.0D); } @Override diff --git a/src/main/java/twilightforest/entity/passive/quest/ram/QuestingRamContext.java b/src/main/java/twilightforest/entity/passive/quest/ram/QuestingRamContext.java index dc0bcd62aa..bf79212ae9 100644 --- a/src/main/java/twilightforest/entity/passive/quest/ram/QuestingRamContext.java +++ b/src/main/java/twilightforest/entity/passive/quest/ram/QuestingRamContext.java @@ -5,16 +5,21 @@ import com.mojang.serialization.DataResult; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.core.registries.Registries; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.resources.ResourceKey; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.storage.loot.LootTable; +import org.jetbrains.annotations.NotNull; import twilightforest.loot.TFLootTables; +import java.util.LinkedHashMap; import java.util.Map; -public record QuestingRamContext(Map questItems, ResourceKey lootTable) { +public record QuestingRamContext(Map questItems, ResourceKey<@NotNull LootTable> lootTable) { public static final QuestingRamContext FALLBACK = new QuestingRamContext(ImmutableMap.builder() .put(DyeColor.WHITE, Ingredient.of(Items.WHITE_WOOL)) @@ -40,6 +45,16 @@ public record QuestingRamContext(Map questItems, ResourceK ResourceKey.codec(Registries.LOOT_TABLE).fieldOf("reward").forGetter(QuestingRamContext::lootTable) ).apply(instance, QuestingRamContext::new)); + public static final StreamCodec<@NotNull RegistryFriendlyByteBuf, @NotNull QuestingRamContext> STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.map( + LinkedHashMap::new, + DyeColor.STREAM_CODEC, + Ingredient.CONTENTS_STREAM_CODEC + ), QuestingRamContext::questItems, + ResourceKey.streamCodec(Registries.LOOT_TABLE), QuestingRamContext::lootTable, + QuestingRamContext::new + ); + private static DataResult> validate(Map map) { int colorFlags = 0; for (var color : map.keySet()) { diff --git a/src/main/java/twilightforest/entity/projectile/TFArrow.java b/src/main/java/twilightforest/entity/projectile/TFArrow.java index 49b2877162..46674b3187 100644 --- a/src/main/java/twilightforest/entity/projectile/TFArrow.java +++ b/src/main/java/twilightforest/entity/projectile/TFArrow.java @@ -6,6 +6,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public abstract class TFArrow extends AbstractArrow implements ITFProjectile { @@ -13,12 +14,12 @@ public abstract class TFArrow extends AbstractArrow implements ITFProjectile { @Nullable protected final AbstractArrow parentArrow; - public TFArrow(EntityType type, Level level) { + public TFArrow(EntityType type, Level level) { super(type, level); this.parentArrow = null; } - public TFArrow(EntityType type, Level level, @Nullable LivingEntity shooter, ItemStack stack, ItemStack weapon) { + public TFArrow(EntityType type, Level level, @Nullable LivingEntity shooter, ItemStack stack, ItemStack weapon) { super(type, shooter, level, stack, weapon); this.setOwner(shooter); if (shooter != null) { @@ -27,7 +28,7 @@ public TFArrow(EntityType type, Level level, @Nullable Living this.parentArrow = null; } - public TFArrow(EntityType type, AbstractArrow parentArrow, ItemStack stack, ItemStack weapon) { + public TFArrow(EntityType type, AbstractArrow parentArrow, ItemStack stack, ItemStack weapon) { super(type, (LivingEntity) parentArrow.getOwner(), parentArrow.level(), stack, weapon); var shooter = (LivingEntity) parentArrow.getOwner(); this.setOwner(shooter); @@ -44,9 +45,6 @@ protected ItemStack getDefaultPickupItem() { @Override public void doPostHurtEffects(LivingEntity target) { - if (this.parentArrow != null) { - this.parentArrow.doPostHurtEffects(target); - } super.doPostHurtEffects(target); } } diff --git a/src/main/java/twilightforest/entity/projectile/TFThrowable.java b/src/main/java/twilightforest/entity/projectile/TFThrowable.java index e0fa825e02..8e4351e48a 100644 --- a/src/main/java/twilightforest/entity/projectile/TFThrowable.java +++ b/src/main/java/twilightforest/entity/projectile/TFThrowable.java @@ -10,25 +10,26 @@ import net.minecraft.world.entity.projectile.throwableitemprojectile.ThrowableItemProjectile; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; +import org.jetbrains.annotations.NotNull; import twilightforest.init.TFSounds; public abstract class TFThrowable extends ThrowableItemProjectile implements ITFProjectile { - public TFThrowable(EntityType type, Level level) { + public TFThrowable(EntityType type, Level level) { super(type, level); } - public TFThrowable(EntityType type, Level level, double x, double y, double z, ItemStack stack) { + public TFThrowable(EntityType type, Level level, double x, double y, double z, ItemStack stack) { super(type, x, y, z, level, stack); } - public TFThrowable(EntityType type, Level level, LivingEntity thrower, ItemStack stack) { + public TFThrowable(EntityType type, Level level, LivingEntity thrower, ItemStack stack) { super(type, thrower, level, stack); } @Override protected void defineSynchedData(SynchedEntityData.Builder builder) { - + super.defineSynchedData(builder); } public void makeTrail(ParticleOptions particle, int amount) { diff --git a/src/main/java/twilightforest/entity/projectile/ThrownBlock.java b/src/main/java/twilightforest/entity/projectile/ThrownBlock.java index df7d1f9b7e..b4ec781a2e 100644 --- a/src/main/java/twilightforest/entity/projectile/ThrownBlock.java +++ b/src/main/java/twilightforest/entity/projectile/ThrownBlock.java @@ -3,9 +3,6 @@ import net.minecraft.core.particles.BlockParticleOption; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.core.registries.Registries; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NbtUtils; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientGamePacketListener; @@ -14,6 +11,8 @@ import net.minecraft.world.entity.EntityEvent; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; @@ -23,6 +22,7 @@ import net.minecraft.world.level.storage.ValueOutput; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.EntityHitResult; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import twilightforest.entity.monster.Troll; import twilightforest.init.TFDamageTypes; @@ -32,17 +32,22 @@ public class ThrownBlock extends TFThrowable { private BlockState state = Blocks.STONE.defaultBlockState(); - public ThrownBlock(EntityType type, Level worldIn) { + public ThrownBlock(EntityType type, Level worldIn) { super(type, worldIn); } - public ThrownBlock(Level world, LivingEntity thrower, @Nullable BlockState state) { - super(TFEntities.THROWN_BLOCK.get(), world, thrower); + public ThrownBlock(Level world, @Nullable BlockState state) { + super(TFEntities.THROWN_BLOCK.get(), world); if (state != null) { this.state = state; } } + @Override + protected Item getDefaultItem() { + return Items.STONE; + } + @Override protected void addAdditionalSaveData(ValueOutput tag) { super.addAdditionalSaveData(tag); @@ -93,7 +98,7 @@ public BlockState getBlockState() { } @Override - public Packet getAddEntityPacket(ServerEntity entity) { + public Packet<@NotNull ClientGamePacketListener> getAddEntityPacket(ServerEntity entity) { return new ClientboundAddEntityPacket(this, entity, Block.getId(this.getBlockState())); } diff --git a/src/main/java/twilightforest/entity/projectile/ThrownWep.java b/src/main/java/twilightforest/entity/projectile/ThrownWep.java index d37887d38d..121aefe047 100644 --- a/src/main/java/twilightforest/entity/projectile/ThrownWep.java +++ b/src/main/java/twilightforest/entity/projectile/ThrownWep.java @@ -7,26 +7,27 @@ import net.minecraft.world.entity.EntityEvent; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.HitResult; +import org.jetbrains.annotations.NotNull; import twilightforest.entity.boss.KnightPhantom; import twilightforest.init.TFDamageTypes; import twilightforest.init.TFItems; public class ThrownWep extends TFThrowable { - - private static final EntityDataAccessor DATA_ITEMSTACK = SynchedEntityData.defineId(ThrownWep.class, EntityDataSerializers.ITEM_STACK); - private static final EntityDataAccessor DATA_VELOCITY = SynchedEntityData.defineId(ThrownWep.class, EntityDataSerializers.FLOAT); + private static final EntityDataAccessor<@NotNull ItemStack> DATA_ITEMSTACK = SynchedEntityData.defineId(ThrownWep.class, EntityDataSerializers.ITEM_STACK); + private static final EntityDataAccessor<@NotNull Float> DATA_VELOCITY = SynchedEntityData.defineId(ThrownWep.class, EntityDataSerializers.FLOAT); private float projectileDamage = 6; - public ThrownWep(EntityType type, Level world, LivingEntity thrower) { - super(type, world, thrower); + public ThrownWep(EntityType type, Level world, LivingEntity thrower) { + super(type, world); } - public ThrownWep(EntityType type, Level world) { + public ThrownWep(EntityType type, Level world) { super(type, world); } @@ -41,11 +42,16 @@ protected void defineSynchedData(SynchedEntityData.Builder builder) { builder.define(DATA_VELOCITY, 0.001F); } - public ThrownWep setItem(ItemStack stack) { + public ThrownWep setCurrentItem(ItemStack stack) { this.getEntityData().set(DATA_ITEMSTACK, stack); return this; } + @Override + protected Item getDefaultItem() { + return TFItems.KNIGHTMETAL_SWORD.asItem(); + } + public ItemStack getItem() { return this.getEntityData().get(DATA_ITEMSTACK); } From 6e6101049efec6eafae165d3164bc8ee9b86d3ea Mon Sep 17 00:00:00 2001 From: Albazavr Date: Sun, 5 Jul 2026 03:54:50 +0300 Subject: [PATCH 2/8] Removed every @NotNull and unnecessary line change --- .../twilightforest/entity/CharmEffect.java | 5 ++--- .../entity/EnforcedHomePoint.java | 4 ++-- .../twilightforest/entity/MagicPainting.java | 19 +++++++++---------- .../twilightforest/entity/SlideBlock.java | 13 ++++++------- .../entity/monster/LoyalZombie.java | 6 +++--- .../passive/quest/ram/QuestingRamContext.java | 5 ++--- .../entity/projectile/TFArrow.java | 7 +++---- .../entity/projectile/TFThrowable.java | 11 +++-------- .../entity/projectile/ThrownBlock.java | 5 ++--- .../entity/projectile/ThrownWep.java | 10 +++++----- 10 files changed, 37 insertions(+), 48 deletions(-) diff --git a/src/main/java/twilightforest/entity/CharmEffect.java b/src/main/java/twilightforest/entity/CharmEffect.java index ba4c1d6c57..fcbb138761 100644 --- a/src/main/java/twilightforest/entity/CharmEffect.java +++ b/src/main/java/twilightforest/entity/CharmEffect.java @@ -16,7 +16,6 @@ import net.minecraft.world.level.storage.ValueInput; import net.minecraft.world.level.storage.ValueOutput; import net.minecraft.world.phys.Vec3; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class CharmEffect extends Entity implements ItemSupplier { @@ -34,12 +33,12 @@ public class CharmEffect extends Entity implements ItemSupplier { private LivingEntity orbiter; private ItemStack displayItem = new ItemStack(Items.BARRIER); - public CharmEffect(EntityType type, Level level) { + public CharmEffect(EntityType type, Level level) { super(type, level); } @SuppressWarnings("this-escape") - public CharmEffect(EntityType type, Level level, LivingEntity owner, ItemStack item) { + public CharmEffect(EntityType type, Level level, LivingEntity owner, ItemStack item) { this(type, level); this.orbiter = owner; this.displayItem = item; diff --git a/src/main/java/twilightforest/entity/EnforcedHomePoint.java b/src/main/java/twilightforest/entity/EnforcedHomePoint.java index f1768b679f..29a096ce7c 100644 --- a/src/main/java/twilightforest/entity/EnforcedHomePoint.java +++ b/src/main/java/twilightforest/entity/EnforcedHomePoint.java @@ -10,12 +10,12 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.storage.ValueInput; import net.minecraft.world.level.storage.ValueOutput; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import twilightforest.entity.ai.goal.AttemptToGoHomeGoal; import twilightforest.init.TFDimension; public interface EnforcedHomePoint { + default void addRestrictionGoals(T entity, GoalSelector selector) { selector.addGoal(5, new AttemptToGoHomeGoal<>(entity, 1.25D)); } @@ -53,7 +53,7 @@ default boolean isMobWithinHomeArea(Entity entity) { return this.getRestrictionPoint().pos().distSqr(entity.blockPosition()) < (double) (this.getHomeRadius() * this.getHomeRadius()); } - default boolean isRestrictionPointValid(ResourceKey<@NotNull Level> currentMobLevel) { + default boolean isRestrictionPointValid(ResourceKey currentMobLevel) { return this.getRestrictionPoint() != null && this.getRestrictionPoint().dimension().equals(currentMobLevel); } diff --git a/src/main/java/twilightforest/entity/MagicPainting.java b/src/main/java/twilightforest/entity/MagicPainting.java index 5c72e12d7c..4c73eba484 100644 --- a/src/main/java/twilightforest/entity/MagicPainting.java +++ b/src/main/java/twilightforest/entity/MagicPainting.java @@ -26,7 +26,6 @@ import net.minecraft.world.level.storage.ValueOutput; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; -import org.jetbrains.annotations.NotNull; import twilightforest.TFRegistries; import twilightforest.init.TFDataComponents; import twilightforest.init.TFDataSerializers; @@ -40,11 +39,11 @@ import java.util.Optional; public class MagicPainting extends HangingEntity { - private static final EntityDataAccessor<@NotNull Holder<@NotNull MagicPaintingVariant>> MAGIC_PAINTING_VARIANT = SynchedEntityData.defineId(MagicPainting.class, TFDataSerializers.MAGIC_PAINTING_VARIANT.value()); + private static final EntityDataAccessor> MAGIC_PAINTING_VARIANT = SynchedEntityData.defineId(MagicPainting.class, TFDataSerializers.MAGIC_PAINTING_VARIANT.value()); private Direction direction; - public MagicPainting(EntityType entityType, Level level) { + public MagicPainting(EntityType entityType, Level level) { super(entityType, level); } @@ -64,17 +63,17 @@ public void onSyncedDataUpdated(EntityDataAccessor pKey) { } } - public void setVariant(Holder<@NotNull MagicPaintingVariant> variant) { + public void setVariant(Holder variant) { this.getEntityData().set(MAGIC_PAINTING_VARIANT, variant); } - public Holder<@NotNull MagicPaintingVariant> getVariant() { + public Holder getVariant() { return this.getEntityData().get(MAGIC_PAINTING_VARIANT); } public static Optional create(Level level, BlockPos pos, Direction direction) { MagicPainting magicPainting = new MagicPainting(level, pos); - List> list = new ArrayList<>(); + List> list = new ArrayList<>(); level.registryAccess().lookupOrThrow(TFRegistries.Keys.MAGIC_PAINTINGS).listElements().forEach(list::add); if (list.isEmpty()) { return Optional.empty(); @@ -89,7 +88,7 @@ public static Optional create(Level level, BlockPos pos, Directio } else { int biggestPossibleArea = list.stream().mapToInt(MagicPainting::variantArea).max().orElse(0); list.removeIf((variant) -> variantArea(variant) < biggestPossibleArea); - Optional> optional = Util.getRandomSafe(list, magicPainting.random); + Optional> optional = Util.getRandomSafe(list, magicPainting.random); if (optional.isEmpty()) { return Optional.empty(); } else { @@ -101,7 +100,7 @@ public static Optional create(Level level, BlockPos pos, Directio } } - private static int variantArea(Holder<@NotNull MagicPaintingVariant> variant) { + private static int variantArea(Holder variant) { return variantArea(variant.value()); } @@ -131,7 +130,7 @@ public void readAdditionalSaveData(ValueInput input) { this.setDirection(this.direction); } - protected Registry<@NotNull MagicPaintingVariant> getReg() { + protected Registry getReg() { return this.registryAccess().lookupOrThrow(TFRegistries.Keys.MAGIC_PAINTINGS); } @@ -194,7 +193,7 @@ public Vec3 trackingPosition() { } @Override - public Packet<@NotNull ClientGamePacketListener> getAddEntityPacket(ServerEntity entity) { + public Packet getAddEntityPacket(ServerEntity entity) { return new ClientboundAddEntityPacket(this, this.direction.get3DDataValue(), this.getPos()); } diff --git a/src/main/java/twilightforest/entity/SlideBlock.java b/src/main/java/twilightforest/entity/SlideBlock.java index fc22a85658..b276dcad58 100644 --- a/src/main/java/twilightforest/entity/SlideBlock.java +++ b/src/main/java/twilightforest/entity/SlideBlock.java @@ -22,29 +22,28 @@ import net.minecraft.world.level.storage.ValueOutput; import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.shapes.CollisionContext; -import org.jetbrains.annotations.NotNull; import twilightforest.init.TFBlocks; import twilightforest.init.TFDamageTypes; import twilightforest.init.TFSounds; -import javax.annotation.Nonnull; import java.util.List; public class SlideBlock extends Entity { + private static final int WARMUP_TIME = 20; - private static final EntityDataAccessor<@NotNull Direction> MOVE_DIRECTION = SynchedEntityData.defineId(SlideBlock.class, EntityDataSerializers.DIRECTION); + private static final EntityDataAccessor MOVE_DIRECTION = SynchedEntityData.defineId(SlideBlock.class, EntityDataSerializers.DIRECTION); private BlockState myState; private int slideTime; - public SlideBlock(EntityType type, Level world) { + public SlideBlock(EntityType type, Level world) { super(type, world); this.blocksBuilding = true; this.myState = TFBlocks.SLIDER.get().defaultBlockState(); } @SuppressWarnings("this-escape") - public SlideBlock(EntityType type, Level world, double x, double y, double z, BlockState state) { + public SlideBlock(EntityType type, Level world, double x, double y, double z, BlockState state) { super(type, world); this.myState = state; @@ -181,14 +180,14 @@ public boolean displayFireAnimation() { } @Override - protected void readAdditionalSaveData(@Nonnull ValueInput compound) { + protected void readAdditionalSaveData(ValueInput compound) { this.slideTime = compound.getInt("Time").get(); this.getEntityData().set(MOVE_DIRECTION, Direction.from3DDataValue(compound.getByteOr("Direction", (byte) 0))); this.myState = NbtUtils.readBlockState(this.level().holderLookup(Registries.BLOCK), new CompoundTag()); } @Override - protected void addAdditionalSaveData(@Nonnull ValueOutput compound) { + protected void addAdditionalSaveData(ValueOutput compound) { compound.putInt("Time", this.slideTime); compound.putByte("Direction", (byte) this.getEntityData().get(MOVE_DIRECTION).get3DDataValue()); compound.store("BlockState", BlockState.CODEC, this.myState); diff --git a/src/main/java/twilightforest/entity/monster/LoyalZombie.java b/src/main/java/twilightforest/entity/monster/LoyalZombie.java index 3217872c03..4d56c14492 100644 --- a/src/main/java/twilightforest/entity/monster/LoyalZombie.java +++ b/src/main/java/twilightforest/entity/monster/LoyalZombie.java @@ -37,19 +37,19 @@ import net.minecraft.world.level.storage.ValueInput; import net.minecraft.world.level.storage.ValueOutput; import net.minecraft.world.phys.Vec3; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import twilightforest.init.TFDamageTypes; import twilightforest.init.TFEntities; import twilightforest.init.TFSounds; public class LoyalZombie extends TamableAnimal { - private static final EntityDataAccessor<@NotNull Boolean> DATA_BABY_ID = SynchedEntityData.defineId(LoyalZombie.class, EntityDataSerializers.BOOLEAN); + + private static final EntityDataAccessor DATA_BABY_ID = SynchedEntityData.defineId(LoyalZombie.class, EntityDataSerializers.BOOLEAN); private static final Identifier SPEED_MODIFIER_BABY_ID = Identifier.withDefaultNamespace("baby"); private static final AttributeModifier SPEED_MODIFIER_BABY = new AttributeModifier(SPEED_MODIFIER_BABY_ID, 0.5, AttributeModifier.Operation.ADD_MULTIPLIED_BASE); private static final EntityDimensions BABY_DIMENSIONS = TFEntities.LOYAL_ZOMBIE.get().getDimensions().scale(0.5F).withEyeHeight(0.93F); - public LoyalZombie(EntityType type, Level level) { + public LoyalZombie(EntityType type, Level level) { super(type, level); } diff --git a/src/main/java/twilightforest/entity/passive/quest/ram/QuestingRamContext.java b/src/main/java/twilightforest/entity/passive/quest/ram/QuestingRamContext.java index bf79212ae9..ca6c24c0d2 100644 --- a/src/main/java/twilightforest/entity/passive/quest/ram/QuestingRamContext.java +++ b/src/main/java/twilightforest/entity/passive/quest/ram/QuestingRamContext.java @@ -13,13 +13,12 @@ import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.storage.loot.LootTable; -import org.jetbrains.annotations.NotNull; import twilightforest.loot.TFLootTables; import java.util.LinkedHashMap; import java.util.Map; -public record QuestingRamContext(Map questItems, ResourceKey<@NotNull LootTable> lootTable) { +public record QuestingRamContext(Map questItems, ResourceKey lootTable) { public static final QuestingRamContext FALLBACK = new QuestingRamContext(ImmutableMap.builder() .put(DyeColor.WHITE, Ingredient.of(Items.WHITE_WOOL)) @@ -45,7 +44,7 @@ public record QuestingRamContext(Map questItems, ResourceK ResourceKey.codec(Registries.LOOT_TABLE).fieldOf("reward").forGetter(QuestingRamContext::lootTable) ).apply(instance, QuestingRamContext::new)); - public static final StreamCodec<@NotNull RegistryFriendlyByteBuf, @NotNull QuestingRamContext> STREAM_CODEC = StreamCodec.composite( + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.map( LinkedHashMap::new, DyeColor.STREAM_CODEC, diff --git a/src/main/java/twilightforest/entity/projectile/TFArrow.java b/src/main/java/twilightforest/entity/projectile/TFArrow.java index 46674b3187..b3112bee50 100644 --- a/src/main/java/twilightforest/entity/projectile/TFArrow.java +++ b/src/main/java/twilightforest/entity/projectile/TFArrow.java @@ -6,7 +6,6 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public abstract class TFArrow extends AbstractArrow implements ITFProjectile { @@ -14,12 +13,12 @@ public abstract class TFArrow extends AbstractArrow implements ITFProjectile { @Nullable protected final AbstractArrow parentArrow; - public TFArrow(EntityType type, Level level) { + public TFArrow(EntityType type, Level level) { super(type, level); this.parentArrow = null; } - public TFArrow(EntityType type, Level level, @Nullable LivingEntity shooter, ItemStack stack, ItemStack weapon) { + public TFArrow(EntityType type, Level level, @Nullable LivingEntity shooter, ItemStack stack, ItemStack weapon) { super(type, shooter, level, stack, weapon); this.setOwner(shooter); if (shooter != null) { @@ -28,7 +27,7 @@ public TFArrow(EntityType type, Level level, @Nullab this.parentArrow = null; } - public TFArrow(EntityType type, AbstractArrow parentArrow, ItemStack stack, ItemStack weapon) { + public TFArrow(EntityType type, AbstractArrow parentArrow, ItemStack stack, ItemStack weapon) { super(type, (LivingEntity) parentArrow.getOwner(), parentArrow.level(), stack, weapon); var shooter = (LivingEntity) parentArrow.getOwner(); this.setOwner(shooter); diff --git a/src/main/java/twilightforest/entity/projectile/TFThrowable.java b/src/main/java/twilightforest/entity/projectile/TFThrowable.java index 8e4351e48a..689617e5d8 100644 --- a/src/main/java/twilightforest/entity/projectile/TFThrowable.java +++ b/src/main/java/twilightforest/entity/projectile/TFThrowable.java @@ -2,28 +2,23 @@ import net.minecraft.core.particles.ParticleOptions; import net.minecraft.network.syncher.SynchedEntityData; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.projectile.ThrowableProjectile; import net.minecraft.world.entity.projectile.throwableitemprojectile.ThrowableItemProjectile; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -import org.jetbrains.annotations.NotNull; -import twilightforest.init.TFSounds; public abstract class TFThrowable extends ThrowableItemProjectile implements ITFProjectile { - public TFThrowable(EntityType type, Level level) { + public TFThrowable(EntityType type, Level level) { super(type, level); } - public TFThrowable(EntityType type, Level level, double x, double y, double z, ItemStack stack) { + public TFThrowable(EntityType type, Level level, double x, double y, double z, ItemStack stack) { super(type, x, y, z, level, stack); } - public TFThrowable(EntityType type, Level level, LivingEntity thrower, ItemStack stack) { + public TFThrowable(EntityType type, Level level, LivingEntity thrower, ItemStack stack) { super(type, thrower, level, stack); } diff --git a/src/main/java/twilightforest/entity/projectile/ThrownBlock.java b/src/main/java/twilightforest/entity/projectile/ThrownBlock.java index b4ec781a2e..a0868322d0 100644 --- a/src/main/java/twilightforest/entity/projectile/ThrownBlock.java +++ b/src/main/java/twilightforest/entity/projectile/ThrownBlock.java @@ -22,7 +22,6 @@ import net.minecraft.world.level.storage.ValueOutput; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.EntityHitResult; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import twilightforest.entity.monster.Troll; import twilightforest.init.TFDamageTypes; @@ -32,7 +31,7 @@ public class ThrownBlock extends TFThrowable { private BlockState state = Blocks.STONE.defaultBlockState(); - public ThrownBlock(EntityType type, Level worldIn) { + public ThrownBlock(EntityType type, Level worldIn) { super(type, worldIn); } @@ -98,7 +97,7 @@ public BlockState getBlockState() { } @Override - public Packet<@NotNull ClientGamePacketListener> getAddEntityPacket(ServerEntity entity) { + public Packet getAddEntityPacket(ServerEntity entity) { return new ClientboundAddEntityPacket(this, entity, Block.getId(this.getBlockState())); } diff --git a/src/main/java/twilightforest/entity/projectile/ThrownWep.java b/src/main/java/twilightforest/entity/projectile/ThrownWep.java index 121aefe047..40d485590b 100644 --- a/src/main/java/twilightforest/entity/projectile/ThrownWep.java +++ b/src/main/java/twilightforest/entity/projectile/ThrownWep.java @@ -12,22 +12,22 @@ import net.minecraft.world.level.Level; import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.HitResult; -import org.jetbrains.annotations.NotNull; import twilightforest.entity.boss.KnightPhantom; import twilightforest.init.TFDamageTypes; import twilightforest.init.TFItems; public class ThrownWep extends TFThrowable { - private static final EntityDataAccessor<@NotNull ItemStack> DATA_ITEMSTACK = SynchedEntityData.defineId(ThrownWep.class, EntityDataSerializers.ITEM_STACK); - private static final EntityDataAccessor<@NotNull Float> DATA_VELOCITY = SynchedEntityData.defineId(ThrownWep.class, EntityDataSerializers.FLOAT); + + private static final EntityDataAccessor DATA_ITEMSTACK = SynchedEntityData.defineId(ThrownWep.class, EntityDataSerializers.ITEM_STACK); + private static final EntityDataAccessor DATA_VELOCITY = SynchedEntityData.defineId(ThrownWep.class, EntityDataSerializers.FLOAT); private float projectileDamage = 6; - public ThrownWep(EntityType type, Level world, LivingEntity thrower) { + public ThrownWep(EntityType type, Level world, LivingEntity thrower) { super(type, world); } - public ThrownWep(EntityType type, Level world) { + public ThrownWep(EntityType type, Level world) { super(type, world); } From 34ee14d9939aad12ba46ccbe27ae8743f6d6e419 Mon Sep 17 00:00:00 2001 From: Albazavr Date: Thu, 16 Jul 2026 01:44:34 +0300 Subject: [PATCH 3/8] Fixed CharmEffect --- .../java/twilightforest/entity/CharmEffect.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/twilightforest/entity/CharmEffect.java b/src/main/java/twilightforest/entity/CharmEffect.java index fcbb138761..0df4a3bec9 100644 --- a/src/main/java/twilightforest/entity/CharmEffect.java +++ b/src/main/java/twilightforest/entity/CharmEffect.java @@ -43,8 +43,7 @@ public CharmEffect(EntityType type, Level level, LivingEn this.orbiter = owner; this.displayItem = item; - this.setPos(owner.getX(), owner.getY() + owner.getEyeHeight(), owner.getZ()); - this.setRot(owner.getYRot(), owner.getXRot()); + this.snapTo(owner.getX(), owner.getY() + owner.getEyeHeight(), owner.getZ(), owner.getYRot(), owner.getXRot()); Vec3 look = new Vec3(DISTANCE, 0, 0); double x = getX() + (look.x() * DISTANCE); @@ -75,8 +74,7 @@ public void tick() { if (this.orbiter != null) { float rotation = this.tickCount / 10.0F + this.offset; Vec3 look = new Vec3(DISTANCE, 0, 0).yRot(rotation); - this.setPos(this.orbiter.getX() + look.x(), this.orbiter.getY() + this.orbiter.getEyeHeight(), this.orbiter.getZ() + look.z()); - this.setRot(this.orbiter.getYRot(), this.orbiter.getXRot()); + this.snapTo(this.orbiter.getX() + look.x(), this.orbiter.getY() + this.orbiter.getEyeHeight(), this.orbiter.getZ() + look.z(), this.orbiter.getYRot(), this.orbiter.getXRot()); } if (!this.displayItem.isEmpty()) { @@ -103,13 +101,17 @@ public void lerpPositionAndRotationStep(int posRotationIncrements, double x, dou } @Override - protected void defineSynchedData(SynchedEntityData.Builder builder) {} + protected void defineSynchedData(SynchedEntityData.Builder builder) { + + } @Override - protected void readAdditionalSaveData(ValueInput valueInput) {} + protected void readAdditionalSaveData(ValueInput valueInput) { + } @Override - protected void addAdditionalSaveData(ValueOutput valueOutput) {} + protected void addAdditionalSaveData(ValueOutput valueOutput) { + } @Override public boolean hurtServer(ServerLevel serverLevel, DamageSource damageSource, float v) { From e518f54e4e9999f274f87b6ae3a6bb9558b560bd Mon Sep 17 00:00:00 2001 From: Albazavr Date: Thu, 16 Jul 2026 01:59:19 +0300 Subject: [PATCH 4/8] Fixed files --- .../java/twilightforest/entity/EnforcedHomePoint.java | 5 +++-- src/main/java/twilightforest/entity/MagicPainting.java | 9 ++------- src/main/java/twilightforest/entity/ProtectionBox.java | 9 ++++++--- src/main/java/twilightforest/entity/SlideBlock.java | 10 +++++----- src/main/java/twilightforest/entity/SpikeBlock.java | 6 ++++-- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/main/java/twilightforest/entity/EnforcedHomePoint.java b/src/main/java/twilightforest/entity/EnforcedHomePoint.java index 29a096ce7c..ab67ee137b 100644 --- a/src/main/java/twilightforest/entity/EnforcedHomePoint.java +++ b/src/main/java/twilightforest/entity/EnforcedHomePoint.java @@ -14,6 +14,8 @@ import twilightforest.entity.ai.goal.AttemptToGoHomeGoal; import twilightforest.init.TFDimension; +import java.util.Optional; + public interface EnforcedHomePoint { default void addRestrictionGoals(T entity, GoalSelector selector) { @@ -27,7 +29,7 @@ default void saveHomePointToNbt(ValueOutput tag) { } default void loadHomePointFromNbt(ValueInput tag) { - var modernPos = tag.read("HomePos", GlobalPos.CODEC); + Optional modernPos = tag.read("HomePos", GlobalPos.CODEC); if (modernPos.isPresent()) { this.setRestrictionPoint(modernPos.get()); @@ -47,7 +49,6 @@ default void loadHomePointFromNbt(ValueInput tag) { } } - default boolean isMobWithinHomeArea(Entity entity) { if (!this.isRestrictionPointValid(entity.level().dimension())) return true; return this.getRestrictionPoint().pos().distSqr(entity.blockPosition()) < (double) (this.getHomeRadius() * this.getHomeRadius()); diff --git a/src/main/java/twilightforest/entity/MagicPainting.java b/src/main/java/twilightforest/entity/MagicPainting.java index 4c73eba484..228728e054 100644 --- a/src/main/java/twilightforest/entity/MagicPainting.java +++ b/src/main/java/twilightforest/entity/MagicPainting.java @@ -118,7 +118,7 @@ protected void addAdditionalSaveData(ValueOutput output) { @Override public void readAdditionalSaveData(ValueInput input) { - if (!input.getStringOr("variant", "-1").equals("-1")) { + if (input.getString("variant").isPresent()) { Identifier location = Identifier.tryParse(input.getString("variant").get()); if (location != null) { this.setVariant(this.getReg().get(location).orElse(this.getReg().getOrThrow(MagicPaintingVariants.DEFAULT))); @@ -178,15 +178,10 @@ public void move(MoverType moverType, Vec3 delta) { } @Override - public void moveTowardsClosestSpace(double x, double y, double z) { + public void lerpPositionAndRotationStep(int stepsToTarget, double x, double y, double z, double targetYRot, double targetXRot) { this.setPos(x, y, z); } - @Override - protected void lerpPositionAndRotationStep(int stepsToTarget, double targetX, double targetY, double targetZ, double targetYRot, double targetXRot) { - this.setPos(targetX, targetY, targetZ); - } - @Override public Vec3 trackingPosition() { return Vec3.atLowerCornerOf(this.pos); diff --git a/src/main/java/twilightforest/entity/ProtectionBox.java b/src/main/java/twilightforest/entity/ProtectionBox.java index d078138b08..a47162dd2a 100644 --- a/src/main/java/twilightforest/entity/ProtectionBox.java +++ b/src/main/java/twilightforest/entity/ProtectionBox.java @@ -67,13 +67,16 @@ public void resetLifetime() { } @Override - protected void defineSynchedData(SynchedEntityData.Builder builder) {} + protected void defineSynchedData(SynchedEntityData.Builder builder) { + } @Override - protected void readAdditionalSaveData(ValueInput compound) {} + protected void readAdditionalSaveData(ValueInput compound) { + } @Override - protected void addAdditionalSaveData(ValueOutput compound) {} + protected void addAdditionalSaveData(ValueOutput compound) { + } @Override public boolean hurtServer(ServerLevel serverLevel, DamageSource damageSource, float v) { diff --git a/src/main/java/twilightforest/entity/SlideBlock.java b/src/main/java/twilightforest/entity/SlideBlock.java index b276dcad58..c2b6db32a6 100644 --- a/src/main/java/twilightforest/entity/SlideBlock.java +++ b/src/main/java/twilightforest/entity/SlideBlock.java @@ -118,7 +118,7 @@ public void tick() { } this.getDeltaMovement().multiply(0.98, 0.98, 0.98); - if (!this.level().isClientSide()) { + if (this.level() instanceof ServerLevel serverLevel) { if (this.slideTime % 5 == 0) { this.playSound(TFSounds.SLIDER.get(), 1.0F, 0.9F + (this.random.nextFloat() * 0.4F)); } @@ -148,10 +148,10 @@ public void tick() { if (this.level().isUnobstructed(this.myState, pos, CollisionContext.empty())) { this.level().setBlockAndUpdate(pos, this.myState); } else { - this.spawnAtLocation((ServerLevel) level(), new ItemStack(this.myState.getBlock()), 0.0F); + this.spawnAtLocation(serverLevel, new ItemStack(this.myState.getBlock()), 0.0F); } } else if (this.slideTime > 100 && (pos.getY() < this.level().getMinY() + 1 || pos.getY() > this.level().getMaxY()) || this.slideTime > 600) { - this.spawnAtLocation((ServerLevel) level(), new ItemStack(this.myState.getBlock()), 0.0F); + this.spawnAtLocation(serverLevel, new ItemStack(this.myState.getBlock()), 0.0F); this.discard(); } @@ -181,9 +181,9 @@ public boolean displayFireAnimation() { @Override protected void readAdditionalSaveData(ValueInput compound) { - this.slideTime = compound.getInt("Time").get(); + this.slideTime = compound.getIntOr("Time", 0); this.getEntityData().set(MOVE_DIRECTION, Direction.from3DDataValue(compound.getByteOr("Direction", (byte) 0))); - this.myState = NbtUtils.readBlockState(this.level().holderLookup(Registries.BLOCK), new CompoundTag()); + this.myState = compound.read("BlockState", BlockState.CODEC).get(); } @Override diff --git a/src/main/java/twilightforest/entity/SpikeBlock.java b/src/main/java/twilightforest/entity/SpikeBlock.java index 19acb5fa18..1d09cb8281 100644 --- a/src/main/java/twilightforest/entity/SpikeBlock.java +++ b/src/main/java/twilightforest/entity/SpikeBlock.java @@ -72,8 +72,10 @@ protected boolean canRide(Entity entity) { } @Override - protected void readAdditionalSaveData(ValueInput compound) {} + protected void readAdditionalSaveData(ValueInput compound) { + } @Override - protected void addAdditionalSaveData(ValueOutput compound) {} + protected void addAdditionalSaveData(ValueOutput compound) { + } } From a250e426be32c8e1becf3a3650bc9cd9dd93123b Mon Sep 17 00:00:00 2001 From: Albazavr Date: Thu, 16 Jul 2026 02:15:17 +0300 Subject: [PATCH 5/8] Fixed files --- .../entity/EnforcedHomePoint.java | 28 ++++++++----------- .../twilightforest/entity/MagicPainting.java | 4 +-- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/main/java/twilightforest/entity/EnforcedHomePoint.java b/src/main/java/twilightforest/entity/EnforcedHomePoint.java index ab67ee137b..f9788deabb 100644 --- a/src/main/java/twilightforest/entity/EnforcedHomePoint.java +++ b/src/main/java/twilightforest/entity/EnforcedHomePoint.java @@ -14,7 +14,7 @@ import twilightforest.entity.ai.goal.AttemptToGoHomeGoal; import twilightforest.init.TFDimension; -import java.util.Optional; +import java.util.List; public interface EnforcedHomePoint { @@ -29,23 +29,17 @@ default void saveHomePointToNbt(ValueOutput tag) { } default void loadHomePointFromNbt(ValueInput tag) { - Optional modernPos = tag.read("HomePos", GlobalPos.CODEC); - - if (modernPos.isPresent()) { - this.setRestrictionPoint(modernPos.get()); + //properly load old home points, just assume theyre set in TF + if (tag.read("Home", Codec.DOUBLE.listOf()).isPresent()) { + List nbttaglist = tag.read("Home", Codec.DOUBLE.listOf()).get(); + double hx = nbttaglist.get(0); + double hy = nbttaglist.get(1); + double hz = nbttaglist.get(2); + this.setRestrictionPoint(GlobalPos.of(TFDimension.DIMENSION_KEY, BlockPos.containing(hx, hy, hz))); } else { - tag.read("Home", Codec.DOUBLE.listOf()).ifPresent(doubleList -> { - if (doubleList.size() >= 3) { - double hx = doubleList.get(0); - double hy = doubleList.get(1); - double hz = doubleList.get(2); - - this.setRestrictionPoint(GlobalPos.of( - TFDimension.DIMENSION_KEY, - BlockPos.containing(hx, hy, hz) - )); - } - }); + if (tag.read("HomePos", GlobalPos.CODEC).isPresent()) { + this.setRestrictionPoint(tag.read("HomePos", GlobalPos.CODEC).get()); + } } } diff --git a/src/main/java/twilightforest/entity/MagicPainting.java b/src/main/java/twilightforest/entity/MagicPainting.java index 228728e054..d2d8340071 100644 --- a/src/main/java/twilightforest/entity/MagicPainting.java +++ b/src/main/java/twilightforest/entity/MagicPainting.java @@ -173,8 +173,8 @@ public void playPlacementSound() { } @Override - public void move(MoverType moverType, Vec3 delta) { - this.setPos(delta.x, delta.y, delta.z); + public void snapTo(double x, double y, double z, float yaw, float pitch) { + this.setPos(x, y, z); } @Override From 74b6edc6477dc9cd603a738458ea62b26eb1407f Mon Sep 17 00:00:00 2001 From: Albazavr Date: Sat, 18 Jul 2026 00:51:57 +0300 Subject: [PATCH 6/8] Fixed usages of EntityUtil. See Utilities port (#2628) --- src/main/java/twilightforest/entity/boss/KnightPhantom.java | 2 +- src/main/java/twilightforest/entity/boss/Minoshroom.java | 2 +- src/main/java/twilightforest/entity/boss/SnowQueen.java | 2 +- .../java/twilightforest/entity/monster/BlockChainGoblin.java | 2 +- src/main/java/twilightforest/entity/monster/GiantMiner.java | 2 +- src/main/java/twilightforest/entity/monster/Minotaur.java | 2 +- src/main/java/twilightforest/entity/monster/PinchBeetle.java | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/twilightforest/entity/boss/KnightPhantom.java b/src/main/java/twilightforest/entity/boss/KnightPhantom.java index 0bab5fc2a9..8aab19168a 100644 --- a/src/main/java/twilightforest/entity/boss/KnightPhantom.java +++ b/src/main/java/twilightforest/entity/boss/KnightPhantom.java @@ -311,7 +311,7 @@ public boolean hurtServer(ServerLevel server, DamageSource source, float amount) @Override public boolean doHurtTarget(ServerLevel server, Entity entity) { - return EntityUtil.properlyApplyCustomDamageSource(this, entity, TFDamageTypes.getEntityDamageSource(this.level(), TFDamageTypes.HAUNT, this), null); + return EntityUtil.properlyApplyCustomDamageSource(server, this, entity, TFDamageTypes.getEntityDamageSource(this.level(), TFDamageTypes.HAUNT, this), null); } @Override diff --git a/src/main/java/twilightforest/entity/boss/Minoshroom.java b/src/main/java/twilightforest/entity/boss/Minoshroom.java index eff69b03ab..c74fe6b7e5 100644 --- a/src/main/java/twilightforest/entity/boss/Minoshroom.java +++ b/src/main/java/twilightforest/entity/boss/Minoshroom.java @@ -144,7 +144,7 @@ public SpawnGroupData finalizeSpawn(ServerLevelAccessor accessor, DifficultyInst @Override public boolean doHurtTarget(ServerLevel server, Entity entity) { - return EntityUtil.properlyApplyCustomDamageSource(this, entity, TFDamageTypes.getEntityDamageSource(this.level(), TFDamageTypes.AXING, this), TFSounds.MINOSHROOM_ATTACK.get()); + return EntityUtil.properlyApplyCustomDamageSource(server, this, entity, TFDamageTypes.getEntityDamageSource(this.level(), TFDamageTypes.AXING, this), TFSounds.MINOSHROOM_ATTACK.get()); } @Override diff --git a/src/main/java/twilightforest/entity/boss/SnowQueen.java b/src/main/java/twilightforest/entity/boss/SnowQueen.java index 9dfe4a45e1..4ab76655c3 100644 --- a/src/main/java/twilightforest/entity/boss/SnowQueen.java +++ b/src/main/java/twilightforest/entity/boss/SnowQueen.java @@ -254,7 +254,7 @@ private void applyShieldCollision(ServerLevel server, Entity collider, Entity co @Override public boolean doHurtTarget(ServerLevel server, Entity entity) { DamageSource source = this.getCurrentPhase() == Phase.DROP ? TFDamageTypes.getEntityDamageSource(this.level(), TFDamageTypes.SQUISH, this, TFEntities.SNOW_QUEEN.get()) : this.level().damageSources().mobAttack(this); - return EntityUtil.properlyApplyCustomDamageSource(this, entity, source, null); + return EntityUtil.properlyApplyCustomDamageSource(server, this, entity, source, null); } @Override diff --git a/src/main/java/twilightforest/entity/monster/BlockChainGoblin.java b/src/main/java/twilightforest/entity/monster/BlockChainGoblin.java index 7f6bc44dc1..e07be272a0 100644 --- a/src/main/java/twilightforest/entity/monster/BlockChainGoblin.java +++ b/src/main/java/twilightforest/entity/monster/BlockChainGoblin.java @@ -137,7 +137,7 @@ public boolean isSwingingChain() { @Override public boolean doHurtTarget(ServerLevel server, Entity entity) { - return EntityUtil.properlyApplyCustomDamageSource(this, entity, TFDamageTypes.getIndirectEntityDamageSource(this.level(), TFDamageTypes.SPIKED, this, this.block), null); + return EntityUtil.properlyApplyCustomDamageSource(server, this, entity, TFDamageTypes.getIndirectEntityDamageSource(this.level(), TFDamageTypes.SPIKED, this, this.block), null); } @Override diff --git a/src/main/java/twilightforest/entity/monster/GiantMiner.java b/src/main/java/twilightforest/entity/monster/GiantMiner.java index 74206d6361..7a1f393946 100644 --- a/src/main/java/twilightforest/entity/monster/GiantMiner.java +++ b/src/main/java/twilightforest/entity/monster/GiantMiner.java @@ -81,7 +81,7 @@ protected void enchantSpawnedArmor(ServerLevelAccessor accessor, RandomSource ra @Override public boolean doHurtTarget(ServerLevel server, Entity entity) { - return EntityUtil.properlyApplyCustomDamageSource(this, entity, TFDamageTypes.getEntityDamageSource(this.level(), TFDamageTypes.ANT, this), null); + return EntityUtil.properlyApplyCustomDamageSource(server, this, entity, TFDamageTypes.getEntityDamageSource(this.level(), TFDamageTypes.ANT, this), null); } @Override diff --git a/src/main/java/twilightforest/entity/monster/Minotaur.java b/src/main/java/twilightforest/entity/monster/Minotaur.java index d76ffb60fe..4ce311dcf1 100644 --- a/src/main/java/twilightforest/entity/monster/Minotaur.java +++ b/src/main/java/twilightforest/entity/monster/Minotaur.java @@ -94,7 +94,7 @@ public void setCharging(boolean flag) { @Override public boolean doHurtTarget(ServerLevel server, Entity entity) { - return EntityUtil.properlyApplyCustomDamageSource(this, entity, TFDamageTypes.getEntityDamageSource(this.level(), TFDamageTypes.AXING, this), TFSounds.MINOTAUR_ATTACK.get()); + return EntityUtil.properlyApplyCustomDamageSource(server, this, entity, TFDamageTypes.getEntityDamageSource(this.level(), TFDamageTypes.AXING, this), TFSounds.MINOTAUR_ATTACK.get()); } @Override diff --git a/src/main/java/twilightforest/entity/monster/PinchBeetle.java b/src/main/java/twilightforest/entity/monster/PinchBeetle.java index 6caa187bc1..74589a3160 100644 --- a/src/main/java/twilightforest/entity/monster/PinchBeetle.java +++ b/src/main/java/twilightforest/entity/monster/PinchBeetle.java @@ -127,7 +127,7 @@ public boolean doHurtTarget(ServerLevel server, Entity entity) { entity.startRiding(this, true, false); //I mean, they aren't riding purposefully, don't send an event } } - return EntityUtil.properlyApplyCustomDamageSource(this, entity, TFDamageTypes.getEntityDamageSource(this.level(), TFDamageTypes.CLAMPED, this), null); + return EntityUtil.properlyApplyCustomDamageSource(server, this, entity, TFDamageTypes.getEntityDamageSource(this.level(), TFDamageTypes.CLAMPED, this), null); } @Override From 7ced40764455969f51678b7b43c1e7bf56b760d7 Mon Sep 17 00:00:00 2001 From: Albazavr Date: Mon, 20 Jul 2026 20:50:52 +0300 Subject: [PATCH 7/8] Fixed review comment for ProtectionBox --- src/main/java/twilightforest/entity/ProtectionBox.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/twilightforest/entity/ProtectionBox.java b/src/main/java/twilightforest/entity/ProtectionBox.java index a47162dd2a..7a808fa0e3 100644 --- a/src/main/java/twilightforest/entity/ProtectionBox.java +++ b/src/main/java/twilightforest/entity/ProtectionBox.java @@ -34,7 +34,7 @@ public ProtectionBox(Level world, BoundingBox sbb) { this.sbb = sbb; - this.setPos(sbb.minX(), sbb.minY(), sbb.minZ()); + this.snapTo(sbb.minX(), sbb.minY(), sbb.minZ(), 0.0F, 0.0F); this.setRot(0.0F, 0.0F); this.sizeX = sbb.getXSpan(); From 82d89a7af440b4729f600a115bba3ae0119f088c Mon Sep 17 00:00:00 2001 From: Albazavr Date: Mon, 20 Jul 2026 23:50:59 +0300 Subject: [PATCH 8/8] Fixed review comment --- src/main/java/twilightforest/entity/ProtectionBox.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/twilightforest/entity/ProtectionBox.java b/src/main/java/twilightforest/entity/ProtectionBox.java index 7a808fa0e3..4ce3f141c9 100644 --- a/src/main/java/twilightforest/entity/ProtectionBox.java +++ b/src/main/java/twilightforest/entity/ProtectionBox.java @@ -35,7 +35,6 @@ public ProtectionBox(Level world, BoundingBox sbb) { this.sbb = sbb; this.snapTo(sbb.minX(), sbb.minY(), sbb.minZ(), 0.0F, 0.0F); - this.setRot(0.0F, 0.0F); this.sizeX = sbb.getXSpan(); this.sizeY = sbb.getYSpan();