Merge pull request #38 from 61352151511/master

Fix chests not keeping contents
This commit is contained in:
Zach 2015-01-29 22:08:28 -05:00
commit a0108b9c20
9 changed files with 73 additions and 84 deletions

View File

@ -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

View File

@ -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 {
}
}

View File

@ -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();
}

View File

@ -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())
{

View File

@ -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;
@ -20,7 +19,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
{
@ -38,59 +36,52 @@ 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;
if (world.isRemote)
return false;
TileEntity te = world.getTileEntity(pos);
TileEntityIronChest newchest;
if (te != null && te instanceof TileEntityIronChest)
TileEntityIronChest newchest = new TileEntityIronChest();
ItemStack[] chestContents = new ItemStack[27];
if (te != null)
{
TileEntityIronChest ironchest = (TileEntityIronChest) te;
newchest = ironchest.applyUpgradeItem(this);
if (te instanceof TileEntityIronChest)
{
chestContents = ((TileEntityIronChest) te).chestContents;
newchest = IronChestType.makeEntity(this.getTargetChestOrdinal(this.type.ordinal()));
if (newchest == null)
{
return false;
}
}
else if (te != null && te instanceof TileEntityChest)
{
TileEntityChest tec = (TileEntityChest) te;
if (tec.numPlayersUsing > 0)
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());
}
// 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;
}
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);
stack.stackSize = 0;
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;
}

View File

@ -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;

View File

@ -60,6 +60,19 @@ 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 +415,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;

View File

@ -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;

View File

@ -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;