[Scarpet Suggestion] event __on_player_pick_block(player, block, found)
Senth opened this issue ยท 2 comments
While using the Scarpet app shulkerboxes.sc I'd like to create a new app that allows the user to pick blocks from these shulkerboxes. To be able to do that I need to listen to an __on_player_pick_block(player, block, found)
event.
Parameters
player
the player...block
what block the player tried to pickfound
true if the block was picked (i.e., it was found in the player's inventory)
I'm not sure if picked
would be a better parameter than found
.
I might be able to implement this feature myself, but I have no prior experience in working on a Minecraft mod.
Looked around in the code, and this functionality seems to be rather non-trivial. The client only sends an event to the server if the picked block is in the inventory, the sent information is only which slot to pick (no block information).
In MinecraftClient.doItemPick():2118-2124
(i => slotIndex)
} else if (i != -1) {
if (PlayerInventory.isValidHotbarIndex(i)) {
playerInventory.selectedSlot = i;
} else {
this.interactionManager.pickFromInventory(i);
}
}
What is needed is another event that gets sent to the server when no slot was found.
} else if (i != -1) {
if (PlayerInventory.isValidHotbarIndex(i)) {
playerInventory.selectedSlot = i;
} else {
this.interactionManager.pickFromInventory(i);
}
} else { // <---- NEW ADDITIONS FROM HERE
this.interactionManager.pickFromInventory(itemStack12.getItem().getId());
}
From that we need to
- Add a new method
ClientPlayerInteractionManager.pickFromInventory(Identifier identifier)
- Either add
Identifier
toPickFromInventoryCS2Packet
(don't know if this causes incompatibility if either client or server is vanilla) or create a new classPickBlockCS2Packet
that sends the block information (don't know if this also will cause incompatibility). Is there another way? - In
ServerPlayNetworkHandler_scarpetEventsMixin.java
- Change
onItemBeingPickedFromInventory(...)
to create a scarpet event - Maybe add another method?
onItemPickBlock(Identifier blockId)
?
Not entirely sure how to continue. If I can add a new packet and how to do that. Compatibility with a scarpet client <-> vanilla server or vanilla server <-> scarpet client is a must.
main problem is that pick block events are handled very differently in various circumstances
- creative players do all client side - server just gets updated inventory without a reason
- survival player with block on a hotbar send these as a change inventory slot event, which is the same as numpad
- survival player that would pick a block from inventory - that's the only event that pick block handles with a proper server communication with pickpacket
Not sure if an elegant solution would be made with that so I left that be