From 48c7c4e5387754f8095ad10a4c805d6e9f3ecc4f Mon Sep 17 00:00:00 2001 From: Adrien1106 Date: Wed, 19 Jun 2024 13:20:12 +0200 Subject: [PATCH] fix: made frames properly update on every client when using blueprint/screwdriver/hammer --- .../adrien1106/reframed/block/ReFramedDoubleEntity.java | 2 +- .../fr/adrien1106/reframed/block/ReFramedEntity.java | 9 ++++----- .../reframed/item/ReFramedBlueprintWrittenItem.java | 9 ++++++++- .../fr/adrien1106/reframed/item/ReFramedHammerItem.java | 2 +- .../reframed/item/ReFramedScrewdriverItem.java | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedDoubleEntity.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedDoubleEntity.java index cecd4f6..61d9785 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedDoubleEntity.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedDoubleEntity.java @@ -57,6 +57,6 @@ public class ReFramedDoubleEntity extends ReFramedEntity { public void writeNbt(NbtCompound nbt) { super.writeNbt(nbt); - if(second_state != Blocks.AIR.getDefaultState()) nbt.put(BLOCKSTATE_KEY + 2, NbtHelper.fromBlockState(second_state)); + nbt.put(BLOCKSTATE_KEY + 2, NbtHelper.fromBlockState(second_state)); } } diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedEntity.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedEntity.java index fc70154..73ec631 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedEntity.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedEntity.java @@ -52,16 +52,15 @@ public class ReFramedEntity extends BlockEntity implements ThemeableBlockEntity if (nbt.contains(BITFIELD_KEY)) bit_field = nbt.getByte(BITFIELD_KEY); // Force a chunk remesh on the client if the displayed blockstate has changed - if(world != null && world.isClient && !Objects.equals(rendered_state, first_state)) { + if(world != null && world.isClient && !Objects.equals(rendered_state, first_state)) ReFramed.chunkRerenderProxy.accept(world, pos); - } } @Override public void writeNbt(NbtCompound nbt) { super.writeNbt(nbt); - - if(first_state != Blocks.AIR.getDefaultState()) nbt.put(BLOCKSTATE_KEY + 1, NbtHelper.fromBlockState(first_state)); + + nbt.put(BLOCKSTATE_KEY + 1, NbtHelper.fromBlockState(first_state)); if(bit_field != SOLIDITY_MASK) nbt.putByte(BITFIELD_KEY, bit_field); } @@ -113,7 +112,7 @@ public class ReFramedEntity extends BlockEntity implements ThemeableBlockEntity } public void setTheme(BlockState new_state, int i) { - if(!Objects.equals(first_state, new_state)) { + if(!Objects.equals(first_state, new_state) && i == 1) { first_state = new_state; markDirtyAndDispatch(); } diff --git a/src/main/java/fr/adrien1106/reframed/item/ReFramedBlueprintWrittenItem.java b/src/main/java/fr/adrien1106/reframed/item/ReFramedBlueprintWrittenItem.java index 0736a50..3ab6714 100644 --- a/src/main/java/fr/adrien1106/reframed/item/ReFramedBlueprintWrittenItem.java +++ b/src/main/java/fr/adrien1106/reframed/item/ReFramedBlueprintWrittenItem.java @@ -74,7 +74,14 @@ public class ReFramedBlueprintWrittenItem extends Item { stacks.stream().map(inventory::getSlotWithStack).forEach(index -> inventory.removeStack(index, 1)); player.playSound(SoundEvents.ENTITY_ITEM_PICKUP, 0.5f, 0.5f); } - frame_entity.readNbt(tag); + for (int i = 1; tag.contains(BLOCKSTATE_KEY + i); i++) { + BlockState state = NbtHelper.toBlockState( + Registries.BLOCK.getReadOnlyWrapper(), + tag.getCompound(BLOCKSTATE_KEY + i) + ); + frame_entity.setTheme(state, i); + } + if (world.isClient) ReFramed.chunkRerenderProxy.accept(world, pos); world.playSound(player, player.getBlockPos(), SoundEvents.ITEM_BOOK_PAGE_TURN, SoundCategory.PLAYERS); return ActionResult.SUCCESS; diff --git a/src/main/java/fr/adrien1106/reframed/item/ReFramedHammerItem.java b/src/main/java/fr/adrien1106/reframed/item/ReFramedHammerItem.java index b3a1f83..d600755 100644 --- a/src/main/java/fr/adrien1106/reframed/item/ReFramedHammerItem.java +++ b/src/main/java/fr/adrien1106/reframed/item/ReFramedHammerItem.java @@ -43,7 +43,7 @@ public class ReFramedHammerItem extends Item { world.playSound(player, pos, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.BLOCKS, 1f, 1.1f); } frame_entity.setTheme(Blocks.AIR.getDefaultState(), theme_index); - ReFramed.chunkRerenderProxy.accept(world, pos); + if (world.isClient) ReFramed.chunkRerenderProxy.accept(world, pos); return ActionResult.SUCCESS; } } diff --git a/src/main/java/fr/adrien1106/reframed/item/ReFramedScrewdriverItem.java b/src/main/java/fr/adrien1106/reframed/item/ReFramedScrewdriverItem.java index b39b06c..603b7ac 100644 --- a/src/main/java/fr/adrien1106/reframed/item/ReFramedScrewdriverItem.java +++ b/src/main/java/fr/adrien1106/reframed/item/ReFramedScrewdriverItem.java @@ -52,7 +52,7 @@ public class ReFramedScrewdriverItem extends Item { case Z -> Direction.Axis.X; } ), theme_index); - ReFramed.chunkRerenderProxy.accept(world, pos); + if (world.isClient) ReFramed.chunkRerenderProxy.accept(world, pos); return ActionResult.SUCCESS; } }