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

Support for cursor stacks #34

Open
BRNSystems opened this issue Jul 2, 2024 · 3 comments
Open

Support for cursor stacks #34

BRNSystems opened this issue Jul 2, 2024 · 3 comments

Comments

@BRNSystems
Copy link

Could you add the ItemStack that the player is clicking with passing to the onClick family of events?
It is possible, since it is sent in the packet.
I know this won't be used much, but at least for my mod it would be useful.

@HyperPaint
Copy link

@BRNSystems hi. Have you found a way to get ItemStack in a click event? I'm trying to put an item in the gui, but I've only been able to take item from it :(

@BRNSystems
Copy link
Author

In my mod, I only needed to take from the slot. @Patbox should be more helpful

@HyperPaint
Copy link

I did it, but not well. Shift + left click for return items, right click for divide items and left click + move doesnt work. But i can put and get items.

final GuiElementInterface.ClickCallback clickCallback = new GuiElementInterface.ClickCallback() {
   @Override
   public void click(int index, ClickType type, SlotActionType action, SlotGuiInterface gui) {
       if (action == SlotActionType.PICKUP) {
           final ItemStack playerItemStack = serverPlayerEntity.currentScreenHandler.getCursorStack();
           final GuiElementInterface slot = gui.getSlot(index);
           final ItemStack slotItemStack = slot == null ? ItemStack.EMPTY : slot.getItemStack();
           if (!playerItemStack.isEmpty() && slotItemStack.isEmpty()) {
               // Положить предмет
               gui.setSlot(index, playerItemStack.copyAndEmpty(), this);
           } else if (!playerItemStack.isEmpty() && playerItemStack.getItem().equals(slotItemStack.getItem())) {
               // Доложить предмет
               final int count = playerItemStack.getCount() + slotItemStack.getCount();
               final int maxCount = slotItemStack.getMaxCount();
               if (count > maxCount) {
                   slotItemStack.setCount(maxCount);
                   playerItemStack.setCount(count - playerItemStack.getCount());
               } else {
                   slotItemStack.setCount(count);
                   playerItemStack.setCount(0);
               }
           } else if (playerItemStack.isEmpty() && !slotItemStack.isEmpty()) {
               // Взять предмет
               serverPlayerEntity.currentScreenHandler.setCursorStack(slotItemStack.copyAndEmpty());
           }
       }
   }
};

SimpleGuiBuilder builder = new SimpleGuiBuilder(ScreenHandlerType.HOPPER, false);
for (int i = 0; i < HopperScreenHandler.SLOT_COUNT; i++) {
   builder.setSlot(i, ItemStack.EMPTY, clickCallback);
}
SimpleGui simpleGui = builder.build(serverPlayerEntity);
simpleGui.setLockPlayerInventory(false);
simpleGui.open();

But at some moment, interaction becomes unstable, as if there is a problem with synchronization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants