Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,16 @@ 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;
});
}

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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()) {
Expand Down