Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix phantom slot ignoring slot limit #90

Merged
merged 1 commit into from
Oct 4, 2024
Merged
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 @@ -83,20 +83,23 @@ public void readOnServer(int id, PacketBuffer buf) throws IOException {
setEnabled(buf.readBoolean(), false);
} else if (id == 5) {
if (!isPhantom()) return;
ItemStack stack = buf.readItemStack();
this.slot.putStack(stack);
phantomClick(MouseData.create(0), buf.readItemStack());
}
}

protected void phantomClick(MouseData mouseData) {
ItemStack cursorStack = getSyncManager().getCursorItem();
phantomClick(mouseData, getSyncManager().getCursorItem());
}

protected void phantomClick(MouseData mouseData, ItemStack cursorStack) {
ItemStack slotStack = getSlot().getStack();
ItemStack stackToPut;
if (!cursorStack.isEmpty() && !slotStack.isEmpty() && !ItemHandlerHelper.canItemStacksStack(cursorStack, slotStack)) {
stackToPut = cursorStack.copy();
if (mouseData.mouseButton == 1) {
stackToPut.setCount(1);
}
stackToPut.setCount(Math.min(stackToPut.getCount(), slot.getItemStackLimit(stackToPut)));
getSlot().putStack(stackToPut);
this.lastStoredPhantomItem = stackToPut.copy();
} else if (slotStack.isEmpty()) {
Expand All @@ -112,6 +115,7 @@ protected void phantomClick(MouseData mouseData) {
if (mouseData.mouseButton == 1) {
stackToPut.setCount(1);
}
stackToPut.setCount(Math.min(stackToPut.getCount(), slot.getItemStackLimit(stackToPut)));
getSlot().putStack(stackToPut);
this.lastStoredPhantomItem = stackToPut.copy();
} else {
Expand Down