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;
@ -33,188 +33,218 @@ import net.minecraftforge.common.ForgeDirection;
public class BlockIronChest extends BlockContainer { public class BlockIronChest extends BlockContainer {
private Random random; private Random random;
public BlockIronChest(int id) { public BlockIronChest(int id)
super(id, Material.iron);
setBlockName("IronChest");
setHardness(3.0F);
setRequiresSelfNotify();
setBlockBounds(0.0625F, 0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
random = new Random();
setCreativeTab(CreativeTabs.tabDecorations);
}
@Override
public TileEntity createNewTileEntity(World w) {
return null;
}
@Override
public String getTextureFile() {
return "/cpw/mods/ironchest/sprites/block_textures.png";
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean renderAsNormalBlock() {
return false;
}
@Override
public int getRenderType() {
return 22;
}
@Override
public TileEntity createNewTileEntity(World world, int metadata) {
return IronChestType.makeEntity(metadata);
}
public int getBlockTexture(IBlockAccess worldAccess, int i, int j, int k, int l) {
int meta = worldAccess.getBlockMetadata(i, j, k);
IronChestType type = IronChestType.values()[meta];
TileEntity te = worldAccess.getBlockTileEntity(i, j, k);
TileEntityIronChest icte = null;
if (te != null && te instanceof TileEntityIronChest) {
icte = (TileEntityIronChest) te;
}
if (l == 0 || l == 1) { // Top and Bottom
return type.getTextureRow() * 16 + 1;
} else if (icte != null && l == icte.getFacing()) { // Front
return type.getTextureRow() * 16 + 2;
} else { // Back and Sides
return type.getTextureRow() * 16;
}
}
@Override
public int getBlockTextureFromSideAndMetadata(int i, int j) {
IronChestType typ = IronChestType.values()[j];
switch (i) {
case 0:
case 1:
return typ.getTextureRow() * 16 + 1;
case 3:
return typ.getTextureRow() * 16 + 2;
default:
return typ.getTextureRow() * 16;
}
}
@Override
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);
if (te == null || !(te instanceof TileEntityIronChest))
{ {
return true; super(id, Material.iron);
setBlockName("IronChest");
setHardness(3.0F);
setRequiresSelfNotify();
setBlockBounds(0.0625F, 0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
random = new Random();
setCreativeTab(CreativeTabs.tabDecorations);
} }
if (world.isBlockSolidOnSide(i, j + 1, k, ForgeDirection.DOWN)) @Override
public TileEntity createNewTileEntity(World w)
{ {
return true; return null;
} }
if (world.isRemote) { @Override
return true; public String getTextureFile()
}
player.openGui(IronChest.instance, ((TileEntityIronChest) te).getType().ordinal(), world, i, j, k);
return true;
}
@Override
public void onBlockAdded(World world, int i, int j, int k) {
super.onBlockAdded(world, i, j, k);
world.markBlockForUpdate(i, j, k);
}
@Override
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving) {
byte chestFacing = 0;
int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
if (facing == 0) {
chestFacing = 2;
}
if (facing == 1) {
chestFacing = 5;
}
if (facing == 2) {
chestFacing = 3;
}
if (facing == 3) {
chestFacing = 4;
}
TileEntity te = world.getBlockTileEntity(i, j, k);
if (te != null && te instanceof TileEntityIronChest) {
((TileEntityIronChest) te).setFacing(chestFacing);
world.markBlockForUpdate(i, j, k);
}
}
@Override
public int damageDropped(int i) {
return i;
}
@Override
public void breakBlock(World world, int i, int j, int k, int i1, int i2)
{
TileEntityIronChest tileentitychest = (TileEntityIronChest) world.getBlockTileEntity(i, j, k);
if (tileentitychest != null)
{ {
dropContent(0, tileentitychest, world, tileentitychest.xCoord, tileentitychest.yCoord, tileentitychest.zCoord); return "/cpw/mods/ironchest/sprites/block_textures.png";
} }
super.breakBlock(world, i, j, k, i1, i2);
}
public void dropContent(int newSize, IInventory chest, World world, int xCoord, int yCoord, int zCoord) { @Override
for (int l = newSize; l < chest.getSizeInventory(); l++) public boolean isOpaqueCube()
{ {
ItemStack itemstack = chest.getStackInSlot(l); return false;
if (itemstack == null) }
{
continue; @Override
} public boolean renderAsNormalBlock()
float f = random.nextFloat() * 0.8F + 0.1F; {
float f1 = random.nextFloat() * 0.8F + 0.1F; return false;
float f2 = random.nextFloat() * 0.8F + 0.1F; }
while (itemstack.stackSize > 0)
{ @Override
int i1 = random.nextInt(21) + 10; public int getRenderType()
if (i1 > itemstack.stackSize) {
return 22;
}
@Override
public TileEntity createNewTileEntity(World world, int metadata)
{
return IronChestType.makeEntity(metadata);
}
public int getBlockTexture(IBlockAccess worldAccess, int i, int j, int k, int l)
{
int meta = worldAccess.getBlockMetadata(i, j, k);
IronChestType type = IronChestType.values()[meta];
TileEntity te = worldAccess.getBlockTileEntity(i, j, k);
TileEntityIronChest icte = null;
if (te != null && te instanceof TileEntityIronChest)
{ {
i1 = itemstack.stackSize; icte = (TileEntityIronChest) te;
} }
itemstack.stackSize -= i1; if (l == 0 || l == 1)
EntityItem entityitem = new EntityItem(world, (float) xCoord + f, (float) yCoord + (newSize > 0 ? 1 : 0) + f1, (float) zCoord + f2, { // Top and Bottom
new ItemStack(itemstack.itemID, i1, itemstack.getItemDamage())); return type.getTextureRow() * 16 + 1;
float f3 = 0.05F; }
entityitem.motionX = (float) random.nextGaussian() * f3; else if (icte != null && l == icte.getFacing())
entityitem.motionY = (float) random.nextGaussian() * f3 + 0.2F; { // Front
entityitem.motionZ = (float) random.nextGaussian() * f3; return type.getTextureRow() * 16 + 2;
if (itemstack.hasTagCompound()) }
{ else
entityitem.item.setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy()); { // Back and Sides
return type.getTextureRow() * 16;
} }
world.spawnEntityInWorld(entityitem);
}
} }
}
@Override @Override
@SuppressWarnings({ "rawtypes", "unchecked" }) public int getBlockTextureFromSideAndMetadata(int i, int j)
@SideOnly(Side.CLIENT) {
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List) { IronChestType typ = IronChestType.values()[j];
for (IronChestType type : IronChestType.values()) { switch (i)
if (type.isValidForCreativeMode()) { {
par3List.add(new ItemStack(this, 1, type.ordinal())); case 0:
} case 1:
} return typ.getTextureRow() * 16 + 1;
} case 3:
return typ.getTextureRow() * 16 + 2;
default:
return typ.getTextureRow() * 16;
}
}
@Override
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);
if (te == null || !(te instanceof TileEntityIronChest))
{
return true;
}
if (world.isBlockSolidOnSide(i, j + 1, k, ForgeDirection.DOWN))
{
return true;
}
if (world.isRemote)
{
return true;
}
player.openGui(IronChest.instance, ((TileEntityIronChest) te).getType().ordinal(), world, i, j, k);
return true;
}
@Override
public void onBlockAdded(World world, int i, int j, int k)
{
super.onBlockAdded(world, i, j, k);
world.markBlockForUpdate(i, j, k);
}
@Override
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving)
{
byte chestFacing = 0;
int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
if (facing == 0)
{
chestFacing = 2;
}
if (facing == 1)
{
chestFacing = 5;
}
if (facing == 2)
{
chestFacing = 3;
}
if (facing == 3)
{
chestFacing = 4;
}
TileEntity te = world.getBlockTileEntity(i, j, k);
if (te != null && te instanceof TileEntityIronChest)
{
((TileEntityIronChest) te).setFacing(chestFacing);
world.markBlockForUpdate(i, j, k);
}
}
@Override
public int damageDropped(int i)
{
return i;
}
@Override
public void breakBlock(World world, int i, int j, int k, int i1, int i2)
{
TileEntityIronChest tileentitychest = (TileEntityIronChest) world.getBlockTileEntity(i, j, k);
if (tileentitychest != null)
{
dropContent(0, tileentitychest, world, tileentitychest.xCoord, tileentitychest.yCoord, tileentitychest.zCoord);
}
super.breakBlock(world, i, j, k, i1, i2);
}
public void dropContent(int newSize, IInventory chest, World world, int xCoord, int yCoord, int zCoord)
{
for (int l = newSize; l < chest.getSizeInventory(); l++)
{
ItemStack itemstack = chest.getStackInSlot(l);
if (itemstack == null)
{
continue;
}
float f = random.nextFloat() * 0.8F + 0.1F;
float f1 = random.nextFloat() * 0.8F + 0.1F;
float f2 = random.nextFloat() * 0.8F + 0.1F;
while (itemstack.stackSize > 0)
{
int i1 = random.nextInt(21) + 10;
if (i1 > itemstack.stackSize)
{
i1 = itemstack.stackSize;
}
itemstack.stackSize -= i1;
EntityItem entityitem = new EntityItem(world, (float) xCoord + f, (float) yCoord + (newSize > 0 ? 1 : 0) + f1, (float) zCoord + f2,
new ItemStack(itemstack.itemID, i1, itemstack.getItemDamage()));
float f3 = 0.05F;
entityitem.motionX = (float) random.nextGaussian() * f3;
entityitem.motionY = (float) random.nextGaussian() * f3 + 0.2F;
entityitem.motionZ = (float) random.nextGaussian() * f3;
if (itemstack.hasTagCompound())
{
entityitem.func_92014_d().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
}
world.spawnEntityInWorld(entityitem);
}
}
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
@SideOnly(Side.CLIENT)
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (IronChestType type : IronChestType.values())
{
if (type.isValidForCreativeMode())
{
par3List.add(new ItemStack(this, 1, type.ordinal()));
}
}
}
} }

View File

@ -19,63 +19,72 @@ 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;
public String itemName; public String itemName;
public String descriptiveName; public String descriptiveName;
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.target = target; this.source = source;
this.itemName = itemName; this.target = target;
this.descriptiveName = descriptiveName; this.itemName = itemName;
this.recipe = recipe; this.descriptiveName = descriptiveName;
} this.recipe = recipe;
public boolean canUpgrade(IronChestType from) {
return from == this.source;
}
public int getTarget() {
return this.target.ordinal();
}
public ItemChestChanger buildItem(Configuration cfg, int id) {
int itemId = cfg.get(Configuration.CATEGORY_ITEM, itemName, id).getInt(id);
item = new ItemChestChanger(itemId, this);
return item;
}
public void addRecipes() {
for (String sourceMat : source.getMatList()) {
for (String targetMat : target.getMatList()) {
Object targetMaterial = IronChestType.translateOreName(targetMat);
Object sourceMaterial = IronChestType.translateOreName(sourceMat);
IronChestType.addRecipe(new ItemStack(item), recipe, 'm', targetMaterial, 's', sourceMaterial, 'G', Block.glass, 'O', Block.obsidian);
}
} }
}
public static void buildItems(Configuration cfg, int defaultId) { public boolean canUpgrade(IronChestType from)
for (ChestChangerType type : values()) { {
type.buildItem(cfg, defaultId++); return from == this.source;
} }
}
public static void generateRecipes() { public int getTarget()
for (ChestChangerType item : values()) { {
item.addRecipes(); return this.target.ordinal();
}
public ItemChestChanger buildItem(Configuration cfg, int id)
{
int itemId = cfg.get(Configuration.CATEGORY_ITEM, itemName, id).getInt(id);
item = new ItemChestChanger(itemId, this);
return item;
}
public void addRecipes()
{
for (String sourceMat : source.getMatList())
{
for (String targetMat : target.getMatList())
{
Object targetMaterial = IronChestType.translateOreName(targetMat);
Object sourceMaterial = IronChestType.translateOreName(sourceMat);
IronChestType.addRecipe(new ItemStack(item), recipe, 'm', targetMaterial, 's', sourceMaterial, 'G', Block.glass, 'O', Block.obsidian);
}
}
}
public static void buildItems(Configuration cfg, int defaultId)
{
for (ChestChangerType type : values())
{
type.buildItem(cfg, defaultId++);
}
}
public static void generateRecipes()
{
for (ChestChangerType item : values())
{
item.addRecipes();
}
} }
}
} }

View File

@ -16,34 +16,40 @@ import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler; import cpw.mods.fml.common.network.IGuiHandler;
public class CommonProxy implements IGuiHandler { public class CommonProxy implements IGuiHandler {
public void registerRenderInformation() public void registerRenderInformation()
{ {
} }
public void registerTileEntitySpecialRenderer(IronChestType typ) public void registerTileEntitySpecialRenderer(IronChestType typ)
{ {
} }
@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); {
if (te != null && te instanceof TileEntityIronChest) { TileEntity te = world.getBlockTileEntity(X, Y, Z);
TileEntityIronChest icte = (TileEntityIronChest) te; if (te != null && te instanceof TileEntityIronChest)
return new ContainerIronChestBase(player.inventory, icte, icte.getType(), 0, 0); {
} else { TileEntityIronChest icte = (TileEntityIronChest) te;
return null; return new ContainerIronChestBase(player.inventory, icte, icte.getType(), 0, 0);
} }
} else
{
return null;
}
}
public World getClientWorld() { public World getClientWorld()
return null; {
} return null;
}
} }

View File

@ -18,88 +18,94 @@ import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
public class ContainerIronChestBase extends Container { public class ContainerIronChestBase extends Container {
private IronChestType type; private IronChestType type;
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;
player = ((InventoryPlayer) playerInventory).player;
this.type = type;
chestInventory.openChest();
layoutContainer(playerInventory, chestInventory, type, xSize, ySize);
}
@Override
public boolean canInteractWith(EntityPlayer player)
{
return chest.isUseableByPlayer(player);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer p, int i)
{
ItemStack itemstack = null;
Slot slot = (Slot) inventorySlots.get(i);
if (slot != null && slot.getHasStack())
{ {
ItemStack itemstack1 = slot.getStack(); chest = chestInventory;
itemstack = itemstack1.copy(); player = ((InventoryPlayer) playerInventory).player;
if (i < type.size) this.type = type;
{ chestInventory.openChest();
if (!mergeItemStack(itemstack1, type.size, inventorySlots.size(), true)) layoutContainer(playerInventory, chestInventory, type, xSize, ySize);
}
@Override
public boolean canInteractWith(EntityPlayer player)
{
return chest.isUseableByPlayer(player);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer p, int i)
{
ItemStack itemstack = null;
Slot slot = (Slot) inventorySlots.get(i);
if (slot != null && slot.getHasStack())
{ {
return null; ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (i < type.size)
{
if (!mergeItemStack(itemstack1, type.size, inventorySlots.size(), true))
{
return null;
}
}
else if (!mergeItemStack(itemstack1, 0, type.size, false))
{
return null;
}
if (itemstack1.stackSize == 0)
{
slot.putStack(null);
}
else
{
slot.onSlotChanged();
}
} }
} else if (!mergeItemStack(itemstack1, 0, type.size, false)) return itemstack;
{
return null;
}
if (itemstack1.stackSize == 0)
{
slot.putStack(null);
} else
{
slot.onSlotChanged();
}
} }
return itemstack;
}
@Override @Override
public void onCraftGuiClosed(EntityPlayer entityplayer) public void onCraftGuiClosed(EntityPlayer entityplayer)
{
super.onCraftGuiClosed(entityplayer);
chest.closeChest();
}
protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) {
for (int chestRow = 0; chestRow < type.getRowCount(); chestRow++)
{ {
for (int chestCol = 0; chestCol < type.getRowLength(); chestCol++) super.onCraftGuiClosed(entityplayer);
{ chest.closeChest();
addSlotToContainer(new Slot(chestInventory, chestCol + chestRow * type.getRowLength(), 12 + chestCol * 18, 8 + chestRow * 18));
}
} }
int leftCol = (xSize - 162) / 2 + 1; protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize)
for (int playerInvRow = 0; playerInvRow < 3; playerInvRow++)
{ {
for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++) for (int chestRow = 0; chestRow < type.getRowCount(); chestRow++)
{ {
addSlotToContainer(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, ySize - (4 - playerInvRow) * 18 - 10)); for (int chestCol = 0; chestCol < type.getRowLength(); chestCol++)
} {
addSlotToContainer(new Slot(chestInventory, chestCol + chestRow * type.getRowLength(), 12 + chestCol * 18, 8 + chestRow * 18));
}
}
int leftCol = (xSize - 162) / 2 + 1;
for (int playerInvRow = 0; playerInvRow < 3; playerInvRow++)
{
for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++)
{
addSlotToContainer(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, ySize - (4 - playerInvRow) * 18
- 10));
}
}
for (int hotbarSlot = 0; hotbarSlot < 9; hotbarSlot++)
{
addSlotToContainer(new Slot(playerInventory, hotbarSlot, leftCol + hotbarSlot * 18, ySize - 24));
}
} }
for (int hotbarSlot = 0; hotbarSlot < 9; hotbarSlot++) public EntityPlayer getPlayer()
{ {
addSlotToContainer(new Slot(playerInventory, hotbarSlot, leftCol + hotbarSlot * 18, ySize - 24)); return player;
} }
}
public EntityPlayer getPlayer() {
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,59 +30,71 @@ 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;
@SidedProxy(clientSide = "cpw.mods.ironchest.client.ClientProxy", serverSide = "cpw.mods.ironchest.CommonProxy") @SidedProxy(clientSide = "cpw.mods.ironchest.client.ClientProxy", serverSide = "cpw.mods.ironchest.CommonProxy")
public static CommonProxy proxy; public static CommonProxy proxy;
@Instance("IronChest") @Instance("IronChest")
public static IronChest instance; public static IronChest instance;
public static boolean CACHE_RENDER = true; public static boolean CACHE_RENDER = true;
public static boolean OCELOTS_SITONCHESTS = true; public static boolean OCELOTS_SITONCHESTS = true;
private int blockId; private int blockId;
@PreInit @PreInit
public void preInit(FMLPreInitializationEvent event) { public void preInit(FMLPreInitializationEvent event)
Version.init(event.getVersionProperties()); {
event.getModMetadata().version = Version.fullVersionString(); Version.init(event.getVersionProperties());
Configuration cfg = new Configuration(event.getSuggestedConfigurationFile()); event.getModMetadata().version = Version.fullVersionString();
try { Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
cfg.load(); try
blockId = cfg.get(Configuration.CATEGORY_BLOCK, "ironChests", 181).getInt(181); {
ChestChangerType.buildItems(cfg, 29501); cfg.load();
CACHE_RENDER = cfg.get(Configuration.CATEGORY_GENERAL, "cacheRenderingInformation", true).getBoolean(true); blockId = cfg.get(Configuration.CATEGORY_BLOCK, "ironChests", 181).getInt(181);
OCELOTS_SITONCHESTS = cfg.get(Configuration.CATEGORY_GENERAL, "ocelotsSitOnChests", true).getBoolean(true); ChestChangerType.buildItems(cfg, 29501);
} catch (Exception e) { CACHE_RENDER = cfg.get(Configuration.CATEGORY_GENERAL, "cacheRenderingInformation", true).getBoolean(true);
FMLLog.log(Level.SEVERE, e, "IronChest has a problem loading it's configuration"); OCELOTS_SITONCHESTS = cfg.get(Configuration.CATEGORY_GENERAL, "ocelotsSitOnChests", true).getBoolean(true);
} finally { }
cfg.save(); catch (Exception e)
} {
} FMLLog.log(Level.SEVERE, e, "IronChest has a problem loading it's configuration");
}
finally
{
cfg.save();
}
}
@Init @Init
public void load(FMLInitializationEvent evt) { public void load(FMLInitializationEvent evt)
ironChestBlock = new BlockIronChest(blockId); {
GameRegistry.registerBlock(ironChestBlock, ItemIronChest.class); ironChestBlock = new BlockIronChest(blockId);
for (IronChestType typ : IronChestType.values()) { GameRegistry.registerBlock(ironChestBlock, ItemIronChest.class);
GameRegistry.registerTileEntity(typ.clazz, typ.name()); for (IronChestType typ : IronChestType.values())
LanguageRegistry.instance().addStringLocalization(typ.name() + ".name", "en_US", typ.friendlyName); {
proxy.registerTileEntitySpecialRenderer(typ); GameRegistry.registerTileEntity(typ.clazz, typ.name());
} LanguageRegistry.instance().addStringLocalization(typ.name() + ".name", "en_US", typ.friendlyName);
for (ChestChangerType typ : ChestChangerType.values()) { proxy.registerTileEntitySpecialRenderer(typ);
LanguageRegistry.instance().addStringLocalization("item." + typ.itemName + ".name", "en_US", typ.descriptiveName); }
} for (ChestChangerType typ : ChestChangerType.values())
IronChestType.generateTieredRecipes(ironChestBlock); {
ChestChangerType.generateRecipes(); LanguageRegistry.instance().addStringLocalization("item." + typ.itemName + ".name", "en_US", typ.descriptiveName);
NetworkRegistry.instance().registerGuiHandler(instance, proxy); }
proxy.registerRenderInformation(); IronChestType.generateTieredRecipes(ironChestBlock);
if (OCELOTS_SITONCHESTS) ChestChangerType.generateRecipes();
{ NetworkRegistry.instance().registerGuiHandler(instance, proxy);
MinecraftForge.EVENT_BUS.register(new OcelotsSitOnChestsHandler()); proxy.registerRenderInformation();
} if (OCELOTS_SITONCHESTS)
} {
MinecraftForge.EVENT_BUS.register(new OcelotsSitOnChestsHandler());
}
MinecraftForge.EVENT_BUS.register(this);
}
@PostInit
public void modsLoaded(FMLPostInitializationEvent evt)
{
}
@PostInit
public void modsLoaded(FMLPostInitializationEvent evt) {
}
} }

View File

@ -5,15 +5,18 @@ 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) { {
return true; if (world.getBlockId(x, y, z) == IronChest.ironChestBlock.blockID)
} {
return super.isSittableBlock(world, x, y, z); return true;
} }
return super.isSittableBlock(world, x, y, z);
}
} }

View File

@ -22,143 +22,182 @@ 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;
private boolean tieredChest; private boolean tieredChest;
private String modelTexture; private String modelTexture;
private int textureRow; private int textureRow;
public Class<? extends TileEntityIronChest> clazz; public Class<? extends TileEntityIronChest> clazz;
private String[] recipes; private String[] recipes;
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.rowLength = rowLength; this.size = size;
this.tieredChest = tieredChest; this.rowLength = rowLength;
this.friendlyName = friendlyName; this.tieredChest = tieredChest;
this.modelTexture = "/cpw/mods/ironchest/sprites/" + modelTexture; this.friendlyName = friendlyName;
this.textureRow = textureRow; this.modelTexture = "/cpw/mods/ironchest/sprites/" + modelTexture;
this.clazz = clazz; this.textureRow = textureRow;
this.recipes = recipes; this.clazz = clazz;
this.matList = new ArrayList<String>(); this.recipes = recipes;
matList.addAll(mats); this.matList = new ArrayList<String>();
} matList.addAll(mats);
public String getModelTexture() {
return modelTexture;
}
public int getTextureRow() {
return textureRow;
}
public static TileEntityIronChest makeEntity(int metadata) {
// Compatibility
int chesttype = validateMeta(metadata);
if (chesttype == metadata) {
try {
TileEntityIronChest te = values()[chesttype].clazz.newInstance();
return te;
} catch (InstantiationException e) {
// unpossible
e.printStackTrace();
} catch (IllegalAccessException e) {
// unpossible
e.printStackTrace();
}
} }
return null;
}
public static void registerTranslations() { public String getModelTexture()
} {
return modelTexture;
public static void generateTieredRecipes(BlockIronChest blockResult) {
ItemStack previous = new ItemStack(Block.chest);
for (IronChestType typ : values()) {
generateRecipesForType(blockResult, previous, typ);
if (typ.tieredChest)
previous = new ItemStack(blockResult, 1, typ.ordinal());
} }
}
public static void generateRecipesForType(BlockIronChest blockResult, Object previousTier, IronChestType type) { public int getTextureRow()
for (String recipe : type.recipes) { {
String[] recipeSplit = new String[] { recipe.substring(0, 3), recipe.substring(3, 6), recipe.substring(6, 9) }; return textureRow;
Object mainMaterial = null;
for (String mat : type.matList) {
mainMaterial = translateOreName(mat);
addRecipe(new ItemStack(blockResult, 1, type.ordinal()), recipeSplit,
'm', mainMaterial,
'P', previousTier, /* previous tier of chest */
'G', Block.glass,
'C', Block.chest,
'0', new ItemStack(blockResult, 1, 0), /* 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 */
'4', new ItemStack(blockResult, 1, 4)/* Silver Chest */
);
}
} }
}
public static Object translateOreName(String mat) { public static TileEntityIronChest makeEntity(int metadata)
if (mat == "ingotIron" ) { {
return Item.ingotIron; // Compatibility
} else if (mat == "ingotGold") { int chesttype = validateMeta(metadata);
return Item.ingotGold; if (chesttype == metadata)
} else if (mat == "gemDiamond") { {
return Item.diamond; try
} else if (mat == "blockGlass") { {
return Block.glass; TileEntityIronChest te = values()[chesttype].clazz.newInstance();
} else if (mat == "blockPlanks") { return te;
return Block.planks; }
catch (InstantiationException e)
{
// unpossible
e.printStackTrace();
}
catch (IllegalAccessException e)
{
// unpossible
e.printStackTrace();
}
}
return null;
} }
return mat;
}
@SuppressWarnings("unchecked") public static void registerTranslations()
public static void addRecipe(ItemStack is, Object... parts) { {
ShapedOreRecipe oreRecipe = new ShapedOreRecipe(is, parts);
GameRegistry.addRecipe(oreRecipe);
}
public int getRowCount() {
return size / rowLength;
}
public int getRowLength() {
return rowLength;
}
public boolean isTransparent() {
return this == CRYSTAL;
}
public List<String> getMatList() {
return matList;
}
public static int validateMeta(int i) {
if (i < values().length && values()[i].size>0) {
return i;
} else {
return 0;
} }
}
public boolean isValidForCreativeMode() { public static void generateTieredRecipes(BlockIronChest blockResult)
return validateMeta(ordinal())==ordinal(); {
} ItemStack previous = new ItemStack(Block.chest);
for (IronChestType typ : values())
{
generateRecipesForType(blockResult, previous, typ);
if (typ.tieredChest) previous = new ItemStack(blockResult, 1, typ.ordinal());
}
}
public static void generateRecipesForType(BlockIronChest blockResult, Object previousTier, IronChestType type)
{
for (String recipe : type.recipes)
{
String[] recipeSplit = new String[] { recipe.substring(0, 3), recipe.substring(3, 6), recipe.substring(6, 9) };
Object mainMaterial = null;
for (String mat : type.matList)
{
mainMaterial = translateOreName(mat);
addRecipe(new ItemStack(blockResult, 1, type.ordinal()), recipeSplit, 'm', mainMaterial, 'P', previousTier, /*
* previous
* tier
* of
* chest
*/
'G', Block.glass, 'C', Block.chest, '0', new ItemStack(blockResult, 1, 0), /*
* 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 */
'4', new ItemStack(blockResult, 1, 4)/* Silver Chest */
);
}
}
}
public static Object translateOreName(String mat)
{
if (mat == "ingotIron")
{
return Item.ingotIron;
}
else if (mat == "ingotGold")
{
return Item.ingotGold;
}
else if (mat == "gemDiamond")
{
return Item.diamond;
}
else if (mat == "blockGlass")
{
return Block.glass;
}
else if (mat == "blockPlanks")
{
return Block.planks;
}
return mat;
}
@SuppressWarnings("unchecked")
public static void addRecipe(ItemStack is, Object... parts)
{
ShapedOreRecipe oreRecipe = new ShapedOreRecipe(is, parts);
GameRegistry.addRecipe(oreRecipe);
}
public int getRowCount()
{
return size / rowLength;
}
public int getRowLength()
{
return rowLength;
}
public boolean isTransparent()
{
return this == CRYSTAL;
}
public List<String> getMatList()
{
return matList;
}
public static int validateMeta(int i)
{
if (i < values().length && values()[i].size > 0)
{
return i;
}
else
{
return 0;
}
}
public boolean isValidForCreativeMode()
{
return validateMeta(ordinal()) == ordinal();
}
} }

View File

@ -21,79 +21,92 @@ import cpw.mods.fml.common.ObfuscationReflectionHelper;
public class ItemChestChanger extends Item { 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); {
setMaxStackSize(1); super(id);
this.type=type; setMaxStackSize(1);
setIconIndex(type.ordinal()); this.type = type;
setItemName(type.itemName); setIconIndex(type.ordinal());
setCreativeTab(CreativeTabs.tabMisc); setItemName(type.itemName);
} 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);
return false; if (newchest == null)
} {
} else if (te!=null && te instanceof TileEntityChest) { return false;
TileEntityChest tec = (TileEntityChest) te; }
if (tec.numUsingPlayers > 0) { }
return false; else if (te != null && te instanceof TileEntityChest)
} {
if (!getType().canUpgrade(IronChestType.WOOD)) { TileEntityChest tec = (TileEntityChest) te;
return false; if (tec.numUsingPlayers > 0)
} {
// Force old TE out of the world so that adjacent chests can update return false;
newchest = IronChestType.makeEntity(getTargetChestOrdinal(IronChestType.WOOD.ordinal())); }
int newSize = newchest.chestContents.length; if (!getType().canUpgrade(IronChestType.WOOD))
ItemStack[] chestContents = ObfuscationReflectionHelper.getPrivateValue(TileEntityChest.class, tec, 0); {
System.arraycopy(chestContents, 0, newchest.chestContents, 0, Math.min(newSize, chestContents.length)); return false;
BlockIronChest block = IronChest.ironChestBlock; }
block.dropContent(newSize, tec, world, tec.xCoord, tec.yCoord, tec.zCoord); // Force old TE out of the world so that adjacent chests can update
newchest.setFacing((byte)tec.getBlockMetadata()); newchest = IronChestType.makeEntity(getTargetChestOrdinal(IronChestType.WOOD.ordinal()));
newchest.sortTopStacks(); int newSize = newchest.chestContents.length;
for (int i = 0; i< Math.min(newSize, chestContents.length); i++) ItemStack[] chestContents = ObfuscationReflectionHelper.getPrivateValue(TileEntityChest.class, tec, 0);
{ System.arraycopy(chestContents, 0, newchest.chestContents, 0, Math.min(newSize, chestContents.length));
chestContents[i]=null; BlockIronChest block = IronChest.ironChestBlock;
} block.dropContent(newSize, tec, world, tec.xCoord, tec.yCoord, tec.zCoord);
// Clear the old block out newchest.setFacing((byte) tec.getBlockMetadata());
world.setBlock(X, Y, Z, 0); newchest.sortTopStacks();
// Force the Chest TE to reset it's knowledge of neighbouring blocks for (int i = 0; i < Math.min(newSize, chestContents.length); i++)
tec.updateContainingBlockInfo(); {
// Force the Chest TE to update any neighbours so they update next tick chestContents[i] = null;
tec.checkForAdjacentChests(); }
// And put in our block instead // Clear the old block out
world.setBlock(X, Y, Z, block.blockID); world.setBlock(X, Y, Z, 0);
} else { // Force the Chest TE to reset it's knowledge of neighbouring blocks
return false; tec.updateContainingBlockInfo();
} // Force the Chest TE to update any neighbours so they update next
world.setBlockTileEntity(X, Y, Z, newchest); // tick
world.setBlockMetadataWithNotify(X, Y, Z, newchest.getType().ordinal()); tec.checkForAdjacentChests();
world.notifyBlocksOfNeighborChange(X, Y, Z, world.getBlockId(X, Y, Z)); // And put in our block instead
world.markBlockForUpdate(X, Y, Z); world.setBlock(X, Y, Z, block.blockID);
stack.stackSize=0; }
return true; else
} {
return false;
}
world.setBlockTileEntity(X, Y, Z, newchest);
world.setBlockMetadataWithNotify(X, Y, Z, newchest.getType().ordinal());
world.notifyBlocksOfNeighborChange(X, Y, Z, world.getBlockId(X, Y, Z));
world.markBlockForUpdate(X, Y, Z);
stack.stackSize = 0;
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 }
public String getItemNameIS(ItemStack itemstack) {
return IronChestType.values()[itemstack.getItemDamage()].name(); @Override
} public String getItemNameIS(ItemStack itemstack)
{
return IronChestType.values()[itemstack.getItemDamage()].name();
}
} }

View File

@ -3,24 +3,31 @@ package cpw.mods.ironchest;
import net.minecraft.item.ItemStack; 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
public boolean equals(Object obj) {
if (!(obj instanceof MappableItemStackWrapper)) return false;
MappableItemStackWrapper isw = (MappableItemStackWrapper) obj;
if (wrap.getHasSubtypes()) {
return isw.wrap.isItemEqual(wrap);
} else {
return isw.wrap.itemID == wrap.itemID;
} }
}
@Override @Override
public int hashCode() { public boolean equals(Object obj)
return wrap.itemID; {
} if (!(obj instanceof MappableItemStackWrapper)) return false;
MappableItemStackWrapper isw = (MappableItemStackWrapper) obj;
if (wrap.getHasSubtypes())
{
return isw.wrap.isItemEqual(wrap);
}
else
{
return isw.wrap.itemID == wrap.itemID;
}
}
@Override
public int hashCode()
{
return wrap.itemID;
}
} }

View File

@ -9,22 +9,23 @@ import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingEvent; 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; {
@SuppressWarnings("unchecked") EntityOcelot ocelot = (EntityOcelot) evt.entityLiving;
List<EntityAITaskEntry> tasks = ocelot.tasks.taskEntries; @SuppressWarnings("unchecked")
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))
{ {
task.action = new IronChestAIOcelotSit(ocelot, 0.4F); task.action = new IronChestAIOcelotSit(ocelot, 0.4F);
} }
} }
} }
} }
} }

View File

@ -27,57 +27,67 @@ import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player; 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); {
int x = dat.readInt(); ByteArrayDataInput dat = ByteStreams.newDataInput(packet.data);
int y = dat.readInt(); int x = dat.readInt();
int z = dat.readInt(); int y = dat.readInt();
byte typ = dat.readByte(); int z = dat.readInt();
boolean hasStacks = dat.readByte() != 0; byte typ = dat.readByte();
int[] items = new int[0]; boolean hasStacks = dat.readByte() != 0;
if (hasStacks) { int[] items = new int[0];
items = new int[24]; if (hasStacks)
for (int i = 0; i < items.length; i++) { {
items[i] = dat.readInt(); items = new int[24];
} for (int i = 0; i < items.length; i++)
} {
World world = IronChest.proxy.getClientWorld(); items[i] = dat.readInt();
TileEntity te = world.getBlockTileEntity(x, y, z); }
if (te instanceof TileEntityIronChest) { }
TileEntityIronChest icte = (TileEntityIronChest) te; World world = IronChest.proxy.getClientWorld();
icte.handlePacketData(typ, items); TileEntity te = world.getBlockTileEntity(x, y, z);
} if (te instanceof TileEntityIronChest)
} {
TileEntityIronChest icte = (TileEntityIronChest) te;
icte.handlePacketData(typ, items);
}
}
public static Packet getPacket(TileEntityIronChest tileEntityIronChest) { public static Packet getPacket(TileEntityIronChest tileEntityIronChest)
ByteArrayOutputStream bos = new ByteArrayOutputStream(140); {
DataOutputStream dos = new DataOutputStream(bos); ByteArrayOutputStream bos = new ByteArrayOutputStream(140);
int x = tileEntityIronChest.xCoord; DataOutputStream dos = new DataOutputStream(bos);
int y = tileEntityIronChest.yCoord; int x = tileEntityIronChest.xCoord;
int z = tileEntityIronChest.zCoord; int y = tileEntityIronChest.yCoord;
int typ = tileEntityIronChest.getType().ordinal(); int z = tileEntityIronChest.zCoord;
int[] items = tileEntityIronChest.buildIntDataList(); int typ = tileEntityIronChest.getType().ordinal();
boolean hasStacks = (items != null); int[] items = tileEntityIronChest.buildIntDataList();
try { boolean hasStacks = (items != null);
dos.writeInt(x); try
dos.writeInt(y); {
dos.writeInt(z); dos.writeInt(x);
dos.writeByte(typ); dos.writeInt(y);
dos.writeByte(hasStacks ? 1 : 0); dos.writeInt(z);
if (hasStacks) { dos.writeByte(typ);
for (int i = 0; i < 24; i++) { dos.writeByte(hasStacks ? 1 : 0);
dos.writeInt(items[i]); if (hasStacks)
} {
} for (int i = 0; i < 24; i++)
} catch (IOException e) { {
// UNPOSSIBLE? dos.writeInt(items[i]);
} }
Packet250CustomPayload pkt = new Packet250CustomPayload(); }
pkt.channel = "IronChest"; }
pkt.data = bos.toByteArray(); catch (IOException e)
pkt.length = bos.size(); {
pkt.isChunkDataPacket = true; // UNPOSSIBLE?
return pkt; }
} Packet250CustomPayload pkt = new Packet250CustomPayload();
pkt.channel = "IronChest";
pkt.data = bos.toByteArray();
pkt.length = bos.size();
pkt.isChunkDataPacket = true;
return pkt;
}
} }

View File

@ -11,8 +11,9 @@
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

@ -22,378 +22,452 @@ import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
public class TileEntityIronChest extends TileEntity implements IInventory { public class TileEntityIronChest extends TileEntity implements IInventory {
private int ticksSinceSync; private int ticksSinceSync;
public float prevLidAngle; public float prevLidAngle;
public float lidAngle; public float lidAngle;
private int numUsingPlayers; private int numUsingPlayers;
private IronChestType type; private IronChestType type;
public ItemStack[] chestContents; public ItemStack[] chestContents;
private ItemStack[] topStacks; private ItemStack[] topStacks;
private byte facing; private byte facing;
private boolean inventoryTouched; private boolean inventoryTouched;
private boolean hadStuff; private boolean hadStuff;
public TileEntityIronChest() { public TileEntityIronChest()
this(IronChestType.IRON);
}
protected TileEntityIronChest(IronChestType type) {
super();
this.type = type;
this.chestContents = new ItemStack[getSizeInventory()];
this.topStacks = new ItemStack[8];
}
public ItemStack[] getContents() {
return chestContents;
}
@Override
public int getSizeInventory() {
return type.size;
}
public byte getFacing() {
return this.facing;
}
@Override
public String getInvName() {
return type.name();
}
public IronChestType getType() {
return type;
}
@Override
public ItemStack getStackInSlot(int i) {
inventoryTouched = true;
return chestContents[i];
}
@Override
public void onInventoryChanged() {
super.onInventoryChanged();
sortTopStacks();
}
protected void sortTopStacks() {
if (!type.isTransparent() || (worldObj != null && worldObj.isRemote)) {
return;
}
ItemStack[] tempCopy = new ItemStack[getSizeInventory()];
boolean hasStuff = false;
int compressedIdx = 0;
mainLoop: for (int i = 0; i < getSizeInventory(); i++) {
if (chestContents[i] != null) {
for (int j = 0; j < compressedIdx; j++) {
if (tempCopy[j].isItemEqual(chestContents[i])) {
tempCopy[j].stackSize += chestContents[i].stackSize;
continue mainLoop;
}
}
tempCopy[compressedIdx++] = chestContents[i].copy();
hasStuff = true;
}
}
if (!hasStuff && hadStuff) {
hadStuff = false;
for (int i = 0; i < topStacks.length; i++) {
topStacks[i] = null;
}
if (worldObj!=null) {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
return;
}
hadStuff = true;
Arrays.sort(tempCopy, new Comparator<ItemStack>() {
@Override
public int compare(ItemStack o1, ItemStack o2) {
if (o1 == null) {
return 1;
} else if (o2 == null) {
return -1;
} else {
return o2.stackSize - o1.stackSize;
}
}
});
int p = 0;
for (int i = 0; i < tempCopy.length; i++) {
if (tempCopy[i] != null && tempCopy[i].stackSize > 0) {
topStacks[p++] = tempCopy[i];
if (p == topStacks.length) {
break;
}
}
}
for (int i = p; i < topStacks.length; i++) {
topStacks[i] = null;
}
if (worldObj!=null) {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
@Override
public ItemStack decrStackSize(int i, int j) {
if (chestContents[i] != null)
{ {
if (chestContents[i].stackSize <= j) this(IronChestType.IRON);
{
ItemStack itemstack = chestContents[i];
chestContents[i] = null;
onInventoryChanged();
return itemstack;
}
ItemStack itemstack1 = chestContents[i].splitStack(j);
if (chestContents[i].stackSize == 0)
{
chestContents[i] = null;
}
onInventoryChanged();
return itemstack1;
} }
else
protected TileEntityIronChest(IronChestType type)
{ {
return null; super();
this.type = type;
this.chestContents = new ItemStack[getSizeInventory()];
this.topStacks = new ItemStack[8];
} }
}
@Override public ItemStack[] getContents()
public void setInventorySlotContents(int i, ItemStack itemstack) {
chestContents[i] = itemstack;
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
{ {
itemstack.stackSize = getInventoryStackLimit(); return chestContents;
} }
onInventoryChanged();
}
@Override @Override
public void readFromNBT(NBTTagCompound nbttagcompound) public int getSizeInventory()
{
super.readFromNBT(nbttagcompound);
NBTTagList nbttaglist = nbttagcompound.getTagList("Items");
chestContents = new ItemStack[getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); i++)
{ {
NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i); return type.size;
int j = nbttagcompound1.getByte("Slot") & 0xff;
if (j >= 0 && j < chestContents.length)
{
chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
}
} }
facing = nbttagcompound.getByte("facing");
sortTopStacks();
}
@Override public byte getFacing()
public void writeToNBT(NBTTagCompound nbttagcompound)
{
super.writeToNBT(nbttagcompound);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < chestContents.length; i++)
{ {
if (chestContents[i] != null) return this.facing;
{
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte) i);
chestContents[i].writeToNBT(nbttagcompound1);
nbttaglist.appendTag(nbttagcompound1);
}
} }
nbttagcompound.setTag("Items", nbttaglist); @Override
nbttagcompound.setByte("facing", facing); public String getInvName()
} {
return type.name();
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
if (worldObj == null) {
return true;
} }
if (worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this) {
return false;
}
return entityplayer.getDistanceSq((double) xCoord + 0.5D, (double) yCoord + 0.5D, (double) zCoord + 0.5D) <= 64D;
}
@Override public IronChestType getType()
public void updateEntity() { {
super.updateEntity(); return type;
// Resynchronize clients with the server state }
if ((++ticksSinceSync % 20) * 4 == 0) {
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock.blockID, 3, ((numUsingPlayers << 3) & 0xF8) | (facing & 0x7)); @Override
if (inventoryTouched) { public ItemStack getStackInSlot(int i)
inventoryTouched = false; {
inventoryTouched = true;
return chestContents[i];
}
@Override
public void onInventoryChanged()
{
super.onInventoryChanged();
sortTopStacks(); sortTopStacks();
}
} }
prevLidAngle = lidAngle;
float f = 0.1F;
if (numUsingPlayers > 0 && lidAngle == 0.0F) {
double d = (double) xCoord + 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);
}
if (numUsingPlayers == 0 && lidAngle > 0.0F || numUsingPlayers > 0 && lidAngle < 1.0F) {
float f1 = lidAngle;
if (numUsingPlayers > 0) {
lidAngle += f;
} else {
lidAngle -= f;
}
if (lidAngle > 1.0F) {
lidAngle = 1.0F;
}
float f2 = 0.5F;
if (lidAngle < f2 && f1 >= f2) {
double d2 = (double) xCoord + 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);
}
if (lidAngle < 0.0F) {
lidAngle = 0.0F;
}
}
}
protected void sortTopStacks()
@Override
public void receiveClientEvent(int i, int j)
{
if (i == 1)
{ {
numUsingPlayers = j; if (!type.isTransparent() || (worldObj != null && worldObj.isRemote))
} else if (i == 2) { {
facing = (byte) j; return;
} else if (i == 3) {
facing = (byte) (j & 0x7);
numUsingPlayers = (j & 0xF8) >> 3;
}
}
@Override
public void openChest() {
if (worldObj == null)
return;
numUsingPlayers++;
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock.blockID, 1, numUsingPlayers);
}
@Override
public void closeChest() {
if (worldObj == null)
return;
numUsingPlayers--;
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock.blockID, 1, numUsingPlayers);
}
public void setFacing(byte chestFacing) {
this.facing = chestFacing;
}
public TileEntityIronChest applyUpgradeItem(ItemChestChanger itemChestChanger) {
if (numUsingPlayers > 0) {
return null;
}
if (!itemChestChanger.getType().canUpgrade(this.getType())) {
return null;
}
TileEntityIronChest newEntity = IronChestType.makeEntity(itemChestChanger.getTargetChestOrdinal(getType().ordinal()));
int newSize = newEntity.chestContents.length;
System.arraycopy(chestContents, 0, newEntity.chestContents, 0, Math.min(newSize, chestContents.length));
BlockIronChest block = IronChest.ironChestBlock;
block.dropContent(newSize, this, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
newEntity.setFacing(facing);
newEntity.sortTopStacks();
return newEntity;
}
public ItemStack[] getTopItemStacks() {
return topStacks;
}
public TileEntityIronChest updateFromMetadata(int l) {
if (worldObj != null && worldObj.isRemote) {
if (l != type.ordinal()) {
worldObj.setBlockTileEntity(xCoord, yCoord, zCoord, IronChestType.makeEntity(l));
return (TileEntityIronChest) worldObj.getBlockTileEntity(xCoord, yCoord, zCoord);
}
}
return this;
}
@Override
public Packet getDescriptionPacket() {
return PacketHandler.getPacket(this);
}
public void handlePacketData(int typeData, int[] intData) {
TileEntityIronChest chest = this;
if (this.type.ordinal() != typeData) {
chest = updateFromMetadata(typeData);
}
if (IronChestType.values()[typeData].isTransparent() && intData != null) {
int pos = 0;
if (intData.length < chest.topStacks.length * 3) {
return;
}
for (int i = 0; i < chest.topStacks.length; i++) {
if (intData[pos + 2] != 0) {
ItemStack is = new ItemStack(intData[pos], intData[pos + 2], intData[pos + 1]);
chest.topStacks[i] = is;
} else {
chest.topStacks[i] = null;
} }
pos += 3; ItemStack[] tempCopy = new ItemStack[getSizeInventory()];
} boolean hasStuff = false;
} int compressedIdx = 0;
} mainLoop: for (int i = 0; i < getSizeInventory(); i++)
{
public int[] buildIntDataList() { if (chestContents[i] != null)
if (type.isTransparent()) { {
int[] sortList = new int[topStacks.length * 3]; for (int j = 0; j < compressedIdx; j++)
int pos = 0; {
for (ItemStack is : topStacks) { if (tempCopy[j].isItemEqual(chestContents[i]))
if (is != null) { {
sortList[pos++] = is.itemID; tempCopy[j].stackSize += chestContents[i].stackSize;
sortList[pos++] = is.getItemDamage(); continue mainLoop;
sortList[pos++] = is.stackSize; }
} else { }
sortList[pos++] = 0; tempCopy[compressedIdx++] = chestContents[i].copy();
sortList[pos++] = 0; hasStuff = true;
sortList[pos++] = 0; }
}
if (!hasStuff && hadStuff)
{
hadStuff = false;
for (int i = 0; i < topStacks.length; i++)
{
topStacks[i] = null;
}
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
return;
}
hadStuff = true;
Arrays.sort(tempCopy, new Comparator<ItemStack>() {
@Override
public int compare(ItemStack o1, ItemStack o2)
{
if (o1 == null)
{
return 1;
}
else if (o2 == null)
{
return -1;
}
else
{
return o2.stackSize - o1.stackSize;
}
}
});
int p = 0;
for (int i = 0; i < tempCopy.length; i++)
{
if (tempCopy[i] != null && tempCopy[i].stackSize > 0)
{
topStacks[p++] = tempCopy[i];
if (p == topStacks.length)
{
break;
}
}
}
for (int i = p; i < topStacks.length; i++)
{
topStacks[i] = null;
}
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
} }
}
return sortList;
} }
return null;
}
public ItemStack getStackInSlotOnClosing(int par1) @Override
{ public ItemStack decrStackSize(int i, int j)
if (this.chestContents[par1] != null)
{ {
ItemStack var2 = this.chestContents[par1]; if (chestContents[i] != null)
this.chestContents[par1] = null; {
return var2; if (chestContents[i].stackSize <= j)
{
ItemStack itemstack = chestContents[i];
chestContents[i] = null;
onInventoryChanged();
return itemstack;
}
ItemStack itemstack1 = chestContents[i].splitStack(j);
if (chestContents[i].stackSize == 0)
{
chestContents[i] = null;
}
onInventoryChanged();
return itemstack1;
}
else
{
return null;
}
} }
else
{
return null;
}
}
public void setMaxStackSize(int size) {
} @Override
public void setInventorySlotContents(int i, ItemStack itemstack)
{
chestContents[i] = itemstack;
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
{
itemstack.stackSize = getInventoryStackLimit();
}
onInventoryChanged();
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound)
{
super.readFromNBT(nbttagcompound);
NBTTagList nbttaglist = nbttagcompound.getTagList("Items");
chestContents = new ItemStack[getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); i++)
{
NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i);
int j = nbttagcompound1.getByte("Slot") & 0xff;
if (j >= 0 && j < chestContents.length)
{
chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
}
}
facing = nbttagcompound.getByte("facing");
sortTopStacks();
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound)
{
super.writeToNBT(nbttagcompound);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < chestContents.length; i++)
{
if (chestContents[i] != null)
{
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte) i);
chestContents[i].writeToNBT(nbttagcompound1);
nbttaglist.appendTag(nbttagcompound1);
}
}
nbttagcompound.setTag("Items", nbttaglist);
nbttagcompound.setByte("facing", facing);
}
@Override
public int getInventoryStackLimit()
{
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer)
{
if (worldObj == null)
{
return true;
}
if (worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this)
{
return false;
}
return entityplayer.getDistanceSq((double) xCoord + 0.5D, (double) yCoord + 0.5D, (double) zCoord + 0.5D) <= 64D;
}
@Override
public void updateEntity()
{
super.updateEntity();
// Resynchronize clients with the server state
if ((++ticksSinceSync % 20) * 4 == 0)
{
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock.blockID, 3, ((numUsingPlayers << 3) & 0xF8) | (facing & 0x7));
if (inventoryTouched)
{
inventoryTouched = false;
sortTopStacks();
}
}
prevLidAngle = lidAngle;
float f = 0.1F;
if (numUsingPlayers > 0 && lidAngle == 0.0F)
{
double d = (double) xCoord + 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);
}
if (numUsingPlayers == 0 && lidAngle > 0.0F || numUsingPlayers > 0 && lidAngle < 1.0F)
{
float f1 = lidAngle;
if (numUsingPlayers > 0)
{
lidAngle += f;
}
else
{
lidAngle -= f;
}
if (lidAngle > 1.0F)
{
lidAngle = 1.0F;
}
float f2 = 0.5F;
if (lidAngle < f2 && f1 >= f2)
{
double d2 = (double) xCoord + 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);
}
if (lidAngle < 0.0F)
{
lidAngle = 0.0F;
}
}
}
@Override
public void receiveClientEvent(int i, int j)
{
if (i == 1)
{
numUsingPlayers = j;
}
else if (i == 2)
{
facing = (byte) j;
}
else if (i == 3)
{
facing = (byte) (j & 0x7);
numUsingPlayers = (j & 0xF8) >> 3;
}
}
@Override
public void openChest()
{
if (worldObj == null) return;
numUsingPlayers++;
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock.blockID, 1, numUsingPlayers);
}
@Override
public void closeChest()
{
if (worldObj == null) return;
numUsingPlayers--;
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock.blockID, 1, numUsingPlayers);
}
public void setFacing(byte chestFacing)
{
this.facing = chestFacing;
}
public TileEntityIronChest applyUpgradeItem(ItemChestChanger itemChestChanger)
{
if (numUsingPlayers > 0)
{
return null;
}
if (!itemChestChanger.getType().canUpgrade(this.getType()))
{
return null;
}
TileEntityIronChest newEntity = IronChestType.makeEntity(itemChestChanger.getTargetChestOrdinal(getType().ordinal()));
int newSize = newEntity.chestContents.length;
System.arraycopy(chestContents, 0, newEntity.chestContents, 0, Math.min(newSize, chestContents.length));
BlockIronChest block = IronChest.ironChestBlock;
block.dropContent(newSize, this, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
newEntity.setFacing(facing);
newEntity.sortTopStacks();
return newEntity;
}
public ItemStack[] getTopItemStacks()
{
return topStacks;
}
public TileEntityIronChest updateFromMetadata(int l)
{
if (worldObj != null && worldObj.isRemote)
{
if (l != type.ordinal())
{
worldObj.setBlockTileEntity(xCoord, yCoord, zCoord, IronChestType.makeEntity(l));
return (TileEntityIronChest) worldObj.getBlockTileEntity(xCoord, yCoord, zCoord);
}
}
return this;
}
@Override
public Packet getDescriptionPacket()
{
return PacketHandler.getPacket(this);
}
public void handlePacketData(int typeData, int[] intData)
{
TileEntityIronChest chest = this;
if (this.type.ordinal() != typeData)
{
chest = updateFromMetadata(typeData);
}
if (IronChestType.values()[typeData].isTransparent() && intData != null)
{
int pos = 0;
if (intData.length < chest.topStacks.length * 3)
{
return;
}
for (int i = 0; i < chest.topStacks.length; i++)
{
if (intData[pos + 2] != 0)
{
ItemStack is = new ItemStack(intData[pos], intData[pos + 2], intData[pos + 1]);
chest.topStacks[i] = is;
}
else
{
chest.topStacks[i] = null;
}
pos += 3;
}
}
}
public int[] buildIntDataList()
{
if (type.isTransparent())
{
int[] sortList = new int[topStacks.length * 3];
int pos = 0;
for (ItemStack is : topStacks)
{
if (is != null)
{
sortList[pos++] = is.itemID;
sortList[pos++] = is.getItemDamage();
sortList[pos++] = is.stackSize;
}
else
{
sortList[pos++] = 0;
sortList[pos++] = 0;
sortList[pos++] = 0;
}
}
return sortList;
}
return null;
}
public ItemStack getStackInSlotOnClosing(int par1)
{
if (this.chestContents[par1] != null)
{
ItemStack var2 = this.chestContents[par1];
this.chestContents[par1] = null;
return var2;
}
else
{
return null;
}
}
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

@ -9,23 +9,26 @@ package cpw.mods.ironchest;
import java.util.Properties; import java.util.Properties;
public class Version { public class Version {
private static String major; private static String major;
private static String minor; private static String minor;
private static String rev; private static String rev;
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) { {
major = properties.getProperty("IronChest.build.major.number"); if (properties != null)
minor = properties.getProperty("IronChest.build.minor.number"); {
rev = properties.getProperty("IronChest.build.revision.number"); major = properties.getProperty("IronChest.build.major.number");
build = properties.getProperty("IronChest.build.number"); minor = properties.getProperty("IronChest.build.minor.number");
mcversion = properties.getProperty("IronChest.build.mcversion"); rev = properties.getProperty("IronChest.build.revision.number");
build = properties.getProperty("IronChest.build.number");
mcversion = properties.getProperty("IronChest.build.mcversion");
}
} }
}
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

@ -23,20 +23,26 @@ import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.TileEntityIronChest; 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 }
public void renderChest(Block block, int i, float f) {
if (block==IronChest.ironChestBlock) { @Override
TileEntityRenderer.instance.renderTileEntityAt(itemRenders.get(i), 0.0D, 0.0D, 0.0D, 0.0F); public void renderChest(Block block, int i, float f)
} else { {
super.renderChest(block, i, f); if (block == IronChest.ironChestBlock)
} {
} TileEntityRenderer.instance.renderTileEntityAt(itemRenders.get(i), 0.0D, 0.0D, 0.0D, 0.0F);
}
else
{
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;
}