diff --git a/src/main/java/biomesoplenty/api/item/IColoredItem.java b/src/main/java/biomesoplenty/api/item/IColoredItem.java new file mode 100644 index 000000000..3dfeb8ae8 --- /dev/null +++ b/src/main/java/biomesoplenty/api/item/IColoredItem.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright 2016, the Biomes O' Plenty Team + * + * This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License. + * + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. + ******************************************************************************/ +package biomesoplenty.api.item; + +import net.minecraft.client.renderer.color.IItemColor; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public interface IColoredItem +{ + @SideOnly(Side.CLIENT) + public IItemColor getItemColor(); +} diff --git a/src/main/java/biomesoplenty/common/init/ModItems.java b/src/main/java/biomesoplenty/common/init/ModItems.java index e9a3121f4..59de022e6 100644 --- a/src/main/java/biomesoplenty/common/init/ModItems.java +++ b/src/main/java/biomesoplenty/common/init/ModItems.java @@ -318,28 +318,7 @@ public class ModItems } GameRegistry.registerItem(item,name); BOPCommand.itemCount++; - - // register sub types if there are any - if (FMLCommonHandler.instance().getSide() == Side.CLIENT) - { - if (item.getHasSubtypes()) - { - List subItems = new ArrayList(); - item.getSubItems(item, CreativeTabBOP.instance, subItems); - for (ItemStack subItem : subItems) - { - String subItemName = item.getUnlocalizedName(subItem); - subItemName = subItemName.substring(subItemName.indexOf(".") + 1); // remove 'item.' from the front - - ModelBakery.registerItemVariants(item, new ResourceLocation(BiomesOPlenty.MOD_ID, subItemName)); - ModelLoader.setCustomModelResourceLocation(item, subItem.getMetadata(), new ModelResourceLocation(BiomesOPlenty.MOD_ID + ":" + subItemName, "inventory")); - } - } - else - { - ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(BiomesOPlenty.MOD_ID + ":" + name, "inventory")); - } - } + BiomesOPlenty.proxy.registerItemSided(item); return item; } diff --git a/src/main/java/biomesoplenty/common/item/ItemBOPSpawnEgg.java b/src/main/java/biomesoplenty/common/item/ItemBOPSpawnEgg.java index 8991d125c..5d52b079a 100644 --- a/src/main/java/biomesoplenty/common/item/ItemBOPSpawnEgg.java +++ b/src/main/java/biomesoplenty/common/item/ItemBOPSpawnEgg.java @@ -10,11 +10,14 @@ package biomesoplenty.common.item; import java.util.Iterator; import java.util.List; +import java.util.Map.Entry; +import biomesoplenty.api.item.IColoredItem; import biomesoplenty.common.init.ModEntities; import net.minecraft.block.BlockFence; import net.minecraft.block.BlockLiquid; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.color.IItemColor; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; @@ -40,7 +43,7 @@ import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -public class ItemBOPSpawnEgg extends Item +public class ItemBOPSpawnEgg extends Item implements IColoredItem { public ItemBOPSpawnEgg() @@ -53,12 +56,9 @@ public class ItemBOPSpawnEgg extends Item @SideOnly(Side.CLIENT) public void getSubItems(Item itemIn, CreativeTabs tab, List subItems) { - Iterator iterator = ModEntities.entityEggs.values().iterator(); - - while (iterator.hasNext()) + for (Entry entry : ModEntities.entityEggs.entrySet()) { - EntityList.EntityEggInfo entityegginfo = (EntityList.EntityEggInfo)iterator.next(); - subItems.add(new ItemStack(itemIn, 1, EntityList.getIDFromString(entityegginfo.spawnedID))); + subItems.add(new ItemStack(itemIn, 1, entry.getKey())); } } @@ -81,7 +81,6 @@ public class ItemBOPSpawnEgg extends Item return entity; } - // get the correct name for this item by looking up the meta value in the DartType enum @Override public String getUnlocalizedName(ItemStack stack) { @@ -89,6 +88,21 @@ public class ItemBOPSpawnEgg extends Item String entityName = ModEntities.idToBOPEntityName.get(bopEntityId); return super.getUnlocalizedName(stack)+"_"+entityName; } + + @SideOnly(Side.CLIENT) + @Override + public IItemColor getItemColor() + { + return new IItemColor() + { + @Override + public int getColorFromItemstack(ItemStack stack, int tintIndex) + { + EntityList.EntityEggInfo entityegginfo = ModEntities.entityEggs.get(Integer.valueOf(stack.getMetadata())); + return entityegginfo != null ? (tintIndex == 0 ? entityegginfo.primaryColor : entityegginfo.secondaryColor) : 16777215; + } + }; + } @Override public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) diff --git a/src/main/java/biomesoplenty/core/ClientProxy.java b/src/main/java/biomesoplenty/core/ClientProxy.java index 2c3af703f..de81442a0 100644 --- a/src/main/java/biomesoplenty/core/ClientProxy.java +++ b/src/main/java/biomesoplenty/core/ClientProxy.java @@ -8,11 +8,13 @@ package biomesoplenty.core; +import java.util.ArrayList; import java.util.List; import java.util.Map; import biomesoplenty.api.block.IBOPBlock; import biomesoplenty.api.item.BOPItems; +import biomesoplenty.api.item.IColoredItem; import biomesoplenty.api.particle.BOPParticleTypes; import biomesoplenty.client.particle.EntityPixieTrailFX; import biomesoplenty.client.particle.EntityTrailFX; @@ -30,6 +32,8 @@ import biomesoplenty.common.entities.projectiles.EntityDart; import biomesoplenty.common.entities.projectiles.EntityMudball; import biomesoplenty.common.entities.projectiles.RenderDart; import biomesoplenty.common.entities.projectiles.RenderMudball; +import biomesoplenty.common.util.inventory.CreativeTabBOP; + import com.google.common.collect.Lists; import net.minecraft.block.Block; import net.minecraft.block.properties.IProperty; @@ -48,6 +52,7 @@ import net.minecraft.client.resources.AbstractResourcePack; import net.minecraft.client.resources.IResourcePack; import net.minecraft.entity.Entity; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.MathHelper; @@ -65,7 +70,8 @@ public class ClientProxy extends CommonProxy public static ResourceLocation particleTexturesLocation = new ResourceLocation("biomesoplenty:textures/particles/particles.png"); private static List blocksToColour = Lists.newArrayList(); - + private static List itemsToColor = Lists.newArrayList(); + @Override public void registerRenderers() { @@ -89,11 +95,14 @@ public class ClientProxy extends CommonProxy for (Block block : blocksToColour) { IBOPBlock bopBlock = (IBOPBlock)block; - - if (bopBlock.getBlockColor() != null) - Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler(bopBlock.getBlockColor(), block); - if (bopBlock.getItemColor() != null) - Minecraft.getMinecraft().getItemColors().registerItemColorHandler(bopBlock.getItemColor(), block); + if (bopBlock.getBlockColor() != null)Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler(bopBlock.getBlockColor(), block); + if (bopBlock.getItemColor() != null) Minecraft.getMinecraft().getItemColors().registerItemColorHandler(bopBlock.getItemColor(), block); + } + + for (Item item : itemsToColor) + { + IColoredItem coloredItem = (IColoredItem)item; + Minecraft.getMinecraft().getItemColors().registerItemColorHandler(coloredItem.getItemColor(), item); } } @@ -131,6 +140,35 @@ public class ClientProxy extends CommonProxy } } } + + @Override + public void registerItemSided(Item item) + { + // register sub types if there are any + if (item.getHasSubtypes()) + { + List subItems = new ArrayList(); + item.getSubItems(item, CreativeTabBOP.instance, subItems); + for (ItemStack subItem : subItems) + { + String subItemName = item.getUnlocalizedName(subItem); + subItemName = subItemName.substring(subItemName.indexOf(".") + 1); // remove 'item.' from the front + + ModelBakery.registerItemVariants(item, new ResourceLocation(BiomesOPlenty.MOD_ID, subItemName)); + ModelLoader.setCustomModelResourceLocation(item, subItem.getMetadata(), new ModelResourceLocation(BiomesOPlenty.MOD_ID + ":" + subItemName, "inventory")); + } + } + else + { + ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(BiomesOPlenty.MOD_ID + ":" + item.delegate.getResourceName().getResourcePath(), "inventory")); + } + + //Register colour handlers + if (item instanceof IColoredItem && ((IColoredItem)item).getItemColor() != null) + { + this.itemsToColor.add(item); + } + } @Override public void registerFluidBlockRendering(Block block, String name) diff --git a/src/main/java/biomesoplenty/core/CommonProxy.java b/src/main/java/biomesoplenty/core/CommonProxy.java index 9fb7dc517..e298e6c39 100644 --- a/src/main/java/biomesoplenty/core/CommonProxy.java +++ b/src/main/java/biomesoplenty/core/CommonProxy.java @@ -18,6 +18,7 @@ public class CommonProxy public void registerColouring() {} public void registerItemVariantModel(Item item, String name, int metadata) {} public void registerBlockSided(Block block) {} + public void registerItemSided(Item item) {} public void registerFluidBlockRendering(Block block, String name) {} public void spawnParticle(BOPParticleTypes type, double x, double y, double z, Object... info) {} } \ No newline at end of file diff --git a/src/main/resources/assets/biomesoplenty/models/item/spawn_egg_butterfly.json b/src/main/resources/assets/biomesoplenty/models/item/spawn_egg_butterfly.json index cff56a886..6f0e8c5be 100644 --- a/src/main/resources/assets/biomesoplenty/models/item/spawn_egg_butterfly.json +++ b/src/main/resources/assets/biomesoplenty/models/item/spawn_egg_butterfly.json @@ -2,5 +2,6 @@ "parent": "item/generated", "textures": { "layer0": "items/spawn_egg", + "layer1": "items/spawn_egg_overlay" } } \ No newline at end of file diff --git a/src/main/resources/assets/biomesoplenty/models/item/spawn_egg_pixie.json b/src/main/resources/assets/biomesoplenty/models/item/spawn_egg_pixie.json index cff56a886..6f0e8c5be 100644 --- a/src/main/resources/assets/biomesoplenty/models/item/spawn_egg_pixie.json +++ b/src/main/resources/assets/biomesoplenty/models/item/spawn_egg_pixie.json @@ -2,5 +2,6 @@ "parent": "item/generated", "textures": { "layer0": "items/spawn_egg", + "layer1": "items/spawn_egg_overlay" } } \ No newline at end of file diff --git a/src/main/resources/assets/biomesoplenty/models/item/spawn_egg_snail.json b/src/main/resources/assets/biomesoplenty/models/item/spawn_egg_snail.json index cff56a886..6f0e8c5be 100644 --- a/src/main/resources/assets/biomesoplenty/models/item/spawn_egg_snail.json +++ b/src/main/resources/assets/biomesoplenty/models/item/spawn_egg_snail.json @@ -2,5 +2,6 @@ "parent": "item/generated", "textures": { "layer0": "items/spawn_egg", + "layer1": "items/spawn_egg_overlay" } } \ No newline at end of file diff --git a/src/main/resources/assets/biomesoplenty/models/item/spawn_egg_wasp.json b/src/main/resources/assets/biomesoplenty/models/item/spawn_egg_wasp.json index cff56a886..6f0e8c5be 100644 --- a/src/main/resources/assets/biomesoplenty/models/item/spawn_egg_wasp.json +++ b/src/main/resources/assets/biomesoplenty/models/item/spawn_egg_wasp.json @@ -2,5 +2,6 @@ "parent": "item/generated", "textures": { "layer0": "items/spawn_egg", + "layer1": "items/spawn_egg_overlay" } } \ No newline at end of file