Skip to content

Commit

Permalink
Pattern chests keep inventory on harvest
Browse files Browse the repository at this point in the history
  • Loading branch information
mDiyo committed Aug 21, 2014
1 parent b1e30d8 commit 94071d0
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/tconstruct/plugins/waila/WailaRegistrar.java
Expand Up @@ -37,7 +37,7 @@ public static void wailaCallback (IWailaRegistrar registrar)

public static String fluidNameHelper (FluidStack f)
{
return f.getFluid().getLocalizedName(f);
return f.getFluid().getLocalizedName();
}

}
93 changes: 91 additions & 2 deletions src/main/java/tconstruct/tools/blocks/ToolStationBlock.java
Expand Up @@ -7,9 +7,11 @@
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;
Expand Down Expand Up @@ -197,7 +199,7 @@ public void getSubBlocks (Item id, CreativeTabs tab, List list)
}
}

@Override
/*@Override
public void onBlockPlacedBy (World world, int x, int y, int z, EntityLivingBase par5EntityLiving, ItemStack par6ItemStack)
{
if (PHConstruct.freePatterns)
Expand All @@ -214,11 +216,98 @@ public void onBlockPlacedBy (World world, int x, int y, int z, EntityLivingBase
}
}
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);
}
}

0 comments on commit 94071d0

Please sign in to comment.