Jump to content

[1.18.2] Caused by: java.lang.NullPointerException: Cannot read field "mending" because "us.blueeyemods.uem.Main.config" is null


Recommended Posts

package us.blueeyemods.uem;

import dev.toma.configuration.Configuration;
import dev.toma.configuration.config.format.ConfigFormats;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import us.blueeyemods.uem.config.ModConfig;

@SuppressWarnings("unused")
@Mod(Main.MODID)
public class Main {
    public static final String MODID = "uem";

    public static ModConfig config;

    public Main() {
        IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
        MinecraftForge.EVENT_BUS.register(this);
        config = Configuration.registerConfig(ModConfig.class, ConfigFormats.json()).getConfigInstance();
    }
}

I don't understand why this is throwing a null pointer exception when I use this in my mixin:

package us.blueeyemods.uem.mixin.mending;

import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;
import net.minecraft.world.item.enchantment.MendingEnchantment;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import us.blueeyemods.uem.Main;

@Mixin(MendingEnchantment.class)
public class MendingMixin {
    int field_1 = Main.config.mending.MAXIMUM_ENCHANTMENT_LEVEL;
    boolean field_2 = Main.config.mending.TREASURE_ONLY;

    private static Enchantment.Rarity field_3 = Main.config.mending.ENCHANTMENT_RARITY;

    private static EnchantmentCategory field_4 = Main.config.mending.ENCHANTMENT_CATEGORY;

    private static EquipmentSlot[] field_5 = Main.config.mending.EQUIPMENT_SLOTS;
    @Inject(
            method = {"getMaxLevel"},
            at = {@At("RETURN")},
            cancellable = true
    )
    public void betterenchantments$getMaxLevel(CallbackInfoReturnable<Integer> cir) {
            cir.setReturnValue(Math.min(field_1, 255));
    }
    @Inject(
            method = {"isTreasureOnly"},
            at = {@At("RETURN")},
            cancellable = true
    )
    public void betterenchantments$isTreasureOnly(CallbackInfoReturnable<Boolean> cir) {
            cir.setReturnValue(field_2);
    }
    @ModifyArg(
            method = {"<init>"},
            at = @At(
                    value = "INVOKE",
                    target = "Lnet/minecraft/world/item/enchantment/Enchantment;" +
                            "<init>(Lnet/minecraft/world/item/enchantment/Enchantment$Rarity;" +
                            "Lnet/minecraft/world/item/enchantment/EnchantmentCategory;" +
                            "[Lnet/minecraft/world/entity/EquipmentSlot;)V"
            ),
            index = 0
    )
    private static Enchantment.Rarity betterenchantments$modifyEnchantmentRarity(Enchantment.Rarity weight) {
        return field_3;
    }
    @ModifyArg(
            method = {"<init>"},
            at = @At(
                    value = "INVOKE",
                    target = "Lnet/minecraft/world/item/enchantment/Enchantment;" +
                            "<init>(Lnet/minecraft/world/item/enchantment/Enchantment$Rarity;" +
                            "Lnet/minecraft/world/item/enchantment/EnchantmentCategory;" +
                            "[Lnet/minecraft/world/entity/EquipmentSlot;)V"
            ),
            index = 1
    )
    private static EnchantmentCategory betterenchantments$modifyEnchantmentCategory(EnchantmentCategory pCategory) {
        return field_4;
    }
    @ModifyArg(
            method = {"<init>"},
            at = @At(
                    value = "INVOKE",
                    target = "Lnet/minecraft/world/item/enchantment/Enchantment;" +
                            "<init>(Lnet/minecraft/world/item/enchantment/Enchantment$Rarity;" +
                            "Lnet/minecraft/world/item/enchantment/EnchantmentCategory;" +
                            "[Lnet/minecraft/world/entity/EquipmentSlot;)V"
            ),
            index = 2
    )
    private static EquipmentSlot[] betterenchantments$modifyEnchantmentSlots(EquipmentSlot[] pApplicableSlots) {
        return field_5;
    }
}

What went wrong?

New year, new me. Nothing's going to get me down!

Link to comment
Share on other sites

Mixins are not supported here.

Try the 3rd party modding channel on forge's discord or wherever mixin provides support.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.