*Hopefully* make Nut cry a bit less.

This commit is contained in:
WayofTime 2018-03-23 13:24:33 -04:00
parent dd6b5bd3b5
commit 25f492ef65
3 changed files with 23 additions and 68 deletions

View file

@ -212,7 +212,7 @@ public class RegistrarBloodMagicItems
new ItemLivingArmourPointsUpgrade().setRegistryName("points_upgrade"),
new ItemDemonWillGauge().setRegistryName("demon_will_gauge"),
new ItemPotionFlask().setRegistryName("potion_flask"),
new ItemEnumColour.Variant<>(AlchemicTypes.class, "alchemicVial").setRegistryName("alchemic_vial")
new ItemAlchemicVial().setRegistryName("alchemic_vial")
));
event.getRegistry().registerAll(items.toArray(new Item[0]));

View file

@ -0,0 +1,22 @@
package WayofTime.bloodmagic.item;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import javax.annotation.Nonnull;
import WayofTime.bloodmagic.item.types.AlchemicTypes;
import WayofTime.bloodmagic.item.types.ISubItem;
public class ItemAlchemicVial<T extends Enum<T> & ISubItem> extends ItemEnum.Variant<T>
{
public ItemAlchemicVial()
{
super((Class<T>) AlchemicTypes.class, "alchemic_vial");
}
@Override
public void gatherVariants(@Nonnull Int2ObjectMap<String> variants)
{
variants.put(0, "type=normal");
}
}

View file

@ -1,67 +0,0 @@
package WayofTime.bloodmagic.item;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.client.IVariantProvider;
import WayofTime.bloodmagic.item.types.ISubItem;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemEnumColour<T extends Enum<T> & ISubItem> extends Item
{
//Copy of @ItemEnum, except all variants use the same textures with different colouring
protected final T[] types;
public ItemEnumColour(Class<T> enumClass, String baseName)
{
super();
this.types = enumClass.getEnumConstants();
setUnlocalizedName(BloodMagic.MODID + "." + baseName);
setHasSubtypes(types.length > 1);
setCreativeTab(BloodMagic.TAB_BM);
}
@Override
public String getUnlocalizedName(ItemStack stack)
{
return super.getUnlocalizedName(stack) + "." + getItemType(stack).getInternalName();
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> subItems)
{
if (!isInCreativeTab(tab))
return;
for (T type : types)
subItems.add(new ItemStack(this, 1, type.ordinal()));
}
public T getItemType(ItemStack stack)
{
return types[MathHelper.clamp(stack.getItemDamage(), 0, types.length)];
}
public static class Variant<T extends Enum<T> & ISubItem> extends ItemEnum<T> implements IVariantProvider
{
public Variant(Class<T> enumClass, String baseName)
{
super(enumClass, baseName);
}
@Override
public void gatherVariants(Int2ObjectMap<String> variants)
{
variants.put(0, "type=normal");
}
}
}