diff --git a/src/main/java/net/maxello/knowledgebound/mechanics/gathering/KnowledgeEvents.java b/src/main/java/net/maxello/knowledgebound/mechanics/gathering/KnowledgeEvents.java index 1845ea4..9745bcf 100644 --- a/src/main/java/net/maxello/knowledgebound/mechanics/gathering/KnowledgeEvents.java +++ b/src/main/java/net/maxello/knowledgebound/mechanics/gathering/KnowledgeEvents.java @@ -536,6 +536,10 @@ private static void registerRangedCombatXp() { // what are we holding? KnowledgeDefinition.ToolTier toolTier = ToolTierHelper.fromItem(player.getMainHandStack()); + if (toolTier != KnowledgeDefinition.ToolTier.BOW + && toolTier != KnowledgeDefinition.ToolTier.CROSSBOW) { + toolTier = ToolTierHelper.fromItem(player.getOffHandStack()); + } // Will only grant XP if that tier is valid for the current knowledge tier grantXpIfValidTool(player, rangedDef, toolTier); diff --git a/src/main/java/net/maxello/knowledgebound/mechanics/jobs/SlaughteringManager.java b/src/main/java/net/maxello/knowledgebound/mechanics/jobs/SlaughteringManager.java index 4d268fc..02e7fa4 100644 --- a/src/main/java/net/maxello/knowledgebound/mechanics/jobs/SlaughteringManager.java +++ b/src/main/java/net/maxello/knowledgebound/mechanics/jobs/SlaughteringManager.java @@ -247,7 +247,7 @@ private static void registerDissectionInteraction() { } // Actually roll the dice and generate the loot - performDissection(serverPlayer, entity, isCleaver, cfg); + performDissection(serverPlayer, entity, isCleaver, cfg, hand); // Cancel further processing so they don't accidentally ride the dead horse or milk the dead cow return ActionResult.SUCCESS; @@ -255,7 +255,8 @@ private static void registerDissectionInteraction() { } private static void performDissection(ServerPlayerEntity player, Entity corpse, - boolean usedCleaver, KnowledgeBoundConfig cfg) { + boolean usedCleaver, KnowledgeBoundConfig cfg, + net.minecraft.util.Hand hand) { if (!(corpse.getWorld() instanceof ServerWorld serverWorld)) return; int slaughterTier = PlayerKnowledgeManager.getTier(player, KnowledgeRegistry.SLAUGHTERING_ID); @@ -267,7 +268,7 @@ private static void performDissection(ServerPlayerEntity player, Entity corpse, double failRoll = RANDOM.nextDouble(); if (failRoll < failChance) { - handleFailedDissection(player, corpse, serverWorld, cfg); + handleFailedDissection(player, corpse, serverWorld, cfg, hand); return; } @@ -319,9 +320,9 @@ private static void performDissection(ServerPlayerEntity player, Entity corpse, 10, 0.3, 0.3, 0.3, 0.02); // Take durability off their tool - ItemStack held = player.getMainHandStack(); + ItemStack held = player.getStackInHand(hand); if (!held.isEmpty()) { - held.damage(1, player, LivingEntity.getSlotForHand(player.getActiveHand())); + held.damage(1, player, LivingEntity.getSlotForHand(hand)); } // Give them XP for trying @@ -351,7 +352,8 @@ private static double getFailChance(int tier, KnowledgeBoundConfig cfg) { * Handle a failed dissection — drops 1 rotten flesh, plays an ugly sound, destroys corpse. */ private static void handleFailedDissection(ServerPlayerEntity player, Entity corpse, - ServerWorld serverWorld, KnowledgeBoundConfig cfg) { + ServerWorld serverWorld, KnowledgeBoundConfig cfg, + net.minecraft.util.Hand hand) { // Toss out a single piece of rotten flesh as a consolation prize ItemStack rottenFlesh = new ItemStack(Items.ROTTEN_FLESH, 1); @@ -371,9 +373,9 @@ private static void handleFailedDissection(ServerPlayerEntity player, Entity cor corpse.getX(), corpse.getY() + 0.5, corpse.getZ(), 15, 0.4, 0.3, 0.4, 0.03); - ItemStack held = player.getMainHandStack(); + ItemStack held = player.getStackInHand(hand); if (!held.isEmpty()) { - held.damage(1, player, LivingEntity.getSlotForHand(player.getActiveHand())); + held.damage(1, player, LivingEntity.getSlotForHand(hand)); } // Even failing teaches you something! diff --git a/src/main/java/net/maxello/knowledgebound/mixin/ScreenHandlerMixin.java b/src/main/java/net/maxello/knowledgebound/mixin/ScreenHandlerMixin.java index 473209a..6ea141a 100644 --- a/src/main/java/net/maxello/knowledgebound/mixin/ScreenHandlerMixin.java +++ b/src/main/java/net/maxello/knowledgebound/mixin/ScreenHandlerMixin.java @@ -172,6 +172,9 @@ public class ScreenHandlerMixin { Identifier id = Registries.ITEM.getId(incoming.getItem()); SupervisedJob.JobType jt = SupervisedJobManager.getJobTypeForItem(id); if (jt != null) { + net.maxello.knowledgebound.config.KnowledgeBoundConfig cfg = net.maxello.knowledgebound.config.KnowledgeBoundConfig.INSTANCE; + boolean jobEnabled = jt == SupervisedJob.JobType.SMELTING ? cfg.smeltingEnabled : cfg.cookingEnabled; + if (!jobEnabled) return; // How many items are trying to be added? Slot inputSlot = self.slots.get(0); int currentCount = inputSlot.hasStack() ? inputSlot.getStack().getCount() : 0; @@ -195,6 +198,9 @@ public class ScreenHandlerMixin { Identifier sourceItemId = Registries.ITEM.getId(sourceStack.getItem()); SupervisedJob.JobType jt = SupervisedJobManager.getJobTypeForItem(sourceItemId); if (jt != null) { + net.maxello.knowledgebound.config.KnowledgeBoundConfig cfg = net.maxello.knowledgebound.config.KnowledgeBoundConfig.INSTANCE; + boolean jobEnabled = jt == SupervisedJob.JobType.SMELTING ? cfg.smeltingEnabled : cfg.cookingEnabled; + if (!jobEnabled) return; // Check if there's already an item in the input slot ItemStack currentInput = self.slots.get(0).getStack(); if (currentInput.isEmpty()) {