drafts:resourceconditions
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| drafts:resourceconditions [2026/03/03 23:51] – datagen example infinitychances | drafts:resourceconditions [2026/03/20 17:27] (current) – changed example again to not require build script changes infinitychances | ||
|---|---|---|---|
| Line 215: | Line 215: | ||
| This section will assume you have already set up a basic datagen setup. It will use recipes as an example. | This section will assume you have already set up a basic datagen setup. It will use recipes as an example. | ||
| - | We will create a custom shaped | + | We will create a recipe that creates |
| - | + | ||
| - | First, in our build.gradle we would define a dependency on iljatech through modLocalRuntime and modCompileOnly to access its code. However, as it does not have a maven, this is not possible(this mod was chosen just to show a simple example). | + | |
| Next, we can go into our recipe provider and begin. | Next, we can go into our recipe provider and begin. | ||
| Line 229: | Line 227: | ||
| @Override | @Override | ||
| public void buildRecipes() { | public void buildRecipes() { | ||
| - | shaped(RecipeCategory.FOOD, Items.EGG) | + | shaped(RecipeCategory.MISC, Items.MINECART) |
| - | .pattern(" | + | .pattern(" |
| - | .pattern(" | + | .pattern(" |
| - | .define(' | + | .define(' |
| - | .define(' | + | .unlockedBy(getHasName(Items.COPPER_INGOT), has(Items.COPPER_INGOT)) |
| - | .unlockedBy(getHasName(ModItems.BOILED_EGG), has(ModItems.BOILED_EGG)) | + | .save(withConditions(output, |
| - | .save(withConditions(output, | + | |
| }; | }; | ||
| } | } | ||
| Line 242: | Line 239: | ||
| The important part of this is when we call the save function. We can wrap our RecipeOutput with the withConditions method provided by FabricRecipeProvider, | The important part of this is when we call the save function. We can wrap our RecipeOutput with the withConditions method provided by FabricRecipeProvider, | ||
| The result will be this: | The result will be this: | ||
| - | < | + | <code > |
| { | { | ||
| " | " | ||
| { | { | ||
| - | " | + | " |
| - | "values": [ | + | "features": [ |
| - | "iljatech" | + | "minecraft: |
| - | ] | + | ] |
| } | } | ||
| ], | ], | ||
| " | " | ||
| - | " | + | " |
| " | " | ||
| - | "b": "iljatech:boiled_egg", | + | "c": "minecraft:copper_ingot", |
| - | " | + | |
| }, | }, | ||
| " | " | ||
| - | "b", | + | "c c", |
| - | "w" | + | "ccc" |
| ], | ], | ||
| " | " | ||
| " | " | ||
| - | " | + | " |
| } | } | ||
| } | } | ||
| </ | </ | ||
| + | ===== Making A Custom Condition ===== | ||
| + | There are two things you need to do to make a custom condition: 1. Create the class and logic for it. 2. Register it. | ||
| + | |||
| + | We are going to make a FalseResourceCondition. | ||
| + | To begin, we must have our class implement ResourceCondition. | ||
| + | We can make a codec through MapCodec.unit, | ||
| + | The test method is where all the logic happens. It passes in a RegistryInfoLookup, | ||
| + | For our use, we do not need it. We can just return false. | ||
| + | Your class should currently look something like this: | ||
| + | <code java [enable_line_numbers=" | ||
| + | public class FalseResourceCondition implements ResourceCondition { | ||
| + | public static final MapCodec< | ||
| + | |||
| + | public ResourceConditionType<?> | ||
| + | return TYPE_HERE; | ||
| + | } | ||
| + | |||
| + | public boolean test(RegistryOps.@Nullable RegistryInfoLookup registryInfo) { | ||
| + | return false; | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Now, we must register the condition. You can refer to DefaultResourceConditionTypes to see how they are done. | ||
| + | A register method will look something like this: | ||
| + | <code java> | ||
| + | protected static <T extends ResourceCondition> | ||
| + | return ResourceConditionType.create(Identifier.fromNamespaceAndPath(" | ||
| + | } | ||
| + | </ | ||
| + | For name, we can pass in " | ||
| + | In your '' | ||
| + | <code java> | ||
| + | public static ResourceConditionType< | ||
| + | |||
| + | @Override | ||
| + | public void onInitialize() { | ||
| + | FALSE = createResourceConditionType(" | ||
| + | // ... | ||
| + | } | ||
| + | |||
| + | protected static <T extends ResourceCondition> | ||
| + | return ResourceConditionType.create(Identifier.fromNamespaceAndPath(" | ||
| + | } | ||
| + | |||
| + | // ... | ||
| + | </ | ||
| + | Now, replace TYPE_HERE with the new condition type. | ||
drafts/resourceconditions.1772581896.txt.gz · Last modified: 2026/03/03 23:51 by infinitychances