Skip to content

Commit

Permalink
rename and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ghzdude committed Jan 29, 2025
1 parent b545de7 commit 647a14f
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ public void setStack(ItemStack stack) {

protected static class InputSyncHandler extends SyncHandler {

public static final int SYNC_STACK = 1;
public static final int SLOT_CHANGED = 1;

private final IItemHandlerModifiable handler;
private final int index;
private ItemStack lastStoredItem;
Expand All @@ -146,7 +147,7 @@ public void init(String key, PanelSyncManager syncHandler) {

@Override
public void readOnClient(int id, PacketBuffer buf) {
if (id == SYNC_STACK) {
if (id == SLOT_CHANGED) {
boolean onlyAmt = buf.readBoolean();
var stack = NetworkUtils.readItemStack(buf);
boolean init = buf.readBoolean();
Expand All @@ -158,7 +159,7 @@ public void readOnClient(int id, PacketBuffer buf) {

@Override
public void readOnServer(int id, PacketBuffer buf) {
if (id == SYNC_STACK) {
if (id == SLOT_CHANGED) {
var onlyAmt = buf.readBoolean();
var stack = NetworkUtils.readItemStack(buf);
this.handler.setStackInSlot(this.index, stack);
Expand All @@ -181,7 +182,7 @@ public void detectAndSendChanges(boolean init) {
this.lastStoredItem = itemStack.isEmpty() ? ItemStack.EMPTY : itemStack.copy();
}
final boolean finalOnlyAmountChanged = onlyAmountChanged;
syncToClient(1, buffer -> {
syncToClient(SLOT_CHANGED, buffer -> {
buffer.writeBoolean(finalOnlyAmountChanged);
NetworkUtils.writeItemStack(buffer, itemStack);
buffer.writeBoolean(init);
Expand All @@ -194,9 +195,8 @@ public void syncStack() {
final var curStack = getStack();
final boolean onlyAmt = ItemHandlerHelper.canItemStacksStackRelaxed(curStack, cursorStack);

this.handler.setStackInSlot(this.index, cursorStack);
this.listener.onChange(cursorStack, onlyAmt, true, false);
syncToServer(SYNC_STACK, buffer -> {
setStack(cursorStack);
syncToServer(SLOT_CHANGED, buffer -> {
buffer.writeBoolean(onlyAmt);
NetworkUtils.writeItemStack(buffer, cursorStack);
});
Expand Down

0 comments on commit 647a14f

Please sign in to comment.