mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-13 00:47:32 +00:00
Pattern chests keep inventory on harvest
This commit is contained in:
1 parent
b1e30d8ab8
commit
94071d05bb
2 files changed
+92
-3
No files matched your search
@@ -7,9 +7,11 @@ 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.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.IIcon;
|
||||
@@ -197,7 +199,7 @@ public class ToolStationBlock extends InventoryBlock
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
/*@Override
|
||||
public void onBlockPlacedBy (World world, int x, int y, int z, EntityLivingBase par5EntityLiving, ItemStack par6ItemStack)
|
||||
{
|
||||
if (PHConstruct.freePatterns)
|
||||
@@ -214,11 +216,98 @@ public class ToolStationBlock extends InventoryBlock
|
||||
}
|
||||
}
|
||||
super.onBlockPlacedBy(world, x, y, z, par5EntityLiving, par6ItemStack);
|
||||
}
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public String getTextureDomain (int textureNameIndex)
|
||||
{
|
||||
return "tinker";
|
||||
}
|
||||
|
||||
/* Keep pattern chest inventory */
|
||||
@Override
|
||||
public void breakBlock (World par1World, int x, int y, int z, Block blockID, int meta)
|
||||
{
|
||||
if (meta < 5 || meta > 9)
|
||||
super.breakBlock(par1World, x, y, z, blockID, meta);
|
||||
else
|
||||
{
|
||||
par1World.removeTileEntity(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
@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 >= 5 && meta <= 9)
|
||||
{
|
||||
ItemStack chest = new ItemStack(this, 1, 5);
|
||||
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);
|
||||
|
||||
//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 < 5 || meta > 9)
|
||||
super.harvestBlock(world, player, x, y, z, meta);
|
||||
//Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy (World world, int x, int y, int z, EntityLivingBase living, ItemStack stack)
|
||||
{
|
||||
boolean keptInventory = false;
|
||||
if (stack.hasTagCompound())
|
||||
{
|
||||
NBTTagCompound inventory = stack.getTagCompound().getCompoundTag("Inventory");
|
||||
if (inventory != null)
|
||||
{
|
||||
PatternChestLogic logic = (PatternChestLogic) world.getTileEntity(x, y, z);
|
||||
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 == 5)
|
||||
{
|
||||
PatternChestLogic logic = (PatternChestLogic) world.getTileEntity(x, y, z);
|
||||
for (int i = 1; i <= 13; i++)
|
||||
{
|
||||
logic.setInventorySlotContents(i - 1, new ItemStack(TinkerTools.woodPattern, 1, i));
|
||||
}
|
||||
logic.setInventorySlotContents(13, new ItemStack(TinkerTools.woodPattern, 1, 22));
|
||||
}
|
||||
}
|
||||
super.onBlockPlacedBy(world, x, y, z, living, stack);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user