Update IronChests to 1.9!

This commit is contained in:
Alexander 2016-03-21 12:44:27 -04:00
parent c4d5a5631f
commit 2b95aab95f
35 changed files with 512 additions and 440 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
build/ build/
.classpath .classpath
.project .project
/*.launch
.gradle/ .gradle/
eclipse/ eclipse/
bin/ bin/

View File

@ -35,8 +35,8 @@ archivesBaseName = "ironchest"
// Setup the forge minecraft plugin data. Specify the preferred forge/minecraft version here // Setup the forge minecraft plugin data. Specify the preferred forge/minecraft version here
minecraft { minecraft {
version = "1.8.9-11.15.0.1689" version = "1.9-12.16.0.1781-1.9"
mappings = "stable_20" mappings = "snapshot_20160319"
runDir = "run" runDir = "run"
} }

View File

@ -6,12 +6,12 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
/** /**
* A marker for containers that have a chest-like persistant storage component. Enables the Inventroy Tweaks sorting * A marker for containers that have a chest-like persistant storage component. Enables the Inventroy Tweaks sorting buttons for this container.
* buttons for this container.
*/ */
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
public @interface ChestContainer { public @interface ChestContainer
{
// Set to true if the Inventory Tweaks sorting buttons should be shown for this container. // Set to true if the Inventory Tweaks sorting buttons should be shown for this container.
boolean showButtons() default true; boolean showButtons() default true;
@ -26,13 +26,15 @@ public @interface ChestContainer {
// Signature int func() // Signature int func()
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
public @interface RowSizeCallback { public @interface RowSizeCallback
{
} }
// Annotation for method to get size of a chest row if it is not a fixed size for this container class // Annotation for method to get size of a chest row if it is not a fixed size for this container class
// Signature int func() // Signature int func()
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
public @interface IsLargeCallback { public @interface IsLargeCallback
{
} }
} }

View File

@ -14,11 +14,13 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import com.google.common.collect.Lists;
import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState; import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -31,20 +33,21 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.MathHelper; import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.Explosion; import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
import com.google.common.collect.Lists;
public class BlockIronChest extends BlockContainer public class BlockIronChest extends BlockContainer
{ {
public static final PropertyEnum<IronChestType> VARIANT_PROP = PropertyEnum.create("variant", IronChestType.class); public static final PropertyEnum<IronChestType> VARIANT_PROP = PropertyEnum.create("variant", IronChestType.class);
protected static final AxisAlignedBB IRON_CHEST_AABB = new AxisAlignedBB(0.0625D, 0.0D, 0.0625D, 0.9375D, 0.875D, 0.9375D);
public BlockIronChest() public BlockIronChest()
{ {
@ -52,26 +55,32 @@ public class BlockIronChest extends BlockContainer
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT_PROP, IronChestType.IRON)); this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT_PROP, IronChestType.IRON));
this.setBlockBounds(0.0625F, 0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
this.setHardness(3.0F); this.setHardness(3.0F);
this.setUnlocalizedName("IronChest"); this.setUnlocalizedName("IronChest");
this.setCreativeTab(CreativeTabs.tabDecorations); this.setCreativeTab(CreativeTabs.tabDecorations);
} }
@Override @Override
public boolean isOpaqueCube() public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return IRON_CHEST_AABB;
}
@Override
public boolean isOpaqueCube(IBlockState state)
{ {
return false; return false;
} }
@Override @Override
public boolean isFullCube() public boolean isFullCube(IBlockState state)
{ {
return false; return false;
} }
@Override @Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState blockState, EntityPlayer player, EnumFacing direction, float p_180639_6_, float p_180639_7_, float p_180639_8_) public boolean onBlockActivated(World world, BlockPos pos, IBlockState blockState, EntityPlayer player, EnumHand hand, ItemStack heldItem,
EnumFacing direction, float hitX, float hitY, float hitZ)
{ {
TileEntity te = world.getTileEntity(pos); TileEntity te = world.getTileEntity(pos);
@ -122,21 +131,21 @@ public class BlockIronChest extends BlockContainer
@Override @Override
public int getMetaFromState(IBlockState blockState) public int getMetaFromState(IBlockState blockState)
{ {
return ((IronChestType) blockState.getValue(VARIANT_PROP)).ordinal(); return blockState.getValue(VARIANT_PROP).ordinal();
} }
@Override @Override
protected BlockState createBlockState() protected BlockStateContainer createBlockState()
{ {
return new BlockState(this, new IProperty<?>[] { VARIANT_PROP }); return new BlockStateContainer(this, new IProperty<?>[] { VARIANT_PROP });
} }
@Override @Override
public ArrayList<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) public ArrayList<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
{ {
ArrayList<ItemStack> items = Lists.newArrayList(); ArrayList<ItemStack> items = Lists.newArrayList();
ItemStack stack = new ItemStack(this, 1, getMetaFromState(state)); ItemStack stack = new ItemStack(this, 1, this.getMetaFromState(state));
IronChestType.values()[IronChestType.validateMeta(getMetaFromState(state))].adornItemDrop(stack); IronChestType.values()[IronChestType.validateMeta(this.getMetaFromState(state))].adornItemDrop(stack);
items.add(stack); items.add(stack);
return items; return items;
} }
@ -145,7 +154,7 @@ public class BlockIronChest extends BlockContainer
public void onBlockAdded(World world, BlockPos pos, IBlockState blockState) public void onBlockAdded(World world, BlockPos pos, IBlockState blockState)
{ {
super.onBlockAdded(world, pos, blockState); super.onBlockAdded(world, pos, blockState);
world.markBlockForUpdate(pos); world.notifyBlockUpdate(pos, blockState, blockState, 3);
} }
@Override @Override
@ -175,14 +184,14 @@ public class BlockIronChest extends BlockContainer
TileEntityIronChest teic = (TileEntityIronChest) te; TileEntityIronChest teic = (TileEntityIronChest) te;
teic.wasPlaced(entityliving, itemStack); teic.wasPlaced(entityliving, itemStack);
teic.setFacing(chestFacing); teic.setFacing(chestFacing);
world.markBlockForUpdate(pos); world.notifyBlockUpdate(pos, blockState, blockState, 3);
} }
} }
@Override @Override
public int damageDropped(IBlockState state) public int damageDropped(IBlockState state)
{ {
return IronChestType.validateMeta(((IronChestType) state.getValue(VARIANT_PROP)).ordinal()); return IronChestType.validateMeta(state.getValue(VARIANT_PROP).ordinal());
} }
@Override @Override
@ -192,7 +201,7 @@ public class BlockIronChest extends BlockContainer
if (tileentitychest != null) if (tileentitychest != null)
{ {
tileentitychest.removeAdornments(); tileentitychest.removeAdornments();
dropContent(0, tileentitychest, world, tileentitychest.getPos()); this.dropContent(0, tileentitychest, world, tileentitychest.getPos());
} }
super.breakBlock(world, pos, blockState); super.breakBlock(world, pos, blockState);
} }
@ -219,7 +228,8 @@ public class BlockIronChest extends BlockContainer
i1 = itemstack.stackSize; i1 = itemstack.stackSize;
} }
itemstack.stackSize -= i1; itemstack.stackSize -= i1;
EntityItem entityitem = new EntityItem(world, pos.getX() + f, (float) pos.getY() + (newSize > 0 ? 1 : 0) + f1, pos.getZ() + f2, new ItemStack(itemstack.getItem(), i1, itemstack.getMetadata())); EntityItem entityitem = new EntityItem(world, pos.getX() + f, (float) pos.getY() + (newSize > 0 ? 1 : 0) + f1, pos.getZ() + f2,
new ItemStack(itemstack.getItem(), i1, itemstack.getMetadata()));
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;
@ -249,13 +259,13 @@ public class BlockIronChest extends BlockContainer
} }
@Override @Override
public boolean hasComparatorInputOverride() public boolean hasComparatorInputOverride(IBlockState state)
{ {
return true; return true;
} }
@Override @Override
public int getComparatorInputOverride(World world, BlockPos pos) public int getComparatorInputOverride(IBlockState blockState, World world, BlockPos pos)
{ {
TileEntity te = world.getTileEntity(pos); TileEntity te = world.getTileEntity(pos);
if (te instanceof IInventory) if (te instanceof IInventory)

View File

@ -14,14 +14,16 @@ import static cpw.mods.ironchest.IronChestType.IRON;
import static cpw.mods.ironchest.IronChestType.OBSIDIAN; import static cpw.mods.ironchest.IronChestType.OBSIDIAN;
import static cpw.mods.ironchest.IronChestType.SILVER; import static cpw.mods.ironchest.IronChestType.SILVER;
import static cpw.mods.ironchest.IronChestType.WOOD; import static cpw.mods.ironchest.IronChestType.WOOD;
import cpw.mods.ironchest.client.ModelHelper;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.registry.GameRegistry;
import cpw.mods.ironchest.client.ModelHelper;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
public enum ChestChangerType { public enum ChestChangerType
{
IRONGOLD(IRON, GOLD, "ironGoldUpgrade", "Iron to Gold Chest Upgrade", "mmm", "msm", "mmm"), IRONGOLD(IRON, GOLD, "ironGoldUpgrade", "Iron to Gold Chest Upgrade", "mmm", "msm", "mmm"),
GOLDDIAMOND(GOLD, DIAMOND, "goldDiamondUpgrade", "Gold to Diamond Chest Upgrade", "GGG", "msm", "GGG"), GOLDDIAMOND(GOLD, DIAMOND, "goldDiamondUpgrade", "Gold to Diamond Chest Upgrade", "GGG", "msm", "GGG"),
COPPERSILVER(COPPER, SILVER, "copperSilverUpgrade", "Copper to Silver Chest Upgrade", "mmm", "msm", "mmm"), COPPERSILVER(COPPER, SILVER, "copperSilverUpgrade", "Copper to Silver Chest Upgrade", "mmm", "msm", "mmm"),
@ -48,8 +50,9 @@ public enum ChestChangerType {
this.recipe = recipe; this.recipe = recipe;
} }
public IronChestType getSource(){ public IronChestType getSource()
return source; {
return this.source;
} }
public boolean canUpgrade(IronChestType from) public boolean canUpgrade(IronChestType from)
@ -64,22 +67,25 @@ public enum ChestChangerType {
public ItemChestChanger buildItem() public ItemChestChanger buildItem()
{ {
item = new ItemChestChanger(this); this.item = new ItemChestChanger(this);
GameRegistry.registerItem(item, itemName); GameRegistry.registerItem(this.item, this.itemName);
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
ModelHelper.registerItem(item, "ironchest:" + itemName); {
return item; ModelHelper.registerItem(this.item, "ironchest:" + this.itemName);
}
return this.item;
} }
public void addRecipes() public void addRecipes()
{ {
for (String sourceMat : source.getMatList()) for (String sourceMat : this.source.getMatList())
{ {
for (String targetMat : target.getMatList()) for (String targetMat : this.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', "blockGlass", 'O', Blocks.obsidian); IronChestType.addRecipe(new ItemStack(this.item), this.recipe, 'm', targetMaterial, 's', sourceMaterial, 'G', "blockGlass", 'O',
Blocks.obsidian);
} }
} }
} }

View File

@ -12,11 +12,12 @@ package cpw.mods.ironchest;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler; import net.minecraftforge.fml.common.network.IGuiHandler;
public class CommonProxy implements IGuiHandler { public class CommonProxy implements IGuiHandler
{
public void registerRenderInformation() public void registerRenderInformation()
{ {

View File

@ -19,47 +19,48 @@ import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ChestContainer(isLargeChest = true) @ChestContainer(isLargeChest = true)
public class ContainerIronChest extends Container { public class ContainerIronChest extends Container
{
private IronChestType type; private IronChestType type;
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; this.chest = chestInventory;
player = ((InventoryPlayer) playerInventory).player; this.player = ((InventoryPlayer) playerInventory).player;
this.type = type; this.type = type;
chestInventory.openInventory(player); chestInventory.openInventory(this.player);
layoutContainer(playerInventory, chestInventory, type, xSize, ySize); this.layoutContainer(playerInventory, chestInventory, type, xSize, ySize);
} }
@Override @Override
public boolean canInteractWith(EntityPlayer player) public boolean canInteractWith(EntityPlayer player)
{ {
return chest.isUseableByPlayer(player); return this.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) this.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 < this.type.size)
{ {
if (!mergeItemStack(itemstack1, type.size, inventorySlots.size(), true)) if (!this.mergeItemStack(itemstack1, this.type.size, this.inventorySlots.size(), true))
{ {
return null; return null;
} }
} }
else if (!type.acceptsStack(itemstack1)) else if (!this.type.acceptsStack(itemstack1))
{ {
return null; return null;
} }
else if (!mergeItemStack(itemstack1, 0, type.size, false)) else if (!this.mergeItemStack(itemstack1, 0, this.type.size, false))
{ {
return null; return null;
} }
@ -79,19 +80,22 @@ public class ContainerIronChest extends Container {
public void onContainerClosed(EntityPlayer entityplayer) public void onContainerClosed(EntityPlayer entityplayer)
{ {
super.onContainerClosed(entityplayer); super.onContainerClosed(entityplayer);
chest.closeInventory(entityplayer); this.chest.closeInventory(entityplayer);
} }
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)); {
} else { this.addSlotToContainer(type.makeSlot(chestInventory, 0, 12 + 4 * 18, 8 + 2 * 18));
}
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)); this.addSlotToContainer(type.makeSlot(chestInventory, chestCol + chestRow * type.getRowLength(), 12 + chestCol * 18, 8 + chestRow * 18));
} }
} }
} }
@ -101,25 +105,26 @@ public class ContainerIronChest extends Container {
{ {
for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++) for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++)
{ {
addSlotToContainer(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, ySize - (4 - playerInvRow) * 18 this.addSlotToContainer(
- 10)); 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)); this.addSlotToContainer(new Slot(playerInventory, hotbarSlot, leftCol + hotbarSlot * 18, ySize - 24));
} }
} }
public EntityPlayer getPlayer() public EntityPlayer getPlayer()
{ {
return player; return this.player;
} }
@ChestContainer.RowSizeCallback @ChestContainer.RowSizeCallback
public int getNumColumns() { public int getNumColumns()
return type.getRowLength(); {
return this.type.getRowLength();
} }
} }

View File

@ -10,14 +10,7 @@
******************************************************************************/ ******************************************************************************/
package cpw.mods.ironchest; package cpw.mods.ironchest;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderFireball;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.projectile.EntitySmallFireball;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.registry.IRenderFactory;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.Mod.Instance;
@ -25,14 +18,9 @@ import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
@Mod(modid = "IronChest", name = "Iron Chests", dependencies = "required-after:Forge@[11.15.0,12.0]", acceptedMinecraftVersions="[1.8,1.8.9]") @Mod(modid = "IronChest", name = "Iron Chests", dependencies = "required-after:Forge@[12.16,)", acceptedMinecraftVersions = "[1.9]")
public class IronChest public class IronChest
{ {
public static BlockIronChest ironChestBlock; public static BlockIronChest ironChestBlock;

View File

@ -2,7 +2,7 @@ package cpw.mods.ironchest;
import net.minecraft.entity.ai.EntityAIOcelotSit; import net.minecraft.entity.ai.EntityAIOcelotSit;
import net.minecraft.entity.passive.EntityOcelot; import net.minecraft.entity.passive.EntityOcelot;
import net.minecraft.util.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
public class IronChestAIOcelotSit extends EntityAIOcelotSit public class IronChestAIOcelotSit extends EntityAIOcelotSit

View File

@ -51,6 +51,7 @@ public enum IronChestType implements IStringSerializable
{ {
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, IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List<String> mats,
Class<? extends TileEntityIronChest> clazz, Item itemFilter, String... recipes) Class<? extends TileEntityIronChest> clazz, Item itemFilter, String... recipes)
{ {
@ -64,23 +65,23 @@ public enum IronChestType implements IStringSerializable
this.itemFilter = itemFilter; this.itemFilter = itemFilter;
this.recipes = recipes; this.recipes = recipes;
this.matList = new ArrayList<String>(); this.matList = new ArrayList<String>();
matList.addAll(mats); this.matList.addAll(mats);
} }
@Override @Override
public String getName() public String getName()
{ {
return name().toLowerCase(); return this.name().toLowerCase();
} }
public String getModelTexture() public String getModelTexture()
{ {
return modelTexture; return this.modelTexture;
} }
public int getTextureRow() public int getTextureRow()
{ {
return textureRow; return this.textureRow;
} }
public static TileEntityIronChest makeEntity(int metadata) public static TileEntityIronChest makeEntity(int metadata)
@ -116,7 +117,10 @@ public enum IronChestType implements IStringSerializable
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);//TODO fix this!! // if (typ.isValidForCreativeMode()) GameRegistry.registerCustomItemStack(typ.friendlyName, chest);//TODO fix this!!
if (typ.tieredChest) previous = chest; if (typ.tieredChest)
{
previous = chest;
}
} }
} }
@ -163,12 +167,12 @@ public enum IronChestType implements IStringSerializable
public int getRowCount() public int getRowCount()
{ {
return size / rowLength; return this.size / this.rowLength;
} }
public int getRowLength() public int getRowLength()
{ {
return rowLength; return this.rowLength;
} }
public boolean isTransparent() public boolean isTransparent()
@ -178,7 +182,7 @@ public enum IronChestType implements IStringSerializable
public List<String> getMatList() public List<String> getMatList()
{ {
return matList; return this.matList;
} }
public static int validateMeta(int i) public static int validateMeta(int i)
@ -195,7 +199,7 @@ public enum IronChestType implements IStringSerializable
public boolean isValidForCreativeMode() public boolean isValidForCreativeMode()
{ {
return validateMeta(ordinal()) == ordinal(); return validateMeta(this.ordinal()) == this.ordinal();
} }
public boolean isExplosionResistant() public boolean isExplosionResistant()
@ -210,7 +214,7 @@ public enum IronChestType implements IStringSerializable
public boolean acceptsStack(ItemStack itemstack) public boolean acceptsStack(ItemStack itemstack)
{ {
return itemFilter == null || itemstack == null || itemstack.getItem() == itemFilter; return this.itemFilter == null || itemstack == null || itemstack.getItem() == this.itemFilter;
} }
public void adornItemDrop(ItemStack item) public void adornItemDrop(ItemStack item)

View File

@ -11,14 +11,17 @@
package cpw.mods.ironchest; package cpw.mods.ironchest;
import net.minecraft.block.BlockChest; import net.minecraft.block.BlockChest;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest; import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.BlockPos; import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
public class ItemChestChanger extends Item public class ItemChestChanger extends Item
@ -35,73 +38,114 @@ public class ItemChestChanger extends Item
} }
@Override @Override
public boolean onItemUseFirst (ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{ {
if (world.isRemote) if (worldIn.isRemote)
return false; {
if(this.type.canUpgrade(IronChestType.WOOD)){ return EnumActionResult.PASS;
if(!(world.getBlockState(pos).getBlock() instanceof BlockChest)){
return false;
} }
}else{ if (this.type.canUpgrade(IronChestType.WOOD))
if(world.getBlockState(pos) != IronChest.ironChestBlock.getStateFromMeta(IronChestType.valueOf(type.getSource().getName().toUpperCase()).ordinal())){ {
return false; if (!(worldIn.getBlockState(pos).getBlock() instanceof BlockChest))
{
return EnumActionResult.PASS;
} }
} }
TileEntity te = world.getTileEntity(pos); else
{
if (worldIn.getBlockState(pos) != IronChest.ironChestBlock
.getStateFromMeta(IronChestType.valueOf(this.type.getSource().getName().toUpperCase()).ordinal()))
{
return EnumActionResult.PASS;
}
}
TileEntity te = worldIn.getTileEntity(pos);
TileEntityIronChest newchest = new TileEntityIronChest(); TileEntityIronChest newchest = new TileEntityIronChest();
ItemStack[] chestContents = new ItemStack[27]; ItemStack[] chestContents = new ItemStack[27];
int chestFacing = 0;
if (te != null) if (te != null)
{ {
if (te instanceof TileEntityIronChest) if (te instanceof TileEntityIronChest)
{ {
chestContents = ((TileEntityIronChest) te).chestContents; chestContents = ((TileEntityIronChest) te).chestContents;
chestFacing = ((TileEntityIronChest) te).getFacing();
newchest = IronChestType.makeEntity(this.getTargetChestOrdinal(this.type.ordinal())); newchest = IronChestType.makeEntity(this.getTargetChestOrdinal(this.type.ordinal()));
if (newchest == null) if (newchest == null)
return false; {
return EnumActionResult.PASS;
}
} }
else if (te instanceof TileEntityChest) else if (te instanceof TileEntityChest)
{ {
IBlockState chestState = worldIn.getBlockState(pos);
EnumFacing orientation = chestState.getValue(BlockChest.FACING);
if (orientation == EnumFacing.NORTH)
{
chestFacing = 2;
}
if (orientation == EnumFacing.EAST)
{
chestFacing = 5;
}
if (orientation == EnumFacing.SOUTH)
{
chestFacing = 3;
}
if (orientation == EnumFacing.WEST)
{
chestFacing = 4;
}
if (((TileEntityChest) te).numPlayersUsing > 0) if (((TileEntityChest) te).numPlayersUsing > 0)
return false; {
if (!getType().canUpgrade(IronChestType.WOOD)) return EnumActionResult.PASS;
return false; }
if (!this.getType().canUpgrade(IronChestType.WOOD))
{
return EnumActionResult.PASS;
}
chestContents = new ItemStack[((TileEntityChest) te).getSizeInventory()]; chestContents = new ItemStack[((TileEntityChest) te).getSizeInventory()];
for (int i = 0; i < chestContents.length; i++) for (int i = 0; i < chestContents.length; i++)
{
chestContents[i] = ((TileEntityChest) te).getStackInSlot(i); chestContents[i] = ((TileEntityChest) te).getStackInSlot(i);
}
newchest = IronChestType.makeEntity(this.getTargetChestOrdinal(this.type.ordinal())); newchest = IronChestType.makeEntity(this.getTargetChestOrdinal(this.type.ordinal()));
} }
} }
te.updateContainingBlockInfo(); te.updateContainingBlockInfo();
if (te instanceof TileEntityChest) if (te instanceof TileEntityChest)
{
((TileEntityChest) te).checkForAdjacentChests(); ((TileEntityChest) te).checkForAdjacentChests();
}
world.removeTileEntity(pos); worldIn.removeTileEntity(pos);
world.setBlockToAir(pos); worldIn.setBlockToAir(pos);
world.setTileEntity(pos, newchest); IBlockState iblockstate = IronChest.ironChestBlock.getStateFromMeta(newchest.getType().ordinal());
world.setBlockState(pos, IronChest.ironChestBlock.getStateFromMeta(newchest.getType().ordinal()), 3);
world.markBlockForUpdate(pos); worldIn.setTileEntity(pos, newchest);
worldIn.setBlockState(pos, iblockstate, 3);
TileEntity te2 = world.getTileEntity(pos); worldIn.notifyBlockUpdate(pos, iblockstate, iblockstate, 3);
TileEntity te2 = worldIn.getTileEntity(pos);
if (te2 instanceof TileEntityIronChest) if (te2 instanceof TileEntityIronChest)
{ {
((TileEntityIronChest) te2).setContents(chestContents); ((TileEntityIronChest) te2).setContents(chestContents);
((TileEntityIronChest) te2).setFacing((byte) chestFacing);
} }
stack.stackSize = player.capabilities.isCreativeMode ? stack.stackSize : stack.stackSize - 1; stack.stackSize = playerIn.capabilities.isCreativeMode ? stack.stackSize : stack.stackSize - 1;
return true; return EnumActionResult.SUCCESS;
} }
public int getTargetChestOrdinal(int sourceOrdinal) public int getTargetChestOrdinal(int sourceOrdinal)
{ {
return type.getTarget(); return this.type.getTarget();
} }
public ChestChangerType getType() public ChestChangerType getType()
{ {
return type; return this.type;
} }
} }

View File

@ -1,28 +1,27 @@
package cpw.mods.ironchest; package cpw.mods.ironchest;
import java.util.List;
import net.minecraft.entity.ai.EntityAIOcelotSit;
import net.minecraft.entity.ai.EntityAITasks;
import net.minecraft.entity.passive.EntityOcelot; import net.minecraft.entity.passive.EntityOcelot;
import net.minecraftforge.event.entity.living.LivingEvent; import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class OcelotsSitOnChestsHandler { public class OcelotsSitOnChestsHandler
{
@SubscribeEvent @SubscribeEvent
public void changeSittingTaskForOcelots(LivingEvent.LivingUpdateEvent evt) public void changeSittingTaskForOcelots(LivingEvent.LivingUpdateEvent evt)
{ {
if (evt.entityLiving.ticksExisted < 5 && evt.entityLiving instanceof EntityOcelot) if (evt.entityLiving.ticksExisted < 5 && evt.entityLiving instanceof EntityOcelot)
{ {
EntityOcelot ocelot = (EntityOcelot) evt.entityLiving; // EntityOcelot ocelot = (EntityOcelot) evt.entityLiving;
List<EntityAITasks.EntityAITaskEntry> tasks = ocelot.tasks.taskEntries; // Set<EntityAITasks.EntityAITaskEntry> tasks = ocelot.tasks.taskEntries;
for (EntityAITasks.EntityAITaskEntry task : tasks) { // for (EntityAITasks.EntityAITaskEntry task : tasks)
if (task.priority == 6 && (task.action instanceof EntityAIOcelotSit) && !(task.action instanceof IronChestAIOcelotSit)) { // {
task.action = new IronChestAIOcelotSit(ocelot, 0.4F); // if (task.priority == 6 && (task.action instanceof EntityAIOcelotSit) && !(task.action instanceof IronChestAIOcelotSit))
} // {
} // task.action = new IronChestAIOcelotSit(ocelot, 0.4F);
// }
// }
} }
} }
} }

View File

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

View File

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

View File

@ -5,38 +5,45 @@ import net.minecraft.init.Items;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString; import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.StatCollector; import net.minecraft.util.text.translation.I18n;
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(I18n.translateToLocal("book.ironchest:dirtchest9000.title")));
NBTTagList pages = new NBTTagList(); NBTTagList pages = new NBTTagList();
pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page1"))); pages.appendTag(new NBTTagString(I18n.translateToLocal("book.ironchest:dirtchest9000.page1")));
pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page2"))); pages.appendTag(new NBTTagString(I18n.translateToLocal("book.ironchest:dirtchest9000.page2")));
pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page3"))); pages.appendTag(new NBTTagString(I18n.translateToLocal("book.ironchest:dirtchest9000.page3")));
pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page4"))); pages.appendTag(new NBTTagString(I18n.translateToLocal("book.ironchest:dirtchest9000.page4")));
pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page5"))); pages.appendTag(new NBTTagString(I18n.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()); {
this.setInventorySlotContents(0, dirtChest9000GuideBook.copy());
} }
} }
@Override @Override
public void removeAdornments() public void removeAdornments()
{ {
if (chestContents[0] != null && chestContents[0].isItemEqual(dirtChest9000GuideBook)) { if (this.chestContents[0] != null && this.chestContents[0].isItemEqual(dirtChest9000GuideBook))
chestContents[0] = null; {
this.chestContents[0] = null;
} }
} }
} }

View File

@ -10,7 +10,8 @@
******************************************************************************/ ******************************************************************************/
package cpw.mods.ironchest; package cpw.mods.ironchest;
public class TileEntityGoldChest extends TileEntityIronChest { public class TileEntityGoldChest extends TileEntityIronChest
{
public TileEntityGoldChest() public TileEntityGoldChest()
{ {

View File

@ -14,9 +14,11 @@ import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
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.init.SoundEvents;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -24,11 +26,12 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetworkManager; import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet; import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntityLockable; import net.minecraft.tileentity.TileEntityLockable;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable; import net.minecraft.util.ITickable;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraftforge.common.util.Constants; import net.minecraftforge.common.util.Constants;
public class TileEntityIronChest extends TileEntityLockable implements ITickable, IInventory public class TileEntityIronChest extends TileEntityLockable implements ITickable, IInventory
@ -54,32 +57,32 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
{ {
super(); super();
this.type = type; this.type = type;
this.chestContents = new ItemStack[getSizeInventory()]; this.chestContents = new ItemStack[this.getSizeInventory()];
this.topStacks = new ItemStack[8]; this.topStacks = new ItemStack[8];
} }
public ItemStack[] getContents() public ItemStack[] getContents()
{ {
return chestContents; return this.chestContents;
} }
public void setContents(ItemStack[] contents) public void setContents(ItemStack[] contents)
{ {
chestContents = new ItemStack[getSizeInventory()]; this.chestContents = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < contents.length; i++) for (int i = 0; i < contents.length; i++)
{ {
if (i < chestContents.length) if (i < this.chestContents.length)
{ {
chestContents[i] = contents[i]; this.chestContents[i] = contents[i];
} }
} }
inventoryTouched = true; this.inventoryTouched = true;
} }
@Override @Override
public int getSizeInventory() public int getSizeInventory()
{ {
return type.size; return this.type.size;
} }
public int getFacing() public int getFacing()
@ -89,121 +92,125 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
public IronChestType getType() public IronChestType getType()
{ {
return type; return this.type;
} }
@Override @Override
public ItemStack getStackInSlot(int i) public ItemStack getStackInSlot(int i)
{ {
inventoryTouched = true; this.inventoryTouched = true;
return chestContents[i]; return this.chestContents[i];
} }
@Override @Override
public void markDirty() public void markDirty()
{ {
super.markDirty(); super.markDirty();
sortTopStacks(); this.sortTopStacks();
} }
protected void sortTopStacks() protected void sortTopStacks()
{ {
if (!type.isTransparent() || (worldObj != null && worldObj.isRemote)) if (!this.type.isTransparent() || (this.worldObj != null && this.worldObj.isRemote))
{ {
return; return;
} }
ItemStack[] tempCopy = new ItemStack[getSizeInventory()]; ItemStack[] tempCopy = new ItemStack[this.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 < this.getSizeInventory(); i++)
{ {
if (chestContents[i] != null) if (this.chestContents[i] != null)
{ {
for (int j = 0; j < compressedIdx; j++) for (int j = 0; j < compressedIdx; j++)
{ {
if (tempCopy[j].isItemEqual(chestContents[i])) if (tempCopy[j].isItemEqual(this.chestContents[i]))
{ {
tempCopy[j].stackSize += chestContents[i].stackSize; tempCopy[j].stackSize += this.chestContents[i].stackSize;
continue mainLoop; continue mainLoop;
} }
} }
tempCopy[compressedIdx++] = chestContents[i].copy(); tempCopy[compressedIdx++] = this.chestContents[i].copy();
hasStuff = true; hasStuff = true;
} }
} }
if (!hasStuff && hadStuff) if (!hasStuff && this.hadStuff)
{ {
hadStuff = false; this.hadStuff = false;
for (int i = 0; i < topStacks.length; i++) for (int i = 0; i < this.topStacks.length; i++)
{ {
topStacks[i] = null; this.topStacks[i] = null;
} }
if (worldObj != null) if (this.worldObj != null)
{ {
worldObj.markBlockForUpdate(pos); IBlockState iblockstate = this.worldObj.getBlockState(this.pos);
this.worldObj.notifyBlockUpdate(this.pos, iblockstate, iblockstate, 3);
} }
return; return;
} }
hadStuff = true; this.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 (ItemStack element : tempCopy)
{ {
if (tempCopy[i] != null && tempCopy[i].stackSize > 0) if (element != null && element.stackSize > 0)
{ {
topStacks[p++] = tempCopy[i]; this.topStacks[p++] = element;
if (p == topStacks.length) if (p == this.topStacks.length)
{ {
break; break;
} }
} }
} }
for (int i = p; i < topStacks.length; i++) for (int i = p; i < this.topStacks.length; i++)
{ {
topStacks[i] = null; this.topStacks[i] = null;
} }
if (worldObj != null) if (this.worldObj != null)
{ {
worldObj.markBlockForUpdate(pos); IBlockState iblockstate = this.worldObj.getBlockState(this.pos);
this.worldObj.notifyBlockUpdate(this.pos, iblockstate, iblockstate, 3);
} }
} }
@Override @Override
public ItemStack decrStackSize(int i, int j) public ItemStack decrStackSize(int i, int j)
{ {
if (chestContents[i] != null) if (this.chestContents[i] != null)
{ {
if (chestContents[i].stackSize <= j) if (this.chestContents[i].stackSize <= j)
{ {
ItemStack itemstack = chestContents[i]; ItemStack itemstack = this.chestContents[i];
chestContents[i] = null; this.chestContents[i] = null;
markDirty(); this.markDirty();
return itemstack; return itemstack;
} }
ItemStack itemstack1 = chestContents[i].splitStack(j); ItemStack itemstack1 = this.chestContents[i].splitStack(j);
if (chestContents[i].stackSize == 0) if (this.chestContents[i].stackSize == 0)
{ {
chestContents[i] = null; this.chestContents[i] = null;
} }
markDirty(); this.markDirty();
return itemstack1; return itemstack1;
} else }
else
{ {
return null; return null;
} }
@ -212,18 +219,18 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
@Override @Override
public void setInventorySlotContents(int i, ItemStack itemstack) public void setInventorySlotContents(int i, ItemStack itemstack)
{ {
chestContents[i] = itemstack; this.chestContents[i] = itemstack;
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit())
{ {
itemstack.stackSize = getInventoryStackLimit(); itemstack.stackSize = this.getInventoryStackLimit();
} }
markDirty(); this.markDirty();
} }
@Override @Override
public String getName() public String getName()
{ {
return this.hasCustomName() ? this.customName : type.name(); return this.hasCustomName() ? this.customName : this.type.name();
} }
@Override @Override
@ -243,7 +250,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
super.readFromNBT(nbttagcompound); super.readFromNBT(nbttagcompound);
NBTTagList nbttaglist = nbttagcompound.getTagList("Items", Constants.NBT.TAG_COMPOUND); NBTTagList nbttaglist = nbttagcompound.getTagList("Items", Constants.NBT.TAG_COMPOUND);
this.chestContents = new ItemStack[getSizeInventory()]; this.chestContents = new ItemStack[this.getSizeInventory()];
if (nbttagcompound.hasKey("CustomName", Constants.NBT.TAG_STRING)) if (nbttagcompound.hasKey("CustomName", Constants.NBT.TAG_STRING))
{ {
@ -254,13 +261,13 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
{ {
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
int j = nbttagcompound1.getByte("Slot") & 0xff; int j = nbttagcompound1.getByte("Slot") & 0xff;
if (j >= 0 && j < chestContents.length) if (j >= 0 && j < this.chestContents.length)
{ {
chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); this.chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
} }
} }
facing = nbttagcompound.getByte("facing"); this.facing = nbttagcompound.getByte("facing");
sortTopStacks(); this.sortTopStacks();
} }
@Override @Override
@ -268,19 +275,19 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
{ {
super.writeToNBT(nbttagcompound); super.writeToNBT(nbttagcompound);
NBTTagList nbttaglist = new NBTTagList(); NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < chestContents.length; i++) for (int i = 0; i < this.chestContents.length; i++)
{ {
if (chestContents[i] != null) if (this.chestContents[i] != null)
{ {
NBTTagCompound nbttagcompound1 = new NBTTagCompound(); NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte) i); nbttagcompound1.setByte("Slot", (byte) i);
chestContents[i].writeToNBT(nbttagcompound1); this.chestContents[i].writeToNBT(nbttagcompound1);
nbttaglist.appendTag(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1);
} }
} }
nbttagcompound.setTag("Items", nbttaglist); nbttagcompound.setTag("Items", nbttaglist);
nbttagcompound.setByte("facing", facing); nbttagcompound.setByte("facing", this.facing);
if (this.hasCustomName()) if (this.hasCustomName())
{ {
@ -297,26 +304,28 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
@Override @Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) public boolean isUseableByPlayer(EntityPlayer entityplayer)
{ {
if (worldObj == null) if (this.worldObj == null)
{ {
return true; return true;
} }
if (worldObj.getTileEntity(pos) != this) if (this.worldObj.getTileEntity(this.pos) != this)
{ {
return false; return false;
} }
return entityplayer.getDistanceSq(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D) <= 64D; return entityplayer.getDistanceSq(this.pos.getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D) <= 64D;
} }
@Override @Override
public void update() public void update()
{ {
// Resynchronize clients with the server state // Resynchronize clients with the server state
if (worldObj != null && !this.worldObj.isRemote && this.numUsingPlayers != 0 && (this.ticksSinceSync + pos.getX() + pos.getY() + pos.getZ()) % 200 == 0) if (this.worldObj != null && !this.worldObj.isRemote && this.numUsingPlayers != 0
&& (this.ticksSinceSync + this.pos.getX() + this.pos.getY() + this.pos.getZ()) % 200 == 0)
{ {
this.numUsingPlayers = 0; this.numUsingPlayers = 0;
float var1 = 5.0F; float var1 = 5.0F;
List<EntityPlayer> var2 = this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(pos.getX() - var1, pos.getY() - var1, pos.getZ() - var1, pos.getX() + 1 + var1, pos.getY() + 1 + var1, pos.getZ() + 1 + var1)); List<EntityPlayer> var2 = this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(this.pos.getX() - var1, this.pos.getY() - var1,
this.pos.getZ() - var1, this.pos.getX() + 1 + var1, this.pos.getY() + 1 + var1, this.pos.getZ() + 1 + var1));
for (EntityPlayer var4 : var2) for (EntityPlayer var4 : var2)
{ {
@ -327,49 +336,52 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
} }
} }
if (worldObj != null && !worldObj.isRemote && ticksSinceSync < 0) if (this.worldObj != null && !this.worldObj.isRemote && this.ticksSinceSync < 0)
{ {
worldObj.addBlockEvent(pos, IronChest.ironChestBlock, 3, ((numUsingPlayers << 3) & 0xF8) | (facing & 0x7)); this.worldObj.addBlockEvent(this.pos, IronChest.ironChestBlock, 3, ((this.numUsingPlayers << 3) & 0xF8) | (this.facing & 0x7));
} }
if (!worldObj.isRemote && inventoryTouched) if (!this.worldObj.isRemote && this.inventoryTouched)
{ {
inventoryTouched = false; this.inventoryTouched = false;
sortTopStacks(); this.sortTopStacks();
} }
this.ticksSinceSync++; this.ticksSinceSync++;
prevLidAngle = lidAngle; this.prevLidAngle = this.lidAngle;
float f = 0.1F; float f = 0.1F;
if (numUsingPlayers > 0 && lidAngle == 0.0F) if (this.numUsingPlayers > 0 && this.lidAngle == 0.0F)
{ {
double d = pos.getX() + 0.5D; double d = this.pos.getX() + 0.5D;
double d1 = pos.getZ() + 0.5D; double d1 = this.pos.getZ() + 0.5D;
worldObj.playSoundEffect(d, pos.getY() + 0.5D, d1, "random.chestopen", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F); this.worldObj.playSound((EntityPlayer) null, d, this.pos.getY() + 0.5D, d1, SoundEvents.block_chest_open, SoundCategory.BLOCKS, 0.5F,
this.worldObj.rand.nextFloat() * 0.1F + 0.9F);
} }
if (numUsingPlayers == 0 && lidAngle > 0.0F || numUsingPlayers > 0 && lidAngle < 1.0F) if (this.numUsingPlayers == 0 && this.lidAngle > 0.0F || this.numUsingPlayers > 0 && this.lidAngle < 1.0F)
{ {
float f1 = lidAngle; float f1 = this.lidAngle;
if (numUsingPlayers > 0) if (this.numUsingPlayers > 0)
{ {
lidAngle += f; this.lidAngle += f;
} else
{
lidAngle -= f;
} }
if (lidAngle > 1.0F) else
{ {
lidAngle = 1.0F; this.lidAngle -= f;
}
if (this.lidAngle > 1.0F)
{
this.lidAngle = 1.0F;
} }
float f2 = 0.5F; float f2 = 0.5F;
if (lidAngle < f2 && f1 >= f2) if (this.lidAngle < f2 && f1 >= f2)
{ {
double d2 = pos.getX() + 0.5D; double d2 = this.pos.getX() + 0.5D;
double d3 = pos.getZ() + 0.5D; double d3 = this.pos.getZ() + 0.5D;
worldObj.playSoundEffect(d2, pos.getY() + 0.5D, d3, "random.chestclosed", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F); this.worldObj.playSound((EntityPlayer) null, d2, this.pos.getY() + 0.5D, d3, SoundEvents.block_chest_close, SoundCategory.BLOCKS, 0.5F,
this.worldObj.rand.nextFloat() * 0.1F + 0.9F);
} }
if (lidAngle < 0.0F) if (this.lidAngle < 0.0F)
{ {
lidAngle = 0.0F; this.lidAngle = 0.0F;
} }
} }
} }
@ -379,14 +391,16 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
{ {
if (i == 1) if (i == 1)
{ {
numUsingPlayers = j; this.numUsingPlayers = j;
} else if (i == 2) }
else if (i == 2)
{ {
facing = (byte) j; this.facing = (byte) j;
} else if (i == 3) }
else if (i == 3)
{ {
facing = (byte) (j & 0x7); this.facing = (byte) (j & 0x7);
numUsingPlayers = (j & 0xF8) >> 3; this.numUsingPlayers = (j & 0xF8) >> 3;
} }
return true; return true;
} }
@ -394,23 +408,23 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
@Override @Override
public void openInventory(EntityPlayer player) public void openInventory(EntityPlayer player)
{ {
if (worldObj == null) if (this.worldObj == null)
{ {
return; return;
} }
numUsingPlayers++; this.numUsingPlayers++;
worldObj.addBlockEvent(pos, IronChest.ironChestBlock, 1, numUsingPlayers); this.worldObj.addBlockEvent(this.pos, IronChest.ironChestBlock, 1, this.numUsingPlayers);
} }
@Override @Override
public void closeInventory(EntityPlayer player) public void closeInventory(EntityPlayer player)
{ {
if (worldObj == null) if (this.worldObj == null)
{ {
return; return;
} }
numUsingPlayers--; this.numUsingPlayers--;
worldObj.addBlockEvent(pos, IronChest.ironChestBlock, 1, numUsingPlayers); this.worldObj.addBlockEvent(this.pos, IronChest.ironChestBlock, 1, this.numUsingPlayers);
} }
public void setFacing(byte facing2) public void setFacing(byte facing2)
@ -420,17 +434,17 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
public ItemStack[] getTopItemStacks() public ItemStack[] getTopItemStacks()
{ {
return topStacks; return this.topStacks;
} }
public TileEntityIronChest updateFromMetadata(int l) public TileEntityIronChest updateFromMetadata(int l)
{ {
if (worldObj != null && worldObj.isRemote) if (this.worldObj != null && this.worldObj.isRemote)
{ {
if (l != type.ordinal()) if (l != this.type.ordinal())
{ {
worldObj.setTileEntity(pos, IronChestType.makeEntity(l)); this.worldObj.setTileEntity(this.pos, IronChestType.makeEntity(l));
return (TileEntityIronChest) worldObj.getTileEntity(pos); return (TileEntityIronChest) this.worldObj.getTileEntity(this.pos);
} }
} }
return this; return this;
@ -441,9 +455,9 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
{ {
NBTTagCompound nbt = new NBTTagCompound(); NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger("type", getType().ordinal()); nbt.setInteger("type", this.getType().ordinal());
nbt.setByte("facing", facing); nbt.setByte("facing", this.facing);
ItemStack[] stacks = buildItemStackDataList(); ItemStack[] stacks = this.buildItemStackDataList();
if (stacks != null) if (stacks != null)
{ {
NBTTagList nbttaglist = new NBTTagList(); NBTTagList nbttaglist = new NBTTagList();
@ -460,20 +474,20 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
nbt.setTag("stacks", nbttaglist); nbt.setTag("stacks", nbttaglist);
} }
return new S35PacketUpdateTileEntity(pos, 0, nbt); return new SPacketUpdateTileEntity(this.pos, 0, nbt);
} }
@Override @Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt)
{ {
if (pkt.getTileEntityType() == 0) if (pkt.getTileEntityType() == 0)
{ {
NBTTagCompound nbt = pkt.getNbtCompound(); NBTTagCompound nbt = pkt.getNbtCompound();
type = IronChestType.values()[nbt.getInteger("type")]; this.type = IronChestType.values()[nbt.getInteger("type")];
facing = nbt.getByte("facing"); this.facing = nbt.getByte("facing");
NBTTagList tagList = nbt.getTagList("stacks", Constants.NBT.TAG_COMPOUND); NBTTagList tagList = nbt.getTagList("stacks", Constants.NBT.TAG_COMPOUND);
ItemStack[] stacks = new ItemStack[topStacks.length]; ItemStack[] stacks = new ItemStack[this.topStacks.length];
for (int i = 0; i < stacks.length; i++) for (int i = 0; i < stacks.length; i++)
{ {
@ -485,17 +499,18 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
} }
} }
if (type.isTransparent() && stacks != null) if (this.type.isTransparent() && stacks != null)
{ {
int pos = 0; int pos = 0;
for (int i = 0; i < topStacks.length; i++) for (int i = 0; i < this.topStacks.length; i++)
{ {
if (stacks[pos] != null) if (stacks[pos] != null)
{ {
topStacks[i] = stacks[pos]; this.topStacks[i] = stacks[pos];
} else }
else
{ {
topStacks[i] = null; this.topStacks[i] = null;
} }
pos++; pos++;
} }
@ -505,16 +520,17 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
public ItemStack[] buildItemStackDataList() public ItemStack[] buildItemStackDataList()
{ {
if (type.isTransparent()) if (this.type.isTransparent())
{ {
ItemStack[] sortList = new ItemStack[topStacks.length]; ItemStack[] sortList = new ItemStack[this.topStacks.length];
int pos = 0; int pos = 0;
for (ItemStack is : topStacks) for (ItemStack is : this.topStacks)
{ {
if (is != null) if (is != null)
{ {
sortList[pos++] = is; sortList[pos++] = is;
} else }
else
{ {
sortList[pos++] = null; sortList[pos++] = null;
} }
@ -532,7 +548,8 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
ItemStack var2 = this.chestContents[par1]; ItemStack var2 = this.chestContents[par1];
this.chestContents[par1] = null; this.chestContents[par1] = null;
return var2; return var2;
} else }
else
{ {
return null; return null;
} }
@ -541,18 +558,18 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
@Override @Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) public boolean isItemValidForSlot(int i, ItemStack itemstack)
{ {
return type.acceptsStack(itemstack); return this.type.acceptsStack(itemstack);
} }
public void rotateAround() public void rotateAround()
{ {
facing++; this.facing++;
if (facing > EnumFacing.EAST.ordinal()) if (this.facing > EnumFacing.EAST.ordinal())
{ {
facing = (byte) EnumFacing.NORTH.ordinal(); this.facing = (byte) EnumFacing.NORTH.ordinal();
} }
setFacing(facing); this.setFacing(this.facing);
worldObj.addBlockEvent(pos, IronChest.ironChestBlock, 2, facing); this.worldObj.addBlockEvent(this.pos, IronChest.ironChestBlock, 2, this.facing);
} }
public void wasPlaced(EntityLivingBase entityliving, ItemStack itemStack) public void wasPlaced(EntityLivingBase entityliving, ItemStack itemStack)
@ -598,7 +615,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
@Override @Override
public String getGuiID() public String getGuiID()
{ {
return "IronChest:" + type.name(); return "IronChest:" + this.type.name();
} }
@Override @Override

View File

@ -1,6 +1,7 @@
package cpw.mods.ironchest; package cpw.mods.ironchest;
public class TileEntityObsidianChest extends TileEntityIronChest { public class TileEntityObsidianChest extends TileEntityIronChest
{
public TileEntityObsidianChest() public TileEntityObsidianChest()
{ {

View File

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

View File

@ -4,7 +4,8 @@ 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;
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 par1iInventory, int par2, int par3, int par4, IronChestType type)
@ -16,6 +17,6 @@ public class ValidatingSlot extends Slot {
@Override @Override
public boolean isItemValid(ItemStack par1ItemStack) public boolean isItemValid(ItemStack par1ItemStack)
{ {
return type.acceptsStack(par1ItemStack); return this.type.acceptsStack(par1ItemStack);
} }
} }

View File

@ -10,21 +10,22 @@
******************************************************************************/ ******************************************************************************/
package cpw.mods.ironchest.client; package cpw.mods.ironchest.client;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemModelMesher;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import cpw.mods.ironchest.CommonProxy; import cpw.mods.ironchest.CommonProxy;
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;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemModelMesher;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.client.registry.ClientRegistry;
public class ClientProxy extends CommonProxy public class ClientProxy extends CommonProxy
{ {
@ -40,7 +41,7 @@ public class ClientProxy extends CommonProxy
{ {
Item chestItem = Item.getItemFromBlock(IronChest.ironChestBlock); Item chestItem = Item.getItemFromBlock(IronChest.ironChestBlock);
mesher.register(chestItem, chestType.ordinal(), new ModelResourceLocation("ironchest:chest_" + chestType.getName().toLowerCase(), "inventory")); mesher.register(chestItem, chestType.ordinal(), new ModelResourceLocation("ironchest:chest_" + chestType.getName().toLowerCase(), "inventory"));
ModelBakery.addVariantName(chestItem, "ironchest:chest_" + chestType.getName().toLowerCase()); ModelBakery.registerItemVariants(chestItem, new ResourceLocation("ironchest:chest_" + chestType.getName().toLowerCase()));
} }
} }
} }
@ -64,7 +65,8 @@ public class ClientProxy extends CommonProxy
if (te != null && te instanceof TileEntityIronChest) if (te != null && te instanceof TileEntityIronChest)
{ {
return GUIChest.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;
} }

View File

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

View File

@ -13,7 +13,7 @@ package cpw.mods.ironchest.client;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemModelMesher; import net.minecraft.client.renderer.ItemModelMesher;
import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;

View File

@ -35,9 +35,11 @@ public class TileEntityIronChestRenderer<T extends TileEntityIronChest> extends
{ {
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();
@ -52,19 +54,24 @@ public class TileEntityIronChestRenderer<T extends TileEntityIronChest> extends
public TileEntityIronChestRenderer(Class<T> type) public TileEntityIronChestRenderer(Class<T> type)
{ {
model = new ModelChest(); this.model = new ModelChest();
random = new Random(); this.random = new Random();
itemRenderer = new RenderEntityItem(Minecraft.getMinecraft().getRenderManager(), Minecraft.getMinecraft().getRenderItem()){ this.itemRenderer = new RenderEntityItem(Minecraft.getMinecraft().getRenderManager(), Minecraft.getMinecraft().getRenderItem()) {
@Override @Override
public int func_177078_a(ItemStack stack) { public int getModelCount(ItemStack stack)
{
return SignedBytes.saturatedCast(Math.min(stack.stackSize / 32, 15) + 1); return SignedBytes.saturatedCast(Math.min(stack.stackSize / 32, 15) + 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;
} }
}; };
@ -72,47 +79,58 @@ public class TileEntityIronChestRenderer<T extends TileEntityIronChest> extends
public void render(TileEntityIronChest tile, double x, double y, double z, float partialTick, int breakStage) public void render(TileEntityIronChest tile, double x, double y, double z, float partialTick, int breakStage)
{ {
if (tile == null) { if (tile == null)
{
return; return;
} }
int facing = 3; int facing = 3;
IronChestType type = tile.getType(); IronChestType type = tile.getType();
if (tile != null && tile.hasWorldObj() && tile.getWorld().getBlockState(tile.getPos()).getBlock() == IronChest.ironChestBlock) { if (tile != null && tile.hasWorldObj() && tile.getWorld().getBlockState(tile.getPos()).getBlock() == IronChest.ironChestBlock)
{
facing = tile.getFacing(); facing = tile.getFacing();
type = tile.getType(); type = tile.getType();
IBlockState state = tile.getWorld().getBlockState(tile.getPos()); IBlockState state = tile.getWorld().getBlockState(tile.getPos());
type = (IronChestType)state.getValue(BlockIronChest.VARIANT_PROP); type = state.getValue(BlockIronChest.VARIANT_PROP);
} }
if (breakStage >= 0) if (breakStage >= 0)
{ {
bindTexture(DESTROY_STAGES[breakStage]); this.bindTexture(DESTROY_STAGES[breakStage]);
GlStateManager.matrixMode(5890); GlStateManager.matrixMode(5890);
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
GlStateManager.scale(4.0F, 4.0F, 1.0F); GlStateManager.scale(4.0F, 4.0F, 1.0F);
GlStateManager.translate(0.0625F, 0.0625F, 0.0625F); GlStateManager.translate(0.0625F, 0.0625F, 0.0625F);
GlStateManager.matrixMode(5888); GlStateManager.matrixMode(5888);
} else }
bindTexture(locations.get(type)); else
{
this.bindTexture(locations.get(type));
}
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
if (type == IronChestType.CRYSTAL) if (type == IronChestType.CRYSTAL)
{
GlStateManager.disableCull(); GlStateManager.disableCull();
}
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.translate((float) x, (float) y + 1.0F, (float) z + 1.0F); GlStateManager.translate((float) x, (float) y + 1.0F, (float) z + 1.0F);
GlStateManager.scale(1.0F, -1F, -1F); GlStateManager.scale(1.0F, -1F, -1F);
GlStateManager.translate(0.5F, 0.5F, 0.5F); GlStateManager.translate(0.5F, 0.5F, 0.5F);
int k = 0; int k = 0;
if (facing == 2) { if (facing == 2)
{
k = 180; k = 180;
} }
if (facing == 3) { if (facing == 3)
{
k = 0; k = 0;
} }
if (facing == 4) { if (facing == 4)
{
k = 90; k = 90;
} }
if (facing == 5) { if (facing == 5)
{
k = -90; k = -90;
} }
GlStateManager.rotate(k, 0.0F, 1.0F, 0.0F); GlStateManager.rotate(k, 0.0F, 1.0F, 0.0F);
@ -120,9 +138,9 @@ public class TileEntityIronChestRenderer<T extends TileEntityIronChest> extends
float lidangle = tile.prevLidAngle + (tile.lidAngle - tile.prevLidAngle) * partialTick; float lidangle = tile.prevLidAngle + (tile.lidAngle - tile.prevLidAngle) * partialTick;
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); this.model.chestLid.rotateAngleX = -((lidangle * 3.141593F) / 2.0F);
// Render the chest itself // Render the chest itself
model.renderAll(); this.model.renderAll();
if (breakStage >= 0) if (breakStage >= 0)
{ {
GlStateManager.matrixMode(5890); GlStateManager.matrixMode(5890);
@ -130,19 +148,24 @@ public class TileEntityIronChestRenderer<T extends TileEntityIronChest> extends
GlStateManager.matrixMode(5888); GlStateManager.matrixMode(5888);
} }
if (type == IronChestType.CRYSTAL) if (type == IronChestType.CRYSTAL)
{
GlStateManager.enableCull(); GlStateManager.enableCull();
}
GlStateManager.popMatrix(); GlStateManager.popMatrix();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
if (type.isTransparent() && tile.getDistanceSq(this.rendererDispatcher.entityX, this.rendererDispatcher.entityY, this.rendererDispatcher.entityZ) < 128d) { if (type.isTransparent()
random.setSeed(254L); && tile.getDistanceSq(this.rendererDispatcher.entityX, this.rendererDispatcher.entityY, this.rendererDispatcher.entityZ) < 128d)
{
this.random.setSeed(254L);
float shiftX; float shiftX;
float shiftY; float shiftY;
float shiftZ; float shiftZ;
int shift = 0; int shift = 0;
float blockScale = 0.70F; float blockScale = 0.70F;
float timeD = (float) (360.0 * (double) (System.currentTimeMillis() & 0x3FFFL) / (double) 0x3FFFL); float timeD = (float) (360.0 * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL);
if (tile.getTopItemStacks()[1] == null) { if (tile.getTopItemStacks()[1] == null)
{
shift = 8; shift = 8;
blockScale = 0.85F; blockScale = 0.85F;
} }
@ -150,11 +173,14 @@ public class TileEntityIronChestRenderer<T extends TileEntityIronChest> extends
GlStateManager.translate((float) x, (float) y, (float) z); GlStateManager.translate((float) x, (float) y, (float) z);
EntityItem customitem = new EntityItem(this.getWorld()); EntityItem customitem = new EntityItem(this.getWorld());
customitem.hoverStart = 0f; customitem.hoverStart = 0f;
for (ItemStack item : tile.getTopItemStacks()) { for (ItemStack item : tile.getTopItemStacks())
if (shift > shifts.length) { {
if (shift > shifts.length)
{
break; break;
} }
if (item == null) { if (item == null)
{
shift++; shift++;
continue; continue;
} }
@ -167,15 +193,16 @@ public class TileEntityIronChestRenderer<T extends TileEntityIronChest> extends
GlStateManager.rotate(timeD, 0.0F, 1.0F, 0.0F); GlStateManager.rotate(timeD, 0.0F, 1.0F, 0.0F);
GlStateManager.scale(blockScale, blockScale, blockScale); GlStateManager.scale(blockScale, blockScale, blockScale);
customitem.setEntityItemStack(item); customitem.setEntityItemStack(item);
itemRenderer.doRender(customitem, 0, 0, 0, 0, 0); this.itemRenderer.doRender(customitem, 0, 0, 0, 0, 0);
GlStateManager.popMatrix(); GlStateManager.popMatrix();
} }
GlStateManager.popMatrix(); GlStateManager.popMatrix();
} }
} }
@Override
public void renderTileEntityAt(TileEntityIronChest tileentity, double x, double y, double z, float partialTick, int breakStage) public void renderTileEntityAt(TileEntityIronChest tileentity, double x, double y, double z, float partialTick, int breakStage)
{ {
render(tileentity, x, y, z, partialTick, breakStage); this.render(tileentity, x, y, z, partialTick, breakStage);
} }
} }

View File

@ -1,4 +1,5 @@
{ {
"parent": "block/block",
"textures": { "textures": {
"texture": "ironchest:model/copperchest" "texture": "ironchest:model/copperchest"
}, },
@ -36,12 +37,5 @@
"east": { "uv": [ 0, 0.25, 0.25, 1.25 ], "texture": "#texture" } "east": { "uv": [ 0, 0.25, 0.25, 1.25 ], "texture": "#texture" }
} }
} }
], ]
"display": {
"thirdperson": {
"rotation": [ 0, 45, 190 ],
"translation": [ 0, 1.5, -2.75 ],
"scale": [ 0.375, 0.375, 0.375 ]
}
}
} }

View File

@ -1,4 +1,5 @@
{ {
"parent": "block/block",
"textures": { "textures": {
"texture": "ironchest:model/crystalchest" "texture": "ironchest:model/crystalchest"
}, },
@ -36,12 +37,5 @@
"east": { "uv": [ 0, 0.25, 0.25, 1.25 ], "texture": "#texture" } "east": { "uv": [ 0, 0.25, 0.25, 1.25 ], "texture": "#texture" }
} }
} }
], ]
"display": {
"thirdperson": {
"rotation": [ 0, 45, 190 ],
"translation": [ 0, 1.5, -2.75 ],
"scale": [ 0.375, 0.375, 0.375 ]
}
}
} }

View File

@ -1,4 +1,5 @@
{ {
"parent": "block/block",
"textures": { "textures": {
"texture": "ironchest:model/diamondchest" "texture": "ironchest:model/diamondchest"
}, },
@ -36,12 +37,5 @@
"east": { "uv": [ 0, 0.25, 0.25, 1.25 ], "texture": "#texture" } "east": { "uv": [ 0, 0.25, 0.25, 1.25 ], "texture": "#texture" }
} }
} }
], ]
"display": {
"thirdperson": {
"rotation": [ 0, 45, 190 ],
"translation": [ 0, 1.5, -2.75 ],
"scale": [ 0.375, 0.375, 0.375 ]
}
}
} }

View File

@ -1,4 +1,5 @@
{ {
"parent": "block/block",
"textures": { "textures": {
"texture": "ironchest:model/dirtchest" "texture": "ironchest:model/dirtchest"
}, },
@ -36,12 +37,5 @@
"east": { "uv": [ 0, 0.25, 0.25, 1.25 ], "texture": "#texture" } "east": { "uv": [ 0, 0.25, 0.25, 1.25 ], "texture": "#texture" }
} }
} }
], ]
"display": {
"thirdperson": {
"rotation": [ 0, 45, 190 ],
"translation": [ 0, 1.5, -2.75 ],
"scale": [ 0.375, 0.375, 0.375 ]
}
}
} }

View File

@ -1,4 +1,5 @@
{ {
"parent": "block/block",
"textures": { "textures": {
"texture": "ironchest:model/goldchest" "texture": "ironchest:model/goldchest"
}, },
@ -36,12 +37,5 @@
"east": { "uv": [ 0, 0.25, 0.25, 1.25 ], "texture": "#texture" } "east": { "uv": [ 0, 0.25, 0.25, 1.25 ], "texture": "#texture" }
} }
} }
], ]
"display": {
"thirdperson": {
"rotation": [ 0, 45, 190 ],
"translation": [ 0, 1.5, -2.75 ],
"scale": [ 0.375, 0.375, 0.375 ]
}
}
} }

View File

@ -1,4 +1,5 @@
{ {
"parent": "block/block",
"textures": { "textures": {
"texture": "ironchest:model/ironchest" "texture": "ironchest:model/ironchest"
}, },
@ -36,12 +37,5 @@
"east": { "uv": [ 0, 0.25, 0.25, 1.25 ], "texture": "#texture" } "east": { "uv": [ 0, 0.25, 0.25, 1.25 ], "texture": "#texture" }
} }
} }
], ]
"display": {
"thirdperson": {
"rotation": [ 0, 45, 190 ],
"translation": [ 0, 1.5, -2.75 ],
"scale": [ 0.375, 0.375, 0.375 ]
}
}
} }

View File

@ -1,4 +1,5 @@
{ {
"parent": "block/block",
"textures": { "textures": {
"texture": "ironchest:model/obsidianchest" "texture": "ironchest:model/obsidianchest"
}, },
@ -36,12 +37,5 @@
"east": { "uv": [ 0, 0.25, 0.25, 1.25 ], "texture": "#texture" } "east": { "uv": [ 0, 0.25, 0.25, 1.25 ], "texture": "#texture" }
} }
} }
], ]
"display": {
"thirdperson": {
"rotation": [ 0, 45, 190 ],
"translation": [ 0, 1.5, -2.75 ],
"scale": [ 0.375, 0.375, 0.375 ]
}
}
} }

View File

@ -1,4 +1,5 @@
{ {
"parent": "block/block",
"textures": { "textures": {
"texture": "ironchest:model/silverchest" "texture": "ironchest:model/silverchest"
}, },
@ -36,12 +37,5 @@
"east": { "uv": [ 0, 0.25, 0.25, 1.25 ], "texture": "#texture" } "east": { "uv": [ 0, 0.25, 0.25, 1.25 ], "texture": "#texture" }
} }
} }
], ]
"display": {
"thirdperson": {
"rotation": [ 0, 45, 190 ],
"translation": [ 0, 1.5, -2.75 ],
"scale": [ 0.375, 0.375, 0.375 ]
}
}
} }