mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Items in jars should now preserve all of their original attributes
This commit is contained in:
parent
b5dc84a139
commit
63f2604e7e
4 changed files with 26 additions and 17 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,10 +16,7 @@ public class JarInsertRecipe extends ItemCombinationRecipe {
|
|||
public final ItemStack craft(CraftingInventory inventory) {
|
||||
Pair<ItemStack, ItemStack> 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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue