Jump to content

Crafting recipes enable/disable with config file [1.16]


Razor

Recommended Posts

Hey guys, i try to make recipes based of config options, but i can`t find the problem here, all recipes linked to an config options are always disabled and theres no error in the console, maybe a problem in the factories?

 

ConditionsFactory

public class ConditionFactory implements IConditionBuilder {

        //@Override
        public BooleanSupplier parse(JsonSerializationContext context, JsonObject json) {
            boolean value = JSONUtils.getBoolean(json , "value", true);
            String key = JSONUtils.getString(json, "type");

            if (key.equals(Uncrafted.MODID + ":spawneggs_enabled")) {
                return () -> Config.ACTIVATE_SPAWNEGG_RECIPES.get().booleanValue() == value;
            }
            else if (key.equals(Uncrafted.MODID + ":spawner_enabled")) {
                return () -> Config.ACTIVATE_SPAWNER_RECIPES.get().booleanValue() == value;
            }
            else if (key.equals(Uncrafted.MODID + ":skulls_enabled")) {
                return () -> Config.ACTIVATE_SKULL_RECIPES.get().booleanValue() == value;
            }
            return null;
        }
}

 

_factories.json

{
    "conditions": {
      "spawneggs_enabled": "xxrexraptorxx.util.ConditionFactory",
      "spawner_enabled": "xxrexraptorxx.util.ConditionFactory",
      "skulls_enabled": "xxrexraptorxx.util.ConditionFactory"
    }
}

 

example recipe: spawner.json

{
  "conditions" : [
    {
      "type" : "uncrafted:spawner_enabled",
      "value" : true
    } ],
  "type": "minecraft:crafting_shaped",
  "pattern": [
  
    "XXX",
    "X#X",
    "XXX"
  ],
  
  "key": {
    "X": {
      "item": "minecraft:iron_bars"
    },
    "#": {
      "item": "minecraft:nether_star"
    }  
  },
  
  
  "result": {
    "item": "minecraft:spawner"
  }
}

 

i hope anyone can help me :D

 

 

Link to comment
Share on other sites

scrap all that (factory and _factories.json), it's for an older version.

do have a condition in a recipe json file. the one you have up there will do fine.

 

make a class that implements ICondition.
getID() should return "uncrafted:spawner_enabled".  test() should check options and enable/disable the recipe.

 

inside the condition class make a serializer class (yes inside, inner class, static) that implements IConditionSerializer<YourCondition>.
getID should return same as above;  read should return an instance of your condition class. use json.getAsJsonPrimitive("value_or_flag_name_or_whatever") to get the setting name (if you use a single condition for several recipes); write should do the opposite of read - json.addProperty.

 

finally, register your condition in FMLCommonSetupEvent. call CraftingHelper.register and pass the serializer instance.

enjoy!

  • Like 1
Link to comment
Share on other sites

one class inside another, just like you have fields and methods inside of a class. ok, i admit it's not very intuitive now that type definitions are no longer a thing...

it doesn't have to be inner class, it can be a separate class. it's just more maintainable if you don't have two separate non-inner classes whose life cycles are connected.

just make both classes. serializer will make condition class instances when the game needs them.

Link to comment
Share on other sites

  • 1 month later...
On 10/21/2021 at 9:41 PM, MFMods said:

one class inside another, just like you have fields and methods inside of a class. ok, i admit it's not very intuitive now that type definitions are no longer a thing...

it doesn't have to be inner class, it can be a separate class. it's just more maintainable if you don't have two separate non-inner classes whose life cycles are connected.

just make both classes. serializer will make condition class instances when the game needs them.

Could You Please Provide a simple example, I do understand java but this has me all in a twist

Link to comment
Share on other sites

{
    "conditions":[
        {
            "type":"mbs:mod_check",
            "modid":"mbs"
        }
    ],
    "type": "minecraft:crafting_shaped",
    "pattern": [
        "###",
        "# #"
    ],
    "key": {
        "#": {
            "item": "mbs:blue_diamond"
        }
    },
    "result": {
        "item": "mbs:armor/blue_diamond_helmet",
        "count": 1
    }
}
package com.SkyWarsFun2019.moreblock.util.Integration;

import com.google.gson.JsonObject;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.GsonHelper;
import net.minecraftforge.common.crafting.conditions.ICondition;
import net.minecraftforge.common.crafting.conditions.IConditionSerializer;
import net.minecraftforge.fml.ModList;

public class ModIntegrationRecipeCondition implements ICondition
{
	private static final ResourceLocation NAME = new ResourceLocation("mbs", "mod_check");
	private final String Modid;

	public ModIntegrationRecipeCondition(String Mod) 
	{
		Modid = Mod;
	}
	
	@Override
	public ResourceLocation getID()
	{
		return NAME;
	}

	@Override
	public boolean test() 
	{
		System.out.println("Testing");
		return ModList.get().isLoaded(Modid);
	}
	 @Override
	public String toString()
	{
	    return "mod_loaded(\"" + Modid + "\")";
	}
	 
	 public static class Serializer implements IConditionSerializer<ModIntegrationRecipeCondition>
	    {
	        public static final Serializer INSTANCE = new Serializer();

	        @Override
	        public void write(JsonObject json, ModIntegrationRecipeCondition value)
	        {
	            json.addProperty("modid", value.Modid);
	        }

	        @Override
	        public ModIntegrationRecipeCondition read(JsonObject json)
	        {
	            return new ModIntegrationRecipeCondition(GsonHelper.getAsString(json, "modid"));
	        }

	        @Override
	        public ResourceLocation getID()
	        {
	            return ModIntegrationRecipeCondition.NAME;
	        }
	    }
}

 

this is my json and class, any reason why it doesnt work.

Edited by DX12
Updated Information, Provided More Details
Link to comment
Share on other sites

Just now, diesieben07 said:
  • "mbs" is a bad ModID. Do not use abbreviations.
  • You do not own SkyWarsFun2019.com.
  • Forge already provides the "forge:mod_loaded" condition, there is no need to implement it yourself.
  • You have not shown where you register your condition.

for the first and second part I Am co-owner, the original owner set that.

private void Setup(FMLCommonSetupEvent event)
	{
		event.enqueueWork(OreGen::RegisterOre);
		List<String> Mods = Searcher.GetModIDs(event);
		Searcher.PrintMods(Mods);
		System.out.println("Condition Register Starting");
		CraftingHelper.register(new ModIntegrationRecipeCondition.Serializer());
		System.out.println("Condition Register Complete");
	}

this is where and how it is registered. as with the third point i plan to change this to run a check on the mod config file

Link to comment
Share on other sites

Quote

[14:39:47] [Render thread/INFO]: Reloading ResourceManager: Default, , main
Serializer Read
mod_check("mbs")
Condition Test
true
[14:40:11] [Render thread/INFO]: Loaded 7 recipes

Here is the specific info you requested. I only included these lines

Edited by DX12
Updated Information, Provided More Details
Link to comment
Share on other sites

Quote

Here is the specific info you requested.

that output was for you, not us.


i wanted you to assert two things:
1) serializer creates a condition with value true when config file says true
2) serializer creates a condition with value false when config file says false (after you exit the game, change config, start the game)

can you confirm that you have that?

Link to comment
Share on other sites

  • 3 weeks later...
On 12/22/2021 at 10:57 PM, MFMods said:

that output was for you, not us.


i wanted you to assert two things:
1) serializer creates a condition with value true when config file says true
2) serializer creates a condition with value false when config file says false (after you exit the game, change config, start the game)

can you confirm that you have that?

Apologies for the late response, My computer had malfunctioned. To answer your question yes I do get the false and true when test is ran. however the issue im having is regardless of the value the recipe doesnt register. Also I have created A new topic to discuss this further.

Here is the topic Topic

Edited by DX12
Added Topic Link
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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • rftoolsbuilder:shielding_cutout (from lostcities-1.19-6.0.24.jar),rftoolsstorage:crafting_manager (from lostcities-1.19-6.0.24.jar),deepresonance:dense_glass (from lostcities-1.19-6.0.24.jar),restrictions:oneway (from lostcities-1.19-6.0.24.jar),restrictions:oneway_wall (from lostcities-1.19-6.0.24.jar),lostruins:glassgray3x2_complete (from lostcities-1.19-6.0.24.jar),lostruins:glassgray3x2_pane_complete (from lostcities-1.19-6.0.24.jar),lostruins:glassgray3x2_mossy (from lostcities-1.19-6.0.24.jar),lostruins:glassgray3x2_pane_mossy (from lostcities-1.19-6.0.24.jar),lostruins:glassgray3x2_broken (from lostcities-1.19-6.0.24.jar),lostruins:glassgray3x2_pane_broken (from lostcities-1.19-6.0.24.jar),lostruins:glassgray3x2_broken_mossy (from lostcities-1.19-6.0.24.jar),lostruins:glassgray3x2_pane_broken_mossy (from lostcities-1.19-6.0.24.jar),lostruins:glassgray3x2_vines (from lostcities-1.19-6.0.24.jar),lostruins:glassgray3x2_pane_vines (from lostcities-1.19-6.0.24.jar)[13:50:17] [main/INFO] [minecraft/RecipeManager]: Skipping loading recipe supplementaries:inspirations/blackboard_clear as it's serializer returned null[13:50:17] [main/INFO] [minecraft/RecipeManager]: Skipping loading recipe supplementaries:inspirations/flag_dye as it's serializer returned null[13:50:17] [main/INFO] [minecraft/RecipeManager]: Skipping loading recipe supplementaries:inspirations/flag_clear as it's serializer returned null[13:50:17] [main/INFO] [minecraft/RecipeManager]: Loaded 36 recipes[13:50:17] [main/INFO] [Spartan Weaponry/]: Adding Diamond Weapons to the End City Treasure Loot Table![13:50:17] [main/INFO] [Spartan Weaponry/]: Adding Longbow and Heavy Crossbow related loot to the Village Fletcher Loot Table![13:50:18] [main/INFO] [Spartan Weaponry/]: Adding Iron Weapons to the Village Weaponsmith Loot Table![13:50:18] [main/ERROR] [minecraft/ServerFunctionLibrary]: Failed to load function watching:checkjava.util.concurrent.CompletionException: java.lang.IllegalArgumentException: Whilst parsing command on line 1: Unknown or incomplete command, see below for error at position 0: <--[HERE]at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315) ~[?:?] {re:mixin}at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320) ~[?:?] {re:mixin}at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1770) ~[?:?] {}at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1760) ~[?:?] {}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) ~[?:?] {re:computing_frames}at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {re:computing_frames}at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {}Caused by: java.lang.IllegalArgumentException: Whilst parsing command on line 1: Unknown or incomplete command, see below for error at position 0: <--[HERE]at net.minecraft.commands.CommandFunction.m_77984_(CommandFunction.java:63) ~[server-1.19.2-20220805.130853-srg.jar%23299!/:?] {re:classloading}at net.minecraft.server.ServerFunctionLibrary.m_214320_(ServerFunctionLibrary.java:85) ~[server-1.19.2-20220805.130853-srg.jar%23299!/:?] {re:classloading}at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768) ~[?:?] {}... 6 more[13:50:18] [main/INFO] [quark/]: [Automatic Recipe Unlock] Removed 3712 recipe advancements[13:50:18] [main/INFO] [minecraft/AdvancementList]: Loaded 684 advancements[13:50:18] [main/INFO] [at.dy.se.ItemLightLevels/]: Clearing item tag to light level mapping cache[13:50:18] [main/INFO] [sl.ma.fl.tr.FluidContainerTransferManager/]: Loaded 0 dynamic modifiers in 0.246528 ms[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:husbandry/wax_on with 2 patches[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:adventure/kill_a_mob with 3 patches[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:husbandry/bred_all_animals with 3 patches[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:adventure/kill_all_mobs with 3 patches[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:husbandry/make_a_sign_glow with 1 patches[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:husbandry/balanced_diet with 3 patches[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:husbandry/plant_seed with 1 patches[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:nether/all_effects with 2 patches[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:husbandry/wax_off with 2 patches[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:adventure/adventuring_time with 1 patches[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:nether/all_potions with 1 patches[13:50:18] [main/INFO] [supplementaries/]: Loaded 8 flute songs[13:50:20] [main/INFO] [Spartan Weaponry/]: Finished initialising Weapon Traits & Attributes! Took 11.202781ms[13:50:20] [main/INFO] [supplementaries/]: Finished additional setup in 103 ms[13:50:20] [main/WARN] [minecraft/DedicatedServerProperties]: Failed to parse level-type biomesoplenty, defaulting to minecraft:normal[13:50:20] [Server thread/INFO] [minecraft/DedicatedServer]: Starting minecraft server version 1.19.2[13:50:20] [Server thread/INFO] [minecraft/DedicatedServer]: Loading properties[13:50:20] [Server thread/INFO] [minecraft/DedicatedServer]: Default game type: SURVIVAL[13:50:20] [Server thread/INFO] [minecraft/MinecraftServer]: Generating keypair[13:50:21] [Server thread/INFO] [minecraft/DedicatedServer]: Starting Minecraft server on :::25983[13:50:21] [Server thread/INFO] [minecraft/ServerConnectionListener]: Using epoll channel type[13:50:21] [Thread-0/INFO] [de.ca.ca.CaveDweller/]: Server configuration has been reloaded[13:50:21] [Thread-0/INFO] [de.ca.ca.CaveDweller/]: Server configuration has been reloaded[13:50:21] [Thread-0/INFO] [de.ca.st.SteveDweller/]: Server configuration has been reloaded[13:50:21] [Thread-0/INFO] [de.ca.st.SteveDweller/]: Server configuration has been reloaded[13:50:21] [Thread-0/INFO] [de.ca.sk.Skinstalker/]: Server configuration has been reloaded[13:50:21] [Thread-0/INFO] [de.ca.sk.SkinwalkerOverhaul/]: Server configuration has been reloaded[13:50:21] [Thread-0/INFO] [de.ca.sk.SkinwalkerOverhaul/]: Server configuration has been reloaded[13:50:21] [Thread-0/INFO] [de.ca.go.Goatman/]: Server configuration has been reloaded[13:50:21] [Thread-0/INFO] [de.ca.go.Goatman/]: Server configuration has been reloaded[13:50:21] [Server thread/INFO] [at.dy.se.mo.PlayerSelfLightSource/]: item config parser identified itemstack 1 torch[13:50:21] [Server thread/INFO] [at.dy.se.mo.PlayerSelfLightSource/]: item config parser identified itemstack 1 glowstone[13:50:21] [Server thread/INFO] [at.dy.se.mo.PlayerSelfLightSource/]: item config parser finished, item count: 2[13:50:21] [Server thread/INFO] [at.dy.se.mo.PlayerSelfLightSource/]: item config parser identified itemstack 1 torch[13:50:21] [Server thread/INFO] [at.dy.se.mo.PlayerSelfLightSource/]: item config parser finished, item count: 1[13:50:21] [Server thread/INFO] [at.dy.se.mo.DroppedItemsLightSource/]: item config parser identified itemstack 1 torch[13:50:21] [Server thread/INFO] [at.dy.se.mo.DroppedItemsLightSource/]: item config parser identified itemstack 1 glowstone[13:50:21] [Server thread/INFO] [at.dy.se.mo.DroppedItemsLightSource/]: item config parser finished, item count: 2[13:50:21] [Server thread/INFO] [at.dy.se.mo.DroppedItemsLightSource/]: item config parser identified itemstack 1 torch[13:50:21] [Server thread/INFO] [at.dy.se.mo.DroppedItemsLightSource/]: item config parser finished, item count: 1[13:50:21] [Server thread/INFO] [Framework/]: Loading server configs...[13:50:22] [Server thread/INFO] [terrablender/]: Initialized TerraBlender biomes for level stem minecraft:overworld[13:50:22] [Server thread/INFO] [terrablender/]: Initialized TerraBlender biomes for level stem minecraft:the_nether[13:50:22] [Server thread/INFO] [minecraft/DedicatedServer]: Preparing level "world"[13:50:35] [Server thread/INFO] [minecraft/MinecraftServer]: Preparing start region for dimension minecraft:overworld[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:41] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:41] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:42] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 17%[13:50:42] [Server thread/INFO] [minecraft/LoggerChunkProgressListener]: Time elapsed: 7618 ms[13:50:42] [Server thread/INFO] [minecraft/DedicatedServer]: Done (21.501s)! For help, type "help"[13:50:42] [Server thread/INFO] [minecraft/DedicatedServer]: Starting GS4 status listener[13:50:42] [Server thread/INFO] [minecraft/GenericThread]: Thread Query Listener started[13:50:42] [Query Listener #1/INFO] [minecraft/QueryThreadGs4]: Query running on :::25983[13:50:42] [Server thread/INFO] [ne.mi.se.pe.PermissionAPI/]: Successfully initialized permission handler forge:default_handler
    • Visit WEB:  https://www.strongspellcaster.us.com New York City, NY's love spells +27732318372 *To Get Back Ex Lover* Black magic cleansing.  
    • +27732318372 MOST GIFTED VOODOO MAGIC LOST LOVE SPELLS TO BRING BACK AN EX LOVER << USA CANADA USA .. >> visit website (https://www.strongspellcaster.us.com) s.
    • The conflict arises from discrepancies between different versions of GSON. My suggestion would be to remove your dependency on GSON 2.8.6 and opt for a different approach. Instead of using the static method JsonParser.parseString, you can create a JsonParser object and then use the parse method.   JsonParser jsonParser = new JsonParser(); jsonParser.parse(jsonString)  
  • Topics

×
×
  • Create New...

Important Information

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