diff --git a/src/main/java/com/minelittlepony/unicopia/item/ChameleonItem.java b/src/main/java/com/minelittlepony/unicopia/item/ChameleonItem.java index 8de1d396..742e4eb4 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/ChameleonItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/ChameleonItem.java @@ -21,10 +21,11 @@ public interface ChameleonItem { } default ItemStack createAppearanceStack(ItemStack stack, Item appearance) { - ItemStack newAppearance = new ItemStack(appearance, stack.getCount()); + ItemStack newAppearance = appearance.getDefaultStack(); if (stack.hasTag()) { newAppearance.setTag(stack.getTag().copy()); } + newAppearance.setCount(stack.getCount()); newAppearance.removeSubTag("appearance"); return newAppearance; } @@ -41,7 +42,17 @@ public interface ChameleonItem { return Items.AIR; } - default void setAppearance(ItemStack stack, Item appearance) { - stack.getOrCreateTag().putString("appearance", Registry.ITEM.getId(appearance).toString()); + default ItemStack setAppearance(ItemStack stack, ItemStack appearance) { + ItemStack result = stack.copy(); + + if (appearance.hasTag()) { + result.setTag(appearance.getTag().copy()); + result.removeCustomName(); + result.setDamage(stack.getDamage()); + result.setCount(stack.getCount()); + } + result.getOrCreateTag().putString("appearance", Registry.ITEM.getId(appearance.getItem()).toString()); + + return result; } } diff --git a/src/main/java/com/minelittlepony/unicopia/item/JarInsertRecipe.java b/src/main/java/com/minelittlepony/unicopia/item/JarInsertRecipe.java index 2d849c3a..411eb791 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/JarInsertRecipe.java +++ b/src/main/java/com/minelittlepony/unicopia/item/JarInsertRecipe.java @@ -16,10 +16,7 @@ public class JarInsertRecipe extends ItemCombinationRecipe { public final ItemStack craft(CraftingInventory inventory) { Pair pair = runMatch(inventory); - ItemStack result = new ItemStack(UItems.FILLED_JAR); - UItems.FILLED_JAR.setAppearance(result, pair.getRight().getItem()); - - return result; + return UItems.FILLED_JAR.setAppearance(UItems.FILLED_JAR.getDefaultStack(), pair.getRight()); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java b/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java index b6385d59..5b95fbd4 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java @@ -15,12 +15,11 @@ import net.minecraft.entity.mob.CreeperEntity; import net.minecraft.entity.passive.PigEntity; import net.minecraft.entity.passive.VillagerEntity; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.server.world.ServerWorld; +import net.minecraft.text.Text; import net.minecraft.util.ActionResult; import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.Hand; @@ -101,19 +100,18 @@ public class ZapAppleItem extends AppleItem implements ChameleonItem { } @Override - public String getTranslationKey(ItemStack stack) { - Item appearance = getAppearance(stack); - return appearance == Items.AIR ? super.getTranslationKey() : appearance.getTranslationKey(stack); + public Text getName(ItemStack stack) { + return hasAppearance(stack) ? getAppearanceStack(stack).getName() : super.getName(stack); } @Override public Toxicity getToxicity(ItemStack stack) { - return getAppearance(stack) == Items.AIR ? Toxicity.SEVERE : Toxicity.SAFE; + return hasAppearance(stack) ? Toxicity.SEVERE : Toxicity.SAFE; } @Override public Rarity getRarity(ItemStack stack) { - if (getAppearance(stack) == Items.AIR) { + if (hasAppearance(stack)) { return Rarity.EPIC; } diff --git a/src/main/java/com/minelittlepony/unicopia/item/ZapAppleRecipe.java b/src/main/java/com/minelittlepony/unicopia/item/ZapAppleRecipe.java index 8cc3a565..13e887c2 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/ZapAppleRecipe.java +++ b/src/main/java/com/minelittlepony/unicopia/item/ZapAppleRecipe.java @@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.item; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; +import com.google.gson.JsonSyntaxException; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketByteBuf; @@ -10,6 +11,7 @@ import net.minecraft.recipe.ShapelessRecipe; import net.minecraft.util.Identifier; import net.minecraft.util.JsonHelper; import net.minecraft.util.collection.DefaultedList; +import net.minecraft.util.registry.Registry; public class ZapAppleRecipe extends ShapelessRecipe { @@ -29,10 +31,11 @@ public class ZapAppleRecipe extends ShapelessRecipe { throw new JsonParseException("Too many ingredients for shapeless recipe"); } - ItemStack stack = UItems.ZAP_APPLE.getDefaultStack(); - stack.getOrCreateTag().putString("appearance", JsonHelper.getString(json, "appearance")); + Identifier id = new Identifier(JsonHelper.getString(json, "appearance")); - return new ZapAppleRecipe(identifier, group, stack, ingredients); + return new ZapAppleRecipe(identifier, group, UItems.ZAP_APPLE.setAppearance(UItems.ZAP_APPLE.getDefaultStack(), Registry.ITEM.getOrEmpty(id).orElseThrow(() -> { + return new JsonSyntaxException("Unknown item '" + id + "'"); + }).getDefaultStack()), ingredients); } @Override