Advertisement
tahg

Untitled

Apr 24th, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. package com.tahgcraft.bedrockium;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.init.Blocks;
  5. import net.minecraft.nbt.NBTTagCompound;
  6. import net.minecraft.network.NetworkManager;
  7. import net.minecraft.network.Packet;
  8. import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
  9. import net.minecraft.tileentity.TileEntity;
  10. import cpw.mods.fml.common.registry.GameRegistry;
  11.  
  12. public class BedrockiumTE extends TileEntity {
  13.  
  14. Block realBlock;
  15. public BedrockiumTE(Block block) {
  16. realBlock = block == null ? Blocks.bedrock : block;
  17. }
  18. public void writeToNBT(NBTTagCompound p_145841_1_)
  19. {
  20. super.writeToNBT(p_145841_1_);
  21. p_145841_1_.setString("Block", GameRegistry.findUniqueIdentifierFor(realBlock).toString());
  22. }
  23.  
  24. public void readFromNBT(NBTTagCompound p_145839_1_)
  25. {
  26. super.readFromNBT(p_145839_1_);
  27. this.realBlock = Block.getBlockFromName(p_145839_1_.getString("Block"));
  28. if (realBlock == null) realBlock = Blocks.bedrock;
  29. }
  30.  
  31. /**
  32. * Overriden in a sign to provide the text.
  33. */
  34. public Packet getDescriptionPacket()
  35. {
  36. NBTTagCompound nbttagcompound = new NBTTagCompound();
  37. this.writeToNBT(nbttagcompound);
  38. return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbttagcompound);
  39. }
  40.  
  41. @Override
  42. public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
  43. super.onDataPacket(net, pkt);
  44. this.readFromNBT(pkt.func_148857_g());
  45. }
  46.  
  47. public void setBlock(Block block) {
  48. realBlock = block == null ? Blocks.bedrock : block;
  49. this.markDirty();
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement