Skip to content

Commit

Permalink
Fix ME hatches crashing on server side (#2812)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnk1234567 authored Feb 12, 2025
1 parent 9e0dd30 commit 9d8085d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ public AmountSetWidget(int x, int y, ConfigWidget widget) {
.setMaxStringLength(10);
}

public void setSlotIndex(int slotIndex) {
@OnlyIn(Dist.CLIENT)
public void setSlotIndexClient(int slotIndex) {
this.index = slotIndex;
writeClientAction(0, buf -> buf.writeVarInt(this.index));
}

public void setSlotIndex(int slotIndex) {
this.index = slotIndex;
}

public String getAmountStr() {
if (this.index < 0) {
return "0";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ public ConfigWidget(int x, int y, IConfigurableSlot[] config, boolean isStocking
this.amountSetWidget.getAmountText().setVisible(false);
}

@OnlyIn(Dist.CLIENT)
public void enableAmountClient(int slotIndex) {
this.amountSetWidget.setSlotIndexClient(slotIndex);
this.amountSetWidget.setVisible(true);
this.amountSetWidget.getAmountText().setVisible(true);
}

@OnlyIn(Dist.CLIENT)
public void disableAmountClient() {
this.amountSetWidget.setSlotIndexClient(-1);
this.amountSetWidget.setVisible(false);
this.amountSetWidget.getAmountText().setVisible(false);
}

public void enableAmount(int slotIndex) {
this.amountSetWidget.setSlotIndex(slotIndex);
this.amountSetWidget.setVisible(true);
Expand All @@ -66,7 +80,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
slot.setSelect(false);
}
}
this.disableAmount();
this.disableAmountClient();
return super.mouseClicked(mouseX, mouseY, button);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
writeClientAction(REMOVE_ID, buf -> {});

if (!parentWidget.isStocking()) {
this.parentWidget.disableAmount();
this.parentWidget.disableAmountClient();
}
} else if (button == 0) {
// Left click to set/select
ItemStack hold = this.gui.getModularUIContainer().getCarried();
FluidUtil.getFluidContained(hold).ifPresent(f -> writeClientAction(UPDATE_ID, f::writeToPacket));

if (!parentWidget.isStocking()) {
this.parentWidget.enableAmount(this.index);
this.parentWidget.enableAmountClient(this.index);
this.select = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
writeClientAction(REMOVE_ID, buf -> {});

if (!parentWidget.isStocking()) {
this.parentWidget.disableAmount();
this.parentWidget.disableAmountClient();
}
} else if (button == 0) {
// Left click to set/select
Expand All @@ -108,7 +108,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
}

if (!parentWidget.isStocking()) {
this.parentWidget.enableAmount(this.index);
this.parentWidget.enableAmountClient(this.index);
this.select = true;
}
}
Expand Down

0 comments on commit 9d8085d

Please sign in to comment.