Fix crafting output not updating sometimes (#4692)

* Only cancel crafting grid future if slot == 0

* Add some comments
This commit is contained in:
Valaphee The Meerkat 2024-05-27 16:53:42 +02:00 committed by GitHub
parent cb0488a271
commit 3570caae25
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -71,10 +71,6 @@ public class JavaContainerSetSlotTranslator extends PacketTranslator<Clientbound
InventoryTranslator translator = session.getInventoryTranslator();
if (translator != null) {
if (session.getCraftingGridFuture() != null) {
session.getCraftingGridFuture().cancel(false);
}
int slot = packet.getSlot();
if (slot >= inventory.getSize()) {
GeyserLogger logger = session.getGeyser().getLogger();
@ -111,14 +107,22 @@ public class JavaContainerSetSlotTranslator extends PacketTranslator<Clientbound
* Checks for a changed output slot in the crafting grid, and ensures Bedrock sees the recipe.
*/
private static void updateCraftingGrid(GeyserSession session, int slot, ItemStack item, Inventory inventory, InventoryTranslator translator) {
// Check if it's the crafting grid result slot.
if (slot != 0) {
return;
}
// Check if there is any crafting grid.
int gridSize = translator.getGridSize();
if (gridSize == -1) {
return;
}
// Only process the most recent crafting grid result, and cancel the previous one.
if (session.getCraftingGridFuture() != null) {
session.getCraftingGridFuture().cancel(false);
}
if (InventoryUtils.isEmpty(item)) {
return;
}