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; }