From b4dd5d1a676505a72f7c109e5061353305bb8333 Mon Sep 17 00:00:00 2001 From: Mitchell Date: Wed, 28 Jan 2015 19:19:38 -0400 Subject: [PATCH 1/7] Fix chests not keeping content on update I'm not sure how much of this code is actually needed but after changing many parts it seems to make the chests keep their contents. Also made it so instead of setting the stack size to 0, if the player is in creative it remains the same, if not it subtracts 1 from the stack size (incase somehow they get a stack of more than 1) All upgrades appear to work and all contents seem to remain in chest. This fixes #31.1 --- .../cpw/mods/ironchest/ItemChestChanger.java | 90 ++++++++----------- 1 file changed, 36 insertions(+), 54 deletions(-) diff --git a/src/main/java/cpw/mods/ironchest/ItemChestChanger.java b/src/main/java/cpw/mods/ironchest/ItemChestChanger.java index 50781ac..62515a6 100755 --- a/src/main/java/cpw/mods/ironchest/ItemChestChanger.java +++ b/src/main/java/cpw/mods/ironchest/ItemChestChanger.java @@ -38,60 +38,42 @@ public class ItemChestChanger extends Item @Override public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) { - if (world.isRemote) return false; - TileEntity te = world.getTileEntity(pos); - TileEntityIronChest newchest; - if (te != null && te instanceof TileEntityIronChest) - { - TileEntityIronChest ironchest = (TileEntityIronChest) te; - newchest = ironchest.applyUpgradeItem(this); - if (newchest == null) - { - return false; - } - } - else if (te != null && te instanceof TileEntityChest) - { - TileEntityChest tec = (TileEntityChest) te; - if (tec.numPlayersUsing > 0) - { - return false; - } - if (!getType().canUpgrade(IronChestType.WOOD)) - { - return false; - } - // Force old TE out of the world so that adjacent chests can update - newchest = IronChestType.makeEntity(getTargetChestOrdinal(IronChestType.WOOD.ordinal())); - int newSize = newchest.chestContents.length; - ItemStack[] chestContents = ObfuscationReflectionHelper.getPrivateValue(TileEntityChest.class, tec, 0); - System.arraycopy(chestContents, 0, newchest.chestContents, 0, Math.min(newSize, chestContents.length)); - BlockIronChest block = IronChest.ironChestBlock; - block.dropContent(newSize, tec, world, tec.getPos()); - newchest.setFacing((byte) tec.getBlockMetadata()); - newchest.sortTopStacks(); - for (int i = 0; i < Math.min(newSize, chestContents.length); i++) - { - chestContents[i] = null; - } - // Clear the old block out - world.setBlockState(pos, Blocks.air.getDefaultState(), 3); - // Force the Chest TE to reset it's knowledge of neighbouring blocks - tec.updateContainingBlockInfo(); - // Force the Chest TE to update any neighbours so they update next - // tick - tec.checkForAdjacentChests(); - // And put in our block instead - world.setBlockState(pos, block.getStateFromMeta(newchest.getType().ordinal()), 3); - } - else - { - return false; - } - world.setTileEntity(pos, newchest); - world.setBlockState(pos, IronChest.ironChestBlock.getStateFromMeta(newchest.getType().ordinal()), 3); - stack.stackSize = 0; - return true; + if (world.isRemote) return false; + TileEntity te = world.getTileEntity(pos); + TileEntityIronChest newchest = new TileEntityIronChest(); + ItemStack[] chestContents = new ItemStack[27]; + if (te != null) { + if (te instanceof TileEntityIronChest) { + chestContents = ((TileEntityIronChest) te).chestContents; + newchest = IronChestType.makeEntity(this.getTargetChestOrdinal(this.type.ordinal())); + if (newchest == null) return false; + } else if (te instanceof TileEntityChest) { + if (((TileEntityChest) te).numPlayersUsing > 0) return false; + if (!getType().canUpgrade(IronChestType.WOOD)) return false; + chestContents = new ItemStack[((TileEntityChest) te).getSizeInventory()]; + for (int i = 0; i < chestContents.length; i ++) chestContents[i] = ((TileEntityChest) te).getStackInSlot(i); + newchest = IronChestType.makeEntity(IronChestType.IRON.ordinal()); + } + } + + te.updateContainingBlockInfo(); + if (te instanceof TileEntityChest) ((TileEntityChest) te).checkForAdjacentChests(); + + world.removeTileEntity(pos); + world.setBlockToAir(pos); + + world.setTileEntity(pos, newchest); + world.setBlockState(pos, IronChest.ironChestBlock.getStateFromMeta(newchest.getType().ordinal()), 3); + + world.markBlockForUpdate(pos); + + TileEntity te2 = world.getTileEntity(pos); + if (te2 instanceof TileEntityIronChest) { + ((TileEntityIronChest) te2).setContents(chestContents); + } + + stack.stackSize = player.capabilities.isCreativeMode ? stack.stackSize : stack.stackSize - 1; + return true; } public int getTargetChestOrdinal(int sourceOrdinal) From a29c12ab849da94625d991337db2bd877fc030a4 Mon Sep 17 00:00:00 2001 From: Mitchell Date: Wed, 28 Jan 2015 19:24:09 -0400 Subject: [PATCH 2/7] setContents method, remove applyUpgradeItem applyUpgradeItem is no longer needed because it's now being completely done from ItemChestChanger setContents added for ItemChestChanger --- .../mods/ironchest/TileEntityIronChest.java | 33 +++++++------------ 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/src/main/java/cpw/mods/ironchest/TileEntityIronChest.java b/src/main/java/cpw/mods/ironchest/TileEntityIronChest.java index 8bf2617..064a7a0 100755 --- a/src/main/java/cpw/mods/ironchest/TileEntityIronChest.java +++ b/src/main/java/cpw/mods/ironchest/TileEntityIronChest.java @@ -59,6 +59,16 @@ public class TileEntityIronChest extends TileEntityLockable implements IUpdatePl { return chestContents; } + + public void setContents(ItemStack[] contents) { + chestContents = new ItemStack[getSizeInventory()]; + for (int i = 0; i < contents.length; i ++) { + if (i < chestContents.length) { + chestContents[i] = contents[i]; + } + } + inventoryTouched = true; + } @Override public int getSizeInventory() @@ -402,27 +412,6 @@ public class TileEntityIronChest extends TileEntityLockable implements IUpdatePl this.facing = facing2; } - public TileEntityIronChest applyUpgradeItem(ItemChestChanger itemChestChanger) - { - if (numUsingPlayers > 0) - { - return null; - } - if (!itemChestChanger.getType().canUpgrade(this.getType())) - { - return null; - } - TileEntityIronChest newEntity = IronChestType.makeEntity(itemChestChanger.getTargetChestOrdinal(getType().ordinal())); - int newSize = newEntity.chestContents.length; - System.arraycopy(chestContents, 0, newEntity.chestContents, 0, Math.min(newSize, chestContents.length)); - BlockIronChest block = IronChest.ironChestBlock; - block.dropContent(newSize, this, this.worldObj, pos); - newEntity.setFacing(facing); - newEntity.sortTopStacks(); - newEntity.ticksSinceSync = -1; - return newEntity; - } - public ItemStack[] getTopItemStacks() { return topStacks; @@ -578,4 +567,4 @@ public class TileEntityIronChest extends TileEntityLockable implements IUpdatePl { return true; } -} \ No newline at end of file +} From e53c319b9bb3b8ace69e7cab86cb695079571607 Mon Sep 17 00:00:00 2001 From: Mitchell Date: Thu, 29 Jan 2015 10:39:59 -0400 Subject: [PATCH 3/7] Remove unused imports --- src/main/java/cpw/mods/ironchest/ItemChestChanger.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/cpw/mods/ironchest/ItemChestChanger.java b/src/main/java/cpw/mods/ironchest/ItemChestChanger.java index 62515a6..d04343f 100755 --- a/src/main/java/cpw/mods/ironchest/ItemChestChanger.java +++ b/src/main/java/cpw/mods/ironchest/ItemChestChanger.java @@ -20,7 +20,6 @@ import net.minecraft.tileentity.TileEntityChest; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; -import net.minecraftforge.fml.common.ObfuscationReflectionHelper; public class ItemChestChanger extends Item { From 3f69b703cd759398d7e45d43fae4b7cfa5231375 Mon Sep 17 00:00:00 2001 From: Mitchell Date: Thu, 29 Jan 2015 10:40:56 -0400 Subject: [PATCH 4/7] Remove unused imports --- src/main/java/cpw/mods/ironchest/RegistryHelper.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/cpw/mods/ironchest/RegistryHelper.java b/src/main/java/cpw/mods/ironchest/RegistryHelper.java index 53d9a58..770f608 100644 --- a/src/main/java/cpw/mods/ironchest/RegistryHelper.java +++ b/src/main/java/cpw/mods/ironchest/RegistryHelper.java @@ -11,13 +11,10 @@ package cpw.mods.ironchest; import java.util.Iterator; -import java.util.Map; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; -import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; -import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import net.minecraftforge.fml.common.registry.GameRegistry; From 82c2dcc995b82ed2ec507f74f36f7cff26f04970 Mon Sep 17 00:00:00 2001 From: 61352151511 Date: Thu, 29 Jan 2015 12:47:46 -0400 Subject: [PATCH 5/7] Remove unused imports, re-add invtweaks, update to new mcp mappings --- .../java/invtweaks/api/container/ChestContainer.java | 10 ++++++++++ .../java/cpw/mods/ironchest/ContainerIronChest.java | 5 +++-- src/main/java/cpw/mods/ironchest/IronChest.java | 2 +- src/main/java/cpw/mods/ironchest/ItemChestChanger.java | 1 - .../java/cpw/mods/ironchest/client/ClientProxy.java | 2 -- .../ironchest/client/TileEntityIronChestRenderer.java | 2 +- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/api/java/invtweaks/api/container/ChestContainer.java b/src/api/java/invtweaks/api/container/ChestContainer.java index 4722921..dc27377 100755 --- a/src/api/java/invtweaks/api/container/ChestContainer.java +++ b/src/api/java/invtweaks/api/container/ChestContainer.java @@ -12,6 +12,9 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface ChestContainer { + // Set to true if the Inventory Tweaks sorting buttons should be shown for this container. + boolean showButtons() default true; + // Size of a chest row int rowSize() default 9; @@ -25,4 +28,11 @@ public @interface ChestContainer { @Target(ElementType.METHOD) public @interface RowSizeCallback { } + + // Annotation for method to get size of a chest row if it is not a fixed size for this container class + // Signature int func() + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + public @interface IsLargeCallback { + } } \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/ContainerIronChest.java b/src/main/java/cpw/mods/ironchest/ContainerIronChest.java index 2257aeb..6c32beb 100755 --- a/src/main/java/cpw/mods/ironchest/ContainerIronChest.java +++ b/src/main/java/cpw/mods/ironchest/ContainerIronChest.java @@ -10,6 +10,7 @@ ******************************************************************************/ package cpw.mods.ironchest; +import invtweaks.api.container.ChestContainer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; @@ -17,7 +18,7 @@ import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -//@ChestContainer(isLargeChest = true) +@ChestContainer(isLargeChest = true) public class ContainerIronChest extends Container { private IronChestType type; private EntityPlayer player; @@ -117,7 +118,7 @@ public class ContainerIronChest extends Container { return player; } - //@ChestContainer.RowSizeCallback + @ChestContainer.RowSizeCallback public int getNumColumns() { return type.getRowLength(); } diff --git a/src/main/java/cpw/mods/ironchest/IronChest.java b/src/main/java/cpw/mods/ironchest/IronChest.java index c190510..6ecfe73 100755 --- a/src/main/java/cpw/mods/ironchest/IronChest.java +++ b/src/main/java/cpw/mods/ironchest/IronChest.java @@ -52,7 +52,7 @@ public class IronChest ironChestBlock = new BlockIronChest(); RegistryHelper.registerBlock(ironChestBlock, ItemIronChest.class, "BlockIronChest"); - if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getModelManager().getBlockModelShapes().func_178123_a(ironChestBlock); + if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getModelManager().getBlockModelShapes().registerBuiltInBlocks(ironChestBlock); for (IronChestType typ : IronChestType.values()) { diff --git a/src/main/java/cpw/mods/ironchest/ItemChestChanger.java b/src/main/java/cpw/mods/ironchest/ItemChestChanger.java index d04343f..f8a34c3 100755 --- a/src/main/java/cpw/mods/ironchest/ItemChestChanger.java +++ b/src/main/java/cpw/mods/ironchest/ItemChestChanger.java @@ -12,7 +12,6 @@ package cpw.mods.ironchest; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; diff --git a/src/main/java/cpw/mods/ironchest/client/ClientProxy.java b/src/main/java/cpw/mods/ironchest/client/ClientProxy.java index 9c45f41..09ad48a 100755 --- a/src/main/java/cpw/mods/ironchest/client/ClientProxy.java +++ b/src/main/java/cpw/mods/ironchest/client/ClientProxy.java @@ -10,9 +10,7 @@ ******************************************************************************/ package cpw.mods.ironchest.client; -import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.tileentity.TileEntityItemStackRenderer; -import net.minecraft.client.resources.IReloadableResourceManager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; diff --git a/src/main/java/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java b/src/main/java/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java index 223c915..b6235ee 100755 --- a/src/main/java/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java +++ b/src/main/java/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java @@ -136,7 +136,7 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer GlStateManager.popMatrix(); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - if (type.isTransparent() && tile.getDistanceSq(this.rendererDispatcher.field_147560_j, this.rendererDispatcher.field_147561_k, this.rendererDispatcher.field_147558_l) < 128d) { + if (type.isTransparent() && tile.getDistanceSq(this.rendererDispatcher.entityX, this.rendererDispatcher.entityY, this.rendererDispatcher.entityZ) < 128d) { random.setSeed(254L); float shiftX; float shiftY; From b6e2f384ae13b2f7bb88aea38a22409ea67b2025 Mon Sep 17 00:00:00 2001 From: 61352151511 Date: Thu, 29 Jan 2015 12:48:02 -0400 Subject: [PATCH 6/7] Update forge version to latest --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index d746c42..f9d5767 100755 --- a/build.gradle +++ b/build.gradle @@ -37,7 +37,7 @@ archivesBaseName = "ironchest" // Setup the forge minecraft plugin data. Specify the preferred forge/minecraft version here minecraft { - version = "1.8-11.14.0.1251-1.8" + version = "1.8-11.14.0.1292-1.8" } // This wrangles the resources for the jar files- stuff like textures and languages From c1912bc4750fb8a4c8f6054a6e649de992375ee5 Mon Sep 17 00:00:00 2001 From: 61352151511 Date: Thu, 29 Jan 2015 12:58:38 -0400 Subject: [PATCH 7/7] Reformat --- .../cpw/mods/ironchest/ItemChestChanger.java | 83 +++++++++++-------- .../mods/ironchest/TileEntityIronChest.java | 21 +++-- 2 files changed, 59 insertions(+), 45 deletions(-) diff --git a/src/main/java/cpw/mods/ironchest/ItemChestChanger.java b/src/main/java/cpw/mods/ironchest/ItemChestChanger.java index f8a34c3..84ab992 100755 --- a/src/main/java/cpw/mods/ironchest/ItemChestChanger.java +++ b/src/main/java/cpw/mods/ironchest/ItemChestChanger.java @@ -34,44 +34,55 @@ public class ItemChestChanger extends Item } @Override - public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) + public boolean onItemUseFirst (ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) { - if (world.isRemote) return false; - TileEntity te = world.getTileEntity(pos); - TileEntityIronChest newchest = new TileEntityIronChest(); - ItemStack[] chestContents = new ItemStack[27]; - if (te != null) { - if (te instanceof TileEntityIronChest) { - chestContents = ((TileEntityIronChest) te).chestContents; - newchest = IronChestType.makeEntity(this.getTargetChestOrdinal(this.type.ordinal())); - if (newchest == null) return false; - } else if (te instanceof TileEntityChest) { - if (((TileEntityChest) te).numPlayersUsing > 0) return false; - if (!getType().canUpgrade(IronChestType.WOOD)) return false; - chestContents = new ItemStack[((TileEntityChest) te).getSizeInventory()]; - for (int i = 0; i < chestContents.length; i ++) chestContents[i] = ((TileEntityChest) te).getStackInSlot(i); - newchest = IronChestType.makeEntity(IronChestType.IRON.ordinal()); - } - } - - te.updateContainingBlockInfo(); - if (te instanceof TileEntityChest) ((TileEntityChest) te).checkForAdjacentChests(); - - world.removeTileEntity(pos); - world.setBlockToAir(pos); - - world.setTileEntity(pos, newchest); - world.setBlockState(pos, IronChest.ironChestBlock.getStateFromMeta(newchest.getType().ordinal()), 3); - - world.markBlockForUpdate(pos); - - TileEntity te2 = world.getTileEntity(pos); - if (te2 instanceof TileEntityIronChest) { - ((TileEntityIronChest) te2).setContents(chestContents); - } + if (world.isRemote) + return false; + TileEntity te = world.getTileEntity(pos); + TileEntityIronChest newchest = new TileEntityIronChest(); + ItemStack[] chestContents = new ItemStack[27]; + if (te != null) + { + if (te instanceof TileEntityIronChest) + { + chestContents = ((TileEntityIronChest) te).chestContents; + newchest = IronChestType.makeEntity(this.getTargetChestOrdinal(this.type.ordinal())); + if (newchest == null) + return false; + } + else if (te instanceof TileEntityChest) + { + if (((TileEntityChest) te).numPlayersUsing > 0) + return false; + if (!getType().canUpgrade(IronChestType.WOOD)) + return false; + chestContents = new ItemStack[((TileEntityChest) te).getSizeInventory()]; + for (int i = 0; i < chestContents.length; i++) + chestContents[i] = ((TileEntityChest) te).getStackInSlot(i); + newchest = IronChestType.makeEntity(IronChestType.IRON.ordinal()); + } + } - stack.stackSize = player.capabilities.isCreativeMode ? stack.stackSize : stack.stackSize - 1; - return true; + te.updateContainingBlockInfo(); + if (te instanceof TileEntityChest) + ((TileEntityChest) te).checkForAdjacentChests(); + + world.removeTileEntity(pos); + world.setBlockToAir(pos); + + world.setTileEntity(pos, newchest); + world.setBlockState(pos, IronChest.ironChestBlock.getStateFromMeta(newchest.getType().ordinal()), 3); + + world.markBlockForUpdate(pos); + + TileEntity te2 = world.getTileEntity(pos); + if (te2 instanceof TileEntityIronChest) + { + ((TileEntityIronChest) te2).setContents(chestContents); + } + + stack.stackSize = player.capabilities.isCreativeMode ? stack.stackSize : stack.stackSize - 1; + return true; } public int getTargetChestOrdinal(int sourceOrdinal) diff --git a/src/main/java/cpw/mods/ironchest/TileEntityIronChest.java b/src/main/java/cpw/mods/ironchest/TileEntityIronChest.java index 064a7a0..217eceb 100755 --- a/src/main/java/cpw/mods/ironchest/TileEntityIronChest.java +++ b/src/main/java/cpw/mods/ironchest/TileEntityIronChest.java @@ -60,15 +60,18 @@ public class TileEntityIronChest extends TileEntityLockable implements IUpdatePl return chestContents; } - public void setContents(ItemStack[] contents) { - chestContents = new ItemStack[getSizeInventory()]; - for (int i = 0; i < contents.length; i ++) { - if (i < chestContents.length) { - chestContents[i] = contents[i]; - } - } - inventoryTouched = true; - } + public void setContents (ItemStack[] contents) + { + chestContents = new ItemStack[getSizeInventory()]; + for (int i = 0; i < contents.length; i++) + { + if (i < chestContents.length) + { + chestContents[i] = contents[i]; + } + } + inventoryTouched = true; + } @Override public int getSizeInventory()