Jump to content

Recommended Posts

Posted (edited)

I'm trying to disable crafting recipes based on config file values. Currently using datagen for crafting recipes, and ICondition seems to have changed compared to the older IConditionFactory.

Edited by CrackedScreen
Marked thread as solved.
Posted (edited)

Late reply, but tried implementing ICondition and copying some code over from ModLoadedCondition:

  Reveal hidden contents

Getting an error for including the test() method since it is marked as deprecated, but forge still requires it to be implemented. Using Forge 1.18.2-40.1.51, if I'm missing anything let me know.

EDIT:
The mod will still compile and run fine since this isn't actually an error, but will need to know how to pass existing datagen recipes through the serializer since forge does not come with any functional examples by itself. Would still appreciate an answer on how to get rid of the deprecated method in case I am missing something obvious.

Edited by CrackedScreen
Changed post.
Posted
  On 10/17/2022 at 4:14 AM, CrackedScreen said:

The mod will still compile and run fine since this isn't actually an error, but will need to know how to pass existing datagen recipes through the serializer since forge does not come with any functional examples by itself.

Expand  

I give you, a Forge provided functional example: https://github.com/MinecraftForge/MinecraftForge/blob/1.19.x/src/test/java/net/minecraftforge/debug/DataGeneratorTest.java#L165-L204

  On 10/17/2022 at 4:14 AM, CrackedScreen said:

Would still appreciate an answer on how to get rid of the deprecated method in case I am missing something obvious.

Expand  

Essentially, the method is removed in 1.19 due to the context parameter addition. However, changing how the method is implemented would induce a breaking change. As such, older versions need to have it implemented until they update to the next version.

Posted (edited)

Used the following to create the recipe:

  Reveal hidden contents

Condition/Serializer class:

  Reveal hidden contents

Registered the serializer class in RegistryEvents class:

  Reveal hidden contents

 

Currently getting an "Unknown condition type" error when using the runData task which likely means the condition wasn't registered correctly, but don't know how this is the case.

  Reveal hidden contents

 

Edited by CrackedScreen
Changed text
Posted

The register event works fine after setting the method to static, though now it seems that changing the config file values inside of the save folder doesn't have any effect on whether the recipe is active or not. Code is still same as above.

Posted

That makes sense, you cache the static value of the boolean. You should not need any parameters and just check in test if the config value is loaded. Then, you need to resave the config and reload the datapack, because the condition won't be checked if the datapack isn't reloaded.

Posted (edited)

I've already tried pulling the value directly from configs, this does not change the result.

  Reveal hidden contents

The recipes aren't being loaded as the serializer is returning null after using /reload, the problem is likely the read() method but I'm not sure what it should return since the examples provided by forge return a new condition with constructor. Would also prefer to reload datapacks from code whenever the world/server is loaded, if possible.

Edited by CrackedScreen
Posted
  On 10/18/2022 at 4:32 PM, CrackedScreen said:

The recipes aren't being loaded as the serializer is returning null after using /reload

Expand  

That would mean the serializer is null.

  On 10/18/2022 at 4:32 PM, CrackedScreen said:

the problem is likely the read() method but I'm not sure what it should return since the examples provided by forge return a new condition with constructor

Expand  

Not really an issue with read, though you don't need to write anything and the single boolean test needs to return the config value as well.

  On 10/18/2022 at 4:32 PM, CrackedScreen said:

Would also prefer to reload datapacks from code whenever the world/server is loaded, if possible.

Expand  

You can look at the `ReloadCommand` to learn how to do this, but it should generally be avoided unless the cached config value changes.

Posted (edited)
  On 10/18/2022 at 5:32 PM, ChampionAsh5357 said:

That would mean the serializer is null.

Expand  

You'll have to elaborate on why this is the case since I don't see any immediate issues. I created the condition almost the exact same way the builtin forge conditions are.

Edit: The recipes are disabled if the config value is set to false, but only after manually reloading. Will need a fix for the serializer issue and best practices for forcing a reload upon entering a world if the serializer fix doesn't correct this behavior.

Edited by CrackedScreen
Update
Posted
  On 10/18/2022 at 9:20 PM, CrackedScreen said:

You'll have to elaborate on why this is the case since I don't see any immediate issues.

Expand  

I wouldn't know the reasoning. There's no inclination in the code provided that there would be an issue. The only thing I can think of is the event listener where you register things, which you would need to show the entire class for. Anything else might result from a separate issue.

Posted

Registry class:

  Reveal hidden contents

I could try registering this outside of event bus in a non-static context.

Posted (edited)

Adding modid = MOD_ID to my event bus subscriber didn't have any effect. The serializer only has the null issue when the config value is set to false for some reason, if I return true/false directly in the condition class or leave the config value as true there aren't any issues with loading/blocking the recipe.

Edited by CrackedScreen
Posted
  On 10/19/2022 at 2:47 PM, CrackedScreen said:

The serializer only has the null issue when the config value is set to false for some reason, if I return true/false directly in the condition class or leave the config value as true there aren't any issues with loading/blocking the recipe.

Expand  

Ah, so it's a defaulting issue. Well, the way to fix that is to either give your config a default, or to cache the value into a boolean and change the boolean when the config is loaded and reloaded using (ConfigEvent$Loading and ConfigEvent$Reloading).

Posted (edited)

The test value that I'm using already has a default value set:

  Reveal hidden contents

Will look into using booleans, but I may have tried this + reloading before with no success using something similar:

  Reveal hidden contents

 

Edited by CrackedScreen
  • CrackedScreen changed the title to [1.18.2] [SOLVED] Disable crafting recipes from config files

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.