Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class ControlValveScreen extends AbstractContainerScreen<ControlValveMenu
/** 客户端本地过滤器物品缓存(服务端回传更新) */
private ItemStack filterItem = ItemStack.EMPTY;
private List<FluidStack> filterFluids = List.of();
private boolean updatingValueBox;

private FluidRateSlider slider;
private EditBox valueBox;
Expand Down Expand Up @@ -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)。 */
Expand Down Expand Up @@ -165,6 +174,9 @@ private void onSliderChange(int value) {
}

private void onValueInput(String text) {
if (this.updatingValueBox) {
return;
}
if (this.isLocked()) {
return;
}
Expand Down
Loading