You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just found out about WItemSlot$setInsertingAllowed and WItemSlot$setTakingAllowed, and honestly I felt dumb for not investigating more on the widget itself.
However, I am still requesting to add slot capacity as the feature enhancement slot constraint. The desired effect on setting slot capacity is that:
If the incoming stack is combineable with the slot stack, then fill up the slot and the extra stack is put into the player's cursor
If the slot stack is empty, then fill up the slot and the extra stack is put into the player's cursor
If the incoming stack is not combineable with the slot stack, drop the original slot stack, and then fill up the slot and the extra stack is put into the player's cursor
The use case is too specific, but I really appreciate it if the feature can be added. As of currently, I am using my original workaround to solve my problem.
Original post
In SyncedGuiDescription, I made a lot of constraints for the blockInventory slot of my GUI, e.g. allowing only certain items to be put into the slot, or defining the slot capacity, etc. Right now, I did the checking in onSlotClick for when user place an item, pick up an item, swap an item, and quick moving an item, and from that, I did a lot of copy-pasting of codes.
For the feature request, I'd like to have something like a slot constraint variable so that I can define in my SyncedGuiDescription constructor like
// can only place cobblestone in this slot slotPredicate.set(0, (incomingStack, currentStack) -> incomingStack.item == Items.COBBLESTONE)
// can only pickup in this slot slotPredicate.set(1, (incomingStack, currentStack) -> incomingStack.isEmpty())
// can only place at most 5 items in this slotslotCapacity.set(0, 5)
and maybe an example of implementation in SyncedGuiDescription$onSlotClick is
...
// when player is placing item into a slotItemStackincomingStack = playerInventory.getCursorStack()
ItemStackcurrentStack = slots[slotNumber].getStack()
if (!slotPredicate.get(slotNumber).test(incomingStack, currentStack)
returnItemStack.EMPTYintcapacity = slotCapacity.get(slotNumber)
// do some capacity checking here
...
// when player is shift-clicking a slotItemStackincomingStack = getFirstEmptySlot(slots).getStack()
ItemStackcurrentStack = slots[slotNumber].getStack()
if (!slotPredicate.get(slotNumber).test(incomingStack, currentStack)
returnItemStack.EMPTY
...
The text was updated successfully, but these errors were encountered:
Sorry with the messy compare, I accidentally auto-formatted on my IDE.
I did changes only to onSlotClick, insertIntoExisting and insertIntoEmpty methods, and added some relevant fields + methods. slotPredicates is for whether or not the item can be placed into the slot or not, slotCapacity is the slot capacity.
Perhaps, is there a better way of adding this feature?
I just found out about
WItemSlot$setInsertingAllowed
andWItemSlot$setTakingAllowed
, and honestly I felt dumb for not investigating more on the widget itself.However, I am still requesting to add slot capacity as the feature enhancement slot constraint. The desired effect on setting slot capacity is that:
The use case is too specific, but I really appreciate it if the feature can be added. As of currently, I am using my original workaround to solve my problem.
Original post
In
SyncedGuiDescription
, I made a lot of constraints for theblockInventory
slot of my GUI, e.g. allowing only certain items to be put into the slot, or defining the slot capacity, etc. Right now, I did the checking inonSlotClick
for when user place an item, pick up an item, swap an item, and quick moving an item, and from that, I did a lot of copy-pasting of codes.For the feature request, I'd like to have something like a slot constraint variable so that I can define in my
SyncedGuiDescription
constructor likeand maybe an example of implementation in
SyncedGuiDescription$onSlotClick
isThe text was updated successfully, but these errors were encountered: