Skip to content

Commit cd1aa27

Browse files
committed
Add proper null check to ApplyBonusLootFunctionMixin
Mitigates #229 Signed-off-by: Noaaan <[email protected]>
1 parent 1494e65 commit cd1aa27

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/main/java/nourl/mythicmetals/mixin/ApplyBonusLootFunctionMixin.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.spongepowered.asm.mixin.Mixin;
1111
import org.spongepowered.asm.mixin.injection.At;
1212
import org.spongepowered.asm.mixin.injection.ModifyVariable;
13-
import java.util.Objects;
1413

1514
@Mixin(ApplyBonusLootFunction.class)
1615
public class ApplyBonusLootFunctionMixin {
@@ -20,10 +19,16 @@ public class ApplyBonusLootFunctionMixin {
2019
target = "Lnet/minecraft/loot/context/LootContext;getRandom()Lnet/minecraft/util/math/random/Random;", shift = At.Shift.BEFORE),
2120
ordinal = 0)
2221
private int mythicmetals$increaseFortune(int level, ItemStack drop, LootContext lootCtx) {
23-
if (Abilities.BONUS_FORTUNE.getItems().contains(Objects.requireNonNull(lootCtx.get(LootContextParameters.TOOL)).getItem())) {
22+
// Return early if there is no item
23+
var toolCtx = lootCtx.get(LootContextParameters.TOOL);
24+
if (toolCtx == null) {
25+
return level;
26+
}
27+
28+
if (Abilities.BONUS_FORTUNE.getItems().contains(toolCtx.getItem())) {
2429
return level + Abilities.BONUS_FORTUNE.getLevel();
2530
}
26-
if (MythrilDrill.hasUpgradeItem(Objects.requireNonNull(lootCtx.get(LootContextParameters.TOOL)), MythicBlocks.CARMOT.getStorageBlock().asItem())) {
31+
if (MythrilDrill.hasUpgradeItem(toolCtx, MythicBlocks.CARMOT.getStorageBlock().asItem())) {
2732
return level + 1;
2833
}
2934
return level;

0 commit comments

Comments
 (0)