mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Fixed models for toxicity variants
This commit is contained in:
parent
ddf48c7fd0
commit
a3232bc263
4 changed files with 52 additions and 5 deletions
|
@ -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<String> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue