From 6149e326bafb130e6246d5e722e0601ef4f2bec6 Mon Sep 17 00:00:00 2001 From: ImmuState Date: Tue, 7 Jun 2022 14:30:11 -0700 Subject: [PATCH] Make UI for blueprint unlocking behave. --- .../managers/ForgingManager/ForgingManager.java | 12 ++++++++---- .../grasscutter/game/managers/InventoryManager.java | 13 +++++++------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/managers/ForgingManager/ForgingManager.java b/src/main/java/emu/grasscutter/game/managers/ForgingManager/ForgingManager.java index e51174fcb..cee06ca31 100644 --- a/src/main/java/emu/grasscutter/game/managers/ForgingManager/ForgingManager.java +++ b/src/main/java/emu/grasscutter/game/managers/ForgingManager/ForgingManager.java @@ -48,11 +48,15 @@ public class ForgingManager { // Determine the forging item we should unlock. int forgeId = Integer.parseInt(blueprintItem.getItemData().getItemUse().get(0).getUseParam().get(0)); - // Tell the client that this blueprint is now unlocked and add the unlocked item to the player. - this.player.sendPacket(new PacketForgeFormulaDataNotify(forgeId)); - this.player.getUnlockedForgingBlueprints().add(forgeId); + // Remove the blueprint from the player's inventory. + // We need to do this here, before sending ForgeFormulaDataNotify, or the the forging UI won't correctly + // update when unlocking the blueprint. + player.getInventory().removeItem(blueprintItem, 1); + + // Tell the client that this blueprint is now unlocked and add the unlocked item to the player. + this.player.getUnlockedForgingBlueprints().add(forgeId); + this.player.sendPacket(new PacketForgeFormulaDataNotify(forgeId)); - // Done. return true; } diff --git a/src/main/java/emu/grasscutter/game/managers/InventoryManager.java b/src/main/java/emu/grasscutter/game/managers/InventoryManager.java index d5811a316..33df0ecf3 100644 --- a/src/main/java/emu/grasscutter/game/managers/InventoryManager.java +++ b/src/main/java/emu/grasscutter/game/managers/InventoryManager.java @@ -822,6 +822,7 @@ public class InventoryManager { } int used = 0; + boolean useSuccess = false; // Use switch (useItem.getItemData().getMaterialType()) { @@ -853,12 +854,7 @@ public class InventoryManager { // Handle forging blueprints. if (useItem.getItemData().getItemUse().get(0).getUseOp().equals("ITEM_USE_UNLOCK_FORGE")) { // Unlock. - boolean success = player.getForgingManager().unlockForgingBlueprint(useItem); - - // Use up the blueprint item if successful. - if (success) { - used = 1; - } + useSuccess = player.getForgingManager().unlockForgingBlueprint(useItem); } break; case MATERIAL_CHEST: @@ -925,10 +921,15 @@ public class InventoryManager { used = 1; } + // If we used at least one item, or one of the methods called here reports using the item successfully, + // we return the item to make UseItemRsp a success. if (used > 0) { player.getInventory().removeItem(useItem, used); return useItem; } + if (useSuccess) { + return useItem; + } return null; }