Jump to content

Switching Block drops when Mod Pickaxe is in hand[1.18.2]


tal124

Recommended Posts

I have created a GlobalLootSerializer
 

Spoiler
public class ModGlobalLootSerializer extends GlobalLootModifierSerializer<ModLootModifier> {

    @Override
    public ModLootModifier read(ResourceLocation location, JsonObject object, LootItemCondition[] lootItemConditions) {
        CompoundTag numRawOre = JsonUtils.readNBT(object, "numRawOre");
        Item ore = ForgeRegistries.ITEMS.getValue(new ResourceLocation(JsonUtils.readNBT(object, "ore_item").toString()));
        Item ingot = ForgeRegistries.ITEMS.getValue(new ResourceLocation(JsonUtils.readNBT(object, "ingot_item").toString()));

        return new ModLootModifier(lootItemConditions, numRawOre, ore, ingot);
    }

    @Override
    public JsonObject write(ModLootModifier instance) {
        return null;
    }
}

 

And a GlobalLootProvider (unsure of what to put in start other than add())

Spoiler
public class ModGlobalLootProvider extends GlobalLootModifierProvider {

    public ModGlobalLootProvider(DataGenerator gen) {
        super(gen, CoalTools.MODID);
    }

    @Override
    protected void start() {

    }
}

 

and I have registered my Serializer so its set up and ready
 

Spoiler
public class ModSerializers {
    public static final DeferredRegister<GlobalLootModifierSerializer<?>> SERIALIZERS = DeferredRegister.create(ForgeRegistries.LOOT_MODIFIER_SERIALIZERS.get(), CoalTools.MODID);

    public static void init() { SERIALIZERS.register(FMLJavaModLoadingContext.get().getModEventBus()); }

    public static RegistryObject<GlobalLootModifierSerializer<?>> AUTOSMELT_SERIALIZER =
            SERIALIZERS.register("autosmelt_serializer", ModGlobalLootSerializer::new);

}

 

But I am unsure as to how to actually go about adding in my custom drop when the tool is in hand. Or if there is an easier way to go about this addition within each ItemClass

Link to comment
Share on other sites

I forgot to add my ModLootModifier
 

Spoiler
public class ModLootModifier extends LootModifier {

    private final int numOreToConvert;
    private final Item itemToCheck;
    private final Item itemReward;


    public ModLootModifier(LootItemCondition[] conditionsIn, CompoundTag numRawOre, Item itemCheck, Item reward) {
        super(conditionsIn);
        numOreToConvert = numRawOre.getInt("numRawOre");
        itemToCheck = itemCheck;
        itemReward = reward;
    }

    @NotNull
    @Override
    protected List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) {
        int numRawOre = 0;
        for (ItemStack stack : generatedLoot) {
            if(stack.getItem() == itemToCheck)
                numRawOre += stack.getCount();
        }
        if (numRawOre <= numOreToConvert) {
            generatedLoot.removeIf(x -> x.getItem() == itemToCheck);
            generatedLoot.add(new ItemStack(itemReward, (numRawOre/numOreToConvert)));
            numRawOre = numRawOre%numOreToConvert;
            if(numRawOre > 0)
                generatedLoot.add(new ItemStack(itemToCheck, numRawOre));
        }
        return generatedLoot;
    }

}

 

 

Link to comment
Share on other sites

It crashes when it tries to register as well?
 

Spoiler
-- Head --
Thread: Render thread
Stacktrace:
	at net.minecraftforge.registries.DeferredRegister.<init>(DeferredRegister.java:119) ~[forge-1.18.2-40.0.32_mapped_parchment_2022.03.13-1.18.2.jar%2375%2381!/:?] {re:classloading}
-- MOD coaltools --
Details:
	Caused by 0: java.lang.reflect.InvocationTargetException
		at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] {}
		at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[?:?] {}
		at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?] {}
		at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[?:?] {}
		at java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[?:?] {}
		at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:81) ~[javafmllanguage-1.18.2-40.0.32.jar%2377!/:?] {}
		at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$4(ModContainer.java:120) ~[fmlcore-1.18.2-40.0.32.jar%2379!/:?] {}
		at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?] {}
		at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) ~[?:?] {}
		at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {}
		at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {}
		at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {}
		at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {}
		at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {}

	Caused by 1: java.lang.ExceptionInInitializerError
		at tyrannys.coaltools.CoalTools.<init>(CoalTools.java:40) ~[%2380!/:?] {re:classloading}
		at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] {}
		at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[?:?] {}
		at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?] {}
		at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[?:?] {}
		at java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[?:?] {}
		at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:81) ~[javafmllanguage-1.18.2-40.0.32.jar%2377!/:?] {}
		at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$4(ModContainer.java:120) ~[fmlcore-1.18.2-40.0.32.jar%2379!/:?] {}
		at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?] {}
		at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) ~[?:?] {}
		at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {}
		at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {}
		at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {}
		at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {}
		at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {}

	Mod File: main
	Failure message: Coal Tools (coaltools) has failed to load correctly
		java.lang.reflect.InvocationTargetException: null
	Mod Version: 0.0NONE
	Mod Issue URL: NOT PROVIDED
	Exception message: java.lang.NullPointerException: Cannot invoke "net.minecraftforge.registries.IForgeRegistry.getRegistryName()" because "reg" is null
Stacktrace:
	at net.minecraftforge.registries.DeferredRegister.<init>(DeferredRegister.java:119) ~[forge-1.18.2-40.0.32_mapped_parchment_2022.03.13-1.18.2.jar%2375%2381!/:?] {re:classloading}
	at net.minecraftforge.registries.DeferredRegister.create(DeferredRegister.java:60) ~[forge-1.18.2-40.0.32_mapped_parchment_2022.03.13-1.18.2.jar%2375%2381!/:?] {re:classloading}
	at tyrannys.coaltools.setup.ModSerializers.<clinit>(ModSerializers.java:12) ~[%2380!/:?] {re:classloading}
	at tyrannys.coaltools.CoalTools.<init>(CoalTools.java:40) ~[%2380!/:?] {re:classloading}
	at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] {}
	at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[?:?] {}
	at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?] {}
	at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[?:?] {}
	at java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[?:?] {}
	at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:81) ~[javafmllanguage-1.18.2-40.0.32.jar%2377!/:?] {}
	at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$4(ModContainer.java:120) ~[fmlcore-1.18.2-40.0.32.jar%2379!/:?] {}
	at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?] {}
	at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) ~[?:?] {}
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {}
	at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {}
	at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {}
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {}
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {}

 

 

Link to comment
Share on other sites

16 hours ago, diesieben07 said:

You have not actually shown the class that has the error.

Spoiler
public CoalTools() {
        IEventBus bus = MinecraftForge.EVENT_BUS;
        ModItems.init();
        ModBlocks.init();
        ModEnchantments.init();
        ModSerializers.init(); //Whats been added


        // Register the setup method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        // Register the enqueueIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        // Register the processIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
        // Register the client Setup method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::DoClientStuff);

        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);
        bus.addListener(OreGen::onBiomeLoadingEvent);
    }

 

All that I have added to the CoalTools class was ModSerializers.init() from the deferred registry from ModSerializers

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.

Announcements



×
×
  • Create New...

Important Information

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