mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-19 11:59:14 +00:00
Slab Pattern Chests now also keep their inventory!
This commit is contained in:
1 parent
6b6928ec00
commit
df64bc8197
1 file changed
+66
-1
@@ -7,8 +7,10 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.world.World;
|
||||
@@ -132,7 +134,22 @@ public class CraftingSlab extends InventorySlab
|
||||
@Override
|
||||
public void onBlockPlacedBy (World world, int x, int y, int z, EntityLivingBase entityliving, ItemStack stack)
|
||||
{
|
||||
if (PHConstruct.freePatterns)
|
||||
boolean keptInventory = false;
|
||||
if (stack.hasTagCompound())
|
||||
{
|
||||
NBTTagCompound inventory = stack.getTagCompound().getCompoundTag("Inventory");
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if (inventory != null && te instanceof PatternChestLogic)
|
||||
{
|
||||
PatternChestLogic logic = (PatternChestLogic) te;
|
||||
logic.readInventoryFromNBT(inventory);
|
||||
logic.xCoord = x;
|
||||
logic.yCoord = y;
|
||||
logic.zCoord = z;
|
||||
keptInventory = true;
|
||||
}
|
||||
}
|
||||
if (!keptInventory && PHConstruct.freePatterns)
|
||||
{
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
if (meta == 4)
|
||||
@@ -169,4 +186,52 @@ public class CraftingSlab extends InventorySlab
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/* Keep pattern chest inventory */
|
||||
@Override
|
||||
public boolean removedByPlayer (World world, EntityPlayer player, int x, int y, int z, boolean willHarvest)
|
||||
{
|
||||
player.addExhaustion(0.025F);
|
||||
|
||||
if (!world.isRemote && world.getGameRules().getGameRuleBooleanValue("doTileDrops"))
|
||||
{
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
if (meta == 4)
|
||||
{
|
||||
ItemStack chest = new ItemStack(this, 1, 4);
|
||||
NBTTagCompound inventory = new NBTTagCompound();
|
||||
PatternChestLogic logic = (PatternChestLogic) world.getTileEntity(x, y, z);
|
||||
logic.writeInventoryToNBT(inventory);
|
||||
NBTTagCompound baseTag = new NBTTagCompound();
|
||||
baseTag.setTag("Inventory", inventory);
|
||||
chest.setTagCompound(baseTag);
|
||||
|
||||
// remove content. This is necessary because otherwise the patterns would also spill into the world
|
||||
// we don't want to prevent that since that's the intended behaviour for explosions.
|
||||
for(int i = 0; i < logic.getSizeInventory(); i++)
|
||||
logic.setInventorySlotContents(i, null);
|
||||
|
||||
//Spawn item
|
||||
if (!player.capabilities.isCreativeMode || player.isSneaking())
|
||||
{
|
||||
float f = 0.7F;
|
||||
double d0 = (double) (world.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
|
||||
double d1 = (double) (world.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
|
||||
double d2 = (double) (world.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
|
||||
EntityItem entityitem = new EntityItem(world, (double) x + d0, (double) y + d1, (double) z + d2, chest);
|
||||
entityitem.delayBeforeCanPickup = 10;
|
||||
world.spawnEntityInWorld(entityitem);
|
||||
}
|
||||
}
|
||||
}
|
||||
return world.setBlockToAir(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void harvestBlock (World world, EntityPlayer player, int x, int y, int z, int meta)
|
||||
{
|
||||
if (meta != 4)
|
||||
super.harvestBlock(world, player, x, y, z, meta);
|
||||
//Do nothing
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user