The Great Wall of Pink (purely aesthetic changes, no logic altered)

This commit is contained in:
Taylor Shuler 2014-05-11 16:00:59 -04:00
parent 895cf66788
commit 138274e1e9
25 changed files with 1443 additions and 1832 deletions

View File

@ -36,19 +36,13 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockIronChest extends BlockContainer {
private Random random = new Random();
private Random random;
@SideOnly(Side.CLIENT)
private IIcon[][] icons;
public BlockIronChest()
{
public BlockIronChest() {
super(Material.iron);
setBlockName("IronChest");
setHardness(3.0F);
setBlockBounds(0.0625F, 0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
random = new Random();
setCreativeTab(CreativeTabs.tabDecorations);
}
@ -56,41 +50,34 @@ public class BlockIronChest extends BlockContainer {
* Overridden by {@link #createTileEntity(World, int)}
*/
@Override
public TileEntity createNewTileEntity(World w, int i)
{
public TileEntity createNewTileEntity(World w, int i) {
return null;
}
@Override
public boolean isOpaqueCube()
{
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean renderAsNormalBlock()
{
public boolean renderAsNormalBlock() {
return false;
}
@Override
public int getRenderType()
{
public int getRenderType() {
return 22;
}
@Override
public TileEntity createTileEntity(World world, int metadata)
{
public TileEntity createTileEntity(World world, int metadata) {
return IronChestType.makeEntity(metadata);
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int i, int j)
{
if (j < IronChestType.values().length)
{
public IIcon getIcon(int i, int j) {
if (j < IronChestType.values().length) {
IronChestType type = IronChestType.values()[j];
return type.getIcon(i);
}
@ -98,116 +85,88 @@ public class BlockIronChest extends BlockContainer {
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
{
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
ArrayList<ItemStack> items = Lists.newArrayList();
ItemStack stack = new ItemStack(this,1,metadata);
ItemStack stack = new ItemStack(this, 1, metadata);
IronChestType.values()[IronChestType.validateMeta(metadata)].adornItemDrop(stack);
items.add(stack);
return items;
}
@Override
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int i1, float f1, float f2, float f3)
{
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int i1, float f1, float f2, float f3) {
if (world.isRemote)
return true;
else
{
else {
IInventory iinventory = chestInventory(world, i, j, k);
if (iinventory != null && world.getTileEntity(i, j, k) instanceof TileEntityIronChest)
if (iinventory != null)
player.openGui(IronChest.instance, ((TileEntityIronChest) world.getTileEntity(i, j, k)).getType().ordinal(), world, i, j, k);
return true;
}
}
public IInventory chestInventory(World world, int i, int j, int k)
{
TileEntity object = (TileEntityIronChest)world.getTileEntity(i, j, k);
public IInventory chestInventory(World world, int i, int j, int k) {
TileEntity object = (TileEntityIronChest) world.getTileEntity(i, j, k);
if (object == null)
{
if (object == null) {
return null;
}
else if (world.isSideSolid(i, j + 1, k, DOWN))
{
} else if (world.isSideSolid(i, j + 1, k, DOWN)) {
return null;
}
else if (isOcelotOnChest(world, i, j, k))
{
} else if (isOcelotOnChest(world, i, j, k)) {
return null;
}
else if (world.getBlock(i - 1, j, k) == this && (world.isSideSolid(i - 1, j + 1, k, DOWN) || isOcelotOnChest(world, i - 1, j, k)))
{
} else if (world.getBlock(i - 1, j, k) == this && (world.isSideSolid(i - 1, j + 1, k, DOWN) || isOcelotOnChest(world, i - 1, j, k))) {
return null;
}
else if (world.getBlock(i + 1, j, k) == this && (world.isSideSolid(i + 1, j + 1, k, DOWN) || isOcelotOnChest(world, i + 1, j, k)))
{
} else if (world.getBlock(i + 1, j, k) == this && (world.isSideSolid(i + 1, j + 1, k, DOWN) || isOcelotOnChest(world, i + 1, j, k))) {
return null;
}
else if (world.getBlock(i, j, k - 1) == this && (world.isSideSolid(i, j + 1, k - 1, DOWN) || isOcelotOnChest(world, i, j, k - 1)))
{
} else if (world.getBlock(i, j, k - 1) == this && (world.isSideSolid(i, j + 1, k - 1, DOWN) || isOcelotOnChest(world, i, j, k - 1))) {
return null;
}
else if (world.getBlock(i, j, k + 1) == this && (world.isSideSolid(i, j + 1, k + 1, DOWN) || isOcelotOnChest(world, i, j, k + 1)))
{
} else if (world.getBlock(i, j, k + 1) == this && (world.isSideSolid(i, j + 1, k + 1, DOWN) || isOcelotOnChest(world, i, j, k + 1))) {
return null;
}
else
return (IInventory)object;
} else
return (IInventory) object;
}
private static boolean isOcelotOnChest(World world, int i, int j, int k)
{
Iterator iterator = world.getEntitiesWithinAABB(EntityOcelot.class, AxisAlignedBB.getAABBPool().getAABB((double)i, (double)(j + 1), (double)k, (double)(i + 1), (double)(j + 2), (double)(k + 1))).iterator();
private static boolean isOcelotOnChest(World world, int i, int j, int k) {
Iterator iterator = world.getEntitiesWithinAABB(EntityOcelot.class, AxisAlignedBB.getAABBPool().getAABB((double) i, (double) (j + 1), (double) k, (double) (i + 1), (double) (j + 2), (double) (k + 1))).iterator();
EntityOcelot entityocelot1;
do
{
do {
if (!iterator.hasNext())
return false;
EntityOcelot entityocelot = (EntityOcelot)iterator.next();
entityocelot1 = (EntityOcelot)entityocelot;
}
while (!entityocelot1.isSitting());
EntityOcelot entityocelot = (EntityOcelot) iterator.next();
entityocelot1 = (EntityOcelot) entityocelot;
} while (!entityocelot1.isSitting());
return true;
}
@Override
public void onBlockAdded(World world, int i, int j, int k)
{
public void onBlockAdded(World world, int i, int j, int k) {
super.onBlockAdded(world, i, j, k);
world.markBlockForUpdate(i, j, k);
}
@Override
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack itemStack)
{
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack itemStack) {
byte chestFacing = 0;
int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
if (facing == 0)
{
if (facing == 0) {
chestFacing = 2;
}
if (facing == 1)
{
if (facing == 1) {
chestFacing = 5;
}
if (facing == 2)
{
if (facing == 2) {
chestFacing = 3;
}
if (facing == 3)
{
if (facing == 3) {
chestFacing = 4;
}
TileEntity te = world.getTileEntity(i, j, k);
if (te != null && te instanceof TileEntityIronChest)
{
if (te != null && te instanceof TileEntityIronChest) {
TileEntityIronChest teic = (TileEntityIronChest) te;
teic.wasPlaced(entityliving, itemStack);
teic.setFacing(chestFacing);
@ -216,51 +175,41 @@ public class BlockIronChest extends BlockContainer {
}
@Override
public int damageDropped(int i)
{
public int damageDropped(int i) {
return i;
}
@Override
public void breakBlock(World world, int i, int j, int k, Block i1, int i2)
{
TileEntityIronChest tileentitychest = (TileEntityIronChest) world.getTileEntity(i, j, k);
if (tileentitychest != null)
{
tileentitychest.removeAdornments();
dropContent(0, tileentitychest, world, tileentitychest.xCoord, tileentitychest.yCoord, tileentitychest.zCoord);
public void breakBlock(World world, int i, int j, int k, Block b, int l) {
TileEntityIronChest te = (TileEntityIronChest) world.getTileEntity(i, j, k);
if (te != null) {
te.removeAdornments();
dropContent(0, te, world, te.xCoord, te.yCoord, te.zCoord);
}
super.breakBlock(world, i, j, k, i1, i2);
super.breakBlock(world, i, j, k, b, l);
}
public void dropContent(int newSize, IInventory chest, World world, int xCoord, int yCoord, int zCoord)
{
for (int l = newSize; l < chest.getSizeInventory(); l++)
{
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)
{
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)
{
while (itemstack.stackSize > 0) {
int i1 = random.nextInt(21) + 10;
if (i1 > itemstack.stackSize)
{
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.getItem(), i1, itemstack.getItemDamage()));
EntityItem entityitem = new EntityItem(world, (float) xCoord + f, (float) yCoord + (newSize > 0 ? 1 : 0) + f1, (float) zCoord + f2, new ItemStack(itemstack.getItem(), 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())
{
if (itemstack.hasTagCompound()) {
entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
}
world.spawnEntityInWorld(entityitem);
@ -270,46 +219,35 @@ public class BlockIronChest extends BlockContainer {
@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (IronChestType type : IronChestType.values())
{
if (type.isValidForCreativeMode())
{
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List) {
for (IronChestType type : IronChestType.values()) {
if (type.isValidForCreativeMode()) {
par3List.add(new ItemStack(this, 1, type.ordinal()));
}
}
}
@Override
public float getExplosionResistance(Entity par1Entity, World world, int x, int y, int z, double explosionX, double explosionY, double explosionZ)
{
public float getExplosionResistance(Entity par1Entity, World world, int x, int y, int z, double explosionX, double explosionY, double explosionZ) {
TileEntity te = world.getTileEntity(x, y, z);
if (te instanceof TileEntityIronChest)
{
if (te instanceof TileEntityIronChest) {
TileEntityIronChest teic = (TileEntityIronChest) te;
if (teic.getType().isExplosionResistant())
{
return 10000f;
if (teic.getType().isExplosionResistant()) {
return 10000F;
}
}
return super.getExplosionResistance(par1Entity, world, x, y, z, explosionX, explosionY, explosionZ);
}
@Override
public int getComparatorInputOverride(World par1World, int par2, int par3, int par4, int par5)
{
return Container.calcRedstoneFromInventory((TileEntityIronChest) par1World.getTileEntity(par2, par3, par4));
public int getComparatorInputOverride(World world, int i, int j, int k, int l) {
return Container.calcRedstoneFromInventory((TileEntityIronChest) world.getTileEntity(i, j, k));
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister par1IconRegister)
{
for (IronChestType typ: IronChestType.values())
{
public void registerBlockIcons(IIconRegister par1IconRegister) {
for (IronChestType typ : IronChestType.values()) {
typ.makeIcons(par1IconRegister);
}
}
@ -317,20 +255,16 @@ public class BlockIronChest extends BlockContainer {
private static final ForgeDirection[] validRotationAxes = new ForgeDirection[] { UP, DOWN };
@Override
public ForgeDirection[] getValidRotations(World worldObj, int x, int y, int z)
{
public ForgeDirection[] getValidRotations(World world, int x, int y, int z) {
return validRotationAxes;
}
@Override
public boolean rotateBlock(World worldObj, int x, int y, int z, ForgeDirection axis)
{
if (worldObj.isRemote)
{
public boolean rotateBlock(World worldObj, int x, int y, int z, ForgeDirection axis) {
if (worldObj.isRemote) {
return false;
}
if (axis == UP || axis == DOWN)
{
if (axis == UP || axis == DOWN) {
TileEntity tileEntity = worldObj.getTileEntity(x, y, z);
if (tileEntity instanceof TileEntityIronChest) {
TileEntityIronChest icte = (TileEntityIronChest) tileEntity;

View File

@ -10,7 +10,6 @@ import static cpw.mods.ironchest.IronChestType.SILVER;
import static cpw.mods.ironchest.IronChestType.WOOD;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.config.Configuration;
import cpw.mods.fml.common.registry.GameRegistry;
public enum ChestChangerType {
@ -24,15 +23,11 @@ public enum ChestChangerType {
WOODCOPPER(WOOD, COPPER, "woodCopperUpgrade", "Normal chest to Copper Chest Upgrade", "mmm", "msm", "mmm"),
DIAMONDOBSIDIAN(DIAMOND, OBSIDIAN, "diamondObsidianUpgrade", "Diamond to Obsidian Chest Upgrade", "mmm", "mGm", "mmm");
private IronChestType source;
private IronChestType target;
public String itemName;
public String descriptiveName;
private IronChestType source, target;
public String itemName, descriptiveName, recipe[];
private ItemChestChanger item;
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.itemName = itemName;
@ -40,29 +35,23 @@ public enum ChestChangerType {
this.recipe = recipe;
}
public boolean canUpgrade(IronChestType from)
{
public boolean canUpgrade(IronChestType from) {
return from == this.source;
}
public int getTarget()
{
public int getTarget() {
return this.target.ordinal();
}
public ItemChestChanger buildItem()
{
public ItemChestChanger buildItem() {
item = new ItemChestChanger(this);
GameRegistry.registerItem(item, itemName);
return item;
}
public void addRecipes()
{
for (String sourceMat : source.getMatList())
{
for (String targetMat : target.getMatList())
{
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', Blocks.glass, 'O', Blocks.obsidian);
@ -70,18 +59,14 @@ public enum ChestChangerType {
}
}
public static void buildItems()
{
for (ChestChangerType type : values())
{
public static void buildItems() {
for (ChestChangerType type : values()) {
type.buildItem();
}
}
public static void generateRecipes()
{
for (ChestChangerType item : values())
{
public static void generateRecipes() {
for (ChestChangerType item : values()) {
item.addRecipes();
}
}

View File

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

View File

@ -1,12 +1,12 @@
package cpw.mods.ironchest;
import invtweaks.api.container.ChestContainer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import invtweaks.api.container.ChestContainer;
@ChestContainer(isLargeChest = true)
public class ContainerIronChest extends Container {
@ -14,8 +14,7 @@ public class ContainerIronChest extends Container {
private EntityPlayer player;
private IInventory chest;
public ContainerIronChest(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize)
{
public ContainerIronChest(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) {
chest = chestInventory;
player = ((InventoryPlayer) playerInventory).player;
this.type = type;
@ -24,41 +23,29 @@ public class ContainerIronChest extends Container {
}
@Override
public boolean canInteractWith(EntityPlayer player)
{
public boolean canInteractWith(EntityPlayer player) {
return chest.isUseableByPlayer(player);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer p, int i)
{
public ItemStack transferStackInSlot(EntityPlayer p, int i) {
ItemStack itemstack = null;
Slot slot = (Slot) inventorySlots.get(i);
if (slot != null && slot.getHasStack())
{
if (slot != null && slot.getHasStack()) {
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (i < type.size)
{
if (!mergeItemStack(itemstack1, type.size, inventorySlots.size(), true))
{
if (i < type.size) {
if (!mergeItemStack(itemstack1, type.size, inventorySlots.size(), true)) {
return null;
}
}
else if (!type.acceptsStack(itemstack1))
{
} else if (!type.acceptsStack(itemstack1)) {
return null;
} else if (!mergeItemStack(itemstack1, 0, type.size, false)) {
return null;
}
else if (!mergeItemStack(itemstack1, 0, type.size, false))
{
return null;
}
if (itemstack1.stackSize == 0)
{
if (itemstack1.stackSize == 0) {
slot.putStack(null);
}
else
{
} else {
slot.onSlotChanged();
}
}
@ -66,45 +53,29 @@ public class ContainerIronChest extends Container {
}
@Override
public void onContainerClosed(EntityPlayer entityplayer)
{
public void onContainerClosed(EntityPlayer entityplayer) {
super.onContainerClosed(entityplayer);
chest.closeInventory();
}
protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize)
{
protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) {
if (type == IronChestType.DIRTCHEST9000) {
addSlotToContainer(type.makeSlot(chestInventory, 0, 12 + 4 * 18, 8 + 2 * 18));
} else {
} else
for (int chestRow = 0; chestRow < type.getRowCount(); chestRow++)
{
for (int chestCol = 0; chestCol < type.getRowLength(); chestCol++)
{
addSlotToContainer(type.makeSlot(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));
}
}
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));
}
}
public EntityPlayer getPlayer()
{
public EntityPlayer getPlayer() {
return player;
}

View File

@ -20,21 +20,21 @@ public class IronChest {
public static IronChest instance;
@EventHandler
public void load(FMLInitializationEvent e)
{
public void load(FMLInitializationEvent e) {
ChestChangerType.buildItems();
ironChestBlock = new BlockIronChest();
GameRegistry.registerBlock(ironChestBlock, ItemIronChest.class, "BlockIronChest");
PacketHandler.INSTANCE.ordinal();
for (IronChestType typ : IronChestType.values())
{
GameRegistry.registerTileEntityWithAlternatives(typ.clazz, "IronChest."+typ.name(), typ.name());
for (IronChestType typ : IronChestType.values()) {
GameRegistry.registerTileEntityWithAlternatives(typ.clazz, "IronChest." + typ.name(), typ.name());
proxy.registerTileEntitySpecialRenderer(typ);
}
IronChestType.registerBlocksAndRecipes(ironChestBlock);
ChestChangerType.generateRecipes();
PacketHandler.INSTANCE.ordinal();
NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);
proxy.registerRenderInformation();
MinecraftForge.EVENT_BUS.register(this);

View File

@ -3,6 +3,7 @@ package cpw.mods.ironchest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
@ -25,27 +26,21 @@ public enum IronChestType {
SILVER(72, 9, false, "Silver Chest", "silverchest.png", 4, Arrays.asList("ingotSilver"), TileEntitySilverChest.class, "mmmm3mmmm", "mGmG0GmGm"),
CRYSTAL(108, 12, true, "Crystal Chest", "crystalchest.png", 5, Arrays.asList("blockGlass"), TileEntityCrystalChest.class, "GGGGPGGGG"),
OBSIDIAN(108, 12, false, "Obsidian Chest", "obsidianchest.png", 6, Arrays.asList("obsidian"), TileEntityObsidianChest.class, "mmmm2mmmm"),
DIRTCHEST9000(1, 1, false, "Dirt Chest 9000", "dirtchest.png",7,Arrays.asList("dirt"), TileEntityDirtChest.class,Item.getItemFromBlock(Blocks.dirt),"mmmmCmmmm"),
DIRTCHEST9000(1, 1, false, "Dirt Chest 9000", "dirtchest.png", 7, Arrays.asList("dirt"), TileEntityDirtChest.class, Item.getItemFromBlock(Blocks.dirt), "mmmmCmmmm"),
WOOD(0, 0, false, "", "", -1, Arrays.asList("plankWood"), null);
int size;
private int rowLength;
public String friendlyName;
public int size, rowLength, textureRow;
public String friendlyName, modelTexture, recipes[];
private boolean tieredChest;
private String modelTexture;
private int textureRow;
public Class<? extends TileEntityIronChest> clazz;
private String[] recipes;
private ArrayList<String> matList;
private Item itemFilter;
IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List<String> mats,
Class<? extends TileEntityIronChest> clazz, String... recipes)
{
this(size, rowLength, tieredChest, friendlyName, modelTexture, textureRow, mats, clazz, (Item)null, recipes);
IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List<String> mats, Class<? extends TileEntityIronChest> clazz, String... recipes) {
this(size, rowLength, tieredChest, friendlyName, modelTexture, textureRow, mats, clazz, (Item) null, recipes);
}
IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List<String> mats,
Class<? extends TileEntityIronChest> clazz, Item itemFilter, String... recipes)
{
IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List<String> mats, Class<? extends TileEntityIronChest> clazz, Item itemFilter, String... recipes) {
this.size = size;
this.rowLength = rowLength;
this.tieredChest = tieredChest;
@ -59,69 +54,47 @@ public enum IronChestType {
matList.addAll(mats);
}
public String getModelTexture()
{
public String getModelTexture() {
return modelTexture;
}
public int getTextureRow()
{
public int getTextureRow() {
return textureRow;
}
public static TileEntityIronChest makeEntity(int metadata)
{
// Compatibility
public static TileEntityIronChest makeEntity(int metadata) {
int chesttype = validateMeta(metadata);
if (chesttype == metadata)
{
try
{
TileEntityIronChest te = values()[chesttype].clazz.newInstance();
return te;
}
catch (InstantiationException e)
{
// unpossible
if (chesttype == metadata) {
try {
return values()[chesttype].clazz.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
}
catch (IllegalAccessException e)
{
// unpossible
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
return null;
}
public static void registerTranslations()
{
}
public static void registerBlocksAndRecipes(BlockIronChest blockResult)
{
public static void registerBlocksAndRecipes(BlockIronChest blockResult) {
ItemStack previous = new ItemStack(Blocks.chest);
for (IronChestType typ : values())
{
for (IronChestType typ : values()) {
generateRecipesForType(blockResult, previous, typ);
ItemStack chest = new ItemStack(blockResult, 1, typ.ordinal());
if (typ.isValidForCreativeMode()) GameRegistry.registerCustomItemStack(typ.friendlyName, chest);
if (typ.tieredChest) previous = chest;
if (typ.isValidForCreativeMode())
GameRegistry.registerCustomItemStack(typ.friendlyName, chest);
if (typ.tieredChest)
previous = chest;
}
}
public static void generateRecipesForType(BlockIronChest blockResult, Object previousTier, IronChestType type)
{
for (String recipe : type.recipes)
{
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)
{
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', Blocks.glass, 'C', Blocks.chest,
addRecipe(new ItemStack(blockResult, 1, type.ordinal()), recipeSplit, 'm', mainMaterial, 'P', previousTier, /* previous chest tier */ 'G', Blocks.glass, 'C', Blocks.chest,
'0', new ItemStack(blockResult, 1, 0), /* Iron Chest */
'1', new ItemStack(blockResult, 1, 1), /* Gold Chest */
'2', new ItemStack(blockResult, 1, 2), /* Diamond Chest */
@ -132,80 +105,57 @@ public enum IronChestType {
}
}
public static Object translateOreName(String mat)
{
if (mat == "ingotIron")
{
public static Object translateOreName(String mat) {
if (mat == "ingotIron") {
return Items.iron_ingot;
}
else if (mat == "ingotGold")
{
} else if (mat == "ingotGold") {
return Items.gold_ingot;
}
else if (mat == "gemDiamond")
{
} else if (mat == "gemDiamond") {
return Items.diamond;
}
else if (mat == "blockGlass")
{
} else if (mat == "blockGlass") {
return Blocks.glass;
}
else if (mat == "obsidian")
{
} else if (mat == "obsidian") {
return Blocks.obsidian;
}
else if (mat == "dirt")
{
} else if (mat == "dirt") {
return Blocks.dirt;
}
return mat;
}
public static void addRecipe(ItemStack is, Object... parts)
{
public static void addRecipe(ItemStack is, Object... parts) {
ShapedOreRecipe oreRecipe = new ShapedOreRecipe(is, parts);
GameRegistry.addRecipe(oreRecipe);
}
public int getRowCount()
{
public int getRowCount() {
return size / rowLength;
}
public int getRowLength()
{
public int getRowLength() {
return rowLength;
}
public boolean isTransparent()
{
public boolean isTransparent() {
return this == CRYSTAL;
}
public List<String> getMatList()
{
public List<String> getMatList() {
return matList;
}
public static int validateMeta(int i)
{
if (i < values().length && values()[i].size > 0)
{
public static int validateMeta(int i) {
if (i < values().length && values()[i].size > 0) {
return i;
}
else
{
} else {
return 0;
}
}
public boolean isValidForCreativeMode()
{
public boolean isValidForCreativeMode() {
return validateMeta(ordinal()) == ordinal();
}
public boolean isExplosionResistant()
{
public boolean isExplosionResistant() {
return this == OBSIDIAN;
}
@ -213,42 +163,34 @@ public enum IronChestType {
private IIcon[] icons;
@SideOnly(Side.CLIENT)
public void makeIcons(IIconRegister par1IconRegister)
{
if (isValidForCreativeMode())
{
public void makeIcons(IIconRegister par1IconRegister) {
if (isValidForCreativeMode()) {
icons = new IIcon[3];
int i = 0;
for (String s : sideNames)
{
icons[i++] = par1IconRegister.registerIcon(String.format("ironchest:%s_%s",name().toLowerCase(),s));
for (String s : sideNames) {
icons[i++] = par1IconRegister.registerIcon(String.format("ironchest:%s_%s", name().toLowerCase(), s));
}
}
}
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side)
{
public IIcon getIcon(int side) {
return icons[sideMapping[side]];
}
private static String[] sideNames = { "top", "front", "side" };
private static int[] sideMapping = { 0, 0, 2, 1, 2, 2, 2 };
public Slot makeSlot(IInventory chestInventory, int index, int x, int y)
{
public Slot makeSlot(IInventory chestInventory, int index, int x, int y) {
return new ValidatingSlot(chestInventory, index, x, y, this);
}
public boolean acceptsStack(ItemStack itemstack)
{
public boolean acceptsStack(ItemStack itemstack) {
return itemFilter == null || itemstack == null || itemstack.getItem() == itemFilter;
}
public void adornItemDrop(ItemStack item)
{
if (this == DIRTCHEST9000)
{
public void adornItemDrop(ItemStack item) {
if (this == DIRTCHEST9000) {
item.setTagInfo("dirtchest", new NBTTagByte((byte) 1));
}
}

View File

@ -14,53 +14,43 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemChestChanger extends Item {
private ChestChangerType type;
public ItemChestChanger(ChestChangerType type)
{
public ItemChestChanger(ChestChangerType type) {
super();
setMaxStackSize(1);
this.type = type;
setUnlocalizedName("ironchest:"+type.name());
setUnlocalizedName("ironchest:" + type.name());
setCreativeTab(CreativeTabs.tabMisc);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister par1IconRegister)
{
this.itemIcon = par1IconRegister.registerIcon("ironchest:"+type.itemName);
public void registerIcons(IIconRegister par1IconRegister) {
this.itemIcon = par1IconRegister.registerIcon("ironchest:" + type.itemName);
}
@Override
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;
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;
TileEntity te = world.getTileEntity(X, Y, Z);
TileEntityIronChest newchest;
if (te != null && te instanceof TileEntityIronChest)
{
if (te != null && te instanceof TileEntityIronChest) {
TileEntityIronChest ironchest = (TileEntityIronChest) te;
newchest = ironchest.applyUpgradeItem(this);
if (newchest == null)
{
if (newchest == null) {
return false;
}
}
else if (te != null && te instanceof TileEntityChest)
{
} else if (te != null && te instanceof TileEntityChest) {
TileEntityChest tec = (TileEntityChest) te;
if (tec.numPlayersUsing > 0)
{
if (tec.numPlayersUsing > 0) {
return false;
}
if (!getType().canUpgrade(IronChestType.WOOD))
{
if (!getType().canUpgrade(IronChestType.WOOD)) {
return false;
}
// Force old TE out of the world so that adjacent chests can update
// force the old tileentity out of the world so that adjacent chests can update
newchest = IronChestType.makeEntity(getTargetChestOrdinal(IronChestType.WOOD.ordinal()));
int newSize = newchest.chestContents.length;
ItemStack[] chestContents = ObfuscationReflectionHelper.getPrivateValue(TileEntityChest.class, tec, 0);
@ -69,22 +59,14 @@ public class ItemChestChanger extends Item {
block.dropContent(newSize, tec, world, tec.xCoord, tec.yCoord, tec.zCoord);
newchest.setFacing((byte) tec.getBlockMetadata());
newchest.sortTopStacks();
for (int i = 0; i < Math.min(newSize, chestContents.length); i++)
{
for (int i = 0; i < Math.min(newSize, chestContents.length); i++) {
chestContents[i] = null;
}
// Clear the old block out
world.setBlock(X, Y, Z, Blocks.air, 0, 3);
// Force the Chest TE to reset it's knowledge of neighbouring blocks
tec.updateContainingBlockInfo();
// Force the Chest TE to update any neighbours so they update next
// tick
tec.checkForAdjacentChests();
// And put in our block instead
world.setBlock(X, Y, Z, block, newchest.getType().ordinal(), 3);
}
else
{
world.setBlock(X, Y, Z, Blocks.air, 0, 3); // clear the old block out
tec.updateContainingBlockInfo(); // reset neighboring block knowledge
tec.checkForAdjacentChests(); // update neighboring blocks
world.setBlock(X, Y, Z, block, newchest.getType().ordinal(), 3); // add in the iron chest
} else {
return false;
}
world.setTileEntity(X, Y, Z, newchest);
@ -93,13 +75,11 @@ public class ItemChestChanger extends Item {
return true;
}
public int getTargetChestOrdinal(int sourceOrdinal)
{
public int getTargetChestOrdinal(int sourceOrdinal) {
return type.getTarget();
}
public ChestChangerType getType()
{
public ChestChangerType getType() {
return type;
}
}

View File

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

View File

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

View File

@ -3,7 +3,9 @@ package cpw.mods.ironchest;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import java.util.EnumMap;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
@ -17,6 +19,7 @@ import cpw.mods.fml.relauncher.SideOnly;
/**
* Handles the packet wrangling for IronChest
*
* @author cpw
*
*/
@ -31,13 +34,11 @@ public enum PacketHandler {
/**
* Make our packet handler, and add an {@link IronChestCodec} always
*/
private PacketHandler()
{
private PacketHandler() {
// request a channel pair for IronChest from the network registry
// Add the IronChestCodec as a member of both channel pipelines
this.channels = NetworkRegistry.INSTANCE.newChannel("IronChest", new IronChestCodec());
if (FMLCommonHandler.instance().getSide() == Side.CLIENT)
{
if (FMLCommonHandler.instance().getSide() == Side.CLIENT) {
addClientHandler();
}
}
@ -50,8 +51,8 @@ public enum PacketHandler {
@SideOnly(Side.CLIENT)
private void addClientHandler() {
FMLEmbeddedChannel clientChannel = this.channels.get(Side.CLIENT);
// These two lines find the existing codec (Ironchestcodec) and insert our message handler after it
// in the pipeline
// These two lines find the existing codec (Ironchestcodec) and insert
// our message handler after it in the pipeline
String codec = clientChannel.findChannelHandlerNameForType(IronChestCodec.class);
clientChannel.pipeline().addAfter(codec, "ClientHandler", new IronChestMessageHandler());
}
@ -64,15 +65,12 @@ public enum PacketHandler {
* @author cpw
*
*/
private static class IronChestMessageHandler extends SimpleChannelInboundHandler<IronChestMessage>
{
private static class IronChestMessageHandler extends SimpleChannelInboundHandler<IronChestMessage> {
@Override
protected void channelRead0(ChannelHandlerContext ctx, IronChestMessage msg) throws Exception
{
protected void channelRead0(ChannelHandlerContext ctx, IronChestMessage msg) throws Exception {
World world = IronChest.proxy.getClientWorld();
TileEntity te = world.getTileEntity(msg.x, msg.y, msg.z);
if (te instanceof TileEntityIronChest)
{
if (te instanceof TileEntityIronChest) {
TileEntityIronChest icte = (TileEntityIronChest) te;
icte.setFacing(msg.facing);
icte.handlePacketData(msg.type, msg.items);
@ -89,14 +87,8 @@ public enum PacketHandler {
* @author cpw
*
*/
public static class IronChestMessage
{
int x;
int y;
int z;
int type;
int facing;
int[] items;
public static class IronChestMessage {
int x, y, z, type, facing, items[];
}
/**
@ -107,30 +99,26 @@ public enum PacketHandler {
* @author cpw
*
*/
private class IronChestCodec extends FMLIndexedMessageToMessageCodec<IronChestMessage>
{
private class IronChestCodec extends FMLIndexedMessageToMessageCodec<IronChestMessage> {
/**
* We register our discriminator bytes here. We only have the one type, so we only
* register one.
* We register our discriminator bytes here. We only have the one type,
* so we only register one.
*/
public IronChestCodec()
{
public IronChestCodec() {
addDiscriminator(0, IronChestMessage.class);
}
@Override
public void encodeInto(ChannelHandlerContext ctx, IronChestMessage msg, ByteBuf target) throws Exception
{
public void encodeInto(ChannelHandlerContext ctx, IronChestMessage msg, ByteBuf target) throws Exception {
target.writeInt(msg.x);
target.writeInt(msg.y);
target.writeInt(msg.z);
int typeAndFacing = ((msg.type & 0x0F) | ((msg.facing & 0x0F) << 4)) & 0xFF;
target.writeByte(typeAndFacing);
target.writeBoolean(msg.items != null);
if (msg.items != null)
{
if (msg.items != null) {
int[] items = msg.items;
for (int j = 0; j < items.length; j++)
{
for (int j = 0; j < items.length; j++) {
int i = items[j];
target.writeInt(i);
}
@ -138,26 +126,22 @@ public enum PacketHandler {
}
@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf dat, IronChestMessage msg)
{
public void decodeInto(ChannelHandlerContext ctx, ByteBuf dat, IronChestMessage msg) {
msg.x = dat.readInt();
msg.y = dat.readInt();
msg.z = dat.readInt();
int typDat = dat.readByte();
msg.type = (byte)(typDat & 0xf);
msg.facing = (byte)((typDat >> 4) & 0xf);
msg.type = (byte) (typDat & 0xf);
msg.facing = (byte) ((typDat >> 4) & 0xf);
boolean hasStacks = dat.readBoolean();
msg.items = new int[0];
if (hasStacks)
{
if (hasStacks) {
msg.items = new int[24];
for (int i = 0; i < msg.items.length; i++)
{
for (int i = 0; i < msg.items.length; i++) {
msg.items[i] = dat.readInt();
}
}
}
}
/**
@ -176,8 +160,7 @@ public enum PacketHandler {
* @param tileEntityIronChest
* @return
*/
public static Packet getPacket(TileEntityIronChest tileEntityIronChest)
{
public static Packet getPacket(TileEntityIronChest tileEntityIronChest) {
IronChestMessage msg = new IronChestMessage();
msg.x = tileEntityIronChest.xCoord;
msg.y = tileEntityIronChest.yCoord;

View File

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

View File

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

View File

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

View File

@ -9,32 +9,32 @@ import net.minecraft.util.StatCollector;
public class TileEntityDirtChest extends TileEntityIronChest {
private static ItemStack dirtChest9000GuideBook = new ItemStack(Items.written_book);
static {
dirtChest9000GuideBook.setTagInfo("author", new NBTTagString("cpw"));
dirtChest9000GuideBook.setTagInfo("title", new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.title")));
NBTTagList pages = new NBTTagList();
pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page1")));
pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page2")));
pages.appendTag(new NBTTagString(StatCollector .translateToLocal("book.ironchest:dirtchest9000.page1")));
pages.appendTag(new NBTTagString(StatCollector .translateToLocal("book.ironchest:dirtchest9000.page2")));
pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page3")));
pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page4")));
pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page5")));
dirtChest9000GuideBook.setTagInfo("pages", pages);
}
public TileEntityDirtChest() {
super(IronChestType.DIRTCHEST9000);
}
@Override
public void wasPlaced(EntityLivingBase entityliving, ItemStack itemStack)
{
public void wasPlaced(EntityLivingBase entityliving, ItemStack itemStack) {
if (!(itemStack.hasTagCompound() && itemStack.getTagCompound().getBoolean("dirtchest"))) {
setInventorySlotContents(0, dirtChest9000GuideBook.copy());
}
}
@Override
public void removeAdornments()
{
public void removeAdornments() {
if (chestContents[0] != null && chestContents[0].isItemEqual(dirtChest9000GuideBook)) {
chestContents[0] = null;
}

View File

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

View File

@ -19,88 +19,68 @@ import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityIronChest extends TileEntity implements IInventory {
private int ticksSinceSync = -1;
public float prevLidAngle;
public float lidAngle;
private int numUsingPlayers;
private int ticksSinceSync = -1, numUsingPlayers, facing;
public float prevLidAngle, lidAngle;
private IronChestType type;
public ItemStack[] chestContents;
private ItemStack[] topStacks;
private int facing;
private boolean inventoryTouched;
private boolean hadStuff;
public ItemStack[] chestContents, topStacks;
private boolean inventoryTouched, hadStuff;
public TileEntityIronChest()
{
public TileEntityIronChest() {
this(IronChestType.IRON);
}
protected TileEntityIronChest(IronChestType type)
{
protected TileEntityIronChest(IronChestType type) {
super();
this.type = type;
this.chestContents = new ItemStack[getSizeInventory()];
this.topStacks = new ItemStack[8];
chestContents = new ItemStack[getSizeInventory()];
topStacks = new ItemStack[8];
}
public ItemStack[] getContents()
{
public ItemStack[] getContents() {
return chestContents;
}
@Override
public int getSizeInventory()
{
public int getSizeInventory() {
return type.size;
}
public int getFacing()
{
return this.facing;
public int getFacing() {
return facing;
}
@Override
public String getInventoryName()
{
public String getInventoryName() {
return type.name();
}
public IronChestType getType()
{
public IronChestType getType() {
return type;
}
@Override
public ItemStack getStackInSlot(int i)
{
public ItemStack getStackInSlot(int i) {
inventoryTouched = true;
return chestContents[i];
}
@Override
public void markDirty()
{
public void markDirty() {
super.markDirty();
sortTopStacks();
}
protected void sortTopStacks()
{
if (!type.isTransparent() || (worldObj != null && worldObj.isRemote))
{
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]))
{
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;
}
@ -109,15 +89,12 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
hasStuff = true;
}
}
if (!hasStuff && hadStuff)
{
if (!hasStuff && hadStuff) {
hadStuff = false;
for (int i = 0; i < topStacks.length; i++)
{
for (int i = 0; i < topStacks.length; i++) {
topStacks[i] = null;
}
if (worldObj != null)
{
if (worldObj != null) {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
return;
@ -125,225 +102,168 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
hadStuff = true;
Arrays.sort(tempCopy, new Comparator<ItemStack>() {
@Override
public int compare(ItemStack o1, ItemStack o2)
{
if (o1 == null)
{
public int compare(ItemStack o1, ItemStack o2) {
if (o1 == null) {
return 1;
}
else if (o2 == null)
{
} else if (o2 == null) {
return -1;
}
else
{
} 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)
{
for (int i = 0; i < tempCopy.length; i++) {
if (tempCopy[i] != null && tempCopy[i].stackSize > 0) {
topStacks[p++] = tempCopy[i];
if (p == topStacks.length)
{
if (p == topStacks.length) {
break;
}
}
}
for (int i = p; i < topStacks.length; i++)
{
for (int i = p; i < topStacks.length; i++) {
topStacks[i] = null;
}
if (worldObj != 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)
{
public ItemStack decrStackSize(int i, int j) {
if (chestContents[i] != null) {
if (chestContents[i].stackSize <= j) {
ItemStack itemstack = chestContents[i];
chestContents[i] = null;
markDirty();
return itemstack;
}
ItemStack itemstack1 = chestContents[i].splitStack(j);
if (chestContents[i].stackSize == 0)
{
if (chestContents[i].stackSize == 0) {
chestContents[i] = null;
}
markDirty();
return itemstack1;
}
else
{
} else {
return null;
}
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack)
{
public void setInventorySlotContents(int i, ItemStack itemstack) {
chestContents[i] = itemstack;
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
{
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) {
itemstack.stackSize = getInventoryStackLimit();
}
markDirty();
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound)
{
super.readFromNBT(nbttagcompound);
NBTTagList nbttaglist = nbttagcompound.getTagList("Items", Constants.NBT.TAG_COMPOUND);
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
NBTTagList nbttaglist = nbt.getTagList("Items", Constants.NBT.TAG_COMPOUND);
chestContents = new ItemStack[getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); i++)
{
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
int j = nbttagcompound1.getByte("Slot") & 0xff;
if (j >= 0 && j < chestContents.length)
{
chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
for (int i = 0; i < nbttaglist.tagCount(); i++) {
NBTTagCompound nbt1 = nbttaglist.getCompoundTagAt(i);
int j = nbt1.getByte("Slot") & 0xff;
if (j >= 0 && j < chestContents.length) {
chestContents[j] = ItemStack.loadItemStackFromNBT(nbt1);
}
}
facing = nbttagcompound.getByte("facing");
facing = nbt.getByte("facing");
sortTopStacks();
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound)
{
super.writeToNBT(nbttagcompound);
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
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);
for (int i = 0; i < chestContents.length; i++) {
if (chestContents[i] != null) {
NBTTagCompound nbt1 = new NBTTagCompound();
nbt1.setByte("Slot", (byte) i);
chestContents[i].writeToNBT(nbt1);
nbttaglist.appendTag(nbt1);
}
}
nbttagcompound.setTag("Items", nbttaglist);
nbttagcompound.setByte("facing", (byte)facing);
nbt.setTag("Items", nbttaglist);
nbt.setByte("facing", (byte) facing);
}
@Override
public int getInventoryStackLimit()
{
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer)
{
if (worldObj == null)
{
return true;
}
if (worldObj.getTileEntity(xCoord, yCoord, zCoord) != this)
{
return false;
}
return entityplayer.getDistanceSq((double) xCoord + 0.5D, (double) yCoord + 0.5D, (double) zCoord + 0.5D) <= 64D;
public boolean isUseableByPlayer(final EntityPlayer player) {
return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) <= 64.0;
}
@Override
public void updateEntity()
{
public void updateEntity() {
super.updateEntity();
// Resynchronize clients with the server state
if (worldObj != null && !this.worldObj.isRemote && this.numUsingPlayers != 0 && (this.ticksSinceSync + this.xCoord + this.yCoord + this.zCoord) % 200 == 0)
{
this.numUsingPlayers = 0;
if (worldObj != null && !worldObj.isRemote && numUsingPlayers != 0 && (ticksSinceSync + xCoord + yCoord + zCoord) % 200 == 0) {
numUsingPlayers = 0;
float var1 = 5.0F;
@SuppressWarnings("unchecked")
List<EntityPlayer> var2 = this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getAABBPool().getAABB((double)((float)this.xCoord - var1), (double)((float)this.yCoord - var1), (double)((float)this.zCoord - var1), (double)((float)(this.xCoord + 1) + var1), (double)((float)(this.yCoord + 1) + var1), (double)((float)(this.zCoord + 1) + var1)));
List<EntityPlayer> var2 = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getAABBPool().getAABB((double) ((float) xCoord - var1), (double) ((float) yCoord - var1), (double) ((float) zCoord - var1), (double) ((float) (xCoord + 1) + var1), (double) ((float) (yCoord + 1) + var1), (double) ((float) (zCoord + 1) + var1)));
Iterator<EntityPlayer> var3 = var2.iterator();
while (var3.hasNext())
{
while (var3.hasNext()) {
EntityPlayer var4 = var3.next();
if (var4.openContainer instanceof ContainerIronChest)
{
++this.numUsingPlayers;
if (var4.openContainer instanceof ContainerIronChest) {
++numUsingPlayers;
}
}
}
if (worldObj != null && !worldObj.isRemote && ticksSinceSync < 0)
{
if (worldObj != null && !worldObj.isRemote && ticksSinceSync < 0) {
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock, 3, ((numUsingPlayers << 3) & 0xF8) | (facing & 0x7));
}
if (!worldObj.isRemote && inventoryTouched)
{
if (!worldObj.isRemote && inventoryTouched) {
inventoryTouched = false;
sortTopStacks();
}
this.ticksSinceSync++;
ticksSinceSync++;
prevLidAngle = lidAngle;
float f = 0.1F;
if (numUsingPlayers > 0 && lidAngle == 0.0F)
{
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)
{
if (numUsingPlayers == 0 && lidAngle > 0.0F || numUsingPlayers > 0
&& lidAngle < 1.0F) {
float f1 = lidAngle;
if (numUsingPlayers > 0)
{
if (numUsingPlayers > 0) {
lidAngle += f;
}
else
{
} else {
lidAngle -= f;
}
if (lidAngle > 1.0F)
{
if (lidAngle > 1.0F) {
lidAngle = 1.0F;
}
float f2 = 0.5F;
if (lidAngle < f2 && f1 >= f2)
{
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)
{
if (lidAngle < 0.0F) {
lidAngle = 0.0F;
}
}
}
@Override
public boolean receiveClientEvent(int i, int j)
{
if (i == 1)
{
public boolean receiveClientEvent(int i, int j) {
if (i == 1) {
numUsingPlayers = j;
}
else if (i == 2)
{
} else if (i == 2) {
facing = (byte) j;
}
else if (i == 3)
{
} else if (i == 3) {
facing = (byte) (j & 0x7);
numUsingPlayers = (j & 0xF8) >> 3;
}
@ -351,58 +271,43 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
}
@Override
public void openInventory()
{
if (worldObj == null) return;
numUsingPlayers++;
public void openInventory() {
++numUsingPlayers;
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock, 1, numUsingPlayers);
}
@Override
public void closeInventory()
{
if (worldObj == null) return;
numUsingPlayers--;
public void closeInventory() {
--numUsingPlayers;
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock, 1, numUsingPlayers);
}
public void setFacing(int facing2)
{
this.facing = facing2;
public void setFacing(int facing2) {
facing = facing2;
}
public TileEntityIronChest applyUpgradeItem(ItemChestChanger itemChestChanger)
{
if (numUsingPlayers > 0)
{
return null;
}
if (!itemChestChanger.getType().canUpgrade(this.getType()))
{
public TileEntityIronChest applyUpgradeItem(ItemChestChanger itemChestChanger) {
if (numUsingPlayers > 0 || !itemChestChanger.getType().canUpgrade(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);
block.dropContent(newSize, this, worldObj, xCoord, yCoord, zCoord);
newEntity.setFacing(facing);
newEntity.sortTopStacks();
newEntity.ticksSinceSync = -1;
return newEntity;
}
public ItemStack[] getTopItemStacks()
{
public ItemStack[] getTopItemStacks() {
return topStacks;
}
public TileEntityIronChest updateFromMetadata(int l)
{
if (worldObj != null && worldObj.isRemote)
{
if (l != type.ordinal())
{
public TileEntityIronChest updateFromMetadata(int l) {
if (worldObj != null && worldObj.isRemote) {
if (l != type.ordinal()) {
worldObj.setTileEntity(xCoord, yCoord, zCoord, IronChestType.makeEntity(l));
return (TileEntityIronChest) worldObj.getTileEntity(xCoord, yCoord, zCoord);
}
@ -411,35 +316,26 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
}
@Override
public Packet getDescriptionPacket()
{
public Packet getDescriptionPacket() {
return PacketHandler.getPacket(this);
}
public void handlePacketData(int typeData, int[] intData)
{
public void handlePacketData(int typeData, int[] intData) {
TileEntityIronChest chest = this;
if (this.type.ordinal() != typeData)
{
if (type.ordinal() != typeData) {
chest = updateFromMetadata(typeData);
}
if (IronChestType.values()[typeData].isTransparent() && intData != null)
{
if (IronChestType.values()[typeData].isTransparent() && intData != null) {
int pos = 0;
if (intData.length < chest.topStacks.length * 3)
{
if (intData.length < chest.topStacks.length * 3) {
return;
}
for (int i = 0; i < chest.topStacks.length; i++)
{
if (intData[pos + 2] != 0)
{
for (int i = 0; i < chest.topStacks.length; i++) {
if (intData[pos + 2] != 0) {
Item it = Item.getItemById(intData[pos]);
ItemStack is = new ItemStack(it, intData[pos + 2], intData[pos + 1]);
chest.topStacks[i] = is;
}
else
{
} else {
chest.topStacks[i] = null;
}
pos += 3;
@ -447,22 +343,16 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
}
}
public int[] buildIntDataList()
{
if (type.isTransparent())
{
public int[] buildIntDataList() {
if (type.isTransparent()) {
int[] sortList = new int[topStacks.length * 3];
int pos = 0;
for (ItemStack is : topStacks)
{
if (is != null)
{
for (ItemStack is : topStacks) {
if (is != null) {
sortList[pos++] = Item.getIdFromItem(is.getItem());
sortList[pos++] = is.getItemDamage();
sortList[pos++] = is.stackSize;
}
else
{
} else {
sortList[pos++] = 0;
sortList[pos++] = 0;
sortList[pos++] = 0;
@ -474,49 +364,32 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
}
@Override
public ItemStack getStackInSlotOnClosing(int par1)
{
if (this.chestContents[par1] != null)
{
ItemStack var2 = this.chestContents[par1];
this.chestContents[par1] = null;
public ItemStack getStackInSlotOnClosing(int par1) {
if (chestContents[par1] != null) {
ItemStack var2 = chestContents[par1];
chestContents[par1] = null;
return var2;
}
else
{
} else {
return null;
}
}
public void setMaxStackSize(int size)
{
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
{
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
return type.acceptsStack(itemstack);
}
@Override
public boolean hasCustomInventoryName()
{
public boolean hasCustomInventoryName() {
return false;
}
void rotateAround(ForgeDirection axis)
{
setFacing((byte)ForgeDirection.getOrientation(facing).getRotation(axis).ordinal());
worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, IronChest.ironChestBlock, 2, getFacing());
void rotateAround(ForgeDirection axis) {
setFacing((byte) ForgeDirection.getOrientation(facing).getRotation(axis).ordinal());
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock, 2, getFacing());
}
public void wasPlaced(EntityLivingBase entityliving, ItemStack itemStack)
{
}
public void wasPlaced(EntityLivingBase entityliving, ItemStack itemStack) {}
public void removeAdornments()
{
}
public void removeAdornments() {}
}

View File

@ -1,8 +1,7 @@
package cpw.mods.ironchest;
public class TileEntityObsidianChest extends TileEntityIronChest {
public TileEntityObsidianChest()
{
public TileEntityObsidianChest() {
super(IronChestType.OBSIDIAN);
}
}

View File

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

View File

@ -7,15 +7,13 @@ import net.minecraft.item.ItemStack;
public class ValidatingSlot extends Slot {
private IronChestType type;
public ValidatingSlot(IInventory par1iInventory, int par2, int par3, int par4, IronChestType type)
{
super(par1iInventory, par2, par3, par4);
public ValidatingSlot(IInventory inv, int i, int j, int k, IronChestType type) {
super(inv, i, j, k);
this.type = type;
}
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
return type.acceptsStack(par1ItemStack);
public boolean isItemValid(ItemStack is) {
return type.acceptsStack(is);
}
}

View File

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

View File

@ -12,34 +12,27 @@ import cpw.mods.ironchest.TileEntityIronChest;
public class ClientProxy extends CommonProxy {
@Override
public void registerRenderInformation()
{
public void registerRenderInformation() {
TileEntityRendererChestHelper.instance = new IronChestRenderHelper();
}
@Override
public void registerTileEntitySpecialRenderer(IronChestType typ)
{
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)
{
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if (te != null && te instanceof TileEntityIronChest)
{
return GUIChest.GUI.buildGUI(IronChestType.values()[ID], player.inventory, (TileEntityIronChest) te);
}
else
{
if (te != null && te instanceof TileEntityIronChest) {
return GuiIronChest.GUI.buildGUI(IronChestType.values()[ID], player.inventory, (TileEntityIronChest) te);
} else {
return null;
}
}
@Override
public World getClientWorld() {
return FMLClientHandler.instance().getClient().theWorld;
}
}

View File

@ -1,88 +0,0 @@
package cpw.mods.ironchest.client;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import cpw.mods.ironchest.ContainerIronChest;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.TileEntityIronChest;
public class GUIChest extends GuiContainer {
public enum ResourceList {
IRON(new ResourceLocation("ironchest", "textures/gui/ironcontainer.png")),
COPPER(new ResourceLocation("ironchest", "textures/gui/coppercontainer.png")),
SILVER(new ResourceLocation("ironchest", "textures/gui/silvercontainer.png")),
GOLD(new ResourceLocation("ironchest", "textures/gui/goldcontainer.png")),
DIAMOND(new ResourceLocation("ironchest", "textures/gui/diamondcontainer.png")),
DIRT(new ResourceLocation("ironchest", "textures/gui/dirtcontainer.png"));
public final ResourceLocation location;
private ResourceList(ResourceLocation loc) {
this.location = loc;
}
}
public enum GUI {
IRON(184, 202, ResourceList.IRON, IronChestType.IRON),
GOLD(184, 256, ResourceList.GOLD, IronChestType.GOLD),
DIAMOND(238, 256, ResourceList.DIAMOND, IronChestType.DIAMOND),
COPPER(184, 184, ResourceList.COPPER, IronChestType.COPPER),
SILVER(184, 238, ResourceList.SILVER, IronChestType.SILVER),
CRYSTAL(238, 256, ResourceList.DIAMOND, IronChestType.CRYSTAL),
OBSIDIAN(238, 256, ResourceList.DIAMOND, IronChestType.OBSIDIAN),
DIRTCHEST9000(184, 184, ResourceList.DIRT, IronChestType.DIRTCHEST9000);
private int xSize;
private int ySize;
private ResourceList guiResourceList;
private IronChestType mainType;
private GUI(int xSize, int ySize, ResourceList guiResourceList, IronChestType mainType)
{
this.xSize = xSize;
this.ySize = ySize;
this.guiResourceList = guiResourceList;
this.mainType = mainType;
}
protected Container makeContainer(IInventory player, IInventory chest)
{
return new ContainerIronChest(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)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
// new "bind tex"
this.mc.getTextureManager().bindTexture(type.guiResourceList.location);
int x = (width - xSize) / 2;
int y = (height - ySize) / 2;
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
}
}

View File

@ -0,0 +1,81 @@
package cpw.mods.ironchest.client;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import cpw.mods.ironchest.ContainerIronChest;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.TileEntityIronChest;
public class GuiIronChest extends GuiContainer {
public enum ResourceList {
IRON(new ResourceLocation("ironchest", "textures/gui/ironcontainer.png")),
COPPER(new ResourceLocation("ironchest", "textures/gui/coppercontainer.png")),
SILVER(new ResourceLocation("ironchest", "textures/gui/silvercontainer.png")),
GOLD(new ResourceLocation("ironchest", "textures/gui/goldcontainer.png")),
DIAMOND(new ResourceLocation("ironchest", "textures/gui/diamondcontainer.png")),
DIRT(new ResourceLocation("ironchest", "textures/gui/dirtcontainer.png"));
public final ResourceLocation location;
private ResourceList(ResourceLocation loc) {
this.location = loc;
}
}
public enum GUI {
IRON(184, 202, ResourceList.IRON, IronChestType.IRON),
GOLD(184, 256, ResourceList.GOLD, IronChestType.GOLD),
DIAMOND(238, 256, ResourceList.DIAMOND, IronChestType.DIAMOND),
COPPER(184, 184, ResourceList.COPPER, IronChestType.COPPER),
SILVER(184, 238, ResourceList.SILVER, IronChestType.SILVER),
CRYSTAL(238, 256, ResourceList.DIAMOND, IronChestType.CRYSTAL),
OBSIDIAN(238, 256, ResourceList.DIAMOND, IronChestType.OBSIDIAN),
DIRTCHEST9000(184, 184, ResourceList.DIRT, IronChestType.DIRTCHEST9000);
private int xSize, ySize;
private ResourceList guiResourceList;
private IronChestType mainType;
private GUI(int xSize, int ySize, ResourceList guiResourceList, IronChestType mainType) {
this.xSize = xSize;
this.ySize = ySize;
this.guiResourceList = guiResourceList;
this.mainType = mainType;
}
protected Container makeContainer(IInventory player, IInventory chest) {
return new ContainerIronChest(player, chest, mainType, xSize, ySize);
}
public static GuiIronChest buildGUI(IronChestType type, IInventory playerInventory, TileEntityIronChest chestInventory) {
return new GuiIronChest(values()[chestInventory.getType().ordinal()], playerInventory, chestInventory);
}
}
public int getRowLength() {
return type.mainType.getRowLength();
}
private GUI type;
private GuiIronChest(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) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(type.guiResourceList.location);
int x = (width - xSize) / 2;
int y = (height - ySize) / 2;
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
}
}

View File

@ -1,10 +1,13 @@
package cpw.mods.ironchest.client;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.tileentity.TileEntityRendererChestHelper;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import com.google.common.collect.Maps;
import cpw.mods.ironchest.IronChest;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.TileEntityIronChest;
@ -12,23 +15,16 @@ import cpw.mods.ironchest.TileEntityIronChest;
public class IronChestRenderHelper extends TileEntityRendererChestHelper {
private Map<Integer, TileEntityIronChest> itemRenders = Maps.newHashMap();
public IronChestRenderHelper()
{
public IronChestRenderHelper() {
for (IronChestType typ : IronChestType.values())
{
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)
{
public void renderChest(Block block, int i, float f) {
if (block == IronChest.ironChestBlock) {
TileEntityRendererDispatcher.instance.renderTileEntityAt(itemRenders.get(i), 0.0D, 0.0D, 0.0D, 0.0F);
}
else
{
} else {
super.renderChest(block, i, f);
}
}

View File

@ -8,11 +8,11 @@ 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.client.model.ModelChest;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
@ -20,32 +20,31 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.primitives.SignedBytes;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.MappableItemStackWrapper;
import cpw.mods.ironchest.TileEntityIronChest;
public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
private ModelChest model;
private static Map<IronChestType, ResourceLocation> locations;
static {
Builder<IronChestType, ResourceLocation> builder = ImmutableMap.<IronChestType,ResourceLocation>builder();
for (IronChestType typ : IronChestType.values()) {
builder.put(typ, new ResourceLocation("ironchest","textures/model/"+typ.getModelTexture()));
}
Builder<IronChestType, ResourceLocation> builder = ImmutableMap.<IronChestType, ResourceLocation> builder();
for (IronChestType typ : IronChestType.values())
builder.put(typ, new ResourceLocation("ironchest", "textures/model/" + typ.getModelTexture()));
locations = builder.build();
}
private Random random;
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 }, };
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()
{
public TileEntityIronChestRenderer() {
model = new ModelChest();
random = new Random();
itemRenderer = new RenderItem() {
@ -53,14 +52,17 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
public byte getMiniBlockCount(ItemStack stack, byte original) {
return SignedBytes.saturatedCast(Math.min(stack.stackSize / 32, 15) + 1);
}
@Override
public byte getMiniItemCount(ItemStack stack, byte original) {
return SignedBytes.saturatedCast(Math.min(stack.stackSize / 32, 7) + 1);
}
@Override
public boolean shouldBob() {
return false;
}
@Override
public boolean shouldSpreadItems() {
return false;
@ -83,7 +85,7 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
}
bindTexture(locations.get(type));
glPushMatrix();
glEnable(32826 /* GL_RESCALE_NORMAL_EXT */);
glEnable(32826);
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);
@ -107,25 +109,20 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
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 */);
glDisable(32826);
glPopMatrix();
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
if (type.isTransparent() && tile.getDistanceFrom(this.field_147501_a.field_147560_j, this.field_147501_a.field_147561_k, this.field_147501_a.field_147558_l) < 128d) {
random.setSeed(254L);
float shiftX;
float shiftY;
float shiftZ;
float shiftX, shiftY, shiftZ, blockScale = 0.70F;
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 */);
glDisable(2896);
glTranslatef((float) x, (float) y, (float) z);
EntityItem customitem = new EntityItem(field_147501_a.field_147550_f);
customitem.hoverStart = 0f;
@ -143,23 +140,20 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
shift++;
glPushMatrix();
glTranslatef(shiftX, shiftY, shiftZ);
glRotatef(timeD, 0.0F, 1.0F, 0.0F);
glRotatef((float) (360.0 * (double) (System.currentTimeMillis() & 0x3FFFL) / (double) 0x3FFFL), 0.0F, 1.0F, 0.0F);
glScalef(blockScale, blockScale, blockScale);
customitem.setEntityItemStack(item);
itemRenderer.doRender(customitem, 0, 0, 0, 0, 0);
glPopMatrix();
}
glEnable(2896 /* GL_LIGHTING */);
glEnable(2896);
glPopMatrix();
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
}
}
@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float partialTick)
{
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float partialTick) {
render((TileEntityIronChest) tileentity, x, y, z, partialTick);
}
private ModelChest model;
}