Skip to content

Instantly share code, notes, and snippets.

@izzyaxel
Created August 30, 2016 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save izzyaxel/d481621602569273a76d275b711afa62 to your computer and use it in GitHub Desktop.
Save izzyaxel/d481621602569273a76d275b711afa62 to your computer and use it in GitHub Desktop.
1.7.10 Pickup/Break NBT Persistance
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta)
{
if(world.getTileEntity(x, y, z) instanceof TileStatue)
{
TileStatue statue = (TileStatue)world.getTileEntity(x, y, z);
ItemStack stackWithNBT = new ItemStack(SBlocks.statue, 1);
stackWithNBT.stackTagCompound = new NBTTagCompound();
stackWithNBT.stackTagCompound.setInteger("BaseRarity", statue.getBaseRarity());
stackWithNBT.stackTagCompound.setInteger("Model", statue.getModel());
stackWithNBT.stackTagCompound.setBoolean("Motor", statue.isMotorInstalled());
stackWithNBT.stackTagCompound.setBoolean("Lights", statue.areLightsInstalled());
EntityItem ei = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, stackWithNBT);
if(!world.isRemote)
{
world.spawnEntityInWorld(ei);
}
}
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
{
return new ArrayList<ItemStack>();
}
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
{
if(super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata))
{
if(world.getTileEntity(x, y, z) != null && world.getTileEntity(x, y, z) instanceof TileStatue)
{
TileStatue statue = (TileStatue)world.getTileEntity(x, y, z);
statue.setDirection(MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3);
if(stack.hasTagCompound())
{
statue.setBaseRarity(stack.stackTagCompound.getInteger("BaseRarity"));
statue.setModel(stack.stackTagCompound.getInteger("Model"));
statue.setMotorInstalled(stack.stackTagCompound.getBoolean("Motor"));
statue.setLightsInstalled(stack.stackTagCompound.getBoolean("Lights"));
}
}
if(player.capabilities.isCreativeMode)
{
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
}
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment