Added an example item whose variants use the same textures but different colours for the layers.

This commit is contained in:
WayofTime 2018-03-23 11:02:43 -04:00
parent f535e331dd
commit dd6b5bd3b5
9 changed files with 209 additions and 25 deletions

View file

@ -16,10 +16,13 @@ import WayofTime.bloodmagic.item.routing.ItemNodeRouter;
import WayofTime.bloodmagic.item.routing.ItemRouterFilter; import WayofTime.bloodmagic.item.routing.ItemRouterFilter;
import WayofTime.bloodmagic.item.sigil.*; import WayofTime.bloodmagic.item.sigil.*;
import WayofTime.bloodmagic.item.soul.*; import WayofTime.bloodmagic.item.soul.*;
import WayofTime.bloodmagic.item.types.AlchemicTypes;
import WayofTime.bloodmagic.item.types.ComponentTypes; import WayofTime.bloodmagic.item.types.ComponentTypes;
import WayofTime.bloodmagic.item.types.ShardType; import WayofTime.bloodmagic.item.types.ShardType;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.block.model.ModelResourceLocation;
@ -43,7 +46,8 @@ import java.util.Set;
@Mod.EventBusSubscriber(modid = BloodMagic.MODID) @Mod.EventBusSubscriber(modid = BloodMagic.MODID)
@GameRegistry.ObjectHolder(BloodMagic.MODID) @GameRegistry.ObjectHolder(BloodMagic.MODID)
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class RegistrarBloodMagicItems { public class RegistrarBloodMagicItems
{
public static final Item BLOOD_ORB = Items.AIR; public static final Item BLOOD_ORB = Items.AIR;
public static final Item ACTIVATION_CRYSTAL = Items.AIR; public static final Item ACTIVATION_CRYSTAL = Items.AIR;
@ -117,6 +121,7 @@ public class RegistrarBloodMagicItems {
public static final Item POINTS_UPGRADE = Items.AIR; public static final Item POINTS_UPGRADE = Items.AIR;
public static final Item DEMON_WILL_GAUGE = Items.AIR; public static final Item DEMON_WILL_GAUGE = Items.AIR;
public static final Item POTION_FLASK = Items.AIR; public static final Item POTION_FLASK = Items.AIR;
public static final Item ALCHEMIC_VIAL = Items.AIR;
public static Item.ToolMaterial BOUND_TOOL_MATERIAL = EnumHelper.addToolMaterial("bound", 4, 1, 10, 8, 50); public static Item.ToolMaterial BOUND_TOOL_MATERIAL = EnumHelper.addToolMaterial("bound", 4, 1, 10, 8, 50);
public static Item.ToolMaterial SOUL_TOOL_MATERIAL = EnumHelper.addToolMaterial("demonic", 4, 520, 7, 8, 50); public static Item.ToolMaterial SOUL_TOOL_MATERIAL = EnumHelper.addToolMaterial("demonic", 4, 520, 7, 8, 50);
@ -124,10 +129,12 @@ public class RegistrarBloodMagicItems {
public static List<Item> items; public static List<Item> items;
@SubscribeEvent @SubscribeEvent
public static void registerItems(RegistryEvent.Register<Item> event) { public static void registerItems(RegistryEvent.Register<Item> event)
{
items = Lists.newArrayList(); items = Lists.newArrayList();
RegistrarBloodMagicBlocks.blocks.stream().filter(block -> block instanceof IBMBlock && ((IBMBlock) block).getItem() != null).forEach(block -> { RegistrarBloodMagicBlocks.blocks.stream().filter(block -> block instanceof IBMBlock && ((IBMBlock) block).getItem() != null).forEach(block ->
{
IBMBlock bmBlock = (IBMBlock) block; IBMBlock bmBlock = (IBMBlock) block;
items.add(bmBlock.getItem().setRegistryName(block.getRegistryName())); items.add(bmBlock.getItem().setRegistryName(block.getRegistryName()));
}); });
@ -204,23 +211,27 @@ public class RegistrarBloodMagicItems {
new ItemSanguineBook().setRegistryName("sanguine_book"), new ItemSanguineBook().setRegistryName("sanguine_book"),
new ItemLivingArmourPointsUpgrade().setRegistryName("points_upgrade"), new ItemLivingArmourPointsUpgrade().setRegistryName("points_upgrade"),
new ItemDemonWillGauge().setRegistryName("demon_will_gauge"), new ItemDemonWillGauge().setRegistryName("demon_will_gauge"),
new ItemPotionFlask().setRegistryName("potion_flask") new ItemPotionFlask().setRegistryName("potion_flask"),
)); new ItemEnumColour.Variant<>(AlchemicTypes.class, "alchemicVial").setRegistryName("alchemic_vial")
));
event.getRegistry().registerAll(items.toArray(new Item[0])); event.getRegistry().registerAll(items.toArray(new Item[0]));
} }
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
@SubscribeEvent @SubscribeEvent
public static void registerRenders(ModelRegistryEvent event) { public static void registerRenders(ModelRegistryEvent event)
items.stream().filter(i -> i instanceof IVariantProvider).forEach(i -> { {
items.stream().filter(i -> i instanceof IVariantProvider).forEach(i ->
{
Int2ObjectMap<String> variants = new Int2ObjectOpenHashMap<>(); Int2ObjectMap<String> variants = new Int2ObjectOpenHashMap<>();
((IVariantProvider) i).gatherVariants(variants); ((IVariantProvider) i).gatherVariants(variants);
for (Int2ObjectMap.Entry<String> variant : variants.int2ObjectEntrySet()) for (Int2ObjectMap.Entry<String> variant : variants.int2ObjectEntrySet())
ModelLoader.setCustomModelResourceLocation(i, variant.getIntKey(), new ModelResourceLocation(i.getRegistryName(), variant.getValue())); ModelLoader.setCustomModelResourceLocation(i, variant.getIntKey(), new ModelResourceLocation(i.getRegistryName(), variant.getValue()));
}); });
items.stream().filter(i -> i instanceof IMeshProvider).forEach(i -> { items.stream().filter(i -> i instanceof IMeshProvider).forEach(i ->
{
IMeshProvider mesh = (IMeshProvider) i; IMeshProvider mesh = (IMeshProvider) i;
ResourceLocation loc = mesh.getCustomLocation(); ResourceLocation loc = mesh.getCustomLocation();
if (loc == null) if (loc == null)
@ -234,7 +245,8 @@ public class RegistrarBloodMagicItems {
ModelLoader.setCustomMeshDefinition(i, mesh.getMeshDefinition()); ModelLoader.setCustomMeshDefinition(i, mesh.getMeshDefinition());
}); });
RegistrarBloodMagicBlocks.blocks.stream().filter(b -> b instanceof IVariantProvider).forEach(b -> { RegistrarBloodMagicBlocks.blocks.stream().filter(b -> b instanceof IVariantProvider).forEach(b ->
{
Int2ObjectMap<String> variants = new Int2ObjectOpenHashMap<>(); Int2ObjectMap<String> variants = new Int2ObjectOpenHashMap<>();
((IVariantProvider) b).gatherVariants(variants); ((IVariantProvider) b).gatherVariants(variants);
for (Int2ObjectMap.Entry<String> variant : variants.int2ObjectEntrySet()) for (Int2ObjectMap.Entry<String> variant : variants.int2ObjectEntrySet())

View 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");
}
}
}

View file

@ -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);
}
}

View file

@ -13,12 +13,15 @@ import WayofTime.bloodmagic.entity.projectile.EntityBloodLight;
import WayofTime.bloodmagic.entity.projectile.EntityMeteor; import WayofTime.bloodmagic.entity.projectile.EntityMeteor;
import WayofTime.bloodmagic.entity.projectile.EntitySentientArrow; import WayofTime.bloodmagic.entity.projectile.EntitySentientArrow;
import WayofTime.bloodmagic.entity.projectile.EntitySoulSnare; import WayofTime.bloodmagic.entity.projectile.EntitySoulSnare;
import WayofTime.bloodmagic.item.types.AlchemicTypes;
import WayofTime.bloodmagic.soul.DemonWillHolder; import WayofTime.bloodmagic.soul.DemonWillHolder;
import WayofTime.bloodmagic.tile.*; import WayofTime.bloodmagic.tile.*;
import WayofTime.bloodmagic.tile.routing.TileRoutingNode; import WayofTime.bloodmagic.tile.routing.TileRoutingNode;
import WayofTime.bloodmagic.util.BMLog; import WayofTime.bloodmagic.util.BMLog;
import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.util.Constants;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.RenderPlayer; import net.minecraft.client.renderer.entity.RenderPlayer;
@ -37,18 +40,22 @@ import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import java.awt.Color; import java.awt.Color;
import java.util.Map; import java.util.Map;
public class ClientProxy extends CommonProxy { public class ClientProxy extends CommonProxy
{
public static DemonWillHolder currentAura = new DemonWillHolder(); public static DemonWillHolder currentAura = new DemonWillHolder();
@Override @Override
public void preInit() { public void preInit()
{
super.preInit(); super.preInit();
OBJLoader.INSTANCE.addDomain(BloodMagic.MODID); OBJLoader.INSTANCE.addDomain(BloodMagic.MODID);
ClientRegistry.bindTileEntitySpecialRenderer(TileInversionPillar.class, new AnimationTESR<TileInversionPillar>() { ClientRegistry.bindTileEntitySpecialRenderer(TileInversionPillar.class, new AnimationTESR<TileInversionPillar>()
{
@Override @Override
public void handleEvents(TileInversionPillar chest, float time, Iterable<Event> pastEvents) { public void handleEvents(TileInversionPillar chest, float time, Iterable<Event> pastEvents)
{
chest.handleEvents(time, pastEvents); chest.handleEvents(time, pastEvents);
} }
}); });
@ -66,7 +73,8 @@ public class ClientProxy extends CommonProxy {
} }
@Override @Override
public void registerRenderers() { public void registerRenderers()
{
RenderingRegistry.registerEntityRenderingHandler(EntitySoulSnare.class, new SoulSnareRenderFactory()); RenderingRegistry.registerEntityRenderingHandler(EntitySoulSnare.class, new SoulSnareRenderFactory());
RenderingRegistry.registerEntityRenderingHandler(EntitySentientArrow.class, new SentientArrowRenderFactory()); RenderingRegistry.registerEntityRenderingHandler(EntitySentientArrow.class, new SentientArrowRenderFactory());
RenderingRegistry.registerEntityRenderingHandler(EntityBloodLight.class, new BloodLightRenderFactory()); RenderingRegistry.registerEntityRenderingHandler(EntityBloodLight.class, new BloodLightRenderFactory());
@ -82,19 +90,24 @@ public class ClientProxy extends CommonProxy {
} }
@Override @Override
public void init() { public void init()
{
super.init(); super.init();
Minecraft.getMinecraft().getItemColors().registerItemColorHandler((stack, tintIndex) -> { Minecraft.getMinecraft().getItemColors().registerItemColorHandler((stack, tintIndex) ->
try { {
try
{
if (stack.hasTagCompound() && stack.getTagCompound().hasKey(Constants.NBT.COLOR)) if (stack.hasTagCompound() && stack.getTagCompound().hasKey(Constants.NBT.COLOR))
if (tintIndex == 1) if (tintIndex == 1)
return Color.decode(stack.getTagCompound().getString(Constants.NBT.COLOR)).getRGB(); return Color.decode(stack.getTagCompound().getString(Constants.NBT.COLOR)).getRGB();
} catch (NumberFormatException e) { } catch (NumberFormatException e)
{
return -1; return -1;
} }
return -1; return -1;
}, RegistrarBloodMagicItems.SIGIL_HOLDING); }, RegistrarBloodMagicItems.SIGIL_HOLDING);
Minecraft.getMinecraft().getItemColors().registerItemColorHandler((stack, tintIndex) -> { Minecraft.getMinecraft().getItemColors().registerItemColorHandler((stack, tintIndex) ->
{
if (tintIndex != 0 && tintIndex != 2) if (tintIndex != 0 && tintIndex != 2)
return -1; return -1;
@ -103,29 +116,43 @@ public class ClientProxy extends CommonProxy {
return PotionUtils.getPotionColorFromEffectList(PotionUtils.getEffectsFromStack(stack)); return PotionUtils.getPotionColorFromEffectList(PotionUtils.getEffectsFromStack(stack));
}, RegistrarBloodMagicItems.POTION_FLASK); }, RegistrarBloodMagicItems.POTION_FLASK);
Minecraft.getMinecraft().getItemColors().registerItemColorHandler((stack, tintIndex) ->
{
// if (tintIndex != 0 && tintIndex != 2)
// return -1;
int variant = stack.getMetadata();
return AlchemicTypes.getColourForLayer(variant, tintIndex);
}, RegistrarBloodMagicItems.ALCHEMIC_VIAL);
addElytraLayer(); addElytraLayer();
} }
@Override @Override
public void postInit() { public void postInit()
{
Elements.createHUDElements(); Elements.createHUDElements();
} }
private void addElytraLayer() { private void addElytraLayer()
{
RenderManager renderManager = Minecraft.getMinecraft().getRenderManager(); RenderManager renderManager = Minecraft.getMinecraft().getRenderManager();
try { try
{
Map<String, RenderPlayer> skinMap = ObfuscationReflectionHelper.getPrivateValue(RenderManager.class, renderManager, "skinMap", "field_178636_l"); Map<String, RenderPlayer> skinMap = ObfuscationReflectionHelper.getPrivateValue(RenderManager.class, renderManager, "skinMap", "field_178636_l");
skinMap.get("default").addLayer(new LayerBloodElytra(skinMap.get("default"))); skinMap.get("default").addLayer(new LayerBloodElytra(skinMap.get("default")));
skinMap.get("slim").addLayer(new LayerBloodElytra(skinMap.get("slim"))); skinMap.get("slim").addLayer(new LayerBloodElytra(skinMap.get("slim")));
BMLog.DEBUG.info("Elytra layer added"); BMLog.DEBUG.info("Elytra layer added");
} catch (Exception e) { } catch (Exception e)
{
BMLog.DEBUG.error("Failed to set custom Elytra Layer for Elytra Living Armour Upgrade: {}", e.getMessage()); BMLog.DEBUG.error("Failed to set custom Elytra Layer for Elytra Living Armour Upgrade: {}", e.getMessage());
} }
} }
@Override @Override
public IAnimationStateMachine load(ResourceLocation location, ImmutableMap<String, ITimeValue> parameters) { public IAnimationStateMachine load(ResourceLocation location, ImmutableMap<String, ITimeValue> parameters)
{
return ModelLoaderRegistry.loadASM(location, parameters); return ModelLoaderRegistry.loadASM(location, parameters);
} }
} }

View file

@ -215,7 +215,8 @@ public class RitualEllipsoid extends Ritual
// } // }
@Override @Override
public void gatherComponents(Consumer<RitualComponent> components) { public void gatherComponents(Consumer<RitualComponent> components)
{
addCornerRunes(components, 1, 0, EnumRuneType.WATER); addCornerRunes(components, 1, 0, EnumRuneType.WATER);
addCornerRunes(components, 1, 1, EnumRuneType.WATER); addCornerRunes(components, 1, 1, EnumRuneType.WATER);
} }

View file

@ -0,0 +1,18 @@
{
"forge_marker": 1,
"defaults": {
"model": "builtin/generated",
"transform": "forge:default-item"
},
"variants": {
"type": {
"normal": {
"textures": {
"layer0": "bloodmagic:items/Alchemic_Liquid",
"layer1": "bloodmagic:items/Alchemic_Vial",
"layer2": "bloodmagic:items/Alchemic_Ribbon"
}
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 B