From e486af67049367bb3c18d487db4f52f24ddd9c27 Mon Sep 17 00:00:00 2001 From: Wormbo Date: Mon, 15 Jan 2024 19:10:20 +0100 Subject: [PATCH] Ensure Crystal Cube block entity updates are persisted (#4549) - fixes #4546 by flagging the containing chunk as containing unsaved changes - replaced all manually dispatched client updates in `CorporeaCrystalCubeBlockEntity` with the vanilla way to send them --- .../CorporeaCrystalCubeBlockEntity.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Xplat/src/main/java/vazkii/botania/common/block/block_entity/corporea/CorporeaCrystalCubeBlockEntity.java b/Xplat/src/main/java/vazkii/botania/common/block/block_entity/corporea/CorporeaCrystalCubeBlockEntity.java index eecfdc9875..c2fece6119 100644 --- a/Xplat/src/main/java/vazkii/botania/common/block/block_entity/corporea/CorporeaCrystalCubeBlockEntity.java +++ b/Xplat/src/main/java/vazkii/botania/common/block/block_entity/corporea/CorporeaCrystalCubeBlockEntity.java @@ -22,6 +22,7 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.Nullable; @@ -31,7 +32,6 @@ import vazkii.botania.api.corporea.CorporeaRequestMatcher; import vazkii.botania.api.corporea.CorporeaRequestor; import vazkii.botania.api.corporea.CorporeaSpark; -import vazkii.botania.api.internal.VanillaPacketDispatcher; import vazkii.botania.client.core.helper.RenderHelper; import vazkii.botania.common.block.block_entity.BotaniaBlockEntities; @@ -62,10 +62,8 @@ public static void serverTick(Level level, BlockPos pos, BlockState state, Corpo public void setRequestTarget(ItemStack stack) { if (!stack.isEmpty() && !locked) { requestTarget = stack.copyWithCount(1); + setChanged(); updateCount(); - if (!level.isClientSide) { - VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this); - } } } @@ -113,12 +111,8 @@ private void setCount(int count) { int oldCount = this.itemCount; this.itemCount = count; if (this.itemCount != oldCount) { - int oldCompValue = this.compValue; this.compValue = CorporeaHelper.instance().signalStrengthForRequestSize(itemCount); - if (this.compValue != oldCompValue && this.level != null) { - this.level.updateNeighbourForOutputSignal(this.worldPosition, getBlockState().getBlock()); - } - VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this); + setChanged(); } } @@ -173,14 +167,20 @@ public void doCorporeaRequest(CorporeaRequestMatcher request, int count, Corpore public boolean onUsedByWand(@Nullable Player player, ItemStack stack, Direction side) { if (player == null || player.isShiftKeyDown()) { this.locked = !this.locked; - if (!level.isClientSide) { - VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this); - } + setChanged(); return true; } return false; } + @Override + public void setChanged() { + super.setChanged(); + if (level != null) { + level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_CLIENTS); + } + } + public static class Hud { public static void render(GuiGraphics gui, CorporeaCrystalCubeBlockEntity cube) { PoseStack ps = gui.pose();