Iron chests can now be placed (with hackery)

This commit is contained in:
Adubbz 2014-09-25 11:54:30 +10:00
parent 5ee76dbe22
commit a015481d3d
7 changed files with 109 additions and 28 deletions

View File

@ -58,6 +58,9 @@ func_177775_a - addObject
func_174889_b - openInventory
func_174886_c - closeInventory
—RenderItem—
func_180451_a - renderEffect
——————————
ESTIMATES
——————————
@ -164,6 +167,11 @@ field_177992_a - ORIGIN
—IStringSerializable—
func_176610_l - getID
—ModelBakery—
func_177580_d - getModelLocation
func_177584_b - getBlockStateLocation
func_177586_a - getModelBlockDefinition
——————————
FIXES
——————————
@ -173,4 +181,50 @@ FIXES
{
ResourceLocation key = new ResourceLocation(modId + ":" + name);
return getMain().iBlockRegistry.containsKey(key) ? getMain().iBlockRegistry.getObject(key) : null;
}
private int registerBlock(Block block, String name, int idHint)
{
// handle ItemBlock-before-Block registrations
ItemBlock itemBlock = null;
for (Item item : iItemRegistry.typeSafeIterable()) // find matching ItemBlock
{
if (item instanceof ItemBlock && ((ItemBlock) item).blockInstance == block)
{
itemBlock = (ItemBlock) item;
break;
}
}
if (itemBlock != null) // has ItemBlock, adjust id and clear the slot already occupied by the corresponding item
{
idHint = iItemRegistry.getId(itemBlock);
FMLLog.fine("Found matching ItemBlock %s for Block %s at id %d", itemBlock, block, idHint);
freeSlot(idHint, block); // temporarily free the slot occupied by the Item for the block registration
}
// add
int blockId = iBlockRegistry.add(idHint, name, block, availabilityMap);
if (itemBlock != null) // verify
{
if (blockId != idHint) throw new IllegalStateException(String.format("Block at itemblock id %d insertion failed, got id %d.", idHint, blockId));
verifyItemBlockName(itemBlock);
}
//Hackery added by me which probably shouldn't be done
Iterator iterator1 = block.getBlockState().getValidStates().iterator();
while (iterator1.hasNext())
{
IBlockState iblockstate = (IBlockState)iterator1.next();
int i = blockRegistry.getIDForObject(block) << 4 | block.getMetaFromBlockState(iblockstate);
Block.field_176229_d.func_148746_a(iblockstate, i);
}
//End hackery
useSlot(blockId);
((RegistryDelegate.Delegate<Block>) block.delegate).setName(name);
return blockId;
}

View File

@ -10,6 +10,7 @@
******************************************************************************/
package cpw.mods.ironchest;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
@ -19,12 +20,15 @@ import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockIronChest extends /*BlockContainer*/Block
{
public static final PropertyEnum VARIANT_PROP = PropertyEnum.func_177709_a("variant", IronChestType.class);
private Random random;
public BlockIronChest()
{
@ -32,11 +36,10 @@ public class BlockIronChest extends /*BlockContainer*/Block
this.setDefaultBlockState(this.blockState.getBaseState().setProperty(VARIANT_PROP, IronChestType.IRON));
setUnlocalizedName("IronChest");
setHardness(3.0F);
setBlockBounds(0.0625F, 0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
random = new Random();
setCreativeTab(CreativeTabs.tabDecorations);
//this.setBlockBounds(0.0625F, 0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
this.setHardness(3.0F);
this.setUnlocalizedName("IronChest");
this.setCreativeTab(CreativeTabs.tabDecorations);
}
@Override
@ -51,6 +54,19 @@ public class BlockIronChest extends /*BlockContainer*/Block
return false;
}
/*@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item itemIn, CreativeTabs tab, List list)
{
for (IronChestType type : IronChestType.values())
{
if (type.isValidForCreativeMode())
{
list.add(new ItemStack(this, 1, type.ordinal()));
}
}
}*/
@Override
public IBlockState getBlockStateFromMeta(int meta)
{
@ -206,20 +222,6 @@ public class BlockIronChest extends /*BlockContainer*/Block
}
}*/
/*@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (IronChestType type : IronChestType.values())
{
if (type.isValidForCreativeMode())
{
par3List.add(new ItemStack(this, 1, type.ordinal()));
}
}
}*/
/*@Override
public float getExplosionResistance(Entity par1Entity, World world, int x, int y, int z, double explosionX, double explosionY, double explosionZ)
{

View File

@ -10,7 +10,9 @@
******************************************************************************/
package cpw.mods.ironchest;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
@ -53,7 +55,7 @@ public class IronChest {
cfg.save();
}*/
ironChestBlock = new BlockIronChest();
GameRegistry.registerBlock(ironChestBlock,/* ItemIronChest.class,*/ "BlockIronChest");
GameRegistry.registerBlock(ironChestBlock, ItemIronChest.class, "BlockIronChest");
//PacketHandler.INSTANCE.ordinal();
}

View File

@ -14,23 +14,25 @@ import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
public class ItemIronChest extends ItemBlock {
public class ItemIronChest extends ItemBlock
{
public ItemIronChest(Block block)
{
super(block);
setHasSubtypes(true);
this.setMaxDurability(0);
this.setHasSubtypes(true);
}
@Override
public int getMetadata(int i)
public int getMetadata(int meta)
{
return IronChestType.validateMeta(i);
return IronChestType.validateMeta(meta);
}
@Override
public String getUnlocalizedName(ItemStack itemstack)
{
return "tile.ironchest:"+IronChestType.values()[itemstack.getMetadata()].name();
return "tile.ironchest:" + IronChestType.values()[itemstack.getMetadata()].name();
}
}

View File

@ -0,0 +1,5 @@
{
"variants": {
"normal": { "model": "ironchest:BlockIronChest" }
}
}

View File

@ -0,0 +1,6 @@
{
"parent": "block/cube_all",
"textures": {
"all": "blocks/clay"
}
}

View File

@ -0,0 +1,10 @@
{
"parent": "ironchest:block/BlockIronChest",
"display": {
"thirdperson": {
"rotation": [ 10, -45, 170 ],
"translation": [ 0, 1.5, -2.75 ],
"scale": [ 0.375, 0.375, 0.375 ]
}
}
}