Added an example item whose variants use the same textures but different colours for the layers.
This commit is contained in:
parent
f535e331dd
commit
dd6b5bd3b5
9 changed files with 209 additions and 25 deletions
67
src/main/java/WayofTime/bloodmagic/item/ItemEnumColour.java
Normal file
67
src/main/java/WayofTime/bloodmagic/item/ItemEnumColour.java
Normal file
|
@ -0,0 +1,67 @@
|
|||
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");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package WayofTime.bloodmagic.item.types;
|
||||
|
||||
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Locale;
|
||||
|
||||
public enum AlchemicTypes implements ISubItem
|
||||
{
|
||||
BASE(0x2e35ff);
|
||||
|
||||
final int potionColour;
|
||||
|
||||
AlchemicTypes(int colour1)
|
||||
{
|
||||
potionColour = colour1;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getInternalName()
|
||||
{
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getStack()
|
||||
{
|
||||
return getStack(1);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getStack(int count)
|
||||
{
|
||||
return new ItemStack(RegistrarBloodMagicItems.ALCHEMIC_VIAL, count, ordinal());
|
||||
}
|
||||
|
||||
public int getColourForLayer(int layer)
|
||||
{
|
||||
if (layer == 0)
|
||||
{
|
||||
return potionColour;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static int getColourForLayer(int variant, int layer)
|
||||
{
|
||||
if (variant >= AlchemicTypes.values().length)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return AlchemicTypes.values()[variant].getColourForLayer(layer);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue