Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public final class DryingRackBlockEntity extends BlockEntity implements BlockEntityClientSerializable, Tickable {
- public static final BlockEntityType<DryingRackBlockEntity> TYPE =
- BlockEntityType.Builder.method_20528(DryingRackBlockEntity::new/*, MyBlocks.DRYING_RACK*/).build(null);
- private static final String STACK = "stack";
- private static final String DRIED = "dried";
- private ItemStack stack = ItemStack.EMPTY;
- private boolean dried = false;
- public DryingRackBlockEntity() {
- super(TYPE);
- }
- public DryingRackBlockEntity(final ItemStack stack) {
- this();
- this.setStack(stack, false);
- }
- public void setStack(final ItemStack stack) {
- this.setStack(stack, true);
- }
- @Override
- public void tick() {
- }
- @Override
- public void fromTag(final CompoundTag nbt) {
- super.fromTag(nbt);
- this.readStack(nbt);
- this.dried = nbt.getBoolean(DRIED);
- }
- @Override
- public CompoundTag toTag(final CompoundTag nbt) {
- super.toTag(nbt);
- this.writeStack(nbt);
- nbt.putBoolean(DRIED, this.dried);
- return nbt;
- }
- @Override
- public void fromClientTag(final CompoundTag nbt) {
- this.readStack(nbt);
- }
- @Override
- public CompoundTag toClientTag(final CompoundTag nbt) {
- this.writeStack(nbt);
- return nbt;
- }
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(this)
- .add("ItemStack", this.stack)
- .add("Dried", this.dried)
- .add("Level", this.world)
- .add("Position", this.pos)
- .toString();
- }
- private void setStack(final ItemStack stack, final boolean refresh) {
- this.stack = stack.isEmpty() ? stack : stack.copy();
- if (refresh) {
- this.markDirty();
- }
- }
- private void writeStack(final CompoundTag nbt) {
- nbt.put(STACK, this.stack.toTag(new CompoundTag()));
- }
- private void readStack(final CompoundTag nbt) {
- this.stack = ItemStack.fromTag(nbt.getCompound(STACK));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement