Made it so that replaced chests from mimics keep their inventory and when broken will drop their inventory.
This commit is contained in:
parent
0420779e5e
commit
1adbe04ab8
|
@ -59,6 +59,14 @@ public class ItemBlockMimic extends ItemBlock
|
|||
// ItemStack replacedStack = new ItemStack(block, 1, block.getMetaFromState(iblockstate));
|
||||
|
||||
NBTTagCompound tileTag = getTagFromTileEntity(tileReplaced);
|
||||
if (tileReplaced != null)
|
||||
{
|
||||
NBTTagCompound voidTag = new NBTTagCompound();
|
||||
voidTag.setInteger("x", pos.getX());
|
||||
voidTag.setInteger("y", pos.getY());
|
||||
voidTag.setInteger("z", pos.getZ());
|
||||
tileReplaced.readFromNBT(voidTag);
|
||||
}
|
||||
|
||||
if (placeBlockAt(stack, player, world, pos, facing, hitX, hitY, hitZ, iblockstate1))
|
||||
{
|
||||
|
@ -71,6 +79,7 @@ public class ItemBlockMimic extends ItemBlock
|
|||
{
|
||||
TileMimic mimic = (TileMimic) tile;
|
||||
mimic.metaOfReplacedBlock = block.getMetaFromState(iblockstate);
|
||||
mimic.tileTag = tileTag;
|
||||
mimic.setInventorySlotContents(0, replacedStack);
|
||||
mimic.refreshTileEntity();
|
||||
|
||||
|
@ -81,6 +90,9 @@ public class ItemBlockMimic extends ItemBlock
|
|||
}
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
} else
|
||||
{
|
||||
tileReplaced.readFromNBT(tileTag);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -71,6 +72,10 @@ public class TileMimic extends TileInventory
|
|||
|
||||
public void refreshTileEntity()
|
||||
{
|
||||
if (mimicedTile != null)
|
||||
{
|
||||
dropMimicedTileInventory();
|
||||
}
|
||||
mimicedTile = getTileFromStackWithTag(worldObj, pos, getStackInSlot(0), tileTag, metaOfReplacedBlock);
|
||||
}
|
||||
|
||||
|
@ -174,6 +179,16 @@ public class TileMimic extends TileInventory
|
|||
{
|
||||
InventoryHelper.dropInventoryItems(getWorld(), getPos(), this);
|
||||
}
|
||||
|
||||
dropMimicedTileInventory();
|
||||
}
|
||||
|
||||
public void dropMimicedTileInventory()
|
||||
{
|
||||
if (!worldObj.isRemote && mimicedTile instanceof IInventory)
|
||||
{
|
||||
InventoryHelper.dropInventoryItems(getWorld(), getPos(), (IInventory) mimicedTile);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue