Update for 1.4.6. Change render handling a bit.

This commit is contained in:
Christian 2012-12-18 11:22:21 -05:00
parent 70232000a8
commit 2735d04de2
27 changed files with 1622 additions and 1437 deletions

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="client"/>
<classpathentry kind="src" path="common"/> <classpathentry kind="src" path="common"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/Forge"/> <classpathentry combineaccessrules="false" kind="src" path="/Forge"/>

View File

@ -1,52 +0,0 @@
/*******************************************************************************
* 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.client.renderer.ChestItemRenderHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.ironchest.CommonProxy;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.TileEntityIronChest;
public class ClientProxy extends CommonProxy {
@Override
public void registerRenderInformation() {
ChestItemRenderHelper.instance = new IronChestRenderHelper();
MinecraftForgeClient.preloadTexture("/cpw/mods/ironchest/sprites/block_textures.png");
MinecraftForgeClient.preloadTexture("/cpw/mods/ironchest/sprites/item_textures.png");
}
@Override
public void registerTileEntitySpecialRenderer(IronChestType typ) {
ClientRegistry.bindTileEntitySpecialRenderer(typ.clazz, new TileEntityIronChestRenderer());
}
@Override
public World getClientWorld() {
return FMLClientHandler.instance().getClient().theWorld;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
TileEntity te = world.getBlockTileEntity(x, y, z);
if (te != null && te instanceof TileEntityIronChest) {
return GUIChest.GUI.buildGUI(IronChestType.values()[ID], player.inventory, (TileEntityIronChest) te);
} else {
return null;
}
}
}

View File

@ -1,75 +0,0 @@
/*******************************************************************************
* 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.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import org.lwjgl.opengl.GL11;
import cpw.mods.ironchest.ContainerIronChestBase;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.TileEntityIronChest;
public class GUIChest extends GuiContainer {
public enum GUI {
IRON(184,202,"/cpw/mods/ironchest/sprites/ironcontainer.png",IronChestType.IRON),
GOLD(184,256,"/cpw/mods/ironchest/sprites/goldcontainer.png",IronChestType.GOLD),
DIAMOND(238,256,"/cpw/mods/ironchest/sprites/diamondcontainer.png",IronChestType.DIAMOND),
COPPER(184,184,"/cpw/mods/ironchest/sprites/coppercontainer.png",IronChestType.COPPER),
SILVER(184,238,"/cpw/mods/ironchest/sprites/silvercontainer.png",IronChestType.SILVER),
CRYSTAL(238,256,"/cpw/mods/ironchest/sprites/diamondcontainer.png",IronChestType.CRYSTAL);
private int xSize;
private int ySize;
private String guiTexture;
private IronChestType mainType;
private GUI(int xSize, int ySize, String guiTexture, IronChestType mainType) {
this.xSize=xSize;
this.ySize=ySize;
this.guiTexture=guiTexture;
this.mainType=mainType;
}
protected Container makeContainer(IInventory player, IInventory chest) {
return new ContainerIronChestBase(player,chest, mainType, xSize, ySize);
}
public static GUIChest buildGUI(IronChestType type, IInventory playerInventory, TileEntityIronChest chestInventory) {
return new GUIChest(values()[chestInventory.getType().ordinal()],playerInventory,chestInventory);
}
}
public int getRowLength() {
return type.mainType.getRowLength();
}
private GUI type;
private GUIChest(GUI type, IInventory player, IInventory chest) {
super(type.makeContainer(player,chest));
this.type=type;
this.xSize=type.xSize;
this.ySize=type.ySize;
this.allowUserInput=false;
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int i, int j) {
int tex = mc.renderEngine.getTexture(type.guiTexture);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(tex);
int x = (width - xSize) / 2;
int y = (height - ySize) / 2;
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
}
}

View File

@ -1,249 +0,0 @@
/*******************************************************************************
* 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 static org.lwjgl.opengl.GL11.GL_COMPILE_AND_EXECUTE;
import static org.lwjgl.opengl.GL11.glCallList;
import static org.lwjgl.opengl.GL11.glColor4f;
import static org.lwjgl.opengl.GL11.glDisable;
import static org.lwjgl.opengl.GL11.glEnable;
import static org.lwjgl.opengl.GL11.glEndList;
import static org.lwjgl.opengl.GL11.glGenLists;
import static org.lwjgl.opengl.GL11.glNewList;
import static org.lwjgl.opengl.GL11.glPopMatrix;
import static org.lwjgl.opengl.GL11.glPushMatrix;
import static org.lwjgl.opengl.GL11.glRotatef;
import static org.lwjgl.opengl.GL11.glScalef;
import static org.lwjgl.opengl.GL11.glTranslatef;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.client.model.ModelChest;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.client.MinecraftForgeClient;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.ironchest.IronChest;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.MappableItemStackWrapper;
import cpw.mods.ironchest.TileEntityIronChest;
public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
private static Map<MappableItemStackWrapper, Integer> renderList = new HashMap<MappableItemStackWrapper, Integer>();
private Random random;
private RenderBlocks renderBlocks;
private static float[][] shifts = { { 0.3F, 0.45F, 0.3F }, { 0.7F, 0.45F, 0.3F }, { 0.3F, 0.45F, 0.7F }, { 0.7F, 0.45F, 0.7F }, { 0.3F, 0.1F, 0.3F },
{ 0.7F, 0.1F, 0.3F }, { 0.3F, 0.1F, 0.7F }, { 0.7F, 0.1F, 0.7F }, { 0.5F, 0.32F, 0.5F }, };
public TileEntityIronChestRenderer() {
model = new ModelChest();
random = new Random();
renderBlocks = new RenderBlocks();
}
private void overrideTexture(Object obj) {
if (obj instanceof Item) {
GL11.glBindTexture(GL11.GL_TEXTURE_2D, FMLClientHandler.instance().getClient().renderEngine.getTexture(((Item) obj).getTextureFile()));
} else if (obj instanceof Block) {
GL11.glBindTexture(GL11.GL_TEXTURE_2D, FMLClientHandler.instance().getClient().renderEngine.getTexture(((Block) obj).getTextureFile()));
}
}
public void render(TileEntityIronChest tile, double x, double y, double z, float partialTick) {
if (tile == null) {
return;
}
int facing = 3;
IronChestType type = tile.getType();
if (tile != null && tile.getWorldObj() != null) {
facing = tile.getFacing();
type = tile.getType();
int typ = tile.getWorldObj().getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord);
type = IronChestType.values()[typ];
}
bindTextureByName(type.getModelTexture());
glPushMatrix();
glEnable(32826 /* GL_RESCALE_NORMAL_EXT */);
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
glTranslatef((float) x, (float) y + 1.0F, (float) z + 1.0F);
glScalef(1.0F, -1F, -1F);
glTranslatef(0.5F, 0.5F, 0.5F);
int k = 0;
if (facing == 2) {
k = 180;
}
if (facing == 3) {
k = 0;
}
if (facing == 4) {
k = 90;
}
if (facing == 5) {
k = -90;
}
glRotatef(k, 0.0F, 1.0F, 0.0F);
glTranslatef(-0.5F, -0.5F, -0.5F);
float lidangle = tile.prevLidAngle + (tile.lidAngle - tile.prevLidAngle) * partialTick;
lidangle = 1.0F - lidangle;
lidangle = 1.0F - lidangle * lidangle * lidangle;
model.chestLid.rotateAngleX = -((lidangle * 3.141593F) / 2.0F);
// Render the chest itself
model.renderAll();
glDisable(32826 /* GL_RESCALE_NORMAL_EXT */);
glPopMatrix();
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
if (type.isTransparent()) {
random.setSeed(254L);
float shiftX;
float shiftY;
float shiftZ;
int shift = 0;
float spread = 0.1F;
float blockScale = 0.15F;
float timeD = (float) (360.0 * (double) (System.currentTimeMillis() & 0x3FFFL) / (double) 0x3FFFL);
if (tile.getTopItemStacks()[1] == null) {
shift = 8;
blockScale = 0.2F;
spread = 0.22F;
}
glPushMatrix();
glDisable(2896 /* GL_LIGHTING */);
glEnable(32826 /* GL_RESCALE_NORMAL_EXT */);
glTranslatef((float) x, (float) y, (float) z);
EntityItem customitem = new EntityItem(tileEntityRenderer.worldObj);
for (ItemStack item : tile.getTopItemStacks()) {
if (shift > shifts.length) {
break;
}
if (item == null) {
shift++;
continue;
}
shiftX = shifts[shift][0];
shiftY = shifts[shift][1];
shiftZ = shifts[shift][2];
shift++;
float localScale = blockScale;
if (item.itemID < Block.blocksList.length && Block.blocksList[item.itemID] != null && Block.blocksList[item.itemID].blockID != 0) {
int j = Block.blocksList[item.itemID].getRenderType();
if (j == 1 || j == 19 || j == 12 || j == 2) {
localScale = 2 * blockScale;
}
}
glPushMatrix();
glTranslatef(shiftX, shiftY, shiftZ);
glScalef(localScale, localScale, localScale);
for (int miniBlocks = 0; miniBlocks < (item.stackSize / 32) + 1; miniBlocks++) {
glPushMatrix();
glRotatef(timeD, 0.0F, 1.0F, 0.0F);
if (miniBlocks > 0) {
float minishiftX = ((random.nextFloat() * 2.0F - 1.0F) * spread) / localScale;
float minishiftY = ((random.nextFloat() * 2.0F - 1.0F) * spread * 0.9F) / localScale;
float minishiftZ = ((random.nextFloat() * 2.0F - 1.0F) * spread) / localScale;
glTranslatef(minishiftX, minishiftY, minishiftZ);
}
MappableItemStackWrapper mis = new MappableItemStackWrapper(item);
if (!IronChest.CACHE_RENDER || !renderList.containsKey(mis)) { // Added support for using only old system.
// TODO add support for the skull TESR
IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(item, IItemRenderer.ItemRenderType.ENTITY);
if (customRenderer != null) {
customitem.item = item;
bindTextureByName("/terrain.png");
overrideTexture(item.getItem());
customRenderer.renderItem(IItemRenderer.ItemRenderType.ENTITY, item, renderBlocks, customitem);
} else if (item.itemID < Block.blocksList.length && Block.blocksList[item.itemID] != null && Block.blocksList[item.itemID].blockID != 0 && RenderBlocks.renderItemIn3d(Block.blocksList[item.itemID].getRenderType())) {
bindTextureByName("/terrain.png");
overrideTexture(Block.blocksList[item.itemID]);
renderBlocks.renderBlockAsItem(Block.blocksList[item.itemID], item.getItemDamage(), 1.0F);
} else {
int render = 0;
if (IronChest.CACHE_RENDER) {
render = glGenLists(1);
if (render != 0)
{
renderList.put(mis, render);
glNewList(render, GL_COMPILE_AND_EXECUTE);
}
}
int i = item.getIconIndex();
if (item.itemID >= Block.blocksList.length || Block.blocksList[item.itemID] == null || Block.blocksList[item.itemID].blockID == 0) {
bindTextureByName("/gui/items.png");
overrideTexture(Item.itemsList[item.itemID]);
} else {
bindTextureByName("/terrain.png");
overrideTexture(Block.blocksList[item.itemID]);
}
Tessellator tessellator = Tessellator.instance;
float f5 = (float) ((i % 16) * 16 + 0) / 256F;
float f8 = (float) ((i % 16) * 16 + 16) / 256F;
float f10 = (float) ((i / 16) * 16 + 0) / 256F;
float f12 = (float) ((i / 16) * 16 + 16) / 256F;
float f13 = 1.0F;
float f14 = 0.5F;
float f15 = 0.25F;
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 1.0F, 0.0F);
tessellator.addVertexWithUV(0.0F - f14, 0.0F - f15, 0.0D, f5, f12);
tessellator.addVertexWithUV(f13 - f14, 0.0F - f15, 0.0D, f8, f12);
tessellator.addVertexWithUV(f13 - f14, 1.0F - f15, 0.0D, f8, f10);
tessellator.addVertexWithUV(0.0F - f14, 1.0F - f15, 0.0D, f5, f10);
tessellator.draw();
glScalef(-1.0F, 1.0F, 1.0F);
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 1.0F, 0.0F);
tessellator.addVertexWithUV(0.0F - f14, 0.0F - f15, 0.0D, f5, f12);
tessellator.addVertexWithUV(f13 - f14, 0.0F - f15, 0.0D, f8, f12);
tessellator.addVertexWithUV(f13 - f14, 1.0F - f15, 0.0D, f8, f10);
tessellator.addVertexWithUV(0.0F - f14, 1.0F - f15, 0.0D, f5, f10);
tessellator.draw();
if (IronChest.CACHE_RENDER && render != 0) {
glEndList();
}
}
} else {
Integer integer = renderList.get(mis);
if (integer != null) { // Added null check for auto-unboxing JUST in case.
glCallList(integer.intValue());
}
}
glPopMatrix();
}
glPopMatrix();
}
glDisable(32826 /* GL_RESCALE_NORMAL_EXT */);
glEnable(2896 /* GL_LIGHTING */);
glPopMatrix();
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
}
}
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float partialTick) {
render((TileEntityIronChest) tileentity, x, y, z, partialTick);
}
private ModelChest model;
}

View File

@ -13,8 +13,8 @@ package cpw.mods.ironchest;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import cpw.mods.fml.common.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.common.asm.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
@ -35,7 +35,8 @@ public class BlockIronChest extends BlockContainer {
private Random random; private Random random;
public BlockIronChest(int id) { public BlockIronChest(int id)
{
super(id, Material.iron); super(id, Material.iron);
setBlockName("IronChest"); setBlockName("IronChest");
setHardness(3.0F); setHardness(3.0F);
@ -46,56 +47,71 @@ public class BlockIronChest extends BlockContainer {
} }
@Override @Override
public TileEntity createNewTileEntity(World w) { public TileEntity createNewTileEntity(World w)
{
return null; return null;
} }
@Override @Override
public String getTextureFile() { public String getTextureFile()
{
return "/cpw/mods/ironchest/sprites/block_textures.png"; return "/cpw/mods/ironchest/sprites/block_textures.png";
} }
@Override @Override
public boolean isOpaqueCube() { public boolean isOpaqueCube()
{
return false; return false;
} }
@Override @Override
public boolean renderAsNormalBlock() { public boolean renderAsNormalBlock()
{
return false; return false;
} }
@Override @Override
public int getRenderType() { public int getRenderType()
{
return 22; return 22;
} }
@Override @Override
public TileEntity createNewTileEntity(World world, int metadata) { public TileEntity createNewTileEntity(World world, int metadata)
{
return IronChestType.makeEntity(metadata); return IronChestType.makeEntity(metadata);
} }
public int getBlockTexture(IBlockAccess worldAccess, int i, int j, int k, int l) { public int getBlockTexture(IBlockAccess worldAccess, int i, int j, int k, int l)
{
int meta = worldAccess.getBlockMetadata(i, j, k); int meta = worldAccess.getBlockMetadata(i, j, k);
IronChestType type = IronChestType.values()[meta]; IronChestType type = IronChestType.values()[meta];
TileEntity te = worldAccess.getBlockTileEntity(i, j, k); TileEntity te = worldAccess.getBlockTileEntity(i, j, k);
TileEntityIronChest icte = null; TileEntityIronChest icte = null;
if (te != null && te instanceof TileEntityIronChest) { if (te != null && te instanceof TileEntityIronChest)
{
icte = (TileEntityIronChest) te; icte = (TileEntityIronChest) te;
} }
if (l == 0 || l == 1) { // Top and Bottom if (l == 0 || l == 1)
{ // Top and Bottom
return type.getTextureRow() * 16 + 1; return type.getTextureRow() * 16 + 1;
} else if (icte != null && l == icte.getFacing()) { // Front }
else if (icte != null && l == icte.getFacing())
{ // Front
return type.getTextureRow() * 16 + 2; return type.getTextureRow() * 16 + 2;
} else { // Back and Sides }
else
{ // Back and Sides
return type.getTextureRow() * 16; return type.getTextureRow() * 16;
} }
} }
@Override @Override
public int getBlockTextureFromSideAndMetadata(int i, int j) { public int getBlockTextureFromSideAndMetadata(int i, int j)
{
IronChestType typ = IronChestType.values()[j]; IronChestType typ = IronChestType.values()[j];
switch (i) { switch (i)
{
case 0: case 0:
case 1: case 1:
return typ.getTextureRow() * 16 + 1; return typ.getTextureRow() * 16 + 1;
@ -107,7 +123,8 @@ public class BlockIronChest extends BlockContainer {
} }
@Override @Override
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int i1, float f1, float f2, float f3) { public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int i1, float f1, float f2, float f3)
{
TileEntity te = world.getBlockTileEntity(i, j, k); TileEntity te = world.getBlockTileEntity(i, j, k);
if (te == null || !(te instanceof TileEntityIronChest)) if (te == null || !(te instanceof TileEntityIronChest))
@ -120,7 +137,8 @@ public class BlockIronChest extends BlockContainer {
return true; return true;
} }
if (world.isRemote) { if (world.isRemote)
{
return true; return true;
} }
@ -129,36 +147,44 @@ public class BlockIronChest extends BlockContainer {
} }
@Override @Override
public void onBlockAdded(World world, int i, int j, int k) { public void onBlockAdded(World world, int i, int j, int k)
{
super.onBlockAdded(world, i, j, k); super.onBlockAdded(world, i, j, k);
world.markBlockForUpdate(i, j, k); world.markBlockForUpdate(i, j, k);
} }
@Override @Override
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving) { public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving)
{
byte chestFacing = 0; byte chestFacing = 0;
int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3; int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
if (facing == 0) { if (facing == 0)
{
chestFacing = 2; chestFacing = 2;
} }
if (facing == 1) { if (facing == 1)
{
chestFacing = 5; chestFacing = 5;
} }
if (facing == 2) { if (facing == 2)
{
chestFacing = 3; chestFacing = 3;
} }
if (facing == 3) { if (facing == 3)
{
chestFacing = 4; chestFacing = 4;
} }
TileEntity te = world.getBlockTileEntity(i, j, k); TileEntity te = world.getBlockTileEntity(i, j, k);
if (te != null && te instanceof TileEntityIronChest) { if (te != null && te instanceof TileEntityIronChest)
{
((TileEntityIronChest) te).setFacing(chestFacing); ((TileEntityIronChest) te).setFacing(chestFacing);
world.markBlockForUpdate(i, j, k); world.markBlockForUpdate(i, j, k);
} }
} }
@Override @Override
public int damageDropped(int i) { public int damageDropped(int i)
{
return i; return i;
} }
@ -173,7 +199,8 @@ public class BlockIronChest extends BlockContainer {
super.breakBlock(world, i, j, k, i1, i2); super.breakBlock(world, i, j, k, i1, i2);
} }
public void dropContent(int newSize, IInventory chest, World world, int xCoord, int yCoord, int zCoord) { public void dropContent(int newSize, IInventory chest, World world, int xCoord, int yCoord, int zCoord)
{
for (int l = newSize; l < chest.getSizeInventory(); l++) for (int l = newSize; l < chest.getSizeInventory(); l++)
{ {
ItemStack itemstack = chest.getStackInSlot(l); ItemStack itemstack = chest.getStackInSlot(l);
@ -200,7 +227,7 @@ public class BlockIronChest extends BlockContainer {
entityitem.motionZ = (float) random.nextGaussian() * f3; entityitem.motionZ = (float) random.nextGaussian() * f3;
if (itemstack.hasTagCompound()) if (itemstack.hasTagCompound())
{ {
entityitem.item.setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy()); entityitem.func_92014_d().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
} }
world.spawnEntityInWorld(entityitem); world.spawnEntityInWorld(entityitem);
} }
@ -210,9 +237,12 @@ public class BlockIronChest extends BlockContainer {
@Override @Override
@SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({ "rawtypes", "unchecked" })
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List) { public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
for (IronChestType type : IronChestType.values()) { {
if (type.isValidForCreativeMode()) { for (IronChestType type : IronChestType.values())
{
if (type.isValidForCreativeMode())
{
par3List.add(new ItemStack(this, 1, type.ordinal())); par3List.add(new ItemStack(this, 1, type.ordinal()));
} }
} }

View File

@ -19,14 +19,12 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.common.Configuration; import net.minecraftforge.common.Configuration;
public enum ChestChangerType { public enum ChestChangerType {
IRONGOLD(IRON, GOLD, "ironGoldUpgrade", "Iron to Gold Chest Upgrade", "mmm", "msm", "mmm"), IRONGOLD(IRON, GOLD, "ironGoldUpgrade", "Iron to Gold Chest Upgrade", "mmm", "msm", "mmm"), GOLDDIAMOND(GOLD, DIAMOND, "goldDiamondUpgrade",
GOLDDIAMOND(GOLD, DIAMOND, "goldDiamondUpgrade", "Gold to Diamond Chest Upgrade", "GGG", "msm", "GGG"), "Gold to Diamond Chest Upgrade", "GGG", "msm", "GGG"), COPPERSILVER(COPPER, SILVER, "copperSilverUpgrade", "Copper to Silver Chest Upgrade", "mmm",
COPPERSILVER(COPPER, SILVER, "copperSilverUpgrade", "Copper to Silver Chest Upgrade", "mmm", "msm", "mmm"), "msm", "mmm"), SILVERGOLD(SILVER, GOLD, "silverGoldUpgrade", "Silver to Gold Chest Upgrade", "mGm", "GsG", "mGm"), COPPERIRON(COPPER, IRON,
SILVERGOLD(SILVER, GOLD, "silverGoldUpgrade", "Silver to Gold Chest Upgrade", "mGm", "GsG", "mGm"), "copperIronUpgrade", "Copper to Iron Chest Upgrade", "mGm", "GsG", "mGm"), DIAMONDCRYSTAL(DIAMOND, CRYSTAL, "diamondCrystalUpgrade",
COPPERIRON(COPPER, IRON, "copperIronUpgrade", "Copper to Iron Chest Upgrade", "mGm", "GsG", "mGm"), "Diamond to Crystal Chest Upgrade", "GGG", "GOG", "GGG"), WOODIRON(WOOD, IRON, "woodIronUpgrade", "Normal chest to Iron Chest Upgrade", "mmm",
DIAMONDCRYSTAL(DIAMOND, CRYSTAL, "diamondCrystalUpgrade", "Diamond to Crystal Chest Upgrade", "GGG", "GOG", "GGG"), "msm", "mmm"), WOODCOPPER(WOOD, COPPER, "woodCopperUpgrade", "Normal chest to Copper Chest Upgrade", "mmm", "msm", "mmm");
WOODIRON(WOOD, IRON, "woodIronUpgrade", "Normal chest to Iron Chest Upgrade", "mmm", "msm", "mmm"),
WOODCOPPER(WOOD, COPPER, "woodCopperUpgrade", "Normal chest to Copper Chest Upgrade", "mmm", "msm", "mmm");
private IronChestType source; private IronChestType source;
private IronChestType target; private IronChestType target;
@ -35,7 +33,8 @@ public enum ChestChangerType {
private ItemChestChanger item; private ItemChestChanger item;
private String[] recipe; private String[] recipe;
private ChestChangerType(IronChestType source, IronChestType target, String itemName, String descriptiveName, String... recipe) { private ChestChangerType(IronChestType source, IronChestType target, String itemName, String descriptiveName, String... recipe)
{
this.source = source; this.source = source;
this.target = target; this.target = target;
this.itemName = itemName; this.itemName = itemName;
@ -43,23 +42,29 @@ public enum ChestChangerType {
this.recipe = recipe; this.recipe = recipe;
} }
public boolean canUpgrade(IronChestType from) { public boolean canUpgrade(IronChestType from)
{
return from == this.source; return from == this.source;
} }
public int getTarget() { public int getTarget()
{
return this.target.ordinal(); return this.target.ordinal();
} }
public ItemChestChanger buildItem(Configuration cfg, int id) { public ItemChestChanger buildItem(Configuration cfg, int id)
{
int itemId = cfg.get(Configuration.CATEGORY_ITEM, itemName, id).getInt(id); int itemId = cfg.get(Configuration.CATEGORY_ITEM, itemName, id).getInt(id);
item = new ItemChestChanger(itemId, this); item = new ItemChestChanger(itemId, this);
return item; return item;
} }
public void addRecipes() { public void addRecipes()
for (String sourceMat : source.getMatList()) { {
for (String targetMat : target.getMatList()) { for (String sourceMat : source.getMatList())
{
for (String targetMat : target.getMatList())
{
Object targetMaterial = IronChestType.translateOreName(targetMat); Object targetMaterial = IronChestType.translateOreName(targetMat);
Object sourceMaterial = IronChestType.translateOreName(sourceMat); Object sourceMaterial = IronChestType.translateOreName(sourceMat);
IronChestType.addRecipe(new ItemStack(item), recipe, 'm', targetMaterial, 's', sourceMaterial, 'G', Block.glass, 'O', Block.obsidian); IronChestType.addRecipe(new ItemStack(item), recipe, 'm', targetMaterial, 's', sourceMaterial, 'G', Block.glass, 'O', Block.obsidian);
@ -67,14 +72,18 @@ public enum ChestChangerType {
} }
} }
public static void buildItems(Configuration cfg, int defaultId) { public static void buildItems(Configuration cfg, int defaultId)
for (ChestChangerType type : values()) { {
for (ChestChangerType type : values())
{
type.buildItem(cfg, defaultId++); type.buildItem(cfg, defaultId++);
} }
} }
public static void generateRecipes() { public static void generateRecipes()
for (ChestChangerType item : values()) { {
for (ChestChangerType item : values())
{
item.addRecipes(); item.addRecipes();
} }
} }

View File

@ -27,22 +27,28 @@ public class CommonProxy implements IGuiHandler {
} }
@Override @Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
return null; return null;
} }
@Override @Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int X, int Y, int Z) { public Object getServerGuiElement(int ID, EntityPlayer player, World world, int X, int Y, int Z)
{
TileEntity te = world.getBlockTileEntity(X, Y, Z); TileEntity te = world.getBlockTileEntity(X, Y, Z);
if (te != null && te instanceof TileEntityIronChest) { if (te != null && te instanceof TileEntityIronChest)
{
TileEntityIronChest icte = (TileEntityIronChest) te; TileEntityIronChest icte = (TileEntityIronChest) te;
return new ContainerIronChestBase(player.inventory, icte, icte.getType(), 0, 0); return new ContainerIronChestBase(player.inventory, icte, icte.getType(), 0, 0);
} else { }
else
{
return null; return null;
} }
} }
public World getClientWorld() { public World getClientWorld()
{
return null; return null;
} }

View File

@ -22,7 +22,8 @@ public class ContainerIronChestBase extends Container {
private EntityPlayer player; private EntityPlayer player;
private IInventory chest; private IInventory chest;
public ContainerIronChestBase(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) { public ContainerIronChestBase(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize)
{
chest = chestInventory; chest = chestInventory;
player = ((InventoryPlayer) playerInventory).player; player = ((InventoryPlayer) playerInventory).player;
this.type = type; this.type = type;
@ -51,14 +52,16 @@ public class ContainerIronChestBase extends Container {
{ {
return null; return null;
} }
} else if (!mergeItemStack(itemstack1, 0, type.size, false)) }
else if (!mergeItemStack(itemstack1, 0, type.size, false))
{ {
return null; return null;
} }
if (itemstack1.stackSize == 0) if (itemstack1.stackSize == 0)
{ {
slot.putStack(null); slot.putStack(null);
} else }
else
{ {
slot.onSlotChanged(); slot.onSlotChanged();
} }
@ -73,7 +76,8 @@ public class ContainerIronChestBase extends Container {
chest.closeChest(); chest.closeChest();
} }
protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) { protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize)
{
for (int chestRow = 0; chestRow < type.getRowCount(); chestRow++) for (int chestRow = 0; chestRow < type.getRowCount(); chestRow++)
{ {
for (int chestCol = 0; chestCol < type.getRowLength(); chestCol++) for (int chestCol = 0; chestCol < type.getRowLength(); chestCol++)
@ -88,7 +92,8 @@ public class ContainerIronChestBase extends Container {
{ {
for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++) for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++)
{ {
addSlotToContainer(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, ySize - (4 - playerInvRow) * 18 - 10)); addSlotToContainer(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, ySize - (4 - playerInvRow) * 18
- 10));
} }
} }
@ -99,7 +104,8 @@ public class ContainerIronChestBase extends Container {
} }
} }
public EntityPlayer getPlayer() { public EntityPlayer getPlayer()
{
return player; return player;
} }
} }

View File

@ -14,6 +14,7 @@ import java.util.logging.Level;
import net.minecraftforge.common.Configuration; import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeSubscribe;
import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init; import cpw.mods.fml.common.Mod.Init;
@ -29,7 +30,7 @@ import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry; import cpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid = "IronChest", name = "Iron Chests", dependencies="required-after:Forge@[6.0,)") @Mod(modid = "IronChest", name = "Iron Chests", dependencies = "required-after:Forge@[6.0,)")
@NetworkMod(channels = { "IronChest" }, versionBounds = "[4.2,)", clientSideRequired = true, serverSideRequired = false, packetHandler = PacketHandler.class) @NetworkMod(channels = { "IronChest" }, versionBounds = "[4.2,)", clientSideRequired = true, serverSideRequired = false, packetHandler = PacketHandler.class)
public class IronChest { public class IronChest {
public static BlockIronChest ironChestBlock; public static BlockIronChest ironChestBlock;
@ -42,33 +43,42 @@ public class IronChest {
private int blockId; private int blockId;
@PreInit @PreInit
public void preInit(FMLPreInitializationEvent event) { public void preInit(FMLPreInitializationEvent event)
{
Version.init(event.getVersionProperties()); Version.init(event.getVersionProperties());
event.getModMetadata().version = Version.fullVersionString(); event.getModMetadata().version = Version.fullVersionString();
Configuration cfg = new Configuration(event.getSuggestedConfigurationFile()); Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
try { try
{
cfg.load(); cfg.load();
blockId = cfg.get(Configuration.CATEGORY_BLOCK, "ironChests", 181).getInt(181); blockId = cfg.get(Configuration.CATEGORY_BLOCK, "ironChests", 181).getInt(181);
ChestChangerType.buildItems(cfg, 29501); ChestChangerType.buildItems(cfg, 29501);
CACHE_RENDER = cfg.get(Configuration.CATEGORY_GENERAL, "cacheRenderingInformation", true).getBoolean(true); CACHE_RENDER = cfg.get(Configuration.CATEGORY_GENERAL, "cacheRenderingInformation", true).getBoolean(true);
OCELOTS_SITONCHESTS = cfg.get(Configuration.CATEGORY_GENERAL, "ocelotsSitOnChests", true).getBoolean(true); OCELOTS_SITONCHESTS = cfg.get(Configuration.CATEGORY_GENERAL, "ocelotsSitOnChests", true).getBoolean(true);
} catch (Exception e) { }
catch (Exception e)
{
FMLLog.log(Level.SEVERE, e, "IronChest has a problem loading it's configuration"); FMLLog.log(Level.SEVERE, e, "IronChest has a problem loading it's configuration");
} finally { }
finally
{
cfg.save(); cfg.save();
} }
} }
@Init @Init
public void load(FMLInitializationEvent evt) { public void load(FMLInitializationEvent evt)
{
ironChestBlock = new BlockIronChest(blockId); ironChestBlock = new BlockIronChest(blockId);
GameRegistry.registerBlock(ironChestBlock, ItemIronChest.class); GameRegistry.registerBlock(ironChestBlock, ItemIronChest.class);
for (IronChestType typ : IronChestType.values()) { for (IronChestType typ : IronChestType.values())
{
GameRegistry.registerTileEntity(typ.clazz, typ.name()); GameRegistry.registerTileEntity(typ.clazz, typ.name());
LanguageRegistry.instance().addStringLocalization(typ.name() + ".name", "en_US", typ.friendlyName); LanguageRegistry.instance().addStringLocalization(typ.name() + ".name", "en_US", typ.friendlyName);
proxy.registerTileEntitySpecialRenderer(typ); proxy.registerTileEntitySpecialRenderer(typ);
} }
for (ChestChangerType typ : ChestChangerType.values()) { for (ChestChangerType typ : ChestChangerType.values())
{
LanguageRegistry.instance().addStringLocalization("item." + typ.itemName + ".name", "en_US", typ.descriptiveName); LanguageRegistry.instance().addStringLocalization("item." + typ.itemName + ".name", "en_US", typ.descriptiveName);
} }
IronChestType.generateTieredRecipes(ironChestBlock); IronChestType.generateTieredRecipes(ironChestBlock);
@ -79,9 +89,12 @@ public class IronChest {
{ {
MinecraftForge.EVENT_BUS.register(new OcelotsSitOnChestsHandler()); MinecraftForge.EVENT_BUS.register(new OcelotsSitOnChestsHandler());
} }
MinecraftForge.EVENT_BUS.register(this);
} }
@PostInit @PostInit
public void modsLoaded(FMLPostInitializationEvent evt) { public void modsLoaded(FMLPostInitializationEvent evt)
{
} }
} }

View File

@ -5,13 +5,16 @@ import net.minecraft.entity.passive.EntityOcelot;
import net.minecraft.world.World; import net.minecraft.world.World;
public class IronChestAIOcelotSit extends EntityAIOcelotSit { public class IronChestAIOcelotSit extends EntityAIOcelotSit {
public IronChestAIOcelotSit(EntityOcelot par1EntityOcelot, float par2) { public IronChestAIOcelotSit(EntityOcelot par1EntityOcelot, float par2)
{
super(par1EntityOcelot, par2); super(par1EntityOcelot, par2);
} }
@Override @Override
protected boolean isSittableBlock(World world, int x, int y, int z) { protected boolean isSittableBlock(World world, int x, int y, int z)
if (world.getBlockId(x, y, z) == IronChest.ironChestBlock.blockID) { {
if (world.getBlockId(x, y, z) == IronChest.ironChestBlock.blockID)
{
return true; return true;
} }
return super.isSittableBlock(world, x, y, z); return super.isSittableBlock(world, x, y, z);

View File

@ -22,13 +22,13 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.ShapedOreRecipe; import net.minecraftforge.oredict.ShapedOreRecipe;
public enum IronChestType { public enum IronChestType {
IRON(54, 9, true, "Iron Chest", "ironchest.png", 0, Arrays.asList("ingotIron","ingotRefinedIron"), TileEntityIronChest.class, "mmmmPmmmm", "mGmG3GmGm"), IRON(54, 9, true, "Iron Chest", "ironchest.png", 0, Arrays.asList("ingotIron", "ingotRefinedIron"), TileEntityIronChest.class, "mmmmPmmmm", "mGmG3GmGm"), GOLD(
GOLD(81, 9, true, "Gold Chest", "goldchest.png", 1, Arrays.asList("ingotGold"), TileEntityGoldChest.class, "mmmmPmmmm", "mGmG4GmGm"), 81, 9, true, "Gold Chest", "goldchest.png", 1, Arrays.asList("ingotGold"), TileEntityGoldChest.class, "mmmmPmmmm", "mGmG4GmGm"), DIAMOND(108, 12,
DIAMOND(108, 12, true, "Diamond Chest", "diamondchest.png", 2, Arrays.asList("gemDiamond"), TileEntityDiamondChest.class, "GGGmPmGGG", "GGGG4Gmmm"), true, "Diamond Chest", "diamondchest.png", 2, Arrays.asList("gemDiamond"), TileEntityDiamondChest.class, "GGGmPmGGG", "GGGG4Gmmm"), COPPER(45, 9,
COPPER(45, 9, false, "Copper Chest", "copperchest.png", 3, Arrays.asList("ingotCopper"), TileEntityCopperChest.class, "mmmmCmmmm"), false, "Copper Chest", "copperchest.png", 3, Arrays.asList("ingotCopper"), TileEntityCopperChest.class, "mmmmCmmmm"), SILVER(72, 9, false,
SILVER(72, 9, false, "Silver Chest", "silverchest.png", 4, Arrays.asList("ingotSilver"), TileEntitySilverChest.class, "mmmm3mmmm", "mGmG0GmGm"), "Silver Chest", "silverchest.png", 4, Arrays.asList("ingotSilver"), TileEntitySilverChest.class, "mmmm3mmmm", "mGmG0GmGm"), CRYSTAL(108, 12, true,
CRYSTAL(108, 12, true, "Crystal Chest", "crystalchest.png", 5, Arrays.asList("blockGlass"), TileEntityCrystalChest.class, "GGGGPGGGG"), "Crystal Chest", "crystalchest.png", 5, Arrays.asList("blockGlass"), TileEntityCrystalChest.class, "GGGGPGGGG"), WOOD(0, 0, false, "", "", -1,
WOOD(0,0,false,"","",-1,Arrays.asList("blockPlanks"),null); Arrays.asList("blockPlanks"), null);
int size; int size;
private int rowLength; private int rowLength;
public String friendlyName; public String friendlyName;
@ -40,7 +40,8 @@ public enum IronChestType {
private ArrayList<String> matList; private ArrayList<String> matList;
IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List<String> mats, IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List<String> mats,
Class<? extends TileEntityIronChest> clazz, String... recipes) { Class<? extends TileEntityIronChest> clazz, String... recipes)
{
this.size = size; this.size = size;
this.rowLength = rowLength; this.rowLength = rowLength;
this.tieredChest = tieredChest; this.tieredChest = tieredChest;
@ -53,25 +54,34 @@ public enum IronChestType {
matList.addAll(mats); matList.addAll(mats);
} }
public String getModelTexture() { public String getModelTexture()
{
return modelTexture; return modelTexture;
} }
public int getTextureRow() { public int getTextureRow()
{
return textureRow; return textureRow;
} }
public static TileEntityIronChest makeEntity(int metadata) { public static TileEntityIronChest makeEntity(int metadata)
{
// Compatibility // Compatibility
int chesttype = validateMeta(metadata); int chesttype = validateMeta(metadata);
if (chesttype == metadata) { if (chesttype == metadata)
try { {
try
{
TileEntityIronChest te = values()[chesttype].clazz.newInstance(); TileEntityIronChest te = values()[chesttype].clazz.newInstance();
return te; return te;
} catch (InstantiationException e) { }
catch (InstantiationException e)
{
// unpossible // unpossible
e.printStackTrace(); e.printStackTrace();
} catch (IllegalAccessException e) { }
catch (IllegalAccessException e)
{
// unpossible // unpossible
e.printStackTrace(); e.printStackTrace();
} }
@ -79,32 +89,41 @@ public enum IronChestType {
return null; return null;
} }
public static void registerTranslations() { public static void registerTranslations()
{
} }
public static void generateTieredRecipes(BlockIronChest blockResult) { public static void generateTieredRecipes(BlockIronChest blockResult)
{
ItemStack previous = new ItemStack(Block.chest); ItemStack previous = new ItemStack(Block.chest);
for (IronChestType typ : values()) { for (IronChestType typ : values())
{
generateRecipesForType(blockResult, previous, typ); generateRecipesForType(blockResult, previous, typ);
if (typ.tieredChest) if (typ.tieredChest) previous = new ItemStack(blockResult, 1, typ.ordinal());
previous = new ItemStack(blockResult, 1, typ.ordinal());
} }
} }
public static void generateRecipesForType(BlockIronChest blockResult, Object previousTier, IronChestType type) { public static void generateRecipesForType(BlockIronChest blockResult, Object previousTier, IronChestType type)
for (String recipe : type.recipes) { {
for (String recipe : type.recipes)
{
String[] recipeSplit = new String[] { recipe.substring(0, 3), recipe.substring(3, 6), recipe.substring(6, 9) }; String[] recipeSplit = new String[] { recipe.substring(0, 3), recipe.substring(3, 6), recipe.substring(6, 9) };
Object mainMaterial = null; Object mainMaterial = null;
for (String mat : type.matList) { for (String mat : type.matList)
{
mainMaterial = translateOreName(mat); mainMaterial = translateOreName(mat);
addRecipe(new ItemStack(blockResult, 1, type.ordinal()), recipeSplit, addRecipe(new ItemStack(blockResult, 1, type.ordinal()), recipeSplit, 'm', mainMaterial, 'P', previousTier, /*
'm', mainMaterial, * previous
'P', previousTier, /* previous tier of chest */ * tier
'G', Block.glass, * of
'C', Block.chest, * chest
'0', new ItemStack(blockResult, 1, 0), /* Iron Chest*/ */
'1', new ItemStack(blockResult, 1, 1), /* Gold Chest*/ 'G', Block.glass, 'C', Block.chest, '0', new ItemStack(blockResult, 1, 0), /*
'2', new ItemStack(blockResult, 1, 1), /* Diamond Chest*/ * Iron
* Chest
*/
'1', new ItemStack(blockResult, 1, 1), /* Gold Chest */
'2', new ItemStack(blockResult, 1, 1), /* Diamond Chest */
'3', new ItemStack(blockResult, 1, 3), /* Copper Chest */ '3', new ItemStack(blockResult, 1, 3), /* Copper Chest */
'4', new ItemStack(blockResult, 1, 4)/* Silver Chest */ '4', new ItemStack(blockResult, 1, 4)/* Silver Chest */
); );
@ -112,53 +131,73 @@ public enum IronChestType {
} }
} }
public static Object translateOreName(String mat) { public static Object translateOreName(String mat)
if (mat == "ingotIron" ) { {
if (mat == "ingotIron")
{
return Item.ingotIron; return Item.ingotIron;
} else if (mat == "ingotGold") { }
else if (mat == "ingotGold")
{
return Item.ingotGold; return Item.ingotGold;
} else if (mat == "gemDiamond") { }
else if (mat == "gemDiamond")
{
return Item.diamond; return Item.diamond;
} else if (mat == "blockGlass") { }
else if (mat == "blockGlass")
{
return Block.glass; return Block.glass;
} else if (mat == "blockPlanks") { }
else if (mat == "blockPlanks")
{
return Block.planks; return Block.planks;
} }
return mat; return mat;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static void addRecipe(ItemStack is, Object... parts) { public static void addRecipe(ItemStack is, Object... parts)
{
ShapedOreRecipe oreRecipe = new ShapedOreRecipe(is, parts); ShapedOreRecipe oreRecipe = new ShapedOreRecipe(is, parts);
GameRegistry.addRecipe(oreRecipe); GameRegistry.addRecipe(oreRecipe);
} }
public int getRowCount() { public int getRowCount()
{
return size / rowLength; return size / rowLength;
} }
public int getRowLength() { public int getRowLength()
{
return rowLength; return rowLength;
} }
public boolean isTransparent() { public boolean isTransparent()
{
return this == CRYSTAL; return this == CRYSTAL;
} }
public List<String> getMatList() { public List<String> getMatList()
{
return matList; return matList;
} }
public static int validateMeta(int i) { public static int validateMeta(int i)
if (i < values().length && values()[i].size>0) { {
if (i < values().length && values()[i].size > 0)
{
return i; return i;
} else { }
else
{
return 0; return 0;
} }
} }
public boolean isValidForCreativeMode() { public boolean isValidForCreativeMode()
return validateMeta(ordinal())==ordinal(); {
return validateMeta(ordinal()) == ordinal();
} }
} }

View File

@ -23,33 +23,40 @@ public class ItemChestChanger extends Item {
private ChestChangerType type; private ChestChangerType type;
public ItemChestChanger(int id, ChestChangerType type) { public ItemChestChanger(int id, ChestChangerType type)
{
super(id); super(id);
setMaxStackSize(1); setMaxStackSize(1);
this.type=type; this.type = type;
setIconIndex(type.ordinal()); setIconIndex(type.ordinal());
setItemName(type.itemName); setItemName(type.itemName);
setCreativeTab(CreativeTabs.tabMisc); setCreativeTab(CreativeTabs.tabMisc);
} }
@Override @Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int X, int Y, int Z, int side) { public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int X, int Y, int Z, int side, float hitX, float hitY, float hitZ)
if (world.isRemote) {
return false; if (world.isRemote) return false;
TileEntity te=world.getBlockTileEntity(X,Y,Z); TileEntity te = world.getBlockTileEntity(X, Y, Z);
TileEntityIronChest newchest; TileEntityIronChest newchest;
if (te!=null && te instanceof TileEntityIronChest) { if (te != null && te instanceof TileEntityIronChest)
TileEntityIronChest ironchest=(TileEntityIronChest)te; {
newchest=ironchest.applyUpgradeItem(this); TileEntityIronChest ironchest = (TileEntityIronChest) te;
if (newchest==null) { newchest = ironchest.applyUpgradeItem(this);
if (newchest == null)
{
return false; return false;
} }
} else if (te!=null && te instanceof TileEntityChest) { }
else if (te != null && te instanceof TileEntityChest)
{
TileEntityChest tec = (TileEntityChest) te; TileEntityChest tec = (TileEntityChest) te;
if (tec.numUsingPlayers > 0) { if (tec.numUsingPlayers > 0)
{
return false; return false;
} }
if (!getType().canUpgrade(IronChestType.WOOD)) { if (!getType().canUpgrade(IronChestType.WOOD))
{
return false; return false;
} }
// Force old TE out of the world so that adjacent chests can update // Force old TE out of the world so that adjacent chests can update
@ -59,41 +66,47 @@ public class ItemChestChanger extends Item {
System.arraycopy(chestContents, 0, newchest.chestContents, 0, Math.min(newSize, chestContents.length)); System.arraycopy(chestContents, 0, newchest.chestContents, 0, Math.min(newSize, chestContents.length));
BlockIronChest block = IronChest.ironChestBlock; BlockIronChest block = IronChest.ironChestBlock;
block.dropContent(newSize, tec, world, tec.xCoord, tec.yCoord, tec.zCoord); block.dropContent(newSize, tec, world, tec.xCoord, tec.yCoord, tec.zCoord);
newchest.setFacing((byte)tec.getBlockMetadata()); newchest.setFacing((byte) tec.getBlockMetadata());
newchest.sortTopStacks(); newchest.sortTopStacks();
for (int i = 0; i< Math.min(newSize, chestContents.length); i++) for (int i = 0; i < Math.min(newSize, chestContents.length); i++)
{ {
chestContents[i]=null; chestContents[i] = null;
} }
// Clear the old block out // Clear the old block out
world.setBlock(X, Y, Z, 0); world.setBlock(X, Y, Z, 0);
// Force the Chest TE to reset it's knowledge of neighbouring blocks // Force the Chest TE to reset it's knowledge of neighbouring blocks
tec.updateContainingBlockInfo(); tec.updateContainingBlockInfo();
// Force the Chest TE to update any neighbours so they update next tick // Force the Chest TE to update any neighbours so they update next
// tick
tec.checkForAdjacentChests(); tec.checkForAdjacentChests();
// And put in our block instead // And put in our block instead
world.setBlock(X, Y, Z, block.blockID); world.setBlock(X, Y, Z, block.blockID);
} else { }
else
{
return false; return false;
} }
world.setBlockTileEntity(X, Y, Z, newchest); world.setBlockTileEntity(X, Y, Z, newchest);
world.setBlockMetadataWithNotify(X, Y, Z, newchest.getType().ordinal()); world.setBlockMetadataWithNotify(X, Y, Z, newchest.getType().ordinal());
world.notifyBlocksOfNeighborChange(X, Y, Z, world.getBlockId(X, Y, Z)); world.notifyBlocksOfNeighborChange(X, Y, Z, world.getBlockId(X, Y, Z));
world.markBlockForUpdate(X, Y, Z); world.markBlockForUpdate(X, Y, Z);
stack.stackSize=0; stack.stackSize = 0;
return true; return true;
} }
@Override @Override
public String getTextureFile() { public String getTextureFile()
{
return "/cpw/mods/ironchest/sprites/item_textures.png"; return "/cpw/mods/ironchest/sprites/item_textures.png";
} }
public int getTargetChestOrdinal(int sourceOrdinal) { public int getTargetChestOrdinal(int sourceOrdinal)
{
return type.getTarget(); return type.getTarget();
} }
public ChestChangerType getType() { public ChestChangerType getType()
{
return type; return type;
} }
} }

View File

@ -15,18 +15,22 @@ import net.minecraft.item.ItemStack;
public class ItemIronChest extends ItemBlock { public class ItemIronChest extends ItemBlock {
public ItemIronChest(int id) { public ItemIronChest(int id)
{
super(id); super(id);
setMaxDamage(0); setMaxDamage(0);
setHasSubtypes(true); setHasSubtypes(true);
} }
@Override @Override
public int getMetadata(int i) { public int getMetadata(int i)
{
return IronChestType.validateMeta(i); return IronChestType.validateMeta(i);
} }
@Override @Override
public String getItemNameIS(ItemStack itemstack) { public String getItemNameIS(ItemStack itemstack)
{
return IronChestType.values()[itemstack.getItemDamage()].name(); return IronChestType.values()[itemstack.getItemDamage()].name();
} }
} }

View File

@ -5,22 +5,29 @@ import net.minecraft.item.ItemStack;
public class MappableItemStackWrapper { public class MappableItemStackWrapper {
private ItemStack wrap; private ItemStack wrap;
public MappableItemStackWrapper(ItemStack toWrap) { public MappableItemStackWrapper(ItemStack toWrap)
wrap=toWrap; {
wrap = toWrap;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj)
{
if (!(obj instanceof MappableItemStackWrapper)) return false; if (!(obj instanceof MappableItemStackWrapper)) return false;
MappableItemStackWrapper isw = (MappableItemStackWrapper) obj; MappableItemStackWrapper isw = (MappableItemStackWrapper) obj;
if (wrap.getHasSubtypes()) { if (wrap.getHasSubtypes())
{
return isw.wrap.isItemEqual(wrap); return isw.wrap.isItemEqual(wrap);
} else { }
else
{
return isw.wrap.itemID == wrap.itemID; return isw.wrap.itemID == wrap.itemID;
} }
} }
@Override @Override
public int hashCode() { public int hashCode()
{
return wrap.itemID; return wrap.itemID;
} }
} }

View File

@ -10,14 +10,15 @@ import net.minecraftforge.event.entity.living.LivingEvent;
public class OcelotsSitOnChestsHandler { public class OcelotsSitOnChestsHandler {
@ForgeSubscribe @ForgeSubscribe
public void changeSittingTaskForOcelots(LivingEvent.LivingUpdateEvent evt) { public void changeSittingTaskForOcelots(LivingEvent.LivingUpdateEvent evt)
{
if (evt.entityLiving.ticksExisted < 5 && evt.entityLiving instanceof EntityOcelot) if (evt.entityLiving.ticksExisted < 5 && evt.entityLiving instanceof EntityOcelot)
{ {
EntityOcelot ocelot = (EntityOcelot) evt.entityLiving; EntityOcelot ocelot = (EntityOcelot) evt.entityLiving;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<EntityAITaskEntry> tasks = ocelot.tasks.taskEntries; List<EntityAITaskEntry> tasks = ocelot.tasks.taskEntries;
for (int i=0; i<tasks.size(); i++) for (int i = 0; i < tasks.size(); i++)
{ {
EntityAITaskEntry task = tasks.get(i); EntityAITaskEntry task = tasks.get(i);
if (task.priority == 6 && (task.action instanceof EntityAIOcelotSit) && !(task.action instanceof IronChestAIOcelotSit)) if (task.priority == 6 && (task.action instanceof EntityAIOcelotSit) && !(task.action instanceof IronChestAIOcelotSit))

View File

@ -28,7 +28,8 @@ import cpw.mods.fml.common.network.Player;
public class PacketHandler implements IPacketHandler { public class PacketHandler implements IPacketHandler {
@Override @Override
public void onPacketData(INetworkManager network, Packet250CustomPayload packet, Player player) { public void onPacketData(INetworkManager network, Packet250CustomPayload packet, Player player)
{
ByteArrayDataInput dat = ByteStreams.newDataInput(packet.data); ByteArrayDataInput dat = ByteStreams.newDataInput(packet.data);
int x = dat.readInt(); int x = dat.readInt();
int y = dat.readInt(); int y = dat.readInt();
@ -36,21 +37,25 @@ public class PacketHandler implements IPacketHandler {
byte typ = dat.readByte(); byte typ = dat.readByte();
boolean hasStacks = dat.readByte() != 0; boolean hasStacks = dat.readByte() != 0;
int[] items = new int[0]; int[] items = new int[0];
if (hasStacks) { if (hasStacks)
{
items = new int[24]; items = new int[24];
for (int i = 0; i < items.length; i++) { for (int i = 0; i < items.length; i++)
{
items[i] = dat.readInt(); items[i] = dat.readInt();
} }
} }
World world = IronChest.proxy.getClientWorld(); World world = IronChest.proxy.getClientWorld();
TileEntity te = world.getBlockTileEntity(x, y, z); TileEntity te = world.getBlockTileEntity(x, y, z);
if (te instanceof TileEntityIronChest) { if (te instanceof TileEntityIronChest)
{
TileEntityIronChest icte = (TileEntityIronChest) te; TileEntityIronChest icte = (TileEntityIronChest) te;
icte.handlePacketData(typ, items); icte.handlePacketData(typ, items);
} }
} }
public static Packet getPacket(TileEntityIronChest tileEntityIronChest) { public static Packet getPacket(TileEntityIronChest tileEntityIronChest)
{
ByteArrayOutputStream bos = new ByteArrayOutputStream(140); ByteArrayOutputStream bos = new ByteArrayOutputStream(140);
DataOutputStream dos = new DataOutputStream(bos); DataOutputStream dos = new DataOutputStream(bos);
int x = tileEntityIronChest.xCoord; int x = tileEntityIronChest.xCoord;
@ -59,18 +64,23 @@ public class PacketHandler implements IPacketHandler {
int typ = tileEntityIronChest.getType().ordinal(); int typ = tileEntityIronChest.getType().ordinal();
int[] items = tileEntityIronChest.buildIntDataList(); int[] items = tileEntityIronChest.buildIntDataList();
boolean hasStacks = (items != null); boolean hasStacks = (items != null);
try { try
{
dos.writeInt(x); dos.writeInt(x);
dos.writeInt(y); dos.writeInt(y);
dos.writeInt(z); dos.writeInt(z);
dos.writeByte(typ); dos.writeByte(typ);
dos.writeByte(hasStacks ? 1 : 0); dos.writeByte(hasStacks ? 1 : 0);
if (hasStacks) { if (hasStacks)
for (int i = 0; i < 24; i++) { {
for (int i = 0; i < 24; i++)
{
dos.writeInt(items[i]); dos.writeInt(items[i]);
} }
} }
} catch (IOException e) { }
catch (IOException e)
{
// UNPOSSIBLE? // UNPOSSIBLE?
} }
Packet250CustomPayload pkt = new Packet250CustomPayload(); Packet250CustomPayload pkt = new Packet250CustomPayload();

View File

@ -11,7 +11,8 @@
package cpw.mods.ironchest; package cpw.mods.ironchest;
public class TileEntityCopperChest extends TileEntityIronChest { public class TileEntityCopperChest extends TileEntityIronChest {
public TileEntityCopperChest() { public TileEntityCopperChest()
{
super(IronChestType.COPPER); super(IronChestType.COPPER);
} }

View File

@ -11,7 +11,8 @@
package cpw.mods.ironchest; package cpw.mods.ironchest;
public class TileEntityCrystalChest extends TileEntityIronChest { public class TileEntityCrystalChest extends TileEntityIronChest {
public TileEntityCrystalChest() { public TileEntityCrystalChest()
{
super(IronChestType.CRYSTAL); super(IronChestType.CRYSTAL);
} }
} }

View File

@ -11,7 +11,8 @@
package cpw.mods.ironchest; package cpw.mods.ironchest;
public class TileEntityDiamondChest extends TileEntityIronChest { public class TileEntityDiamondChest extends TileEntityIronChest {
public TileEntityDiamondChest() { public TileEntityDiamondChest()
{
super(IronChestType.DIAMOND); super(IronChestType.DIAMOND);
} }
} }

View File

@ -12,7 +12,8 @@ package cpw.mods.ironchest;
public class TileEntityGoldChest extends TileEntityIronChest { public class TileEntityGoldChest extends TileEntityIronChest {
public TileEntityGoldChest() { public TileEntityGoldChest()
{
super(IronChestType.GOLD); super(IronChestType.GOLD);
} }
} }

View File

@ -33,62 +33,77 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
private boolean inventoryTouched; private boolean inventoryTouched;
private boolean hadStuff; private boolean hadStuff;
public TileEntityIronChest() { public TileEntityIronChest()
{
this(IronChestType.IRON); this(IronChestType.IRON);
} }
protected TileEntityIronChest(IronChestType type) { protected TileEntityIronChest(IronChestType type)
{
super(); super();
this.type = type; this.type = type;
this.chestContents = new ItemStack[getSizeInventory()]; this.chestContents = new ItemStack[getSizeInventory()];
this.topStacks = new ItemStack[8]; this.topStacks = new ItemStack[8];
} }
public ItemStack[] getContents() { public ItemStack[] getContents()
{
return chestContents; return chestContents;
} }
@Override @Override
public int getSizeInventory() { public int getSizeInventory()
{
return type.size; return type.size;
} }
public byte getFacing() { public byte getFacing()
{
return this.facing; return this.facing;
} }
@Override @Override
public String getInvName() { public String getInvName()
{
return type.name(); return type.name();
} }
public IronChestType getType() { public IronChestType getType()
{
return type; return type;
} }
@Override @Override
public ItemStack getStackInSlot(int i) { public ItemStack getStackInSlot(int i)
{
inventoryTouched = true; inventoryTouched = true;
return chestContents[i]; return chestContents[i];
} }
@Override @Override
public void onInventoryChanged() { public void onInventoryChanged()
{
super.onInventoryChanged(); super.onInventoryChanged();
sortTopStacks(); sortTopStacks();
} }
protected void sortTopStacks() { protected void sortTopStacks()
if (!type.isTransparent() || (worldObj != null && worldObj.isRemote)) { {
if (!type.isTransparent() || (worldObj != null && worldObj.isRemote))
{
return; return;
} }
ItemStack[] tempCopy = new ItemStack[getSizeInventory()]; ItemStack[] tempCopy = new ItemStack[getSizeInventory()];
boolean hasStuff = false; boolean hasStuff = false;
int compressedIdx = 0; int compressedIdx = 0;
mainLoop: for (int i = 0; i < getSizeInventory(); i++) { mainLoop: for (int i = 0; i < getSizeInventory(); i++)
if (chestContents[i] != null) { {
for (int j = 0; j < compressedIdx; j++) { if (chestContents[i] != null)
if (tempCopy[j].isItemEqual(chestContents[i])) { {
for (int j = 0; j < compressedIdx; j++)
{
if (tempCopy[j].isItemEqual(chestContents[i]))
{
tempCopy[j].stackSize += chestContents[i].stackSize; tempCopy[j].stackSize += chestContents[i].stackSize;
continue mainLoop; continue mainLoop;
} }
@ -97,12 +112,15 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
hasStuff = true; hasStuff = true;
} }
} }
if (!hasStuff && hadStuff) { if (!hasStuff && hadStuff)
{
hadStuff = false; hadStuff = false;
for (int i = 0; i < topStacks.length; i++) { for (int i = 0; i < topStacks.length; i++)
{
topStacks[i] = null; topStacks[i] = null;
} }
if (worldObj!=null) { if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
} }
return; return;
@ -110,35 +128,47 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
hadStuff = true; hadStuff = true;
Arrays.sort(tempCopy, new Comparator<ItemStack>() { Arrays.sort(tempCopy, new Comparator<ItemStack>() {
@Override @Override
public int compare(ItemStack o1, ItemStack o2) { public int compare(ItemStack o1, ItemStack o2)
if (o1 == null) { {
if (o1 == null)
{
return 1; return 1;
} else if (o2 == null) { }
else if (o2 == null)
{
return -1; return -1;
} else { }
else
{
return o2.stackSize - o1.stackSize; return o2.stackSize - o1.stackSize;
} }
} }
}); });
int p = 0; int p = 0;
for (int i = 0; i < tempCopy.length; i++) { for (int i = 0; i < tempCopy.length; i++)
if (tempCopy[i] != null && tempCopy[i].stackSize > 0) { {
if (tempCopy[i] != null && tempCopy[i].stackSize > 0)
{
topStacks[p++] = tempCopy[i]; topStacks[p++] = tempCopy[i];
if (p == topStacks.length) { if (p == topStacks.length)
{
break; break;
} }
} }
} }
for (int i = p; i < topStacks.length; i++) { for (int i = p; i < topStacks.length; i++)
{
topStacks[i] = null; topStacks[i] = null;
} }
if (worldObj!=null) { if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
} }
} }
@Override @Override
public ItemStack decrStackSize(int i, int j) { public ItemStack decrStackSize(int i, int j)
{
if (chestContents[i] != null) if (chestContents[i] != null)
{ {
if (chestContents[i].stackSize <= j) if (chestContents[i].stackSize <= j)
@ -163,7 +193,8 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
} }
@Override @Override
public void setInventorySlotContents(int i, ItemStack itemstack) { public void setInventorySlotContents(int i, ItemStack itemstack)
{
chestContents[i] = itemstack; chestContents[i] = itemstack;
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
{ {
@ -212,101 +243,123 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
} }
@Override @Override
public int getInventoryStackLimit() { public int getInventoryStackLimit()
{
return 64; return 64;
} }
@Override @Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) { public boolean isUseableByPlayer(EntityPlayer entityplayer)
if (worldObj == null) { {
if (worldObj == null)
{
return true; return true;
} }
if (worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this) { if (worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this)
{
return false; return false;
} }
return entityplayer.getDistanceSq((double) xCoord + 0.5D, (double) yCoord + 0.5D, (double) zCoord + 0.5D) <= 64D; return entityplayer.getDistanceSq((double) xCoord + 0.5D, (double) yCoord + 0.5D, (double) zCoord + 0.5D) <= 64D;
} }
@Override @Override
public void updateEntity() { public void updateEntity()
{
super.updateEntity(); super.updateEntity();
// Resynchronize clients with the server state // Resynchronize clients with the server state
if ((++ticksSinceSync % 20) * 4 == 0) { if ((++ticksSinceSync % 20) * 4 == 0)
{
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock.blockID, 3, ((numUsingPlayers << 3) & 0xF8) | (facing & 0x7)); worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock.blockID, 3, ((numUsingPlayers << 3) & 0xF8) | (facing & 0x7));
if (inventoryTouched) { if (inventoryTouched)
{
inventoryTouched = false; inventoryTouched = false;
sortTopStacks(); sortTopStacks();
} }
} }
prevLidAngle = lidAngle; prevLidAngle = lidAngle;
float f = 0.1F; float f = 0.1F;
if (numUsingPlayers > 0 && lidAngle == 0.0F) { if (numUsingPlayers > 0 && lidAngle == 0.0F)
{
double d = (double) xCoord + 0.5D; double d = (double) xCoord + 0.5D;
double d1 = (double) zCoord + 0.5D; double d1 = (double) zCoord + 0.5D;
worldObj.playSoundEffect(d, (double) yCoord + 0.5D, d1, "random.chestopen", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F); worldObj.playSoundEffect(d, (double) yCoord + 0.5D, d1, "random.chestopen", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F);
} }
if (numUsingPlayers == 0 && lidAngle > 0.0F || numUsingPlayers > 0 && lidAngle < 1.0F) { if (numUsingPlayers == 0 && lidAngle > 0.0F || numUsingPlayers > 0 && lidAngle < 1.0F)
{
float f1 = lidAngle; float f1 = lidAngle;
if (numUsingPlayers > 0) { if (numUsingPlayers > 0)
{
lidAngle += f; lidAngle += f;
} else { }
else
{
lidAngle -= f; lidAngle -= f;
} }
if (lidAngle > 1.0F) { if (lidAngle > 1.0F)
{
lidAngle = 1.0F; lidAngle = 1.0F;
} }
float f2 = 0.5F; float f2 = 0.5F;
if (lidAngle < f2 && f1 >= f2) { if (lidAngle < f2 && f1 >= f2)
{
double d2 = (double) xCoord + 0.5D; double d2 = (double) xCoord + 0.5D;
double d3 = (double) zCoord + 0.5D; double d3 = (double) zCoord + 0.5D;
worldObj.playSoundEffect(d2, (double) yCoord + 0.5D, d3, "random.chestclosed", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F); worldObj.playSoundEffect(d2, (double) yCoord + 0.5D, d3, "random.chestclosed", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F);
} }
if (lidAngle < 0.0F) { if (lidAngle < 0.0F)
{
lidAngle = 0.0F; lidAngle = 0.0F;
} }
} }
} }
@Override @Override
public void receiveClientEvent(int i, int j) public void receiveClientEvent(int i, int j)
{ {
if (i == 1) if (i == 1)
{ {
numUsingPlayers = j; numUsingPlayers = j;
} else if (i == 2) { }
else if (i == 2)
{
facing = (byte) j; facing = (byte) j;
} else if (i == 3) { }
else if (i == 3)
{
facing = (byte) (j & 0x7); facing = (byte) (j & 0x7);
numUsingPlayers = (j & 0xF8) >> 3; numUsingPlayers = (j & 0xF8) >> 3;
} }
} }
@Override @Override
public void openChest() { public void openChest()
if (worldObj == null) {
return; if (worldObj == null) return;
numUsingPlayers++; numUsingPlayers++;
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock.blockID, 1, numUsingPlayers); worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock.blockID, 1, numUsingPlayers);
} }
@Override @Override
public void closeChest() { public void closeChest()
if (worldObj == null) {
return; if (worldObj == null) return;
numUsingPlayers--; numUsingPlayers--;
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock.blockID, 1, numUsingPlayers); worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock.blockID, 1, numUsingPlayers);
} }
public void setFacing(byte chestFacing) { public void setFacing(byte chestFacing)
{
this.facing = chestFacing; this.facing = chestFacing;
} }
public TileEntityIronChest applyUpgradeItem(ItemChestChanger itemChestChanger) { public TileEntityIronChest applyUpgradeItem(ItemChestChanger itemChestChanger)
if (numUsingPlayers > 0) { {
if (numUsingPlayers > 0)
{
return null; return null;
} }
if (!itemChestChanger.getType().canUpgrade(this.getType())) { if (!itemChestChanger.getType().canUpgrade(this.getType()))
{
return null; return null;
} }
TileEntityIronChest newEntity = IronChestType.makeEntity(itemChestChanger.getTargetChestOrdinal(getType().ordinal())); TileEntityIronChest newEntity = IronChestType.makeEntity(itemChestChanger.getTargetChestOrdinal(getType().ordinal()));
@ -319,13 +372,17 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
return newEntity; return newEntity;
} }
public ItemStack[] getTopItemStacks() { public ItemStack[] getTopItemStacks()
{
return topStacks; return topStacks;
} }
public TileEntityIronChest updateFromMetadata(int l) { public TileEntityIronChest updateFromMetadata(int l)
if (worldObj != null && worldObj.isRemote) { {
if (l != type.ordinal()) { if (worldObj != null && worldObj.isRemote)
{
if (l != type.ordinal())
{
worldObj.setBlockTileEntity(xCoord, yCoord, zCoord, IronChestType.makeEntity(l)); worldObj.setBlockTileEntity(xCoord, yCoord, zCoord, IronChestType.makeEntity(l));
return (TileEntityIronChest) worldObj.getBlockTileEntity(xCoord, yCoord, zCoord); return (TileEntityIronChest) worldObj.getBlockTileEntity(xCoord, yCoord, zCoord);
} }
@ -334,25 +391,34 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
} }
@Override @Override
public Packet getDescriptionPacket() { public Packet getDescriptionPacket()
{
return PacketHandler.getPacket(this); return PacketHandler.getPacket(this);
} }
public void handlePacketData(int typeData, int[] intData) { public void handlePacketData(int typeData, int[] intData)
{
TileEntityIronChest chest = this; TileEntityIronChest chest = this;
if (this.type.ordinal() != typeData) { if (this.type.ordinal() != typeData)
{
chest = updateFromMetadata(typeData); chest = updateFromMetadata(typeData);
} }
if (IronChestType.values()[typeData].isTransparent() && intData != null) { if (IronChestType.values()[typeData].isTransparent() && intData != null)
{
int pos = 0; int pos = 0;
if (intData.length < chest.topStacks.length * 3) { if (intData.length < chest.topStacks.length * 3)
{
return; return;
} }
for (int i = 0; i < chest.topStacks.length; i++) { for (int i = 0; i < chest.topStacks.length; i++)
if (intData[pos + 2] != 0) { {
if (intData[pos + 2] != 0)
{
ItemStack is = new ItemStack(intData[pos], intData[pos + 2], intData[pos + 1]); ItemStack is = new ItemStack(intData[pos], intData[pos + 2], intData[pos + 1]);
chest.topStacks[i] = is; chest.topStacks[i] = is;
} else { }
else
{
chest.topStacks[i] = null; chest.topStacks[i] = null;
} }
pos += 3; pos += 3;
@ -360,16 +426,22 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
} }
} }
public int[] buildIntDataList() { public int[] buildIntDataList()
if (type.isTransparent()) { {
if (type.isTransparent())
{
int[] sortList = new int[topStacks.length * 3]; int[] sortList = new int[topStacks.length * 3];
int pos = 0; int pos = 0;
for (ItemStack is : topStacks) { for (ItemStack is : topStacks)
if (is != null) { {
if (is != null)
{
sortList[pos++] = is.itemID; sortList[pos++] = is.itemID;
sortList[pos++] = is.getItemDamage(); sortList[pos++] = is.getItemDamage();
sortList[pos++] = is.stackSize; sortList[pos++] = is.stackSize;
} else { }
else
{
sortList[pos++] = 0; sortList[pos++] = 0;
sortList[pos++] = 0; sortList[pos++] = 0;
sortList[pos++] = 0; sortList[pos++] = 0;
@ -393,7 +465,9 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
return null; return null;
} }
} }
public void setMaxStackSize(int size) {
public void setMaxStackSize(int size)
{
} }
} }

View File

@ -11,7 +11,8 @@
package cpw.mods.ironchest; package cpw.mods.ironchest;
public class TileEntitySilverChest extends TileEntityIronChest { public class TileEntitySilverChest extends TileEntityIronChest {
public TileEntitySilverChest() { public TileEntitySilverChest()
{
super(IronChestType.SILVER); super(IronChestType.SILVER);
} }
} }

View File

@ -15,8 +15,10 @@ public class Version {
private static String build; private static String build;
private static String mcversion; private static String mcversion;
static void init(Properties properties) { static void init(Properties properties)
if (properties != null) { {
if (properties != null)
{
major = properties.getProperty("IronChest.build.major.number"); major = properties.getProperty("IronChest.build.major.number");
minor = properties.getProperty("IronChest.build.minor.number"); minor = properties.getProperty("IronChest.build.minor.number");
rev = properties.getProperty("IronChest.build.revision.number"); rev = properties.getProperty("IronChest.build.revision.number");
@ -25,7 +27,8 @@ public class Version {
} }
} }
public static String fullVersionString() { public static String fullVersionString()
return String.format("%s.%s.%s build %s", major,minor,rev, build); {
return String.format("%s.%s.%s build %s", major, minor, rev, build);
} }
} }

View File

@ -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.client;
import net.minecraft.client.renderer.ChestItemRenderHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.ironchest.CommonProxy;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.TileEntityIronChest;
public class ClientProxy extends CommonProxy {
@Override
public void registerRenderInformation()
{
ChestItemRenderHelper.instance = new IronChestRenderHelper();
MinecraftForgeClient.preloadTexture("/cpw/mods/ironchest/sprites/block_textures.png");
MinecraftForgeClient.preloadTexture("/cpw/mods/ironchest/sprites/item_textures.png");
}
@Override
public void registerTileEntitySpecialRenderer(IronChestType typ)
{
ClientRegistry.bindTileEntitySpecialRenderer(typ.clazz, new TileEntityIronChestRenderer());
}
@Override
public World getClientWorld()
{
return FMLClientHandler.instance().getClient().theWorld;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
TileEntity te = world.getBlockTileEntity(x, y, z);
if (te != null && te instanceof TileEntityIronChest)
{
return GUIChest.GUI.buildGUI(IronChestType.values()[ID], player.inventory, (TileEntityIronChest) te);
}
else
{
return null;
}
}
}

View File

@ -0,0 +1,80 @@
/*******************************************************************************
* 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.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import org.lwjgl.opengl.GL11;
import cpw.mods.ironchest.ContainerIronChestBase;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.TileEntityIronChest;
public class GUIChest extends GuiContainer {
public enum GUI {
IRON(184, 202, "/cpw/mods/ironchest/sprites/ironcontainer.png", IronChestType.IRON), GOLD(184, 256, "/cpw/mods/ironchest/sprites/goldcontainer.png",
IronChestType.GOLD), DIAMOND(238, 256, "/cpw/mods/ironchest/sprites/diamondcontainer.png", IronChestType.DIAMOND), COPPER(184, 184,
"/cpw/mods/ironchest/sprites/coppercontainer.png", IronChestType.COPPER), SILVER(184, 238, "/cpw/mods/ironchest/sprites/silvercontainer.png",
IronChestType.SILVER), CRYSTAL(238, 256, "/cpw/mods/ironchest/sprites/diamondcontainer.png", IronChestType.CRYSTAL);
private int xSize;
private int ySize;
private String guiTexture;
private IronChestType mainType;
private GUI(int xSize, int ySize, String guiTexture, IronChestType mainType)
{
this.xSize = xSize;
this.ySize = ySize;
this.guiTexture = guiTexture;
this.mainType = mainType;
}
protected Container makeContainer(IInventory player, IInventory chest)
{
return new ContainerIronChestBase(player, chest, mainType, xSize, ySize);
}
public static GUIChest buildGUI(IronChestType type, IInventory playerInventory, TileEntityIronChest chestInventory)
{
return new GUIChest(values()[chestInventory.getType().ordinal()], playerInventory, chestInventory);
}
}
public int getRowLength()
{
return type.mainType.getRowLength();
}
private GUI type;
private GUIChest(GUI type, IInventory player, IInventory chest)
{
super(type.makeContainer(player, chest));
this.type = type;
this.xSize = type.xSize;
this.ySize = type.ySize;
this.allowUserInput = false;
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int i, int j)
{
int tex = mc.renderEngine.getTexture(type.guiTexture);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(tex);
int x = (width - xSize) / 2;
int y = (height - ySize) / 2;
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
}
}

View File

@ -25,17 +25,23 @@ import cpw.mods.ironchest.TileEntityIronChest;
public class IronChestRenderHelper extends ChestItemRenderHelper { public class IronChestRenderHelper extends ChestItemRenderHelper {
private Map<Integer, TileEntityIronChest> itemRenders = Maps.newHashMap(); private Map<Integer, TileEntityIronChest> itemRenders = Maps.newHashMap();
public IronChestRenderHelper() { public IronChestRenderHelper()
{
for (IronChestType typ : IronChestType.values()) for (IronChestType typ : IronChestType.values())
{ {
itemRenders.put(typ.ordinal(), (TileEntityIronChest) IronChest.ironChestBlock.createTileEntity(null, typ.ordinal())); itemRenders.put(typ.ordinal(), (TileEntityIronChest) IronChest.ironChestBlock.createTileEntity(null, typ.ordinal()));
} }
} }
@Override @Override
public void renderChest(Block block, int i, float f) { public void renderChest(Block block, int i, float f)
if (block==IronChest.ironChestBlock) { {
if (block == IronChest.ironChestBlock)
{
TileEntityRenderer.instance.renderTileEntityAt(itemRenders.get(i), 0.0D, 0.0D, 0.0D, 0.0F); TileEntityRenderer.instance.renderTileEntityAt(itemRenders.get(i), 0.0D, 0.0D, 0.0D, 0.0F);
} else { }
else
{
super.renderChest(block, i, f); super.renderChest(block, i, f);
} }
} }

View File

@ -0,0 +1,195 @@
/*******************************************************************************
* 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 static org.lwjgl.opengl.GL11.GL_COMPILE_AND_EXECUTE;
import static org.lwjgl.opengl.GL11.glCallList;
import static org.lwjgl.opengl.GL11.glColor4f;
import static org.lwjgl.opengl.GL11.glDisable;
import static org.lwjgl.opengl.GL11.glEnable;
import static org.lwjgl.opengl.GL11.glEndList;
import static org.lwjgl.opengl.GL11.glGenLists;
import static org.lwjgl.opengl.GL11.glNewList;
import static org.lwjgl.opengl.GL11.glPopMatrix;
import static org.lwjgl.opengl.GL11.glPushMatrix;
import static org.lwjgl.opengl.GL11.glRotatef;
import static org.lwjgl.opengl.GL11.glScalef;
import static org.lwjgl.opengl.GL11.glTranslatef;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.client.model.ModelChest;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.client.MinecraftForgeClient;
import org.lwjgl.opengl.GL11;
import com.google.common.primitives.SignedBytes;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.ironchest.IronChest;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.MappableItemStackWrapper;
import cpw.mods.ironchest.TileEntityIronChest;
public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
private static Map<MappableItemStackWrapper, Integer> renderList = new HashMap<MappableItemStackWrapper, Integer>();
private Random random;
private RenderBlocks renderBlocks;
private RenderItem itemRenderer;
private static float[][] shifts = { { 0.3F, 0.45F, 0.3F }, { 0.7F, 0.45F, 0.3F }, { 0.3F, 0.45F, 0.7F }, { 0.7F, 0.45F, 0.7F }, { 0.3F, 0.1F, 0.3F },
{ 0.7F, 0.1F, 0.3F }, { 0.3F, 0.1F, 0.7F }, { 0.7F, 0.1F, 0.7F }, { 0.5F, 0.32F, 0.5F }, };
public TileEntityIronChestRenderer()
{
model = new ModelChest();
random = new Random();
renderBlocks = new RenderBlocks();
itemRenderer = new RenderItem() {
@Override
public byte getMiniBlockCountForItemStack(ItemStack stack) {
return SignedBytes.saturatedCast((stack.stackSize / 32) + 1);
}
public byte getMiniItemCountForItemStack(ItemStack stack) {
return SignedBytes.saturatedCast((stack.stackSize / 32) + 1);
};
public boolean shouldBob() {
return false;
};
public boolean shouldSpreadItems() {
return false;
};
};
itemRenderer.setRenderManager(RenderManager.instance);
}
private void overrideTexture(Object obj)
{
if (obj instanceof Item)
{
GL11.glBindTexture(GL11.GL_TEXTURE_2D, FMLClientHandler.instance().getClient().renderEngine.getTexture(((Item) obj).getTextureFile()));
}
else if (obj instanceof Block)
{
GL11.glBindTexture(GL11.GL_TEXTURE_2D, FMLClientHandler.instance().getClient().renderEngine.getTexture(((Block) obj).getTextureFile()));
}
}
public void render(TileEntityIronChest tile, double x, double y, double z, float partialTick) {
if (tile == null) {
return;
}
int facing = 3;
IronChestType type = tile.getType();
if (tile != null && tile.getWorldObj() != null) {
facing = tile.getFacing();
type = tile.getType();
int typ = tile.getWorldObj().getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord);
type = IronChestType.values()[typ];
}
bindTextureByName(type.getModelTexture());
glPushMatrix();
glEnable(32826 /* GL_RESCALE_NORMAL_EXT */);
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
glTranslatef((float) x, (float) y + 1.0F, (float) z + 1.0F);
glScalef(1.0F, -1F, -1F);
glTranslatef(0.5F, 0.5F, 0.5F);
int k = 0;
if (facing == 2) {
k = 180;
}
if (facing == 3) {
k = 0;
}
if (facing == 4) {
k = 90;
}
if (facing == 5) {
k = -90;
}
glRotatef(k, 0.0F, 1.0F, 0.0F);
glTranslatef(-0.5F, -0.5F, -0.5F);
float lidangle = tile.prevLidAngle + (tile.lidAngle - tile.prevLidAngle) * partialTick;
lidangle = 1.0F - lidangle;
lidangle = 1.0F - lidangle * lidangle * lidangle;
model.chestLid.rotateAngleX = -((lidangle * 3.141593F) / 2.0F);
// Render the chest itself
model.renderAll();
glDisable(32826 /* GL_RESCALE_NORMAL_EXT */);
glPopMatrix();
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
if (type.isTransparent() && tile.getDistanceFrom(this.tileEntityRenderer.playerX, this.tileEntityRenderer.playerY, this.tileEntityRenderer.playerZ) < 128d) {
random.setSeed(254L);
float shiftX;
float shiftY;
float shiftZ;
int shift = 0;
float blockScale = 0.70F;
float timeD = (float) (360.0 * (double) (System.currentTimeMillis() & 0x3FFFL) / (double) 0x3FFFL);
if (tile.getTopItemStacks()[1] == null) {
shift = 8;
blockScale = 0.85F;
}
glPushMatrix();
glDisable(2896 /* GL_LIGHTING */);
glTranslatef((float) x, (float) y, (float) z);
EntityItem customitem = new EntityItem(tileEntityRenderer.worldObj);
customitem.hoverStart = 0f;
for (ItemStack item : tile.getTopItemStacks()) {
if (shift > shifts.length) {
break;
}
if (item == null) {
shift++;
continue;
}
shiftX = shifts[shift][0];
shiftY = shifts[shift][1];
shiftZ = shifts[shift][2];
shift++;
glPushMatrix();
glTranslatef(shiftX, shiftY, shiftZ);
glRotatef(timeD, 0.0F, 1.0F, 0.0F);
glScalef(blockScale, blockScale, blockScale);
customitem.func_92013_a(item);
itemRenderer.doRenderItem(customitem, 0, 0, 0, 0, 0);
glPopMatrix();
}
glEnable(2896 /* GL_LIGHTING */);
glPopMatrix();
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
}
}
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float partialTick)
{
render((TileEntityIronChest) tileentity, x, y, z, partialTick);
}
private ModelChest model;
}