Advertisement
Guest User

Untitled

a guest
May 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. public final class DryingRackBlockEntity extends BlockEntity implements BlockEntityClientSerializable, Tickable {
  2. public static final BlockEntityType<DryingRackBlockEntity> TYPE =
  3. BlockEntityType.Builder.method_20528(DryingRackBlockEntity::new/*, MyBlocks.DRYING_RACK*/).build(null);
  4.  
  5. private static final String STACK = "stack";
  6. private static final String DRIED = "dried";
  7.  
  8. private ItemStack stack = ItemStack.EMPTY;
  9. private boolean dried = false;
  10.  
  11. public DryingRackBlockEntity() {
  12. super(TYPE);
  13. }
  14.  
  15. public DryingRackBlockEntity(final ItemStack stack) {
  16. this();
  17. this.setStack(stack, false);
  18. }
  19.  
  20. public void setStack(final ItemStack stack) {
  21. this.setStack(stack, true);
  22. }
  23.  
  24. @Override
  25. public void tick() {
  26.  
  27. }
  28.  
  29. @Override
  30. public void fromTag(final CompoundTag nbt) {
  31. super.fromTag(nbt);
  32. this.readStack(nbt);
  33. this.dried = nbt.getBoolean(DRIED);
  34. }
  35.  
  36. @Override
  37. public CompoundTag toTag(final CompoundTag nbt) {
  38. super.toTag(nbt);
  39. this.writeStack(nbt);
  40. nbt.putBoolean(DRIED, this.dried);
  41. return nbt;
  42. }
  43.  
  44. @Override
  45. public void fromClientTag(final CompoundTag nbt) {
  46. this.readStack(nbt);
  47. }
  48.  
  49. @Override
  50. public CompoundTag toClientTag(final CompoundTag nbt) {
  51. this.writeStack(nbt);
  52. return nbt;
  53. }
  54.  
  55. @Override
  56. public String toString() {
  57. return MoreObjects.toStringHelper(this)
  58. .add("ItemStack", this.stack)
  59. .add("Dried", this.dried)
  60. .add("Level", this.world)
  61. .add("Position", this.pos)
  62. .toString();
  63. }
  64.  
  65. private void setStack(final ItemStack stack, final boolean refresh) {
  66. this.stack = stack.isEmpty() ? stack : stack.copy();
  67. if (refresh) {
  68. this.markDirty();
  69. }
  70. }
  71.  
  72. private void writeStack(final CompoundTag nbt) {
  73. nbt.put(STACK, this.stack.toTag(new CompoundTag()));
  74. }
  75.  
  76. private void readStack(final CompoundTag nbt) {
  77. this.stack = ItemStack.fromTag(nbt.getCompound(STACK));
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement