diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/AirBalloonEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/AirBalloonEntity.java index 3cdb693a..8e1b89ac 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/AirBalloonEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/AirBalloonEntity.java @@ -1,11 +1,12 @@ package com.minelittlepony.unicopia.entity.mob; -import net.fabricmc.fabric.api.tag.convention.v1.ConventionalItemTags; +import net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags; import net.minecraft.block.BlockState; import net.minecraft.block.ShapeContext; import net.minecraft.block.entity.FurnaceBlockEntity; import net.minecraft.entity.*; import net.minecraft.entity.data.*; +import net.minecraft.entity.data.DataTracker.Builder; import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.vehicle.BoatEntity; @@ -93,13 +94,13 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp } @Override - protected void initDataTracker() { - super.initDataTracker(); - dataTracker.startTracking(ASCENDING, false); - dataTracker.startTracking(BOOSTING, 0); - dataTracker.startTracking(INFLATION, 0); - dataTracker.startTracking(BASKET_TYPE, BasketType.DEFAULT.id().toString()); - dataTracker.startTracking(BALLOON_DESIGN, 0); + protected void initDataTracker(Builder builder) { + super.initDataTracker(builder); + builder.add(ASCENDING, false); + builder.add(BOOSTING, 0); + builder.add(INFLATION, 0); + builder.add(BASKET_TYPE, BasketType.DEFAULT.id().toString()); + builder.add(BALLOON_DESIGN, 0); } public BasketType getBasketType() { @@ -269,7 +270,7 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp } if (isLeashed()) { - Vec3d leashPost = getHoldingEntity().getPos(); + Vec3d leashPost = getLeashHolder().getPos(); Vec3d pos = getPos(); if (leashPost.distanceTo(pos) >= 5) { @@ -313,7 +314,7 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp if (isAscending()) { playSound(USounds.ENTITY_HOT_AIR_BALLOON_BOOST, 1, 1); } - stack.damage(1, player, p -> p.sendToolBreakStatus(hand)); + stack.damage(1, player, getSlotForHand(hand)); playSound(USounds.Vanilla.ITEM_FLINTANDSTEEL_USE, 1, 1); if (!player.isSneaky()) { getWorld().emitGameEvent(player, GameEvent.ENTITY_INTERACT, getBlockPos()); @@ -370,7 +371,7 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp if (!player.getAbilities().creativeMode) { stack.decrement(1); } - playSound(USounds.ENTITY_HOT_AIR_BALLOON_EQUIP_CANOPY, 1, 1); + playSound(USounds.ENTITY_HOT_AIR_BALLOON_EQUIP_CANOPY.value(), 1, 1); if (!player.isSneaky()) { getWorld().emitGameEvent(player, GameEvent.EQUIP, getBlockPos()); } @@ -381,11 +382,11 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp return ActionResult.SUCCESS; } - if (stack.isIn(ConventionalItemTags.SHEARS) && hasBalloon()) { - stack.damage(1, player, p -> p.sendToolBreakStatus(hand)); + if (stack.isIn(ConventionalItemTags.SHEAR_TOOLS) && hasBalloon()) { + stack.damage(1, player, getSlotForHand(hand)); setDesign(BalloonDesign.NONE); dropItem(UItems.GIANT_BALLOON); - playSound(USounds.ENTITY_HOT_AIR_BALLOON_EQUIP_CANOPY, 1, 1); + playSound(USounds.ENTITY_HOT_AIR_BALLOON_EQUIP_CANOPY.value(), 1, 1); if (!player.isSneaky()) { getWorld().emitGameEvent(player, GameEvent.EQUIP, getBlockPos()); } @@ -830,7 +831,7 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp } public static BasketType of(BoatEntity.Type boatType) { - return REGISTRY.computeIfAbsent(new Identifier(boatType.asString()), id -> new BasketType(id, boatType)); + return REGISTRY.computeIfAbsent(Identifier.of(boatType.asString()), id -> new BasketType(id, boatType)); } public static BasketType of(RegistryKey id) { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/CastSpellEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/CastSpellEntity.java index 34216ea4..7e63af08 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/CastSpellEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/CastSpellEntity.java @@ -28,6 +28,7 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedDataHandlerRegistry; +import net.minecraft.entity.data.DataTracker.Builder; import net.minecraft.nbt.NbtCompound; import net.minecraft.text.Text; import net.minecraft.util.math.MathHelper; @@ -76,7 +77,7 @@ public class CastSpellEntity extends LightEmittingEntity implements Caster type, World world) { @@ -86,12 +87,12 @@ public class CastSpellEntity extends LightEmittingEntity implements Caster { tag.put("stayingPos", NbtHelper.fromBlockPos(pos)); }); @@ -235,9 +230,9 @@ public class FairyEntity extends PathAwareEntity implements DynamicLightSource, public void readCustomDataFromNbt(NbtCompound tag) { super.readCustomDataFromNbt(tag); if (tag.contains("owner")) { - owner.fromNBT(tag.getCompound("owner")); + owner.fromNBT(tag.getCompound("owner"), getWorld().getRegistryManager()); } - stayingPos = tag.contains("stayingPos") ? Optional.of(NbtHelper.toBlockPos(tag.getCompound("stayingPos"))) : Optional.empty(); + stayingPos = tag.contains("stayingPos") ? NbtHelper.toBlockPos(tag, "stayingPos") : Optional.empty(); } class FollowEntityGoal extends Goal { @@ -308,7 +303,7 @@ public class FairyEntity extends PathAwareEntity implements DynamicLightSource, double speed = this.speed; if (distance > 100) { - teleport( + setPosition( target.getX() + getWorld().random.nextFloat() / 2F - 0.5F, target.getEyeY(), target.getZ() + getWorld().random.nextFloat() / 2F - 0.5F diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/FloatingArtefactEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/FloatingArtefactEntity.java index f653d96d..2f739a18 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/FloatingArtefactEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/FloatingArtefactEntity.java @@ -5,12 +5,14 @@ import java.util.Optional; import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.server.world.Altar; +import com.minelittlepony.unicopia.util.NbtSerialisable; import net.minecraft.entity.EntityType; import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedDataHandlerRegistry; +import net.minecraft.entity.data.DataTracker.Builder; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; import net.minecraft.text.Text; @@ -55,11 +57,11 @@ public class FloatingArtefactEntity extends StationaryObjectEntity { } @Override - protected void initDataTracker() { - super.initDataTracker(); - dataTracker.startTracking(ITEM, ItemStack.EMPTY); - dataTracker.startTracking(STATE, (byte)0); - dataTracker.startTracking(TARGET_ROTATION_SPEED, 1F); + protected void initDataTracker(Builder builder) { + super.initDataTracker(builder); + builder.add(ITEM, ItemStack.EMPTY); + builder.add(STATE, (byte)0); + builder.add(TARGET_ROTATION_SPEED, 1F); } public void setAltar(Altar altar) { @@ -159,11 +161,11 @@ public class FloatingArtefactEntity extends StationaryObjectEntity { @Override protected void readCustomDataFromNbt(NbtCompound compound) { super.readCustomDataFromNbt(compound); - setStack(ItemStack.fromNbt(compound.getCompound("Item"))); + setStack(ItemStack.fromNbtOrEmpty(getWorld().getRegistryManager(), compound.getCompound("Item"))); setState(State.valueOf(compound.getInt("State"))); setRotationSpeed(compound.getFloat("spin"), compound.getInt("spinDuration")); ticksUntilRegen = compound.getInt("regen"); - altar = Altar.SERIALIZER.readOptional("altar", compound); + altar = NbtSerialisable.decode(Altar.CODEC, compound.get("altar")); } @Override @@ -171,13 +173,13 @@ public class FloatingArtefactEntity extends StationaryObjectEntity { super.writeCustomDataToNbt(compound); ItemStack stack = getStack(); if (!stack.isEmpty()) { - compound.put("Item", stack.writeNbt(new NbtCompound())); + compound.put("Item", NbtSerialisable.encode(ItemStack.CODEC, stack)); } compound.putInt("State", getState().ordinal()); compound.putFloat("spin", getRotationSpeed()); compound.putInt("spinDuration", boostDuration); compound.putInt("regen", ticksUntilRegen); - Altar.SERIALIZER.writeOptional("altar", compound, altar); + altar.ifPresent(altar -> compound.put("altar", NbtSerialisable.encode(Altar.CODEC, altar))); } @Override @@ -187,7 +189,7 @@ public class FloatingArtefactEntity extends StationaryObjectEntity { return false; } - if (isInvulnerableTo(source) || !getStack().getItem().damage(source)) { + if (isInvulnerableTo(source) || !getStack().takesDamageFrom(source)) { return false; } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/FriendlyCreeperEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/FriendlyCreeperEntity.java index 785dad5f..ccd5c6b9 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/FriendlyCreeperEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/FriendlyCreeperEntity.java @@ -3,8 +3,6 @@ package com.minelittlepony.unicopia.entity.mob; import java.util.Collection; import java.util.EnumSet; import java.util.UUID; -import java.util.function.Consumer; - import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.entity.Creature; @@ -13,13 +11,13 @@ import com.minelittlepony.unicopia.entity.ai.FleeExplosionGoal; import com.minelittlepony.unicopia.entity.behaviour.Guest; import net.minecraft.block.BlockState; -import net.minecraft.client.render.entity.feature.SkinOverlayOwner; import net.minecraft.entity.AreaEffectCloudEntity; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityStatuses; import net.minecraft.entity.EntityType; import net.minecraft.entity.LightningEntity; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.SkinOverlayOwner; import net.minecraft.entity.ai.goal.ActiveTargetGoal; import net.minecraft.entity.ai.goal.AttackWithOwnerGoal; import net.minecraft.entity.ai.goal.EscapeDangerGoal; @@ -41,6 +39,7 @@ import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedDataHandlerRegistry; +import net.minecraft.entity.data.DataTracker.Builder; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.mob.AbstractSkeletonEntity; import net.minecraft.entity.mob.Angerable; @@ -70,7 +69,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.intprovider.UniformIntProvider; import net.minecraft.world.BlockView; -import net.minecraft.world.EntityView; import net.minecraft.world.World; import net.minecraft.world.event.GameEvent; import net.minecraft.world.explosion.Explosion; @@ -90,20 +88,23 @@ public class FriendlyCreeperEntity extends TameableEntity implements SkinOverlay private short hugTime; private short lastHugTime; + @Nullable + private UUID angerTarget; + protected FriendlyCreeperEntity(EntityType type, World world) { super(type, world); - setTamed(false); + setTamed(false, true); setPathfindingPenalty(PathNodeType.POWDER_SNOW, -1); setPathfindingPenalty(PathNodeType.DANGER_POWDER_SNOW, -1); } @Override - protected void initDataTracker() { - super.initDataTracker(); - dataTracker.startTracking(FUSE_SPEED, -1); - dataTracker.startTracking(CHARGED, false); - dataTracker.startTracking(IGNITED, false); - dataTracker.startTracking(ANGER_TIME, 0); + protected void initDataTracker(Builder builder) { + super.initDataTracker(builder); + builder.add(FUSE_SPEED, -1); + builder.add(CHARGED, false); + builder.add(IGNITED, false); + builder.add(ANGER_TIME, 0); } @Override @@ -271,8 +272,8 @@ public class FriendlyCreeperEntity extends TameableEntity implements SkinOverlay } @Override - protected void dropEquipment(DamageSource source, int lootingMultiplier, boolean allowDrops) { - super.dropEquipment(source, lootingMultiplier, allowDrops); + protected void dropEquipment(ServerWorld world, DamageSource source, boolean causedByPlayer) { + super.dropEquipment(world, source, causedByPlayer); if (source.getAttacker() instanceof CreeperEntity c && c.shouldDropHead()) { c.onHeadDropped(); dropItem(Items.CREEPER_HEAD); @@ -308,12 +309,16 @@ public class FriendlyCreeperEntity extends TameableEntity implements SkinOverlay dataTracker.set(CHARGED, true); } + + @Override + public boolean isBreedingItem(ItemStack stack) { + return stack.isOf(Items.GUNPOWDER); + } + @Override public ActionResult interactMob(PlayerEntity player, Hand hand) { ItemStack stack = player.getStackInHand(hand); - Consumer statusCallback = p -> p.sendToolBreakStatus(hand); - if (stack.isEmpty() && isOwner(player)) { setSitting(!isSitting()); setInSittingPose(isSitting()); @@ -329,7 +334,7 @@ public class FriendlyCreeperEntity extends TameableEntity implements SkinOverlay if (!stack.isDamageable()) { stack.decrement(1); } else { - stack.damage(1, player, statusCallback); + stack.damage(1, player, getSlotForHand(hand)); } } @@ -346,7 +351,7 @@ public class FriendlyCreeperEntity extends TameableEntity implements SkinOverlay if (!stack.isDamageable()) { stack.decrement(1); } else { - stack.damage(1, player, statusCallback); + stack.damage(1, player, getSlotForHand(hand)); } } @@ -405,25 +410,17 @@ public class FriendlyCreeperEntity extends TameableEntity implements SkinOverlay headsDropped++; } - @Override - public EntityView method_48926() { - return getWorld(); - } - @Override public PassiveEntity createChild(ServerWorld world, PassiveEntity partner) { FriendlyCreeperEntity child = (FriendlyCreeperEntity)getType().create(world); UUID uUID = getOwnerUuid(); if (uUID != null) { child.setOwnerUuid(uUID); - child.setTamed(true); + child.setTamed(true, true); } return child; } - @Nullable - private UUID angerTarget; - @Override public int getAngerTime() { return dataTracker.get(ANGER_TIME); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/IgnominiousBulbEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/IgnominiousBulbEntity.java index dbdb019d..c307c45f 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/IgnominiousBulbEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/IgnominiousBulbEntity.java @@ -12,13 +12,10 @@ import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.entity.EntityReference; import com.minelittlepony.unicopia.entity.player.Pony; -import com.minelittlepony.unicopia.util.NbtSerialisable; import com.minelittlepony.unicopia.util.VecHelper; import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityDimensions; -import net.minecraft.entity.EntityPose; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.MovementType; @@ -26,6 +23,7 @@ import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedDataHandlerRegistry; +import net.minecraft.entity.data.DataTracker.Builder; import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.passive.PassiveEntity; import net.minecraft.entity.player.PlayerEntity; @@ -33,6 +31,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; +import net.minecraft.nbt.NbtHelper; import net.minecraft.nbt.NbtList; import net.minecraft.particle.ParticleTypes; import net.minecraft.predicate.entity.EntityPredicates; @@ -74,10 +73,10 @@ public class IgnominiousBulbEntity extends MobEntity { } @Override - protected void initDataTracker() { - super.initDataTracker(); - dataTracker.startTracking(ANGRY, false); - dataTracker.startTracking(AGE, 0); + protected void initDataTracker(Builder builder) { + super.initDataTracker(builder); + builder.add(ANGRY, false); + builder.add(AGE, 0); } @Override @@ -102,6 +101,11 @@ public class IgnominiousBulbEntity extends MobEntity { return Math.max(0.2F, 1 - (MathHelper.clamp(MathHelper.lerp(tickDelta, prevAge, getAge()), BABY_AGE, 0F) / BABY_AGE)); } + @Override + public float getScale() { + return super.getScale() * getScale(1); + } + public boolean isAngry() { return dataTracker.get(ANGRY); } @@ -335,8 +339,8 @@ public class IgnominiousBulbEntity extends MobEntity { NbtList tentacles = new NbtList(); getTentacles().forEach((pos, tentacle) -> { var compound = new NbtCompound(); - compound.put("pos", NbtSerialisable.BLOCK_POS.write(pos)); - compound.put("target", tentacle.toNBT()); + compound.put("pos", NbtHelper.fromBlockPos(pos)); + compound.put("target", tentacle.toNBT(getWorld().getRegistryManager())); tentacles.add(compound); }); nbt.put("tentacles", tentacles); @@ -352,7 +356,9 @@ public class IgnominiousBulbEntity extends MobEntity { var tentacles = new HashMap>(); nbt.getList("tentacles", NbtElement.COMPOUND_TYPE).forEach(tag -> { var compound = (NbtCompound)tag; - tentacles.put(NbtSerialisable.BLOCK_POS.read(compound.getCompound("pos"), getWorld().getRegistryManager()), new EntityReference<>(compound.getCompound("target"), getWorld().getRegistryManager())); + NbtHelper.toBlockPos(compound, "pos").ifPresent(pos -> { + tentacles.put(pos, new EntityReference<>(compound.getCompound("target"), getWorld().getRegistryManager())); + }); }); this.tentacles = tentacles; } @@ -366,9 +372,4 @@ public class IgnominiousBulbEntity extends MobEntity { } super.onTrackedDataSet(data); } - - @Override - public EntityDimensions getDimensions(EntityPose pose) { - return EntityDimensions.changing(3, 2).scaled(getScale(1)); - } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/MimicEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/MimicEntity.java index a76e3d7d..cbfc1c6f 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/MimicEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/MimicEntity.java @@ -23,6 +23,7 @@ import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedDataHandlerRegistry; +import net.minecraft.entity.data.DataTracker.Builder; import net.minecraft.entity.mob.PathAwareEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; @@ -110,10 +111,10 @@ public class MimicEntity extends PathAwareEntity { } @Override - protected void initDataTracker() { - super.initDataTracker(); - dataTracker.startTracking(CHEST_DATA, new NbtCompound()); - dataTracker.startTracking(MOUTH_OPEN, false); + protected void initDataTracker(Builder builder) { + super.initDataTracker(builder); + builder.add(CHEST_DATA, new NbtCompound()); + builder.add(MOUTH_OPEN, false); } @Override @@ -327,7 +328,7 @@ public class MimicEntity extends PathAwareEntity { @Nullable private ChestBlockEntity readChestData(NbtCompound nbt) { BlockState state = BlockState.CODEC.decode(NbtOps.INSTANCE, nbt.getCompound("state")).result().get().getFirst(); - if (BlockEntity.createFromNbt(getBlockPos(), state, nbt.getCompound("data")) instanceof ChestBlockEntity data) { + if (BlockEntity.createFromNbt(getBlockPos(), state, nbt.getCompound("data"), getWorld().getRegistryManager()) instanceof ChestBlockEntity data) { data.setWorld(getWorld()); ((MimicGeneratable)data).setAllowMimics(false); return data; @@ -346,7 +347,7 @@ public class MimicEntity extends PathAwareEntity { @Nullable private NbtCompound writeChestData(ChestBlockEntity chestData) { NbtCompound chest = new NbtCompound(); - chest.put("data", chestData.createNbtWithId()); + chest.put("data", chestData.createNbtWithId(getWorld().getRegistryManager())); chest.put("state", BlockState.CODEC.encode(chestData.getCachedState(), NbtOps.INSTANCE, new NbtCompound()).result().get()); return chest; } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/SombraEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/SombraEntity.java index 3a0a9bac..d88b2574 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/SombraEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/SombraEntity.java @@ -56,6 +56,7 @@ import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedDataHandlerRegistry; +import net.minecraft.entity.data.DataTracker.Builder; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.mob.FlyingEntity; @@ -167,10 +168,10 @@ public class SombraEntity extends HostileEntity implements ArenaCombatant, Parti } @Override - protected void initDataTracker() { - super.initDataTracker(); - dataTracker.startTracking(HOME_POS, Optional.empty()); - dataTracker.startTracking(TARGET_SIZE, 1F); + protected void initDataTracker(Builder builder) { + super.initDataTracker(builder); + builder.add(HOME_POS, Optional.empty()); + builder.add(TARGET_SIZE, 1F); } @Override @@ -236,6 +237,10 @@ public class SombraEntity extends HostileEntity implements ArenaCombatant, Parti dataTracker.set(HOME_POS, Optional.of(pos)); } + public void setHomePos(Optional pos) { + dataTracker.set(HOME_POS, pos); + } + public float getBiteAmount(float tickDelta) { float progress = (MathHelper.lerp(tickDelta, prevBiteTime, biteTime) / (float)MAX_BITE_TIME); return 1 - Math.abs(MathHelper.sin(progress * MathHelper.PI * 3)); @@ -533,8 +538,8 @@ public class SombraEntity extends HostileEntity implements ArenaCombatant, Parti } @Override - protected void dropEquipment(DamageSource source, int lootingMultiplier, boolean allowDrops) { - super.dropEquipment(source, lootingMultiplier, allowDrops); + protected void dropEquipment(ServerWorld world, DamageSource source, boolean causedByPlayer) { + super.dropEquipment(world, source, causedByPlayer); ItemEntity itemEntity = dropItem(UItems.BROKEN_ALICORN_AMULET); if (itemEntity != null) { itemEntity.setCovetedItem(); @@ -671,7 +676,7 @@ public class SombraEntity extends HostileEntity implements ArenaCombatant, Parti getHomePos().map(NbtHelper::fromBlockPos).ifPresent(pos -> { nbt.put("homePos", pos); }); - nbt.put("cloud", stormCloud.toNBT()); + nbt.put("cloud", stormCloud.toNBT(getWorld().getRegistryManager())); nbt.putFloat("size", getScaleFactor()); } @@ -679,13 +684,13 @@ public class SombraEntity extends HostileEntity implements ArenaCombatant, Parti public void readCustomDataFromNbt(NbtCompound nbt) { super.readCustomDataFromNbt(nbt); if (nbt.contains("homePos", NbtElement.COMPOUND_TYPE)) { - setHomePos(NbtHelper.toBlockPos(nbt.getCompound("homePos"))); + setHomePos(NbtHelper.toBlockPos(nbt, "homePos")); } if (hasCustomName()) { bossBar.setName(getDisplayName()); } setScaleFactor(nbt.getFloat("size")); - stormCloud.fromNBT(nbt.getCompound("cloud")); + stormCloud.fromNBT(nbt.getCompound("cloud"), getWorld().getRegistryManager()); } private static class SombraBossBar extends ServerBossBar { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/SpecterEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/SpecterEntity.java index 41dc5a4b..765819ae 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/SpecterEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/SpecterEntity.java @@ -24,7 +24,6 @@ import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.mob.HostileEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Items; -import net.minecraft.nbt.NbtCompound; import net.minecraft.particle.BlockStateParticleEffect; import net.minecraft.particle.ParticleTypes; import net.minecraft.registry.tag.BlockTags; @@ -135,8 +134,8 @@ public class SpecterEntity extends HostileEntity { @Nullable @Override - public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData data, @Nullable NbtCompound entityNbt) { - data = super.initialize(world, difficulty, spawnReason, data, entityNbt); + public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData data) { + data = super.initialize(world, difficulty, spawnReason, data); Random random = world.getRandom(); float diff = difficulty.getClampedLocalDifficulty(); setCanPickUpLoot(random.nextFloat() < 0.55F * diff); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/SpellbookEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/SpellbookEntity.java index daa910c3..6405cdde 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/SpellbookEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/SpellbookEntity.java @@ -391,7 +391,7 @@ public class SpellbookEntity extends MobEntity implements MagicImmune { activeTicks = compound.getInt("activeTicks"); setAltered(compound.getBoolean("altered")); setForcedState(compound.contains("locked") ? TriState.of(compound.getBoolean("locked")) : TriState.DEFAULT); - state.fromNBT(compound.getCompound("spellbookState"), getWorld().getRegistryManager()); + setSpellbookState(NbtSerialisable.decode(SpellbookState.CODEC, compound.getCompound("spellbookState")).orElse(new SpellbookState())); altar = NbtSerialisable.decode(Altar.CODEC, compound.get("altar")); } @@ -401,7 +401,7 @@ public class SpellbookEntity extends MobEntity implements MagicImmune { compound.putInt("activeTicks", activeTicks); compound.putBoolean("prevDaytime", prevDaytime); compound.putBoolean("altered", isAltered()); - compound.put("spellbookState", state.toNBT(getWorld().getRegistryManager())); + compound.put("spellbookState", NbtSerialisable.encode(SpellbookState.CODEC, state)); getForcedState().map(t -> { compound.putBoolean("locked", t); return null; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/StationaryObjectEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/StationaryObjectEntity.java index 8b0c61e8..2b5f5c49 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/StationaryObjectEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/StationaryObjectEntity.java @@ -13,6 +13,8 @@ import net.minecraft.nbt.NbtElement; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; +import static net.minecraft.entity.data.DataTracker.Builder;; + public abstract class StationaryObjectEntity extends Entity implements UDamageSources, MagicImmune { private static final TrackedData HEALTH = DataTracker.registerData(StationaryObjectEntity.class, TrackedDataHandlerRegistry.FLOAT); @@ -21,8 +23,8 @@ public abstract class StationaryObjectEntity extends Entity implements UDamageSo } @Override - protected void initDataTracker() { - dataTracker.startTracking(HEALTH, getMaxHealth()); + protected void initDataTracker(Builder builder) { + builder.add(HEALTH, getMaxHealth()); } public abstract float getMaxHealth(); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/TentacleEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/TentacleEntity.java index e22cd79a..b8ba09d7 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/TentacleEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/TentacleEntity.java @@ -20,6 +20,7 @@ import net.minecraft.entity.damage.DamageTypes; import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedDataHandlerRegistry; +import net.minecraft.entity.data.DataTracker.Builder; import net.minecraft.entity.decoration.AbstractDecorationEntity; import net.minecraft.entity.mob.HostileEntity; import net.minecraft.entity.player.PlayerEntity; @@ -31,6 +32,7 @@ import net.minecraft.util.Hand; import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; +import net.minecraft.util.math.Direction; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.world.RaycastContext; @@ -69,10 +71,9 @@ public class TentacleEntity extends AbstractDecorationEntity { } @Override - protected void initDataTracker() { - super.initDataTracker(); - dataTracker.startTracking(GROWTH, 0); - dataTracker.startTracking(MOTION_OFFSET, 0); + protected void initDataTracker(Builder builder) { + builder.add(GROWTH, 0); + builder.add(MOTION_OFFSET, 0); } public void setBulb(IgnominiousBulbEntity bulb) { @@ -130,16 +131,6 @@ public class TentacleEntity extends AbstractDecorationEntity { return attackingTicks > 0; } - @Override - public int getWidthPixels() { - return 9; - } - - @Override - public int getHeightPixels() { - return 9; - } - @Override public boolean damage(DamageSource source, float amount) { if (source.getAttacker() instanceof PlayerEntity player) { @@ -319,11 +310,9 @@ public class TentacleEntity extends AbstractDecorationEntity { } @Override - protected void updateAttachmentPosition() { + protected Box calculateBoundingBox(BlockPos pos, Direction side) { visibilityBox = null; - Vec3d pos = attachedBlockPos.toCenterPos(); - setPos(pos.x, pos.y, pos.z); - setBoundingBox(Box.of(pos, 1, 1, 1).stretch(0, 2, 0)); + return Box.of(pos.toCenterPos(), 1, 1, 1).stretch(0, 2, 0); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/UTradeOffers.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/UTradeOffers.java index 74e38429..3c2d6799 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/UTradeOffers.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/UTradeOffers.java @@ -1,5 +1,7 @@ package com.minelittlepony.unicopia.entity.mob; +import java.util.Optional; + import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.UTags; @@ -19,6 +21,7 @@ import net.minecraft.util.Util; import net.minecraft.util.math.random.Random; import net.minecraft.village.TradeOffer; import net.minecraft.village.TradeOffers; +import net.minecraft.village.TradedItem; import net.minecraft.village.VillagerProfession; public interface UTradeOffers { @@ -41,7 +44,7 @@ public interface UTradeOffers { TradeOfferHelper.registerWanderingTraderOffers(1, factories -> { factories.add(buyTiered(UItems.GEMSTONE, 30, UItems.GOLDEN_FEATHER, 1, UItems.GOLDEN_WING, 1, 30, 2, 0.05F)); - factories.add((e, rng) -> new TradeOffer(new ItemStack(UItems.GEMSTONE, 3), EnchantableItem.enchant(UItems.GEMSTONE.getDefaultStack(), SpellType.REGISTRY.getRandom(rng).get().value()), 20, 1, 0.05F)); + factories.add((e, rng) -> new TradeOffer(new TradedItem(UItems.GEMSTONE, 3), EnchantableItem.enchant(UItems.GEMSTONE.getDefaultStack(), SpellType.REGISTRY.getRandom(rng).get().value()), 20, 1, 0.05F)); factories.add(buy(UItems.GEMSTONE, 20, UItems.HAY_FRIES, 5, 50, 3, 0.06F)); factories.add(buy(Items.WHEAT, 17, UItems.HAY_BURGER, 1, 10, 6, 0.08F)); factories.add(buy(ItemTags.SMALL_FLOWERS, 2, UItems.DAFFODIL_DAISY_SANDWICH, 1, 10, 6, 0.08F)); @@ -64,19 +67,19 @@ public interface UTradeOffers { } private static TradeOffers.Factory buy(Item item, int count, Item returnItem, int returnCount, int maxUses, int experience, float priceChange) { - return (e, rng) -> new TradeOffer(new ItemStack(item, count), new ItemStack(returnItem, returnCount), maxUses, experience, priceChange); + return (e, rng) -> new TradeOffer(new TradedItem(item, count), new ItemStack(returnItem, returnCount), maxUses, experience, priceChange); } private static TradeOffers.Factory buyTiered(Item item, int count, Item intermediate, int intermediatCount, Item returnItem, int returnCount, int maxUses, int experience, float priceChange) { - return (e, rng) -> new TradeOffer(new ItemStack(item, count), new ItemStack(intermediate, intermediatCount), new ItemStack(returnItem, returnCount), maxUses, experience, priceChange); + return (e, rng) -> new TradeOffer(new TradedItem(item, count), Optional.of(new TradedItem(intermediate, intermediatCount)), new ItemStack(returnItem, returnCount), maxUses, experience, priceChange); } private static TradeOffers.Factory buy(TagKey item, int count, Item returnItem, int returnCount, int maxUses, int experience, float priceChange) { - return (e, rng) -> new TradeOffer(new ItemStack(random(e, item, rng), count), new ItemStack(returnItem, returnCount), maxUses, experience, priceChange); + return (e, rng) -> new TradeOffer(new TradedItem(random(e, item, rng), count), new ItemStack(returnItem, returnCount), maxUses, experience, priceChange); } private static TradeOffers.Factory buy(Item item, int count, TagKey returnItem, int returnCount, int maxUses, int experience, float priceChange) { - return (e, rng) -> new TradeOffer(new ItemStack(item, count), new ItemStack(random(e, returnItem, rng), returnCount), maxUses, experience, priceChange); + return (e, rng) -> new TradeOffer(new TradedItem(item, count), new ItemStack(random(e, returnItem, rng), returnCount), maxUses, experience, priceChange); } private static Item random(Entity e, TagKey item, Random rng) { @@ -95,7 +98,12 @@ public interface UTradeOffers { TradeOffer offer = factory.create(entity, rng); - return new TradeOffer(offer.getOriginalFirstBuyItem(), offer.getSecondBuyItem(), UItems.FILLED_JAR.withContents(offer.getSellItem()), offer.getUses(), offer.getMaxUses(), offer.getMerchantExperience(), offer.getPriceMultiplier(), offer.getDemandBonus()); + return new TradeOffer( + offer.getFirstBuyItem(), + offer.getSecondBuyItem(), + UItems.FILLED_JAR.withContents(offer.getSellItem()), + offer.getUses(), offer.getMaxUses(), offer.getMerchantExperience(), offer.getPriceMultiplier(), offer.getDemandBonus() + ); } } }