Skip to content

Commit

Permalink
Fix early crash when enchantability is checked before AE2 is initiali…
Browse files Browse the repository at this point in the history
…zed (#7792)

Fixes #7791
  • Loading branch information
shartte authored Mar 26, 2024
1 parent 68258f1 commit 36f3809
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/main/java/appeng/hooks/EnchantmentHooks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package appeng.hooks;

import net.minecraft.world.item.Item;

import appeng.core.definitions.AEParts;
import appeng.items.parts.PartItem;

public final class EnchantmentHooks {
private EnchantmentHooks() {
}

public static boolean isDiggerEnchantable(Item item) {
// The instanceof check here tries to avoid class-init of AEParts until it is called for an actual AE item
// Otherwise it might try to initialize all AE Parts
if (item instanceof PartItem) {
return isAnnihilationPlane(item);
}
return false;
}

private static boolean isAnnihilationPlane(Item item) {
return item == AEParts.ANNIHILATION_PLANE.asItem();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import net.minecraft.world.item.Item;

import appeng.core.definitions.AEParts;
import appeng.hooks.EnchantmentHooks;

/**
* Adds the ME Annihilation Plane to the items to check for when applying
Expand All @@ -17,7 +17,7 @@
public class AnnihilationPlaneEnchantmentMixin {
@Inject(method = "canEnchant", at = @At("RETURN"), cancellable = true)
public void enchantPlane(Item item, CallbackInfoReturnable<Boolean> cir) {
if (item == AEParts.ANNIHILATION_PLANE.asItem()) {
if (EnchantmentHooks.isDiggerEnchantable(item)) {
cir.setReturnValue(true);
}
}
Expand Down

0 comments on commit 36f3809

Please sign in to comment.