Skip to content

Commit

Permalink
fix: familiar ring name initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
klikli-dev committed Apr 27, 2023
1 parent a928f56 commit 53a5230
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ public static IFamiliar getFamiliar(ItemStack stack, Level level) {
return tag;
}

@Override
public int getMaxStackSize(ItemStack stack) {
//force generation of a name if it does not exist yet.
//this might get around loot tables caching the stack
ItemNBTUtil.getBoundSpiritName(stack);
return super.getMaxStackSize(stack);
}

@Override
public void readShareTag(ItemStack stack, @Nullable CompoundTag nbt) {
super.readShareTag(stack, nbt);
Expand Down Expand Up @@ -182,8 +190,7 @@ public void handleFamiliarTypeTag(CompoundTag tag){
var familiar = (IFamiliar) entity;
if (familiar != null) {
curio.setFamiliar(familiar);
var name = ItemNBTUtil.getBoundSpiritName(stack);
entity.setCustomName(Component.literal(name));

stack.getTag().putBoolean("occupied", true);
//now we also need to create the "familiar" nbt tag
stack.getTag().put("familiar", curio.serializeNBT());
Expand Down Expand Up @@ -232,6 +239,10 @@ private boolean releaseFamiliar(Player player, Level level) {
e.setPos(player.getX(), player.getY(), player.getZ());
//on release overwrite owner -> familiar rings can be used to trade familiars.
((IFamiliar) e).setFamiliarOwner(player);

var name = ItemNBTUtil.getBoundSpiritName(stack);
e.setCustomName(Component.literal(name)); //set the name from the ring. the reverse happens when ring is used on entity.

level.addFreshEntity(e);
return e;
});
Expand Down

0 comments on commit 53a5230

Please sign in to comment.