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; import cpw.mods.fml.relauncher.SideOnly;
public class BlockIronChest extends BlockContainer { public class BlockIronChest extends BlockContainer {
private Random random = new Random();
private Random random; public BlockIronChest() {
@SideOnly(Side.CLIENT)
private IIcon[][] icons;
public BlockIronChest()
{
super(Material.iron); super(Material.iron);
setBlockName("IronChest"); setBlockName("IronChest");
setHardness(3.0F); setHardness(3.0F);
setBlockBounds(0.0625F, 0F, 0.0625F, 0.9375F, 0.875F, 0.9375F); setBlockBounds(0.0625F, 0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
random = new Random();
setCreativeTab(CreativeTabs.tabDecorations); setCreativeTab(CreativeTabs.tabDecorations);
} }
@ -56,41 +50,34 @@ public class BlockIronChest extends BlockContainer {
* Overridden by {@link #createTileEntity(World, int)} * Overridden by {@link #createTileEntity(World, int)}
*/ */
@Override @Override
public TileEntity createNewTileEntity(World w, int i) public TileEntity createNewTileEntity(World w, int i) {
{
return null; return null;
} }
@Override @Override
public boolean isOpaqueCube() public boolean isOpaqueCube() {
{
return false; return false;
} }
@Override @Override
public boolean renderAsNormalBlock() public boolean renderAsNormalBlock() {
{
return false; return false;
} }
@Override @Override
public int getRenderType() public int getRenderType() {
{
return 22; return 22;
} }
@Override @Override
public TileEntity createTileEntity(World world, int metadata) public TileEntity createTileEntity(World world, int metadata) {
{
return IronChestType.makeEntity(metadata); return IronChestType.makeEntity(metadata);
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public IIcon getIcon(int i, int j) public IIcon getIcon(int i, int j) {
{ if (j < IronChestType.values().length) {
if (j < IronChestType.values().length)
{
IronChestType type = IronChestType.values()[j]; IronChestType type = IronChestType.values()[j];
return type.getIcon(i); return type.getIcon(i);
} }
@ -98,8 +85,7 @@ public class BlockIronChest extends BlockContainer {
} }
@Override @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(); 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); IronChestType.values()[IronChestType.validateMeta(metadata)].adornItemDrop(stack);
@ -108,106 +94,79 @@ public class BlockIronChest extends BlockContainer {
} }
@Override @Override
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int i1, float f1, float f2, float f3) public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int i1, float f1, float f2, float f3) {
{
if (world.isRemote) if (world.isRemote)
return true; return true;
else else {
{
IInventory iinventory = chestInventory(world, i, j, k); 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); player.openGui(IronChest.instance, ((TileEntityIronChest) world.getTileEntity(i, j, k)).getType().ordinal(), world, i, j, k);
return true; return true;
} }
} }
public IInventory chestInventory(World world, int i, int j, int k) public IInventory chestInventory(World world, int i, int j, int k) {
{
TileEntity object = (TileEntityIronChest) world.getTileEntity(i, j, k); TileEntity object = (TileEntityIronChest) world.getTileEntity(i, j, k);
if (object == null) if (object == null) {
{
return null; return null;
} } else if (world.isSideSolid(i, j + 1, k, DOWN)) {
else if (world.isSideSolid(i, j + 1, k, DOWN))
{
return null; return null;
} } else if (isOcelotOnChest(world, i, j, k)) {
else if (isOcelotOnChest(world, i, j, k))
{
return null; 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; 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; 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; 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; return null;
} } else
else
return (IInventory) object; return (IInventory) object;
} }
private static boolean isOcelotOnChest(World world, int i, int j, int k) 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(); 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; EntityOcelot entityocelot1;
do do {
{
if (!iterator.hasNext()) if (!iterator.hasNext())
return false; return false;
EntityOcelot entityocelot = (EntityOcelot) iterator.next(); EntityOcelot entityocelot = (EntityOcelot) iterator.next();
entityocelot1 = (EntityOcelot) entityocelot; entityocelot1 = (EntityOcelot) entityocelot;
} } while (!entityocelot1.isSitting());
while (!entityocelot1.isSitting());
return true; return true;
} }
@Override @Override
public void onBlockAdded(World world, int i, int j, int k) public void onBlockAdded(World world, int i, int j, int k) {
{
super.onBlockAdded(world, i, j, k); super.onBlockAdded(world, i, j, k);
world.markBlockForUpdate(i, j, k); world.markBlockForUpdate(i, j, k);
} }
@Override @Override
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack itemStack) public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack itemStack) {
{
byte chestFacing = 0; byte chestFacing = 0;
int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3; int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
if (facing == 0) if (facing == 0) {
{
chestFacing = 2; chestFacing = 2;
} }
if (facing == 1) if (facing == 1) {
{
chestFacing = 5; chestFacing = 5;
} }
if (facing == 2) if (facing == 2) {
{
chestFacing = 3; chestFacing = 3;
} }
if (facing == 3) if (facing == 3) {
{
chestFacing = 4; chestFacing = 4;
} }
TileEntity te = world.getTileEntity(i, j, k); TileEntity te = world.getTileEntity(i, j, k);
if (te != null && te instanceof TileEntityIronChest) if (te != null && te instanceof TileEntityIronChest) {
{
TileEntityIronChest teic = (TileEntityIronChest) te; TileEntityIronChest teic = (TileEntityIronChest) te;
teic.wasPlaced(entityliving, itemStack); teic.wasPlaced(entityliving, itemStack);
teic.setFacing(chestFacing); teic.setFacing(chestFacing);
@ -216,51 +175,41 @@ public class BlockIronChest extends BlockContainer {
} }
@Override @Override
public int damageDropped(int i) public int damageDropped(int i) {
{
return i; return i;
} }
@Override @Override
public void breakBlock(World world, int i, int j, int k, Block i1, int i2) public void breakBlock(World world, int i, int j, int k, Block b, int l) {
{ TileEntityIronChest te = (TileEntityIronChest) world.getTileEntity(i, j, k);
TileEntityIronChest tileentitychest = (TileEntityIronChest) world.getTileEntity(i, j, k); if (te != null) {
if (tileentitychest != null) te.removeAdornments();
{ dropContent(0, te, world, te.xCoord, te.yCoord, te.zCoord);
tileentitychest.removeAdornments();
dropContent(0, tileentitychest, world, tileentitychest.xCoord, tileentitychest.yCoord, tileentitychest.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) public void dropContent(int newSize, IInventory chest, World world, int xCoord, int yCoord, int zCoord) {
{ for (int l = newSize; l < chest.getSizeInventory(); l++) {
for (int l = newSize; l < chest.getSizeInventory(); l++)
{
ItemStack itemstack = chest.getStackInSlot(l); ItemStack itemstack = chest.getStackInSlot(l);
if (itemstack == null) if (itemstack == null) {
{
continue; continue;
} }
float f = random.nextFloat() * 0.8F + 0.1F; float f = random.nextFloat() * 0.8F + 0.1F;
float f1 = random.nextFloat() * 0.8F + 0.1F; float f1 = random.nextFloat() * 0.8F + 0.1F;
float f2 = 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; int i1 = random.nextInt(21) + 10;
if (i1 > itemstack.stackSize) if (i1 > itemstack.stackSize) {
{
i1 = itemstack.stackSize; i1 = itemstack.stackSize;
} }
itemstack.stackSize -= i1; itemstack.stackSize -= i1;
EntityItem entityitem = new EntityItem(world, (float) xCoord + f, (float) yCoord + (newSize > 0 ? 1 : 0) + f1, (float) zCoord + f2, 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()));
new ItemStack(itemstack.getItem(), i1, itemstack.getItemDamage()));
float f3 = 0.05F; float f3 = 0.05F;
entityitem.motionX = (float) random.nextGaussian() * f3; entityitem.motionX = (float) random.nextGaussian() * f3;
entityitem.motionY = (float) random.nextGaussian() * f3 + 0.2F; entityitem.motionY = (float) random.nextGaussian() * f3 + 0.2F;
entityitem.motionZ = (float) random.nextGaussian() * f3; entityitem.motionZ = (float) random.nextGaussian() * f3;
if (itemstack.hasTagCompound()) if (itemstack.hasTagCompound()) {
{
entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy()); entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
} }
world.spawnEntityInWorld(entityitem); world.spawnEntityInWorld(entityitem);
@ -270,46 +219,35 @@ public class BlockIronChest extends BlockContainer {
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List) public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List) {
{ for (IronChestType type : IronChestType.values()) {
for (IronChestType type : IronChestType.values()) if (type.isValidForCreativeMode()) {
{
if (type.isValidForCreativeMode())
{
par3List.add(new ItemStack(this, 1, type.ordinal())); par3List.add(new ItemStack(this, 1, type.ordinal()));
} }
} }
} }
@Override @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); TileEntity te = world.getTileEntity(x, y, z);
if (te instanceof TileEntityIronChest) if (te instanceof TileEntityIronChest) {
{
TileEntityIronChest teic = (TileEntityIronChest) te; TileEntityIronChest teic = (TileEntityIronChest) te;
if (teic.getType().isExplosionResistant()) if (teic.getType().isExplosionResistant()) {
{ return 10000F;
return 10000f;
} }
} }
return super.getExplosionResistance(par1Entity, world, x, y, z, explosionX, explosionY, explosionZ); return super.getExplosionResistance(par1Entity, world, x, y, z, explosionX, explosionY, explosionZ);
} }
@Override @Override
public int getComparatorInputOverride(World par1World, int par2, int par3, int par4, int par5) public int getComparatorInputOverride(World world, int i, int j, int k, int l) {
{ return Container.calcRedstoneFromInventory((TileEntityIronChest) world.getTileEntity(i, j, k));
return Container.calcRedstoneFromInventory((TileEntityIronChest) par1World.getTileEntity(par2, par3, par4));
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister par1IconRegister) public void registerBlockIcons(IIconRegister par1IconRegister) {
{ for (IronChestType typ : IronChestType.values()) {
for (IronChestType typ: IronChestType.values())
{
typ.makeIcons(par1IconRegister); typ.makeIcons(par1IconRegister);
} }
} }
@ -317,20 +255,16 @@ public class BlockIronChest extends BlockContainer {
private static final ForgeDirection[] validRotationAxes = new ForgeDirection[] { UP, DOWN }; private static final ForgeDirection[] validRotationAxes = new ForgeDirection[] { UP, DOWN };
@Override @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; return validRotationAxes;
} }
@Override @Override
public boolean rotateBlock(World worldObj, int x, int y, int z, ForgeDirection axis) public boolean rotateBlock(World worldObj, int x, int y, int z, ForgeDirection axis) {
{ if (worldObj.isRemote) {
if (worldObj.isRemote)
{
return false; return false;
} }
if (axis == UP || axis == DOWN) if (axis == UP || axis == DOWN) {
{
TileEntity tileEntity = worldObj.getTileEntity(x, y, z); TileEntity tileEntity = worldObj.getTileEntity(x, y, z);
if (tileEntity instanceof TileEntityIronChest) { if (tileEntity instanceof TileEntityIronChest) {
TileEntityIronChest icte = (TileEntityIronChest) tileEntity; 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 static cpw.mods.ironchest.IronChestType.WOOD;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.common.config.Configuration;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
public enum ChestChangerType { public enum ChestChangerType {
@ -24,15 +23,11 @@ public enum ChestChangerType {
WOODCOPPER(WOOD, COPPER, "woodCopperUpgrade", "Normal chest to Copper Chest Upgrade", "mmm", "msm", "mmm"), 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"); DIAMONDOBSIDIAN(DIAMOND, OBSIDIAN, "diamondObsidianUpgrade", "Diamond to Obsidian Chest Upgrade", "mmm", "mGm", "mmm");
private IronChestType source; private IronChestType source, target;
private IronChestType target; public String itemName, descriptiveName, recipe[];
public String itemName;
public String descriptiveName;
private ItemChestChanger item; 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.source = source;
this.target = target; this.target = target;
this.itemName = itemName; this.itemName = itemName;
@ -40,29 +35,23 @@ public enum ChestChangerType {
this.recipe = recipe; this.recipe = recipe;
} }
public boolean canUpgrade(IronChestType from) public boolean canUpgrade(IronChestType from) {
{
return from == this.source; return from == this.source;
} }
public int getTarget() public int getTarget() {
{
return this.target.ordinal(); return this.target.ordinal();
} }
public ItemChestChanger buildItem() public ItemChestChanger buildItem() {
{
item = new ItemChestChanger(this); item = new ItemChestChanger(this);
GameRegistry.registerItem(item, itemName); GameRegistry.registerItem(item, itemName);
return item; return item;
} }
public void addRecipes() public void addRecipes() {
{ for (String sourceMat : source.getMatList()) {
for (String sourceMat : source.getMatList()) for (String targetMat : target.getMatList()) {
{
for (String targetMat : target.getMatList())
{
Object targetMaterial = IronChestType.translateOreName(targetMat); Object targetMaterial = IronChestType.translateOreName(targetMat);
Object sourceMaterial = IronChestType.translateOreName(sourceMat); Object sourceMaterial = IronChestType.translateOreName(sourceMat);
IronChestType.addRecipe(new ItemStack(item), recipe, 'm', targetMaterial, 's', sourceMaterial, 'G', Blocks.glass, 'O', Blocks.obsidian); 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() public static void buildItems() {
{ for (ChestChangerType type : values()) {
for (ChestChangerType type : values())
{
type.buildItem(); type.buildItem();
} }
} }
public static void generateRecipes() public static void generateRecipes() {
{ for (ChestChangerType item : values()) {
for (ChestChangerType item : values())
{
item.addRecipes(); item.addRecipes();
} }
} }

View File

@ -6,40 +6,27 @@ 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.getTileEntity(X, Y, Z); TileEntity te = world.getTileEntity(X, Y, Z);
if (te != null && te instanceof TileEntityIronChest) if (te != null && te instanceof TileEntityIronChest) {
{
TileEntityIronChest icte = (TileEntityIronChest) te; TileEntityIronChest icte = (TileEntityIronChest) te;
return new ContainerIronChest(player.inventory, icte, icte.getType(), 0, 0); return new ContainerIronChest(player.inventory, icte, icte.getType(), 0, 0);
} } else {
else
{
return null; return null;
} }
} }
public World getClientWorld() public World getClientWorld() {
{
return null; return null;
} }
} }

View File

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

View File

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

View File

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

View File

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

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

View File

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

View File

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

View File

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

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

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

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

View File

@ -1,8 +1,7 @@
package cpw.mods.ironchest; 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

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

View File

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

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

View File

@ -5,10 +5,8 @@ import java.util.Properties;
public class Version { public class Version {
private static String major, minor, rev, build, mcversion; private static String major, minor, rev, build, mcversion;
static void init(Properties properties) static void init(Properties properties) {
{ if (properties != null) {
if (properties != null)
{
major = properties.getProperty("IronChest.build.major.number"); major = properties.getProperty("IronChest.build.major.number");
minor = properties.getProperty("IronChest.build.minor.number"); minor = properties.getProperty("IronChest.build.minor.number");
rev = properties.getProperty("IronChest.build.revision.number"); rev = properties.getProperty("IronChest.build.revision.number");
@ -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); 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 { public class ClientProxy extends CommonProxy {
@Override @Override
public void registerRenderInformation() public void registerRenderInformation() {
{
TileEntityRendererChestHelper.instance = new IronChestRenderHelper(); TileEntityRendererChestHelper.instance = new IronChestRenderHelper();
} }
@Override @Override
public void registerTileEntitySpecialRenderer(IronChestType typ) public void registerTileEntitySpecialRenderer(IronChestType typ) {
{
ClientRegistry.bindTileEntitySpecialRenderer(typ.clazz, new TileEntityIronChestRenderer()); ClientRegistry.bindTileEntitySpecialRenderer(typ.clazz, new TileEntityIronChestRenderer());
} }
@Override @Override
public World getClientWorld() public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
{
return FMLClientHandler.instance().getClient().theWorld;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
TileEntity te = world.getTileEntity(x, y, z); TileEntity te = world.getTileEntity(x, y, z);
if (te != null && te instanceof TileEntityIronChest) if (te != null && te instanceof TileEntityIronChest) {
{ return GuiIronChest.GUI.buildGUI(IronChestType.values()[ID], player.inventory, (TileEntityIronChest) te);
return GUIChest.GUI.buildGUI(IronChestType.values()[ID], player.inventory, (TileEntityIronChest) te); } else {
}
else
{
return null; 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; package cpw.mods.ironchest.client;
import java.util.Map; import java.util.Map;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.renderer.tileentity.TileEntityRendererChestHelper; import net.minecraft.client.renderer.tileentity.TileEntityRendererChestHelper;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import cpw.mods.ironchest.IronChest; import cpw.mods.ironchest.IronChest;
import cpw.mods.ironchest.IronChestType; import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.TileEntityIronChest; import cpw.mods.ironchest.TileEntityIronChest;
@ -12,23 +15,16 @@ import cpw.mods.ironchest.TileEntityIronChest;
public class IronChestRenderHelper extends TileEntityRendererChestHelper { public class IronChestRenderHelper extends TileEntityRendererChestHelper {
private Map<Integer, TileEntityIronChest> itemRenders = Maps.newHashMap(); private Map<Integer, TileEntityIronChest> itemRenders = Maps.newHashMap();
public IronChestRenderHelper() public IronChestRenderHelper() {
{
for (IronChestType typ : IronChestType.values()) for (IronChestType typ : IronChestType.values())
{
itemRenders.put(typ.ordinal(), (TileEntityIronChest) IronChest.ironChestBlock.createTileEntity(null, typ.ordinal())); itemRenders.put(typ.ordinal(), (TileEntityIronChest) IronChest.ironChestBlock.createTileEntity(null, typ.ordinal()));
} }
}
@Override @Override
public void renderChest(Block block, int i, float f) public void renderChest(Block block, int i, float f) {
{ if (block == IronChest.ironChestBlock) {
if (block == IronChest.ironChestBlock)
{
TileEntityRendererDispatcher.instance.renderTileEntityAt(itemRenders.get(i), 0.0D, 0.0D, 0.0D, 0.0F); TileEntityRendererDispatcher.instance.renderTileEntityAt(itemRenders.get(i), 0.0D, 0.0D, 0.0D, 0.0F);
} } else {
else
{
super.renderChest(block, i, f); super.renderChest(block, i, f);
} }
} }

View File

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