Inventory rendering now works correctly
This commit is contained in:
parent
e53f48b08f
commit
a84311f0d3
|
@ -64,7 +64,7 @@ public enum ChestChangerType {
|
|||
{
|
||||
item = new ItemChestChanger(this);
|
||||
GameRegistry.registerItem(item, itemName);
|
||||
ModelHelper.loadInventoryModel(item, "ironchest:" + itemName);
|
||||
ModelHelper.registerItem(item, "ironchest:" + itemName);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import net.minecraft.client.Minecraft;
|
|||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.RegistrySimple;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
@ -50,6 +51,8 @@ public class IronChest
|
|||
PacketHandler.INSTANCE.ordinal();
|
||||
}
|
||||
|
||||
private static boolean run = false;
|
||||
|
||||
@EventHandler
|
||||
public void load(FMLInitializationEvent evt)
|
||||
{
|
||||
|
@ -57,9 +60,9 @@ public class IronChest
|
|||
//Minecraft.getRenderItem() returns null before this stage
|
||||
ChestChangerType.buildItems();
|
||||
ironChestBlock = new BlockIronChest();
|
||||
GameRegistry.registerBlock(ironChestBlock, ItemIronChest.class, "BlockIronChest");
|
||||
RegistryHelper.registerBlock(ironChestBlock, ItemIronChest.class, "BlockIronChest");
|
||||
|
||||
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getModelManager().getBlockModelShapes().func_178123_a(ironChestBlock);
|
||||
ModelHelper.loadInventoryModel(ironChestBlock, "ironchest:BlockIronChest");
|
||||
|
||||
for (IronChestType typ : IronChestType.values())
|
||||
{
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.LoaderException;
|
||||
import net.minecraftforge.fml.common.LoaderState;
|
||||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
||||
import net.minecraftforge.fml.common.registry.GameData;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import com.google.common.collect.ObjectArrays;
|
||||
|
||||
public class RegistryHelper
|
||||
{
|
||||
/**
|
||||
* A temporary workaround whilst GameRegistry hasn't been fully updated to support 1.8
|
||||
*/
|
||||
public static Block registerBlock(Block block, Class<? extends ItemBlock> itemclass, String name, Object... itemCtorArgs)
|
||||
{
|
||||
block = GameRegistry.registerBlock(block, itemclass, name, itemCtorArgs);
|
||||
Item associatedItem = GameRegistry.findItem("ironchest", name);
|
||||
|
||||
Map itemBlockMap = (Map)ObfuscationReflectionHelper.getPrivateValue(Item.class, null, "field_179220_a");
|
||||
|
||||
if (!itemBlockMap.containsKey(block)) itemBlockMap.put(block, associatedItem);
|
||||
|
||||
Iterator iterator = block.getBlockState().getValidStates().iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
IBlockState iblockstate = (IBlockState)iterator.next();
|
||||
int id = Block.blockRegistry.getIDForObject(block) << 4 | block.getMetaFromBlockState(iblockstate);
|
||||
Block.field_176229_d.func_148746_a(iblockstate, id);
|
||||
}
|
||||
|
||||
return block;
|
||||
}
|
||||
}
|
|
@ -208,13 +208,13 @@ public class TileEntityIronChest extends TileEntityLockable implements IUpdatePl
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
public String getCommandSenderName()
|
||||
{
|
||||
return this.hasCustomName() ? this.customName : type.name();
|
||||
return this.hasName() ? this.customName : type.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
public boolean hasName()
|
||||
{
|
||||
return this.customName != null && this.customName.length() > 0;
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ public class TileEntityIronChest extends TileEntityLockable implements IUpdatePl
|
|||
nbttagcompound.setTag("Items", nbttaglist);
|
||||
nbttagcompound.setByte("facing", (byte)facing);
|
||||
|
||||
if (this.hasCustomName())
|
||||
if (this.hasName())
|
||||
{
|
||||
nbttagcompound.setString("CustomName", this.customName);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import net.minecraft.world.World;
|
|||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.ironchest.CommonProxy;
|
||||
import cpw.mods.ironchest.IronChest;
|
||||
import cpw.mods.ironchest.IronChestType;
|
||||
import cpw.mods.ironchest.TileEntityIronChest;
|
||||
|
||||
|
@ -28,6 +29,14 @@ public class ClientProxy extends CommonProxy
|
|||
@Override
|
||||
public void registerRenderInformation()
|
||||
{
|
||||
for (IronChestType chestType : IronChestType.values())
|
||||
{
|
||||
if (chestType != IronChestType.WOOD)
|
||||
{
|
||||
ModelHelper.registerBlock(IronChest.ironChestBlock, chestType.ordinal(), "ironchest:BlockIronChest");
|
||||
}
|
||||
}
|
||||
|
||||
TileEntityRendererChestHelper.instance = new IronChestRenderHelper();
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ public class IronChestRenderHelper extends TileEntityRendererChestHelper
|
|||
}
|
||||
|
||||
@Override
|
||||
public void renderChest(ItemStack itemStack)
|
||||
public void renderByItem(ItemStack itemStack)
|
||||
{
|
||||
Block block = Block.getBlockFromItem(itemStack.getItem());
|
||||
|
||||
|
@ -46,7 +46,7 @@ public class IronChestRenderHelper extends TileEntityRendererChestHelper
|
|||
}
|
||||
else
|
||||
{
|
||||
super.renderChest(itemStack);
|
||||
super.renderByItem(itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,18 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest.client;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.ItemModelMesher;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
@ -10,23 +21,24 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
|||
@SideOnly(Side.CLIENT)
|
||||
public class ModelHelper
|
||||
{
|
||||
public static void loadInventoryModel(Item item, int metadata, String itemName)
|
||||
public static void registerItem(Item item, int metadata, String itemName)
|
||||
{
|
||||
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().loadItemModel(item, metadata, new ModelResourceLocation(itemName, "inventory"));
|
||||
ItemModelMesher mesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();
|
||||
mesher.register(item, metadata, new ModelResourceLocation(itemName, "inventory"));
|
||||
}
|
||||
|
||||
public static void loadInventoryModel(Block block, int metadata, String blockName)
|
||||
public static void registerBlock(Block block, int metadata, String blockName)
|
||||
{
|
||||
loadInventoryModel(Item.getItemFromBlock(block), metadata, blockName);
|
||||
registerItem(Item.getItemFromBlock(block), metadata, blockName);
|
||||
}
|
||||
|
||||
public static void loadInventoryModel(Block block, String blockName)
|
||||
public static void registerBlock(Block block, String blockName)
|
||||
{
|
||||
loadInventoryModel(block, 0, blockName);
|
||||
registerBlock(block, 0, blockName);
|
||||
}
|
||||
|
||||
public static void loadInventoryModel(Item item, String itemName)
|
||||
public static void registerItem(Item item, String itemName)
|
||||
{
|
||||
loadInventoryModel(item, 0, itemName);
|
||||
registerItem(item, 0, itemName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"variants": {
|
||||
"normal": { "model": "ironchest:BlockIronChest" }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue