Advertisement
Creepinson

Untitled

May 15th, 2017
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. package me.creepinson.entities.tileentity;
  2.  
  3. import me.creepinson.blocks.pedestal.Pedastal_Magic;
  4. import net.minecraft.block.state.IBlockState;
  5. import net.minecraft.item.ItemStack;
  6. import net.minecraft.nbt.NBTTagCompound;
  7. import net.minecraft.network.NetworkManager;
  8. import net.minecraft.network.play.server.SPacketUpdateTileEntity;
  9. import net.minecraft.tileentity.TileEntity;
  10.  
  11. public class TileEntityPedastal_Magic extends TileEntity {
  12.  
  13. public static boolean locked;
  14.  
  15.  
  16. public boolean isLocked() {
  17.  
  18. return this.locked;
  19. }
  20.  
  21. public void setLocked(boolean locked) {
  22.  
  23. this.locked = locked;
  24.  
  25.  
  26. }
  27.  
  28.  
  29. private ItemStack stack = ItemStack.EMPTY;
  30.  
  31. public ItemStack getStack() {
  32. return stack;
  33. }
  34.  
  35. public void setStack(ItemStack stack) {
  36. this.stack = stack;
  37. markDirty();
  38. if (world != null) {
  39. IBlockState state = world.getBlockState(getPos());
  40. world.notifyBlockUpdate(getPos(), state, state, 3);
  41. }
  42. }
  43.  
  44. @Override
  45. public NBTTagCompound getUpdateTag() {
  46. // getUpdateTag() is called whenever the chunkdata is sent to the
  47. // client. In contrast getUpdatePacket() is called when the tile entity
  48. // itself wants to sync to the client. In many cases you want to send
  49. // over the same information in getUpdateTag() as in getUpdatePacket().
  50. return writeToNBT(new NBTTagCompound());
  51. }
  52.  
  53. @Override
  54. public SPacketUpdateTileEntity getUpdatePacket() {
  55. // Prepare a packet for syncing our TE to the client. Since we only have to sync the stack
  56. // and that's all we have we just write our entire NBT here. If you have a complex
  57. // tile entity that doesn't need to have all information on the client you can write
  58. // a more optimal NBT here.
  59. NBTTagCompound nbtTag = new NBTTagCompound();
  60. this.writeToNBT(nbtTag);
  61. return new SPacketUpdateTileEntity(getPos(), 1, nbtTag);
  62. }
  63.  
  64. @Override
  65. public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
  66. // Here we get the packet from the server and read it into our client side tile entity
  67. this.readFromNBT(packet.getNbtCompound());
  68. }
  69.  
  70. @Override
  71. public void readFromNBT(NBTTagCompound compound) {
  72. super.readFromNBT(compound);
  73. if (compound.hasKey("item")) {
  74. stack = new ItemStack(compound.getCompoundTag("item"));
  75. } else {
  76. stack = ItemStack.EMPTY;
  77. }
  78. if (compound.hasKey("locked")) {
  79. this.setLocked(compound.getBoolean("locked"));
  80. } else {
  81. this.setLocked(false);
  82. }
  83. }
  84.  
  85. @Override
  86. public NBTTagCompound writeToNBT(NBTTagCompound compound) {
  87.  
  88. if (stack.isEmpty()) {
  89.  
  90. stack.writeToNBT(compound);
  91.  
  92.  
  93. }
  94. compound.setBoolean("locked", this.locked);
  95. return super.writeToNBT(compound);
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement