From 871dcc7a72c322b2bd5a2aa85d11e1ddfd67c6b3 Mon Sep 17 00:00:00 2001 From: Fff Date: Thu, 12 Nov 2026 11:34:25 -0800 Subject: [PATCH] =?UTF-8?q?fix(menu):=20=E4=BF=AE=E5=A4=8D=E6=97=81?= =?UTF-8?q?=E8=A7=82=E8=80=85=E6=89=93=E5=BC=80=E6=8E=A7=E5=88=B6=E9=98=80?= =?UTF-8?q?=E6=97=B6=E6=96=AD=E5=BC=80=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在控制阀菜单初始化数据中发送方块位置 - 打开界面时读取已同步的流速与过滤配置 - 初始化数值时阻止客户端回写配置 --- .../block/entity/fluid/ControlValveBlockEntity.java | 6 ++++++ .../client/gui/screen/ControlValveScreen.java | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/main/java/dev/dubhe/anvilcraft/block/entity/fluid/ControlValveBlockEntity.java b/src/main/java/dev/dubhe/anvilcraft/block/entity/fluid/ControlValveBlockEntity.java index 6cc0654abd..2846ce8aab 100644 --- a/src/main/java/dev/dubhe/anvilcraft/block/entity/fluid/ControlValveBlockEntity.java +++ b/src/main/java/dev/dubhe/anvilcraft/block/entity/fluid/ControlValveBlockEntity.java @@ -13,6 +13,7 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; +import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientGamePacketListener; @@ -344,4 +345,9 @@ public Component getDisplayName() { public @Nullable AbstractContainerMenu createMenu(int containerId, Inventory inventory, Player player) { return new ControlValveMenu(containerId, inventory, this); } + + @Override + public void writeClientSideData(AbstractContainerMenu menu, RegistryFriendlyByteBuf buffer) { + buffer.writeBlockPos(this.getBlockPos()); + } } diff --git a/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/ControlValveScreen.java b/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/ControlValveScreen.java index 0775062847..37c53f84b7 100644 --- a/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/ControlValveScreen.java +++ b/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/ControlValveScreen.java @@ -72,6 +72,7 @@ public class ControlValveScreen extends AbstractContainerScreen filterFluids = List.of(); + private boolean updatingValueBox; private FluidRateSlider slider; private EditBox valueBox; @@ -119,12 +120,20 @@ protected void init() { this.addRenderableWidget(add); this.addRenderableWidget(max); this.addRenderableWidget(this.valueBox); + ControlValveBlockEntity blockEntity = this.menu.getBlockEntity(); + if (blockEntity != null) { + this.setValue(blockEntity.getMaxRate()); + this.setFilter(0, blockEntity.getFilter(0)); + this.setFilterItem(blockEntity.getFilterItem()); + } } /** 服务端 init 包设置初值。 */ public void setValue(int value) { this.slider.setValue(value); + this.updatingValueBox = true; this.valueBox.setValue(Integer.toString(value)); + this.updatingValueBox = false; } /** 该阀门是否被红石锁定(实时读客户端 BE)。 */ @@ -165,6 +174,9 @@ private void onSliderChange(int value) { } private void onValueInput(String text) { + if (this.updatingValueBox) { + return; + } if (this.isLocked()) { return; }