Cleaned up model registration

This commit is contained in:
Adubbz 2015-04-05 11:28:59 +10:00
parent 666b3f2424
commit eb78d15c08
5 changed files with 35 additions and 168 deletions

View file

@ -1,52 +0,0 @@
/*******************************************************************************
* Copyright 2014, 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.client.util;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockModelShapes;
import net.minecraft.client.renderer.ItemModelMesher;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ModelHelper
{
public static void registerItem(Item item, int metadata, String itemName)
{
getItemModelMesher().register(item, metadata, new ModelResourceLocation(itemName, "inventory"));
}
public static void registerBlock(Block block, int metadata, String blockName)
{
registerItem(Item.getItemFromBlock(block), metadata, blockName);
}
public static void registerBlock(Block block, String blockName)
{
registerBlock(block, 0, blockName);
}
public static void registerItem(Item item, String itemName)
{
registerItem(item, 0, itemName);
}
public static ItemModelMesher getItemModelMesher()
{
return Minecraft.getMinecraft().getRenderItem().getItemModelMesher();
}
public static BlockModelShapes getBlockModelShapes()
{
return getItemModelMesher().getModelManager().getBlockModelShapes();
}
}

View file

@ -9,19 +9,21 @@
package biomesoplenty.common.init; package biomesoplenty.common.init;
import static biomesoplenty.api.block.BOPBlocks.*; import static biomesoplenty.api.block.BOPBlocks.*;
import com.google.common.collect.ImmutableSet;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemDoor; import net.minecraft.item.ItemDoor;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.registry.GameRegistry;
import biomesoplenty.api.block.IBOPBlock; import net.minecraftforge.fml.relauncher.Side;
import biomesoplenty.api.block.BOPWoodEnums.allWoods; import biomesoplenty.api.block.BOPWoodEnums.allWoods;
import biomesoplenty.api.block.IBOPBlock;
import biomesoplenty.api.item.BOPItems; import biomesoplenty.api.item.BOPItems;
import biomesoplenty.common.block.BlockAsh; import biomesoplenty.common.block.BlockAsh;
import biomesoplenty.common.block.BlockBOPDirt; import biomesoplenty.common.block.BlockBOPDirt;
@ -46,6 +48,7 @@ import biomesoplenty.common.block.BlockBones;
import biomesoplenty.common.block.BlockCoral; import biomesoplenty.common.block.BlockCoral;
import biomesoplenty.common.block.BlockCrystal; import biomesoplenty.common.block.BlockCrystal;
import biomesoplenty.common.block.BlockDoubleFoliage; import biomesoplenty.common.block.BlockDoubleFoliage;
import biomesoplenty.common.block.BlockFlesh;
import biomesoplenty.common.block.BlockFoliage; import biomesoplenty.common.block.BlockFoliage;
import biomesoplenty.common.block.BlockFruit; import biomesoplenty.common.block.BlockFruit;
import biomesoplenty.common.block.BlockGem; import biomesoplenty.common.block.BlockGem;
@ -54,12 +57,13 @@ import biomesoplenty.common.block.BlockHive;
import biomesoplenty.common.block.BlockMud; import biomesoplenty.common.block.BlockMud;
import biomesoplenty.common.block.BlockStoneFormations; import biomesoplenty.common.block.BlockStoneFormations;
import biomesoplenty.common.block.BlockTurnip; import biomesoplenty.common.block.BlockTurnip;
import biomesoplenty.common.block.BlockFlesh;
import biomesoplenty.common.handler.GuiEventHandler; import biomesoplenty.common.handler.GuiEventHandler;
import biomesoplenty.common.util.block.BlockStateUtils; import biomesoplenty.common.util.block.BlockStateUtils;
import biomesoplenty.common.util.inventory.CreativeTabBOP; import biomesoplenty.common.util.inventory.CreativeTabBOP;
import biomesoplenty.core.BiomesOPlenty; import biomesoplenty.core.BiomesOPlenty;
import com.google.common.collect.ImmutableSet;
public class ModBlocks public class ModBlocks
{ {
@ -208,10 +212,11 @@ public class ModBlocks
public static void registerBlockVariant(Block block, String stateName, int stateMeta) public static void registerBlockVariant(Block block, String stateName, int stateMeta)
{ {
Item item = Item.getItemFromBlock(block); Item item = Item.getItemFromBlock(block);
if (item != null){ if (item != null && FMLCommonHandler.instance().getSide() == Side.CLIENT) {
BiomesOPlenty.proxy.addVariantName(item, BiomesOPlenty.MOD_ID + ":" + stateName); ModelBakery.addVariantName(item, BiomesOPlenty.MOD_ID + ":" + stateName);
ModelLoader.setCustomModelResourceLocation(item, stateMeta, new ModelResourceLocation(BiomesOPlenty.MOD_ID + ":" + stateName, "inventory"));
} }
BiomesOPlenty.proxy.registerBlockForMeshing(block, stateMeta, stateName);
GuiEventHandler.blockCount++; GuiEventHandler.blockCount++;
} }

View file

@ -18,12 +18,17 @@ import biomesoplenty.common.item.ItemGem;
import biomesoplenty.common.item.ItemMudball; import biomesoplenty.common.item.ItemMudball;
import biomesoplenty.common.util.inventory.CreativeTabBOP; import biomesoplenty.common.util.inventory.CreativeTabBOP;
import biomesoplenty.core.BiomesOPlenty; import biomesoplenty.core.BiomesOPlenty;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemFood; import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemSeeds; import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
public class ModItems public class ModItems
{ {
@ -48,11 +53,9 @@ public class ModItems
item.setUnlocalizedName(name).setCreativeTab(CreativeTabBOP.instance); item.setUnlocalizedName(name).setCreativeTab(CreativeTabBOP.instance);
GameRegistry.registerItem(item,name); GameRegistry.registerItem(item,name);
// register sub types if there are any // register sub types if there are any
if (FMLCommonHandler.instance().getSide() == Side.CLIENT)
{
if (item.getHasSubtypes()) if (item.getHasSubtypes())
{ {
List<ItemStack> subItems = new ArrayList<ItemStack>(); List<ItemStack> subItems = new ArrayList<ItemStack>();
@ -61,13 +64,15 @@ public class ModItems
{ {
String subItemName = item.getUnlocalizedName(subItem); String subItemName = item.getUnlocalizedName(subItem);
subItemName = subItemName.substring(subItemName.indexOf(".") + 1); // remove 'item.' from the front subItemName = subItemName.substring(subItemName.indexOf(".") + 1); // remove 'item.' from the front
BiomesOPlenty.proxy.addVariantName(item, BiomesOPlenty.MOD_ID + ":" + subItemName);
BiomesOPlenty.proxy.registerItemForMeshing(item, subItem.getMetadata(), subItemName); ModelBakery.addVariantName(item, BiomesOPlenty.MOD_ID + ":" + subItemName);
ModelLoader.setCustomModelResourceLocation(item, subItem.getMetadata(), new ModelResourceLocation(BiomesOPlenty.MOD_ID + ":" + subItemName, "inventory"));
} }
} }
else else
{ {
BiomesOPlenty.proxy.registerItemForMeshing(item,name); ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(BiomesOPlenty.MOD_ID + ":" + name, "inventory"));
}
} }
return item; return item;

View file

@ -8,92 +8,12 @@
package biomesoplenty.core; package biomesoplenty.core;
import java.util.ArrayList;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLeaves;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.item.Item;
import biomesoplenty.client.util.ModelHelper;
public class ClientProxy extends CommonProxy public class ClientProxy extends CommonProxy
{ {
private static ArrayList<ModelEntry> blocksToRegister = new ArrayList<ModelEntry>();
private static ArrayList<ItemEntry> itemsToRegister = new ArrayList<ItemEntry>();
@Override @Override
public void registerRenderers() public void registerRenderers()
{ {
//Entity rendering and other stuff will go here in future
for (ModelEntry modelEntry : blocksToRegister)
{
// set the correct rendering mode for leaves based on the fancyGraphics game setting
if (modelEntry.block instanceof BlockLeaves)
{
((BlockLeaves)modelEntry.block).setGraphicsLevel( Minecraft.getMinecraft().gameSettings.fancyGraphics );
}
// register the block model
ModelHelper.registerBlock(modelEntry.block, modelEntry.metadata, BiomesOPlenty.MOD_ID + ":" + modelEntry.name);
}
for (ItemEntry itemEntry : itemsToRegister)
{
// register the item model
ModelHelper.registerItem(itemEntry.item, itemEntry.metadata, BiomesOPlenty.MOD_ID + ":" + itemEntry.name);
}
}
@Override
public void addVariantName(Item item, String... names)
{
ModelBakery.addVariantName(item, names);
}
@Override
public void registerBlockForMeshing(Block block, int metadata, String name)
{
blocksToRegister.add(new ModelEntry(block, metadata, name));
}
@Override
public void registerItemForMeshing(Item item, String name)
{
itemsToRegister.add(new ItemEntry(item, 0, name));
}
@Override
public void registerItemForMeshing(Item item, int meta, String name)
{
itemsToRegister.add(new ItemEntry(item, meta, name));
}
private static class ModelEntry
{
public Block block;
public int metadata;
public String name;
public ModelEntry(Block block, int metadata, String name)
{
this.block = block;
this.metadata = metadata;
this.name = name;
}
}
private static class ItemEntry
{
public Item item;
public int metadata;
public String name;
public ItemEntry(Item item, int metadata, String name)
{
this.item = item;
this.metadata = metadata;
this.name = name;
}
} }
} }

View file

@ -8,19 +8,8 @@
package biomesoplenty.core; package biomesoplenty.core;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
public class CommonProxy public class CommonProxy
{ {
public void registerRenderers() {} public void registerRenderers() {}
public void addVariantName(Item item, String... names) {}
public void registerBlockForMeshing(Block block, int metadata, String name) {}
public void registerItemForMeshing(Item item, String name) {}
public void registerItemForMeshing(Item item, int meta, String name) {}
} }