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

    • Hi, I'm trying to render a single quad in the world. I'm mixing into the ChestRenderer class. If I understand correctly, BufferSource#getBuffer opens a buffer according to the supplied RenderType (Quads with POSITION_COLOR in my case). Then, I can supply my vertices (a simple 1-block plane along the Z Axis) and close the buffer using BufferSource#endBatch for rendering. This is the code I'm using: @Inject(at = @At("TAIL"), method = "render(...)V") public void render(T blockEntity, float partialTick, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight, int packedOverlay, CallbackInfo ci) { BlockPos pos = blockEntity.getBlockPos(); AABB box = new AABB(pos, pos.offset(1, 1, 1)); BufferSource buffer = Minecraft.getInstance().renderBuffers().bufferSource(); VertexConsumer consumer = buffer.getBuffer(RenderType.guiOverlay()); poseStack.pushPose(); poseStack.translate(-pos.getX(), -pos.getY(), -pos.getZ()); consumer.vertex(box.minX, box.maxY, box.minZ).color(1, 1, 1, 1).endVertex(); consumer.vertex(box.minX, box.maxY, box.maxZ).color(1, 1, 1, 1).endVertex(); consumer.vertex(box.minX, box.minY, box.maxZ).color(1, 1, 1, 1).endVertex(); consumer.vertex(box.minX, box.minY, box.minZ).color(1, 1, 1, 1).endVertex(); buffer.endBatch(RenderType.guiOverlay()); poseStack.popPose(); } However, the plane does not get rendered. However, if I replace those 4 vertices with a call to LevelRenderer#renderLineBox and set the RenderType to LINES, it works. Do I need something else to render planes other than the 4 edges of the quad? I used QUADS back in 1.8 where it was still the raw OpenGL type and it worked then. Or am I missing something else entirely? Thanks!
    • The Essential Role of Brunoe Quick Hack in Bitcoin Recovery Efforts The Brunoe Quick Hack has emerged as a vital tool in the ongoing efforts to recover lost or stolen Bitcoin. As the cryptocurrency landscape has evolved, the need for reliable and effective methods to regain access to misplaced or compromised digital assets has become increasingly pressing. The Brunoe Quick Hack, a specialized software solution, has stepped in to fill this critical void, offering Bitcoin users a lifeline when faced with the devastating prospect of permanently losing their hard-earned cryptocurrency holdings. At the core of this innovative technique lies a deep understanding of the underlying blockchain technology that powers Bitcoin, combined with a meticulous, methodical approach to identifying and exploiting vulnerabilities in the system. Through a series of carefully orchestrated steps, the Brunoe Quick Hack is able to bypass security measures, recover private keys, and restore access to Bitcoin wallets that were previously thought to be irretrievable. This process, while highly technical and requiring a skilled hand, has proven to be a game-changer for countless individuals and businesses who have fallen victim to the inherent risks of the cryptocurrency ecosystem. As the adoption of Bitcoin continues to grow, the Brunoe Quick Hack has emerged as an essential safeguard, providing a crucial safety net for those navigating the complex and ever-evolving world of digital finance. Contact this experts through: WhtasApp: + 170-"578-42"-635 Website: brunoequickhack.COM Email: brunoequickhack (AT) GMAIL (DOT) COM Thanks.
    • it doesnt let me import the zip that i use with curseforge
    • it doesnt let me import the zip that i use with curseforge
    • Halo semua, Kembali lagi bersama kami di situs Duta89 situs Aman, Terpercaya dan Situs yang memberikan hadiah terbesar kepada semua membernya. Pada kesempatan kali ini kami akan memberi tahu kalian semua mengenai situs permainan online yang bisa menghasilkan uang dengan cepat hanya dengan modal receh. Permainan apa kah itu? Saran bukan? >>>akungameaman<<< >>>akunminecrafsuper<<< >>>daftarsitus<<<
  • Topics

×
×
  • Create New...

Important Information

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