content: package thebetweenlands.common.tile;
  
  import javax.annotation.Nullable;
  
  import net.minecraft.block.state.IBlockState;
  import net.minecraft.item.ItemStack;
  import net.minecraft.nbt.NBTTagCompound;
  import net.minecraft.network.NetworkManager;
  import net.minecraft.network.play.server.SPacketUpdateTileEntity;
  import net.minecraft.tileentity.TileEntity;
  import net.minecraft.util.math.BlockPos;
  import net.minecraft.world.World;
  
  public class TileEntityGroundItem extends TileEntity {
  
      private ItemStack stack = ItemStack.EMPTY;
  
      public boolean hasRandomOffset() {
      	return true;
      }
      
      public float getYOffset() {
      	return 0.4f;
      }
      
      public boolean isItemUpsideDown() {
      	return true;
      }
      
      public float getYRotation(float randomRotation) {
      	return randomRotation;
      }
      
      public float getTiltRotation() {
      	return this.isItemUpsideDown() ? -120.0f : 15.0f;
      }
      
      public float getItemScale() {
      	return 0.75f;
      }
      
      public ItemStack getStack() {
          return stack;
      }
  
      public void setStack(ItemStack stack) {
          this.stack = stack;
          markDirty();
      }
  
      @Override
      public void markDirty() {
          final IBlockState state = getWorld().getBlockState(getPos());
          getWorld().notifyBlockUpdate(getPos(), state, state, 2);
          super.markDirty();
      }
  
      @Override
      public void readFromNBT(NBTTagCompound compound) {
          super.readFromNBT(compound);
          stack = new ItemStack(compound.getCompoundTag("Stack"));
      }
  
      @Override
      public NBTTagCompound writeToNBT(NBTTagCompound compound) {
          compound.setTag("Stack", stack.writeToNBT(new NBTTagCompound()));
          return super.writeToNBT(compound);
      }
  
      @Nullable
      @Override
      public SPacketUpdateTileEntity getUpdatePacket() {
          return new SPacketUpdateTileEntity(getPos(), 0, getUpdateTag());
      }
  
      @Override
      public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
          handleUpdateTag(pkt.getNbtCompound());
      }
  
      @Override
      public NBTTagCompound getUpdateTag() {
          return writeToNBT(super.getUpdateTag());
      }
  
      @Override
      public void handleUpdateTag(NBTTagCompound tag) {
          super.handleUpdateTag(tag);
          readFromNBT(tag);
      }
  
      @Override
      public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) {
          return oldState.getBlock() != newSate.getBlock();
      }
  }
  