Fix errors in entity classes

This commit is contained in:
Sollace 2024-09-29 21:38:01 +01:00
parent 98eff467c4
commit 654562014e
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
14 changed files with 140 additions and 138 deletions

View file

@ -1,11 +1,12 @@
package com.minelittlepony.unicopia.entity.mob; 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.BlockState;
import net.minecraft.block.ShapeContext; import net.minecraft.block.ShapeContext;
import net.minecraft.block.entity.FurnaceBlockEntity; import net.minecraft.block.entity.FurnaceBlockEntity;
import net.minecraft.entity.*; import net.minecraft.entity.*;
import net.minecraft.entity.data.*; import net.minecraft.entity.data.*;
import net.minecraft.entity.data.DataTracker.Builder;
import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.vehicle.BoatEntity; import net.minecraft.entity.vehicle.BoatEntity;
@ -93,13 +94,13 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp
} }
@Override @Override
protected void initDataTracker() { protected void initDataTracker(Builder builder) {
super.initDataTracker(); super.initDataTracker(builder);
dataTracker.startTracking(ASCENDING, false); builder.add(ASCENDING, false);
dataTracker.startTracking(BOOSTING, 0); builder.add(BOOSTING, 0);
dataTracker.startTracking(INFLATION, 0); builder.add(INFLATION, 0);
dataTracker.startTracking(BASKET_TYPE, BasketType.DEFAULT.id().toString()); builder.add(BASKET_TYPE, BasketType.DEFAULT.id().toString());
dataTracker.startTracking(BALLOON_DESIGN, 0); builder.add(BALLOON_DESIGN, 0);
} }
public BasketType getBasketType() { public BasketType getBasketType() {
@ -269,7 +270,7 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp
} }
if (isLeashed()) { if (isLeashed()) {
Vec3d leashPost = getHoldingEntity().getPos(); Vec3d leashPost = getLeashHolder().getPos();
Vec3d pos = getPos(); Vec3d pos = getPos();
if (leashPost.distanceTo(pos) >= 5) { if (leashPost.distanceTo(pos) >= 5) {
@ -313,7 +314,7 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp
if (isAscending()) { if (isAscending()) {
playSound(USounds.ENTITY_HOT_AIR_BALLOON_BOOST, 1, 1); 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); playSound(USounds.Vanilla.ITEM_FLINTANDSTEEL_USE, 1, 1);
if (!player.isSneaky()) { if (!player.isSneaky()) {
getWorld().emitGameEvent(player, GameEvent.ENTITY_INTERACT, getBlockPos()); getWorld().emitGameEvent(player, GameEvent.ENTITY_INTERACT, getBlockPos());
@ -370,7 +371,7 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp
if (!player.getAbilities().creativeMode) { if (!player.getAbilities().creativeMode) {
stack.decrement(1); 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()) { if (!player.isSneaky()) {
getWorld().emitGameEvent(player, GameEvent.EQUIP, getBlockPos()); getWorld().emitGameEvent(player, GameEvent.EQUIP, getBlockPos());
} }
@ -381,11 +382,11 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp
return ActionResult.SUCCESS; return ActionResult.SUCCESS;
} }
if (stack.isIn(ConventionalItemTags.SHEARS) && hasBalloon()) { if (stack.isIn(ConventionalItemTags.SHEAR_TOOLS) && hasBalloon()) {
stack.damage(1, player, p -> p.sendToolBreakStatus(hand)); stack.damage(1, player, getSlotForHand(hand));
setDesign(BalloonDesign.NONE); setDesign(BalloonDesign.NONE);
dropItem(UItems.GIANT_BALLOON); 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()) { if (!player.isSneaky()) {
getWorld().emitGameEvent(player, GameEvent.EQUIP, getBlockPos()); 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) { 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<TerraformBoatType> id) { public static BasketType of(RegistryKey<TerraformBoatType> id) {

View file

@ -28,6 +28,7 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry; import net.minecraft.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.entity.data.DataTracker.Builder;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
@ -76,7 +77,7 @@ public class CastSpellEntity extends LightEmittingEntity implements Caster<CastS
delegate.onPlaced(caster, control); delegate.onPlaced(caster, control);
} }
spells.getSlots().put(Spell.copy(control.getDelegate())); spells.getSlots().put(Spell.copy(control.getDelegate(), world.getRegistryManager()));
} }
public CastSpellEntity(EntityType<?> type, World world) { public CastSpellEntity(EntityType<?> type, World world) {
@ -86,12 +87,12 @@ public class CastSpellEntity extends LightEmittingEntity implements Caster<CastS
} }
@Override @Override
protected void initDataTracker() { protected void initDataTracker(Builder builder) {
dataTracker.startTracking(LEVEL, 0); builder.add(LEVEL, 0);
dataTracker.startTracking(CORRUPTION, 0); builder.add(CORRUPTION, 0);
dataTracker.startTracking(MAX_LEVEL, 1); builder.add(MAX_LEVEL, 1);
dataTracker.startTracking(MAX_CORRUPTION, 1); builder.add(MAX_CORRUPTION, 1);
dataTracker.startTracking(DEAD, false); builder.add(DEAD, false);
} }
@Override @Override
@ -246,11 +247,11 @@ public class CastSpellEntity extends LightEmittingEntity implements Caster<CastS
tag.putUuid("owningSpell", controllingSpellUuid); tag.putUuid("owningSpell", controllingSpellUuid);
} }
spells.getSlots().toNBT(tag); spells.getSlots().toNBT(tag, getWorld().getRegistryManager());
tag.putInt("age", age); tag.putInt("age", age);
tag.putInt("prevAge", prevAge); tag.putInt("prevAge", prevAge);
tag.putBoolean("dead", isDead()); tag.putBoolean("dead", isDead());
tag.put("owner", owner.toNBT()); tag.put("owner", owner.toNBT(getWorld().getRegistryManager()));
} }
@Override @Override
@ -265,13 +266,13 @@ public class CastSpellEntity extends LightEmittingEntity implements Caster<CastS
controllingEntityUuid = tag.containsUuid("owningEntity") ? tag.getUuid("owningEntity") : null; controllingEntityUuid = tag.containsUuid("owningEntity") ? tag.getUuid("owningEntity") : null;
controllingSpellUuid = tag.containsUuid("owningSpell") ? tag.getUuid("owningSpell") : null; controllingSpellUuid = tag.containsUuid("owningSpell") ? tag.getUuid("owningSpell") : null;
spells.getSlots().fromNBT(tag); spells.getSlots().fromNBT(tag, getWorld().getRegistryManager());
age = tag.getInt("age"); age = tag.getInt("age");
prevAge = tag.getInt("prevAge"); prevAge = tag.getInt("prevAge");
setDead(tag.getBoolean("dead")); setDead(tag.getBoolean("dead"));
if (tag.contains("owner")) { if (tag.contains("owner")) {
owner.fromNBT(tag.getCompound("owner")); owner.fromNBT(tag.getCompound("owner"), getWorld().getRegistryManager());
} }
} }
} }

View file

@ -17,6 +17,7 @@ import net.minecraft.entity.EntityType;
import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry; import net.minecraft.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.entity.data.DataTracker.Builder;
import net.minecraft.fluid.Fluids; import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
@ -91,12 +92,12 @@ public class CrystalShardsEntity extends StationaryObjectEntity {
} }
@Override @Override
protected void initDataTracker() { protected void initDataTracker(Builder builder) {
super.initDataTracker(); super.initDataTracker(builder);
dataTracker.startTracking(ATTACHMENT_FACE, Direction.UP); builder.add(ATTACHMENT_FACE, Direction.UP);
dataTracker.startTracking(GROWTH, 0); builder.add(GROWTH, 0);
dataTracker.startTracking(DECAYING, false); builder.add(DECAYING, false);
dataTracker.startTracking(CORRUPT, false); builder.add(CORRUPT, false);
} }
@Override @Override

View file

@ -72,11 +72,6 @@ public class FairyEntity extends PathAwareEntity implements DynamicLightSource,
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.25); .add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.25);
} }
@Override
protected void initDataTracker() {
super.initDataTracker();
}
@Override @Override
protected void initGoals() { protected void initGoals() {
goalSelector.add(5, new StayGoal()); goalSelector.add(5, new StayGoal());
@ -225,7 +220,7 @@ public class FairyEntity extends PathAwareEntity implements DynamicLightSource,
@Override @Override
public void writeCustomDataToNbt(NbtCompound tag) { public void writeCustomDataToNbt(NbtCompound tag) {
super.writeCustomDataToNbt(tag); super.writeCustomDataToNbt(tag);
tag.put("owner", owner.toNBT()); tag.put("owner", owner.toNBT(getWorld().getRegistryManager()));
stayingPos.ifPresent(pos -> { stayingPos.ifPresent(pos -> {
tag.put("stayingPos", NbtHelper.fromBlockPos(pos)); tag.put("stayingPos", NbtHelper.fromBlockPos(pos));
}); });
@ -235,9 +230,9 @@ public class FairyEntity extends PathAwareEntity implements DynamicLightSource,
public void readCustomDataFromNbt(NbtCompound tag) { public void readCustomDataFromNbt(NbtCompound tag) {
super.readCustomDataFromNbt(tag); super.readCustomDataFromNbt(tag);
if (tag.contains("owner")) { 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 { class FollowEntityGoal extends Goal {
@ -308,7 +303,7 @@ public class FairyEntity extends PathAwareEntity implements DynamicLightSource,
double speed = this.speed; double speed = this.speed;
if (distance > 100) { if (distance > 100) {
teleport( setPosition(
target.getX() + getWorld().random.nextFloat() / 2F - 0.5F, target.getX() + getWorld().random.nextFloat() / 2F - 0.5F,
target.getEyeY(), target.getEyeY(),
target.getZ() + getWorld().random.nextFloat() / 2F - 0.5F target.getZ() + getWorld().random.nextFloat() / 2F - 0.5F

View file

@ -5,12 +5,14 @@ import java.util.Optional;
import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.server.world.Altar; import com.minelittlepony.unicopia.server.world.Altar;
import com.minelittlepony.unicopia.util.NbtSerialisable;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry; import net.minecraft.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.entity.data.DataTracker.Builder;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.Text; import net.minecraft.text.Text;
@ -55,11 +57,11 @@ public class FloatingArtefactEntity extends StationaryObjectEntity {
} }
@Override @Override
protected void initDataTracker() { protected void initDataTracker(Builder builder) {
super.initDataTracker(); super.initDataTracker(builder);
dataTracker.startTracking(ITEM, ItemStack.EMPTY); builder.add(ITEM, ItemStack.EMPTY);
dataTracker.startTracking(STATE, (byte)0); builder.add(STATE, (byte)0);
dataTracker.startTracking(TARGET_ROTATION_SPEED, 1F); builder.add(TARGET_ROTATION_SPEED, 1F);
} }
public void setAltar(Altar altar) { public void setAltar(Altar altar) {
@ -159,11 +161,11 @@ public class FloatingArtefactEntity extends StationaryObjectEntity {
@Override @Override
protected void readCustomDataFromNbt(NbtCompound compound) { protected void readCustomDataFromNbt(NbtCompound compound) {
super.readCustomDataFromNbt(compound); super.readCustomDataFromNbt(compound);
setStack(ItemStack.fromNbt(compound.getCompound("Item"))); setStack(ItemStack.fromNbtOrEmpty(getWorld().getRegistryManager(), compound.getCompound("Item")));
setState(State.valueOf(compound.getInt("State"))); setState(State.valueOf(compound.getInt("State")));
setRotationSpeed(compound.getFloat("spin"), compound.getInt("spinDuration")); setRotationSpeed(compound.getFloat("spin"), compound.getInt("spinDuration"));
ticksUntilRegen = compound.getInt("regen"); ticksUntilRegen = compound.getInt("regen");
altar = Altar.SERIALIZER.readOptional("altar", compound); altar = NbtSerialisable.decode(Altar.CODEC, compound.get("altar"));
} }
@Override @Override
@ -171,13 +173,13 @@ public class FloatingArtefactEntity extends StationaryObjectEntity {
super.writeCustomDataToNbt(compound); super.writeCustomDataToNbt(compound);
ItemStack stack = getStack(); ItemStack stack = getStack();
if (!stack.isEmpty()) { if (!stack.isEmpty()) {
compound.put("Item", stack.writeNbt(new NbtCompound())); compound.put("Item", NbtSerialisable.encode(ItemStack.CODEC, stack));
} }
compound.putInt("State", getState().ordinal()); compound.putInt("State", getState().ordinal());
compound.putFloat("spin", getRotationSpeed()); compound.putFloat("spin", getRotationSpeed());
compound.putInt("spinDuration", boostDuration); compound.putInt("spinDuration", boostDuration);
compound.putInt("regen", ticksUntilRegen); compound.putInt("regen", ticksUntilRegen);
Altar.SERIALIZER.writeOptional("altar", compound, altar); altar.ifPresent(altar -> compound.put("altar", NbtSerialisable.encode(Altar.CODEC, altar)));
} }
@Override @Override
@ -187,7 +189,7 @@ public class FloatingArtefactEntity extends StationaryObjectEntity {
return false; return false;
} }
if (isInvulnerableTo(source) || !getStack().getItem().damage(source)) { if (isInvulnerableTo(source) || !getStack().takesDamageFrom(source)) {
return false; return false;
} }

View file

@ -3,8 +3,6 @@ package com.minelittlepony.unicopia.entity.mob;
import java.util.Collection; import java.util.Collection;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.UUID; import java.util.UUID;
import java.util.function.Consumer;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.entity.Creature; 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 com.minelittlepony.unicopia.entity.behaviour.Guest;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.client.render.entity.feature.SkinOverlayOwner;
import net.minecraft.entity.AreaEffectCloudEntity; import net.minecraft.entity.AreaEffectCloudEntity;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityStatuses; import net.minecraft.entity.EntityStatuses;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.entity.LightningEntity; import net.minecraft.entity.LightningEntity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SkinOverlayOwner;
import net.minecraft.entity.ai.goal.ActiveTargetGoal; import net.minecraft.entity.ai.goal.ActiveTargetGoal;
import net.minecraft.entity.ai.goal.AttackWithOwnerGoal; import net.minecraft.entity.ai.goal.AttackWithOwnerGoal;
import net.minecraft.entity.ai.goal.EscapeDangerGoal; 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.DataTracker;
import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry; import net.minecraft.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.entity.data.DataTracker.Builder;
import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.mob.AbstractSkeletonEntity; import net.minecraft.entity.mob.AbstractSkeletonEntity;
import net.minecraft.entity.mob.Angerable; 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.MathHelper;
import net.minecraft.util.math.intprovider.UniformIntProvider; import net.minecraft.util.math.intprovider.UniformIntProvider;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
import net.minecraft.world.EntityView;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent; import net.minecraft.world.event.GameEvent;
import net.minecraft.world.explosion.Explosion; import net.minecraft.world.explosion.Explosion;
@ -90,20 +88,23 @@ public class FriendlyCreeperEntity extends TameableEntity implements SkinOverlay
private short hugTime; private short hugTime;
private short lastHugTime; private short lastHugTime;
@Nullable
private UUID angerTarget;
protected FriendlyCreeperEntity(EntityType<? extends FriendlyCreeperEntity> type, World world) { protected FriendlyCreeperEntity(EntityType<? extends FriendlyCreeperEntity> type, World world) {
super(type, world); super(type, world);
setTamed(false); setTamed(false, true);
setPathfindingPenalty(PathNodeType.POWDER_SNOW, -1); setPathfindingPenalty(PathNodeType.POWDER_SNOW, -1);
setPathfindingPenalty(PathNodeType.DANGER_POWDER_SNOW, -1); setPathfindingPenalty(PathNodeType.DANGER_POWDER_SNOW, -1);
} }
@Override @Override
protected void initDataTracker() { protected void initDataTracker(Builder builder) {
super.initDataTracker(); super.initDataTracker(builder);
dataTracker.startTracking(FUSE_SPEED, -1); builder.add(FUSE_SPEED, -1);
dataTracker.startTracking(CHARGED, false); builder.add(CHARGED, false);
dataTracker.startTracking(IGNITED, false); builder.add(IGNITED, false);
dataTracker.startTracking(ANGER_TIME, 0); builder.add(ANGER_TIME, 0);
} }
@Override @Override
@ -271,8 +272,8 @@ public class FriendlyCreeperEntity extends TameableEntity implements SkinOverlay
} }
@Override @Override
protected void dropEquipment(DamageSource source, int lootingMultiplier, boolean allowDrops) { protected void dropEquipment(ServerWorld world, DamageSource source, boolean causedByPlayer) {
super.dropEquipment(source, lootingMultiplier, allowDrops); super.dropEquipment(world, source, causedByPlayer);
if (source.getAttacker() instanceof CreeperEntity c && c.shouldDropHead()) { if (source.getAttacker() instanceof CreeperEntity c && c.shouldDropHead()) {
c.onHeadDropped(); c.onHeadDropped();
dropItem(Items.CREEPER_HEAD); dropItem(Items.CREEPER_HEAD);
@ -308,12 +309,16 @@ public class FriendlyCreeperEntity extends TameableEntity implements SkinOverlay
dataTracker.set(CHARGED, true); dataTracker.set(CHARGED, true);
} }
@Override
public boolean isBreedingItem(ItemStack stack) {
return stack.isOf(Items.GUNPOWDER);
}
@Override @Override
public ActionResult interactMob(PlayerEntity player, Hand hand) { public ActionResult interactMob(PlayerEntity player, Hand hand) {
ItemStack stack = player.getStackInHand(hand); ItemStack stack = player.getStackInHand(hand);
Consumer<PlayerEntity> statusCallback = p -> p.sendToolBreakStatus(hand);
if (stack.isEmpty() && isOwner(player)) { if (stack.isEmpty() && isOwner(player)) {
setSitting(!isSitting()); setSitting(!isSitting());
setInSittingPose(isSitting()); setInSittingPose(isSitting());
@ -329,7 +334,7 @@ public class FriendlyCreeperEntity extends TameableEntity implements SkinOverlay
if (!stack.isDamageable()) { if (!stack.isDamageable()) {
stack.decrement(1); stack.decrement(1);
} else { } 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()) { if (!stack.isDamageable()) {
stack.decrement(1); stack.decrement(1);
} else { } else {
stack.damage(1, player, statusCallback); stack.damage(1, player, getSlotForHand(hand));
} }
} }
@ -405,25 +410,17 @@ public class FriendlyCreeperEntity extends TameableEntity implements SkinOverlay
headsDropped++; headsDropped++;
} }
@Override
public EntityView method_48926() {
return getWorld();
}
@Override @Override
public PassiveEntity createChild(ServerWorld world, PassiveEntity partner) { public PassiveEntity createChild(ServerWorld world, PassiveEntity partner) {
FriendlyCreeperEntity child = (FriendlyCreeperEntity)getType().create(world); FriendlyCreeperEntity child = (FriendlyCreeperEntity)getType().create(world);
UUID uUID = getOwnerUuid(); UUID uUID = getOwnerUuid();
if (uUID != null) { if (uUID != null) {
child.setOwnerUuid(uUID); child.setOwnerUuid(uUID);
child.setTamed(true); child.setTamed(true, true);
} }
return child; return child;
} }
@Nullable
private UUID angerTarget;
@Override @Override
public int getAngerTime() { public int getAngerTime() {
return dataTracker.get(ANGER_TIME); return dataTracker.get(ANGER_TIME);

View file

@ -12,13 +12,10 @@ import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.entity.EntityReference; import com.minelittlepony.unicopia.entity.EntityReference;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.NbtSerialisable;
import com.minelittlepony.unicopia.util.VecHelper; import com.minelittlepony.unicopia.util.VecHelper;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityPose;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.MovementType; 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.DataTracker;
import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry; import net.minecraft.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.entity.data.DataTracker.Builder;
import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.passive.PassiveEntity; import net.minecraft.entity.passive.PassiveEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
@ -33,6 +31,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.nbt.NbtList; import net.minecraft.nbt.NbtList;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.predicate.entity.EntityPredicates;
@ -74,10 +73,10 @@ public class IgnominiousBulbEntity extends MobEntity {
} }
@Override @Override
protected void initDataTracker() { protected void initDataTracker(Builder builder) {
super.initDataTracker(); super.initDataTracker(builder);
dataTracker.startTracking(ANGRY, false); builder.add(ANGRY, false);
dataTracker.startTracking(AGE, 0); builder.add(AGE, 0);
} }
@Override @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)); 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() { public boolean isAngry() {
return dataTracker.get(ANGRY); return dataTracker.get(ANGRY);
} }
@ -335,8 +339,8 @@ public class IgnominiousBulbEntity extends MobEntity {
NbtList tentacles = new NbtList(); NbtList tentacles = new NbtList();
getTentacles().forEach((pos, tentacle) -> { getTentacles().forEach((pos, tentacle) -> {
var compound = new NbtCompound(); var compound = new NbtCompound();
compound.put("pos", NbtSerialisable.BLOCK_POS.write(pos)); compound.put("pos", NbtHelper.fromBlockPos(pos));
compound.put("target", tentacle.toNBT()); compound.put("target", tentacle.toNBT(getWorld().getRegistryManager()));
tentacles.add(compound); tentacles.add(compound);
}); });
nbt.put("tentacles", tentacles); nbt.put("tentacles", tentacles);
@ -352,7 +356,9 @@ public class IgnominiousBulbEntity extends MobEntity {
var tentacles = new HashMap<BlockPos, EntityReference<TentacleEntity>>(); var tentacles = new HashMap<BlockPos, EntityReference<TentacleEntity>>();
nbt.getList("tentacles", NbtElement.COMPOUND_TYPE).forEach(tag -> { nbt.getList("tentacles", NbtElement.COMPOUND_TYPE).forEach(tag -> {
var compound = (NbtCompound)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; this.tentacles = tentacles;
} }
@ -366,9 +372,4 @@ public class IgnominiousBulbEntity extends MobEntity {
} }
super.onTrackedDataSet(data); super.onTrackedDataSet(data);
} }
@Override
public EntityDimensions getDimensions(EntityPose pose) {
return EntityDimensions.changing(3, 2).scaled(getScale(1));
}
} }

View file

@ -23,6 +23,7 @@ import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry; import net.minecraft.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.entity.data.DataTracker.Builder;
import net.minecraft.entity.mob.PathAwareEntity; import net.minecraft.entity.mob.PathAwareEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
@ -110,10 +111,10 @@ public class MimicEntity extends PathAwareEntity {
} }
@Override @Override
protected void initDataTracker() { protected void initDataTracker(Builder builder) {
super.initDataTracker(); super.initDataTracker(builder);
dataTracker.startTracking(CHEST_DATA, new NbtCompound()); builder.add(CHEST_DATA, new NbtCompound());
dataTracker.startTracking(MOUTH_OPEN, false); builder.add(MOUTH_OPEN, false);
} }
@Override @Override
@ -327,7 +328,7 @@ public class MimicEntity extends PathAwareEntity {
@Nullable @Nullable
private ChestBlockEntity readChestData(NbtCompound nbt) { private ChestBlockEntity readChestData(NbtCompound nbt) {
BlockState state = BlockState.CODEC.decode(NbtOps.INSTANCE, nbt.getCompound("state")).result().get().getFirst(); 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()); data.setWorld(getWorld());
((MimicGeneratable)data).setAllowMimics(false); ((MimicGeneratable)data).setAllowMimics(false);
return data; return data;
@ -346,7 +347,7 @@ public class MimicEntity extends PathAwareEntity {
@Nullable @Nullable
private NbtCompound writeChestData(ChestBlockEntity chestData) { private NbtCompound writeChestData(ChestBlockEntity chestData) {
NbtCompound chest = new NbtCompound(); 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()); chest.put("state", BlockState.CODEC.encode(chestData.getCachedState(), NbtOps.INSTANCE, new NbtCompound()).result().get());
return chest; return chest;
} }

View file

@ -56,6 +56,7 @@ import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry; import net.minecraft.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.entity.data.DataTracker.Builder;
import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.mob.FlyingEntity; import net.minecraft.entity.mob.FlyingEntity;
@ -167,10 +168,10 @@ public class SombraEntity extends HostileEntity implements ArenaCombatant, Parti
} }
@Override @Override
protected void initDataTracker() { protected void initDataTracker(Builder builder) {
super.initDataTracker(); super.initDataTracker(builder);
dataTracker.startTracking(HOME_POS, Optional.empty()); builder.add(HOME_POS, Optional.empty());
dataTracker.startTracking(TARGET_SIZE, 1F); builder.add(TARGET_SIZE, 1F);
} }
@Override @Override
@ -236,6 +237,10 @@ public class SombraEntity extends HostileEntity implements ArenaCombatant, Parti
dataTracker.set(HOME_POS, Optional.of(pos)); dataTracker.set(HOME_POS, Optional.of(pos));
} }
public void setHomePos(Optional<BlockPos> pos) {
dataTracker.set(HOME_POS, pos);
}
public float getBiteAmount(float tickDelta) { public float getBiteAmount(float tickDelta) {
float progress = (MathHelper.lerp(tickDelta, prevBiteTime, biteTime) / (float)MAX_BITE_TIME); float progress = (MathHelper.lerp(tickDelta, prevBiteTime, biteTime) / (float)MAX_BITE_TIME);
return 1 - Math.abs(MathHelper.sin(progress * MathHelper.PI * 3)); return 1 - Math.abs(MathHelper.sin(progress * MathHelper.PI * 3));
@ -533,8 +538,8 @@ public class SombraEntity extends HostileEntity implements ArenaCombatant, Parti
} }
@Override @Override
protected void dropEquipment(DamageSource source, int lootingMultiplier, boolean allowDrops) { protected void dropEquipment(ServerWorld world, DamageSource source, boolean causedByPlayer) {
super.dropEquipment(source, lootingMultiplier, allowDrops); super.dropEquipment(world, source, causedByPlayer);
ItemEntity itemEntity = dropItem(UItems.BROKEN_ALICORN_AMULET); ItemEntity itemEntity = dropItem(UItems.BROKEN_ALICORN_AMULET);
if (itemEntity != null) { if (itemEntity != null) {
itemEntity.setCovetedItem(); itemEntity.setCovetedItem();
@ -671,7 +676,7 @@ public class SombraEntity extends HostileEntity implements ArenaCombatant, Parti
getHomePos().map(NbtHelper::fromBlockPos).ifPresent(pos -> { getHomePos().map(NbtHelper::fromBlockPos).ifPresent(pos -> {
nbt.put("homePos", pos); nbt.put("homePos", pos);
}); });
nbt.put("cloud", stormCloud.toNBT()); nbt.put("cloud", stormCloud.toNBT(getWorld().getRegistryManager()));
nbt.putFloat("size", getScaleFactor()); nbt.putFloat("size", getScaleFactor());
} }
@ -679,13 +684,13 @@ public class SombraEntity extends HostileEntity implements ArenaCombatant, Parti
public void readCustomDataFromNbt(NbtCompound nbt) { public void readCustomDataFromNbt(NbtCompound nbt) {
super.readCustomDataFromNbt(nbt); super.readCustomDataFromNbt(nbt);
if (nbt.contains("homePos", NbtElement.COMPOUND_TYPE)) { if (nbt.contains("homePos", NbtElement.COMPOUND_TYPE)) {
setHomePos(NbtHelper.toBlockPos(nbt.getCompound("homePos"))); setHomePos(NbtHelper.toBlockPos(nbt, "homePos"));
} }
if (hasCustomName()) { if (hasCustomName()) {
bossBar.setName(getDisplayName()); bossBar.setName(getDisplayName());
} }
setScaleFactor(nbt.getFloat("size")); setScaleFactor(nbt.getFloat("size"));
stormCloud.fromNBT(nbt.getCompound("cloud")); stormCloud.fromNBT(nbt.getCompound("cloud"), getWorld().getRegistryManager());
} }
private static class SombraBossBar extends ServerBossBar { private static class SombraBossBar extends ServerBossBar {

View file

@ -24,7 +24,6 @@ import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.mob.HostileEntity; import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.particle.BlockStateParticleEffect; import net.minecraft.particle.BlockStateParticleEffect;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.tag.BlockTags; import net.minecraft.registry.tag.BlockTags;
@ -135,8 +134,8 @@ public class SpecterEntity extends HostileEntity {
@Nullable @Nullable
@Override @Override
public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData data, @Nullable NbtCompound entityNbt) { public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData data) {
data = super.initialize(world, difficulty, spawnReason, data, entityNbt); data = super.initialize(world, difficulty, spawnReason, data);
Random random = world.getRandom(); Random random = world.getRandom();
float diff = difficulty.getClampedLocalDifficulty(); float diff = difficulty.getClampedLocalDifficulty();
setCanPickUpLoot(random.nextFloat() < 0.55F * diff); setCanPickUpLoot(random.nextFloat() < 0.55F * diff);

View file

@ -391,7 +391,7 @@ public class SpellbookEntity extends MobEntity implements MagicImmune {
activeTicks = compound.getInt("activeTicks"); activeTicks = compound.getInt("activeTicks");
setAltered(compound.getBoolean("altered")); setAltered(compound.getBoolean("altered"));
setForcedState(compound.contains("locked") ? TriState.of(compound.getBoolean("locked")) : TriState.DEFAULT); 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")); altar = NbtSerialisable.decode(Altar.CODEC, compound.get("altar"));
} }
@ -401,7 +401,7 @@ public class SpellbookEntity extends MobEntity implements MagicImmune {
compound.putInt("activeTicks", activeTicks); compound.putInt("activeTicks", activeTicks);
compound.putBoolean("prevDaytime", prevDaytime); compound.putBoolean("prevDaytime", prevDaytime);
compound.putBoolean("altered", isAltered()); compound.putBoolean("altered", isAltered());
compound.put("spellbookState", state.toNBT(getWorld().getRegistryManager())); compound.put("spellbookState", NbtSerialisable.encode(SpellbookState.CODEC, state));
getForcedState().map(t -> { getForcedState().map(t -> {
compound.putBoolean("locked", t); compound.putBoolean("locked", t);
return null; return null;

View file

@ -13,6 +13,8 @@ import net.minecraft.nbt.NbtElement;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World; import net.minecraft.world.World;
import static net.minecraft.entity.data.DataTracker.Builder;;
public abstract class StationaryObjectEntity extends Entity implements UDamageSources, MagicImmune { public abstract class StationaryObjectEntity extends Entity implements UDamageSources, MagicImmune {
private static final TrackedData<Float> HEALTH = DataTracker.registerData(StationaryObjectEntity.class, TrackedDataHandlerRegistry.FLOAT); private static final TrackedData<Float> HEALTH = DataTracker.registerData(StationaryObjectEntity.class, TrackedDataHandlerRegistry.FLOAT);
@ -21,8 +23,8 @@ public abstract class StationaryObjectEntity extends Entity implements UDamageSo
} }
@Override @Override
protected void initDataTracker() { protected void initDataTracker(Builder builder) {
dataTracker.startTracking(HEALTH, getMaxHealth()); builder.add(HEALTH, getMaxHealth());
} }
public abstract float getMaxHealth(); public abstract float getMaxHealth();

View file

@ -20,6 +20,7 @@ import net.minecraft.entity.damage.DamageTypes;
import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry; import net.minecraft.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.entity.data.DataTracker.Builder;
import net.minecraft.entity.decoration.AbstractDecorationEntity; import net.minecraft.entity.decoration.AbstractDecorationEntity;
import net.minecraft.entity.mob.HostileEntity; import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.entity.player.PlayerEntity; 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.hit.HitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box; import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.RaycastContext; import net.minecraft.world.RaycastContext;
@ -69,10 +71,9 @@ public class TentacleEntity extends AbstractDecorationEntity {
} }
@Override @Override
protected void initDataTracker() { protected void initDataTracker(Builder builder) {
super.initDataTracker(); builder.add(GROWTH, 0);
dataTracker.startTracking(GROWTH, 0); builder.add(MOTION_OFFSET, 0);
dataTracker.startTracking(MOTION_OFFSET, 0);
} }
public void setBulb(IgnominiousBulbEntity bulb) { public void setBulb(IgnominiousBulbEntity bulb) {
@ -130,16 +131,6 @@ public class TentacleEntity extends AbstractDecorationEntity {
return attackingTicks > 0; return attackingTicks > 0;
} }
@Override
public int getWidthPixels() {
return 9;
}
@Override
public int getHeightPixels() {
return 9;
}
@Override @Override
public boolean damage(DamageSource source, float amount) { public boolean damage(DamageSource source, float amount) {
if (source.getAttacker() instanceof PlayerEntity player) { if (source.getAttacker() instanceof PlayerEntity player) {
@ -319,11 +310,9 @@ public class TentacleEntity extends AbstractDecorationEntity {
} }
@Override @Override
protected void updateAttachmentPosition() { protected Box calculateBoundingBox(BlockPos pos, Direction side) {
visibilityBox = null; visibilityBox = null;
Vec3d pos = attachedBlockPos.toCenterPos(); return Box.of(pos.toCenterPos(), 1, 1, 1).stretch(0, 2, 0);
setPos(pos.x, pos.y, pos.z);
setBoundingBox(Box.of(pos, 1, 1, 1).stretch(0, 2, 0));
} }
@Override @Override

View file

@ -1,5 +1,7 @@
package com.minelittlepony.unicopia.entity.mob; package com.minelittlepony.unicopia.entity.mob;
import java.util.Optional;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.UTags; import com.minelittlepony.unicopia.UTags;
@ -19,6 +21,7 @@ import net.minecraft.util.Util;
import net.minecraft.util.math.random.Random; import net.minecraft.util.math.random.Random;
import net.minecraft.village.TradeOffer; import net.minecraft.village.TradeOffer;
import net.minecraft.village.TradeOffers; import net.minecraft.village.TradeOffers;
import net.minecraft.village.TradedItem;
import net.minecraft.village.VillagerProfession; import net.minecraft.village.VillagerProfession;
public interface UTradeOffers { public interface UTradeOffers {
@ -41,7 +44,7 @@ public interface UTradeOffers {
TradeOfferHelper.registerWanderingTraderOffers(1, factories -> { TradeOfferHelper.registerWanderingTraderOffers(1, factories -> {
factories.add(buyTiered(UItems.GEMSTONE, 30, UItems.GOLDEN_FEATHER, 1, UItems.GOLDEN_WING, 1, 30, 2, 0.05F)); 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(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(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)); 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) { 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) { 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> item, int count, Item returnItem, int returnCount, int maxUses, int experience, float priceChange) { private static TradeOffers.Factory buy(TagKey<Item> 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<Item> returnItem, int returnCount, int maxUses, int experience, float priceChange) { private static TradeOffers.Factory buy(Item item, int count, TagKey<Item> 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> item, Random rng) { private static Item random(Entity e, TagKey<Item> item, Random rng) {
@ -95,7 +98,12 @@ public interface UTradeOffers {
TradeOffer offer = factory.create(entity, rng); 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()
);
} }
} }
} }