diff --git a/src/main/java/com/minelittlepony/unicopia/edibles/ItemEdible.java b/src/main/java/com/minelittlepony/unicopia/edibles/ItemEdible.java index 2eee7275..9e4502f4 100644 --- a/src/main/java/com/minelittlepony/unicopia/edibles/ItemEdible.java +++ b/src/main/java/com/minelittlepony/unicopia/edibles/ItemEdible.java @@ -6,6 +6,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import com.minelittlepony.unicopia.Race; +import com.minelittlepony.unicopia.forgebullshit.IMultiItem; import com.minelittlepony.unicopia.player.PlayerSpeciesList; import net.minecraft.advancements.CriteriaTriggers; @@ -16,6 +17,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.MobEffects; import net.minecraft.init.SoundEvents; +import net.minecraft.item.Item; import net.minecraft.item.ItemFood; import net.minecraft.item.ItemStack; import net.minecraft.potion.PotionEffect; @@ -27,7 +29,9 @@ import net.minecraft.util.SoundCategory; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; -public class ItemEdible extends ItemFood implements IEdible { +public class ItemEdible extends ItemFood implements IEdible, IMultiItem { + + private String translationKey; private final IEdible toxicityDeterminant; @@ -46,6 +50,11 @@ public class ItemEdible extends ItemFood implements IEdible { toxicityDeterminant = mapper; } + public Item setTranslationKey(String key) { + translationKey = key; + return super.setTranslationKey(key); + } + protected void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player) { Race race = PlayerSpeciesList.instance().getPlayer(player).getPlayerSpecies(); Toxicity toxicity = (race.isDefault() || race == Race.CHANGELING) ? Toxicity.LETHAL : getToxicityLevel(stack); @@ -57,8 +66,6 @@ public class ItemEdible extends ItemFood implements IEdible { public void addInformation(ItemStack stack, @Nullable World worldIn, List tooltip, ITooltipFlag flagIn) { Toxicity toxicity = getToxicityLevel(stack); - setAlwaysEdible(); - TextFormatting color = toxicity.toxicWhenCooked() ? TextFormatting.RED : toxicity.toxicWhenRaw() ? TextFormatting.DARK_PURPLE : TextFormatting.GRAY; tooltip.add(color + I18n.format(toxicity.getTranslationKey())); @@ -135,4 +142,14 @@ public class ItemEdible extends ItemFood implements IEdible { public Toxicity getToxicityLevel(ItemStack stack) { return toxicityDeterminant.getToxicityLevel(stack); } + + @Override + public String[] getVariants() { + return Toxicity.getVariants(translationKey); + } + + @Override + public boolean variantsAreHidden() { + return true; + } } diff --git a/src/main/java/com/minelittlepony/unicopia/edibles/Toxicity.java b/src/main/java/com/minelittlepony/unicopia/edibles/Toxicity.java index 13acb0c8..24dafade 100644 --- a/src/main/java/com/minelittlepony/unicopia/edibles/Toxicity.java +++ b/src/main/java/com/minelittlepony/unicopia/edibles/Toxicity.java @@ -47,4 +47,14 @@ public enum Toxicity { public static Toxicity byMetadata(int metadata) { return values[metadata % values.length]; } + + public static String[] getVariants(String key) { + String[] result = new String[values.length]; + + for (int i = 0; i < result.length; i++) { + result[i] = values[i].name() + key; + } + + return result; + } } diff --git a/src/main/java/com/minelittlepony/unicopia/forgebullshit/IMultiItem.java b/src/main/java/com/minelittlepony/unicopia/forgebullshit/IMultiItem.java index a4226f34..2d130a20 100644 --- a/src/main/java/com/minelittlepony/unicopia/forgebullshit/IMultiItem.java +++ b/src/main/java/com/minelittlepony/unicopia/forgebullshit/IMultiItem.java @@ -9,4 +9,12 @@ public interface IMultiItem { * Used to register models and textures on the client. */ String[] getVariants(); + + default boolean variantsAreHidden() { + return false; + } + + default int getMaxMetadata() { + return getVariants().length; + } } diff --git a/src/main/java/com/minelittlepony/unicopia/forgebullshit/ItemModels.java b/src/main/java/com/minelittlepony/unicopia/forgebullshit/ItemModels.java index 194a23c3..528a05c9 100644 --- a/src/main/java/com/minelittlepony/unicopia/forgebullshit/ItemModels.java +++ b/src/main/java/com/minelittlepony/unicopia/forgebullshit/ItemModels.java @@ -12,13 +12,25 @@ public class ItemModels { public static void registerAll(Item...items) { for (Item i : items) { if (i instanceof IMultiItem && i.getHasSubtypes()) { - registerAllVariants(i, ((IMultiItem)i).getVariants()); + IMultiItem multi = (IMultiItem)i; + + if (multi.variantsAreHidden()) { + registerAll(i, multi.getMaxMetadata(), new ModelResourceLocation(i.getRegistryName().toString())); + } else { + registerAllVariants(i, multi.getVariants()); + } } else { - ModelLoader.setCustomModelResourceLocation(i, 0, new ModelResourceLocation(i.getRegistryName().toString())); + registerAll(i, 1, new ModelResourceLocation(i.getRegistryName().toString())); } } } + private static void registerAll(Item item, int maxMeta, ModelResourceLocation resource) { + for (int i = 0; i < maxMeta; i++) { + ModelLoader.setCustomModelResourceLocation(item, i, resource); + } + } + /** * Registers a model for the given item and all associated variants. */