diff --git a/src/main/java/twilightforest/entity/CharmEffect.java b/src/main/java/twilightforest/entity/CharmEffect.java index d4ddeb60c0..0df4a3bec9 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,11 @@ 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.Nullable; -import javax.annotation.Nonnull; - public class CharmEffect extends Entity implements ItemSupplier { private static final double DISTANCE = 0.75D; private double interpTargetX; @@ -42,7 +43,7 @@ public CharmEffect(EntityType type, Level level, LivingEn this.orbiter = owner; this.displayItem = item; - this.moveTo(owner.getX(), owner.getY() + owner.getEyeHeight(), owner.getZ(), 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); @@ -73,7 +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.moveTo(this.orbiter.getX() + look.x(), this.orbiter.getY() + this.orbiter.getEyeHeight(), this.orbiter.getZ() + look.z(), 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()) { @@ -81,7 +82,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 +91,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; @@ -105,14 +106,18 @@ protected void defineSynchedData(SynchedEntityData.Builder builder) { } @Override - protected void readAdditionalSaveData(CompoundTag cmp) { + protected void readAdditionalSaveData(ValueInput valueInput) { } @Override - protected void addAdditionalSaveData(CompoundTag cmp) { + protected void addAdditionalSaveData(ValueOutput valueOutput) { + } + + @Override + 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..f9788deabb 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; @@ -13,10 +11,11 @@ import net.minecraft.world.level.storage.ValueInput; import net.minecraft.world.level.storage.ValueOutput; import org.jetbrains.annotations.Nullable; -import twilightforest.TwilightForestMod; import twilightforest.entity.ai.goal.AttemptToGoHomeGoal; import twilightforest.init.TFDimension; +import java.util.List; + public interface EnforcedHomePoint { default void addRestrictionGoals(T entity, GoalSelector selector) { @@ -25,21 +24,21 @@ default void addRestrictionGoals(T 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); + 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 { - if (tag.contains("HomePos")) { - this.setRestrictionPoint(GlobalPos.CODEC.parse(NbtOps.INSTANCE, tag.get("HomePos")).resultOrPartial(TwilightForestMod.LOGGER::error).orElse(null)); + 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 b8253ccdad..d2d8340071 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,14 +16,16 @@ 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; import twilightforest.TFRegistries; import twilightforest.init.TFDataComponents; import twilightforest.init.TFDataSerializers; @@ -39,6 +41,8 @@ public class MagicPainting extends HangingEntity { 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) { super(entityType, level); } @@ -49,7 +53,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 @@ -69,8 +73,8 @@ public Holder getVariant() { 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 +87,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 { @@ -105,29 +109,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.getString("variant").isPresent()) { + 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); + return this.registryAccess().lookupOrThrow(TFRegistries.Keys.MAGIC_PAINTINGS); } @Override @@ -150,8 +154,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 +163,7 @@ public void dropItem(@Nullable Entity entity) { } } - this.spawnAtLocation(this.getPickResult()); + this.spawnAtLocation(serverLevel, this.getPickResult()); } } @@ -169,12 +173,12 @@ public void playPlacementSound() { } @Override - public void moveTo(double x, double y, double z, float yaw, float pitch) { + public void snapTo(double x, double y, double z, float yaw, float pitch) { this.setPos(x, y, z); } @Override - public void lerpTo(double x, double y, double z, float yaw, float pitch, int posRotationIncrements) { + public void lerpPositionAndRotationStep(int stepsToTarget, double x, double y, double z, double targetYRot, double targetXRot) { this.setPos(x, y, z); } @@ -195,7 +199,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..4ce3f141c9 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,7 @@ public ProtectionBox(Level world, BoundingBox sbb) { this.sbb = sbb; - this.moveTo(sbb.minX(), sbb.minY(), sbb.minZ(), 0.0F, 0.0F); + this.snapTo(sbb.minX(), sbb.minY(), sbb.minZ(), 0.0F, 0.0F); this.sizeX = sbb.getXSpan(); this.sizeY = sbb.getYSpan(); @@ -67,11 +70,16 @@ 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..c2b6db32a6 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,13 +18,14 @@ 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 twilightforest.init.TFBlocks; import twilightforest.init.TFDamageTypes; import twilightforest.init.TFSounds; -import javax.annotation.Nonnull; import java.util.List; public class SlideBlock extends Entity { @@ -115,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)); } @@ -145,10 +148,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, 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, new ItemStack(this.myState.getBlock()), 0.0F); this.discard(); } @@ -177,17 +180,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(ValueInput compound) { + this.slideTime = compound.getIntOr("Time", 0); + this.getEntityData().set(MOVE_DIRECTION, Direction.from3DDataValue(compound.getByteOr("Direction", (byte) 0))); + this.myState = compound.read("BlockState", BlockState.CODEC).get(); } @Override - protected void addAdditionalSaveData(@Nonnull CompoundTag compound) { + protected void addAdditionalSaveData(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..1d09cb8281 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,10 @@ 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/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/LoyalZombie.java b/src/main/java/twilightforest/entity/monster/LoyalZombie.java index 757e2e7794..4d56c14492 100644 --- a/src/main/java/twilightforest/entity/monster/LoyalZombie.java +++ b/src/main/java/twilightforest/entity/monster/LoyalZombie.java @@ -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/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 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..ca6c24c0d2 100644 --- a/src/main/java/twilightforest/entity/passive/quest/ram/QuestingRamContext.java +++ b/src/main/java/twilightforest/entity/passive/quest/ram/QuestingRamContext.java @@ -5,6 +5,9 @@ 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; @@ -12,6 +15,7 @@ import net.minecraft.world.level.storage.loot.LootTable; import twilightforest.loot.TFLootTables; +import java.util.LinkedHashMap; import java.util.Map; public record QuestingRamContext(Map questItems, ResourceKey lootTable) { @@ -40,6 +44,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 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..b3112bee50 100644 --- a/src/main/java/twilightforest/entity/projectile/TFArrow.java +++ b/src/main/java/twilightforest/entity/projectile/TFArrow.java @@ -44,9 +44,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..689617e5d8 100644 --- a/src/main/java/twilightforest/entity/projectile/TFThrowable.java +++ b/src/main/java/twilightforest/entity/projectile/TFThrowable.java @@ -2,15 +2,11 @@ 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 twilightforest.init.TFSounds; public abstract class TFThrowable extends ThrowableItemProjectile implements ITFProjectile { @@ -28,7 +24,7 @@ public TFThrowable(EntityType type, Level level, LivingEn @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..a0868322d0 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; @@ -36,13 +35,18 @@ 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); diff --git a/src/main/java/twilightforest/entity/projectile/ThrownWep.java b/src/main/java/twilightforest/entity/projectile/ThrownWep.java index d37887d38d..40d485590b 100644 --- a/src/main/java/twilightforest/entity/projectile/ThrownWep.java +++ b/src/main/java/twilightforest/entity/projectile/ThrownWep.java @@ -7,6 +7,7 @@ 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; @@ -23,7 +24,7 @@ public class ThrownWep extends TFThrowable { private float projectileDamage = 6; public ThrownWep(EntityType type, Level world, LivingEntity thrower) { - super(type, world, thrower); + super(type, world); } public ThrownWep(EntityType type, Level 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); }