Fix smithing recipes on 1.21.1

This commit is contained in:
Camotoy 2024-11-11 20:11:03 -05:00
parent e645935533
commit fd58c729d8
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
2 changed files with 13 additions and 1 deletions

View file

@ -31,6 +31,7 @@ import org.geysermc.geyser.inventory.Inventory;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.inventory.InventoryTranslator;
import org.geysermc.geyser.translator.inventory.PlayerInventoryTranslator;
import org.geysermc.geyser.translator.inventory.SmithingInventoryTranslator;
import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator;
import org.geysermc.geyser.util.InventoryUtils;
@ -74,6 +75,17 @@ public class JavaContainerSetContentTranslator extends PacketTranslator<Clientbo
session.getPlayerInventory().setCursor(GeyserItemStack.from(packet.getCarriedItem()), session);
InventoryUtils.updateCursor(session);
if (session.getInventoryTranslator() instanceof SmithingInventoryTranslator) {
// On 1.21.1, the recipe output is sometimes only updated here.
// This can be replicated with shift-clicking the last item into the smithing table.
// It seems that something in Via 5.1.1 causes 1.21.3 clients - even Java ones -
// to make the server send a slot update.
// That plus shift-clicking means that the state ID becomes outdated and forces
// a complete inventory update.
JavaContainerSetSlotTranslator.updateSmithingTableOutput(session, SmithingInventoryTranslator.OUTPUT,
packet.getItems()[SmithingInventoryTranslator.OUTPUT], inventory);
}
}
private void updateInventory(GeyserSession session, Inventory inventory, int containerId) {

View file

@ -224,7 +224,7 @@ public class JavaContainerSetSlotTranslator extends PacketTranslator<Clientbound
}, 150, TimeUnit.MILLISECONDS));
}
private static void updateSmithingTableOutput(GeyserSession session, int slot, ItemStack output, Inventory inventory) {
static void updateSmithingTableOutput(GeyserSession session, int slot, ItemStack output, Inventory inventory) {
if (slot != SmithingInventoryTranslator.OUTPUT) {
return;
}