Fixed spawn eggs
This commit is contained in:
parent
c3f6f0e011
commit
d739eb966e
9 changed files with 89 additions and 35 deletions
18
src/main/java/biomesoplenty/api/item/IColoredItem.java
Normal file
18
src/main/java/biomesoplenty/api/item/IColoredItem.java
Normal file
|
@ -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();
|
||||
}
|
|
@ -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<ItemStack> subItems = new ArrayList<ItemStack>();
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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<Integer, EntityList.EntityEggInfo> 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)
|
||||
{
|
||||
|
@ -90,6 +89,21 @@ public class ItemBOPSpawnEgg extends Item
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -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,6 +70,7 @@ public class ClientProxy extends CommonProxy
|
|||
public static ResourceLocation particleTexturesLocation = new ResourceLocation("biomesoplenty:textures/particles/particles.png");
|
||||
|
||||
private static List<Block> blocksToColour = Lists.newArrayList();
|
||||
private static List<Item> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,6 +141,35 @@ public class ClientProxy extends CommonProxy
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerItemSided(Item item)
|
||||
{
|
||||
// register sub types if there are any
|
||||
if (item.getHasSubtypes())
|
||||
{
|
||||
List<ItemStack> subItems = new ArrayList<ItemStack>();
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -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) {}
|
||||
}
|
|
@ -2,5 +2,6 @@
|
|||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "items/spawn_egg",
|
||||
"layer1": "items/spawn_egg_overlay"
|
||||
}
|
||||
}
|
|
@ -2,5 +2,6 @@
|
|||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "items/spawn_egg",
|
||||
"layer1": "items/spawn_egg_overlay"
|
||||
}
|
||||
}
|
|
@ -2,5 +2,6 @@
|
|||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "items/spawn_egg",
|
||||
"layer1": "items/spawn_egg_overlay"
|
||||
}
|
||||
}
|
|
@ -2,5 +2,6 @@
|
|||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "items/spawn_egg",
|
||||
"layer1": "items/spawn_egg_overlay"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue