Revive ConditionalRecipe and ConditionalAdvancement.

Also directly add conditional support to all vanilla recipe data generators.
This commit is contained in:
LexManos committed 2023-10-06 21:01:03 -07:00
1 parent 90dafb0df0
commit 587b684035
49 files changed
+1826 -512

No files matched your search

@@ -158,7 +158,6 @@ public class DataGeneratorTest {
gen.addProvider(event.includeClient(), new SoundDefinitions(packOutput, event.getExistingFileHelper()));
gen.addProvider(event.includeClient(), new ParticleDescriptions(packOutput, event.getExistingFileHelper()));
//gen.addProvider(event.includeServer(), new Recipes(packOutput));
gen.addProvider(event.includeServer(), new Tags(packOutput, lookupProvider, event.getExistingFileHelper()));
gen.addProvider(event.includeServer(), new ForgeAdvancementProvider(packOutput, lookupProvider, event.getExistingFileHelper(), List.of(new Advancements())));
gen.addProvider(event.includeServer(), new DatapackBuiltinEntriesProvider(packOutput, lookupProvider, BUILDER, Set.of(MODID)));
@@ -174,188 +173,6 @@ public class DataGeneratorTest {
context.register(TEST_LEVEL_STEM, levelStem);
}
/*
public static class Recipes extends RecipeProvider implements IConditionBuilder
{
public Recipes(PackOutput gen)
{
super(gen);
}
@Override
protected void buildRecipes(Consumer<FinishedRecipe> consumer)
{
// conditional recipe
ResourceLocation ID = new ResourceLocation("data_gen_test", "conditional");
ConditionalRecipe.builder()
.addCondition(
and(
not(modLoaded("minecraft")),
itemExists("minecraft", "dirt"),
FALSE()
)
)
.addRecipe(
ShapedRecipeBuilder.shaped(RecipeCategory.BUILDING_BLOCKS, Blocks.DIAMOND_BLOCK, 64)
.pattern("XXX")
.pattern("XXX")
.pattern("XXX")
.define('X', Blocks.DIRT)
.group("")
.unlockedBy("has_dirt", has(Blocks.DIRT)) // DUMMY: Necessary, but not used when a custom advancement is provided through setAdvancement
::save
)
.setAdvancement(ID,
ConditionalAdvancement.builder()
.addCondition(
and(
not(modLoaded("minecraft")),
itemExists("minecraft", "dirt"),
FALSE()
)
)
.addAdvancement(
Advancement.Builder.advancement()
.parent(new ResourceLocation("minecraft", "root"))
.display(Blocks.DIAMOND_BLOCK,
Component.literal("Dirt2Diamonds"),
Component.literal("The BEST crafting recipe in the game!"),
null, FrameType.TASK, false, false, false
)
.rewards(AdvancementRewards.Builder.recipe(ID))
.addCriterion("has_dirt", has(Blocks.DIRT))
)
)
.build(consumer, ID);
ConditionalRecipe.builder()
.addCondition(
not(
and(
not(modLoaded("minecraft")),
itemExists("minecraft", "dirt"),
FALSE()
)
)
)
.addRecipe(
ShapedRecipeBuilder.shaped(RecipeCategory.BUILDING_BLOCKS, Blocks.DIAMOND_BLOCK, 64)
.pattern("XXX")
.pattern("XXX")
.pattern("XXX")
.define('X', Blocks.DIRT)
.group("")
.unlockedBy("has_dirt", has(Blocks.DIRT))
::save
)
.generateAdvancement()
.build(consumer, new ResourceLocation("data_gen_test", "conditional2"));
ConditionalRecipe.builder()
.addCondition(
tagEmpty(ItemTags.PLANKS)
)
.addRecipe(
ShapedRecipeBuilder.shaped(RecipeCategory.BUILDING_BLOCKS, Blocks.NETHERITE_BLOCK, 1)
.pattern("XX")
.pattern("XX")
.define('X', Blocks.DIAMOND_BLOCK)
.group("")
.unlockedBy("has_diamond_block", has(Blocks.DIAMOND_BLOCK))
::save
)
.addCondition(
not(
tagEmpty(ItemTags.PLANKS)
)
)
.addRecipe(
ShapedRecipeBuilder.shaped(RecipeCategory.BUILDING_BLOCKS, Blocks.NETHERITE_BLOCK, 9)
.pattern("XX")
.pattern("XX")
.define('X', Blocks.DIAMOND_BLOCK)
.group("")
.unlockedBy("has_diamond_block", has(Blocks.DIAMOND_BLOCK))
::save
)
.generateAdvancement()
.build(consumer, new ResourceLocation("data_gen_test", "conditional3"));
// ingredient tests
// strict NBT match - should match an unnamed iron pickaxe that lost 3 durability
Ingredient nbtIngredient = StrictNBTIngredient.of(Util.make(() ->
{
ItemStack stack = new ItemStack(Items.IRON_PICKAXE);
stack.setDamageValue(3);
return stack;
}));
ShapelessRecipeBuilder.shapeless(RecipeCategory.TOOLS, Items.GOLDEN_PICKAXE)
.requires(nbtIngredient)
.unlockedBy("has_pickaxe", has(Items.IRON_PICKAXE))
.save(consumer, new ResourceLocation("data_gen_test", "exact_nbt_ingredient"));
// ingredient tests
// contains NBT match - should match a stone pickaxe that lost 3 durability, regardless of setting its name
ShapelessRecipeBuilder.shapeless(RecipeCategory.TOOLS, Items.IRON_PICKAXE)
.requires(PartialNBTIngredient.of(Items.STONE_PICKAXE, Util.make(() ->
{
CompoundTag nbt = new CompoundTag();
nbt.putInt(ItemStack.TAG_DAMAGE, 3);
return nbt;
})))
.unlockedBy("has_pickaxe", has(Items.STONE_PICKAXE))
.save(consumer, new ResourceLocation("data_gen_test", "contains_nbt_ingredient_single_item"));
// contains NBT match - should match a wood, stone, or iron pickaxe that was named "Diamond Pickaxe", regardless of damage
ShapelessRecipeBuilder.shapeless(RecipeCategory.TOOLS, Items.DIAMOND_PICKAXE)
.requires(PartialNBTIngredient.of(Util.make(() ->
{
CompoundTag nbt = new CompoundTag();
CompoundTag display = new CompoundTag();
display.putString(ItemStack.TAG_DISPLAY_NAME, "{\"text\":\"Diamond Pickaxe\"}");
nbt.put(ItemStack.TAG_DISPLAY, display);
return nbt;
}), Items.WOODEN_PICKAXE, Items.STONE_PICKAXE, Items.IRON_PICKAXE))
.unlockedBy("has_pickaxe", has(Items.WOODEN_PICKAXE))
.save(consumer, new ResourceLocation("data_gen_test", "contains_nbt_ingredient_item_set"));
// intersection - should match all non-flammable planks
ShapedRecipeBuilder.shaped(RecipeCategory.BUILDING_BLOCKS, Blocks.NETHERRACK)
.pattern("###")
.pattern("###")
.pattern(" # ")
.define('#', IntersectionIngredient.of(Ingredient.of(ItemTags.PLANKS), Ingredient.of(ItemTags.NON_FLAMMABLE_WOOD)))
.unlockedBy("has_planks", has(Items.CRIMSON_PLANKS))
.save(consumer, new ResourceLocation("data_gen_test", "intersection_ingredient"));
// difference - should match all flammable fences
ShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, Items.FLINT_AND_STEEL)
.pattern(" # ")
.pattern("###")
.pattern(" # ")
.define('#', DifferenceIngredient.of(Ingredient.of(ItemTags.FENCES), Ingredient.of(ItemTags.NON_FLAMMABLE_WOOD)))
.unlockedBy("has_fence", has(Items.CRIMSON_FENCE))
.save(consumer, new ResourceLocation("data_gen_test", "difference_ingredient"));
// compound - should match planks, logs, or bedrock
ShapedRecipeBuilder.shaped(RecipeCategory.BUILDING_BLOCKS, Blocks.DIRT)
.pattern("###")
.pattern(" # ")
.define('#', CompoundIngredient.of(Ingredient.of(ItemTags.PLANKS), Ingredient.of(ItemTags.LOGS), Ingredient.of(Blocks.BEDROCK)))
.unlockedBy("has_planks", has(Items.CRIMSON_PLANKS))
.save(consumer, new ResourceLocation("data_gen_test", "compound_ingredient_only_vanilla"));
// compound - should match planks, logs, or a stone pickaxe with 3 damage
ShapedRecipeBuilder.shaped(RecipeCategory.BUILDING_BLOCKS, Blocks.GOLD_BLOCK)
.pattern("#")
.pattern("#")
.define('#', CompoundIngredient.of(Ingredient.of(ItemTags.PLANKS), Ingredient.of(ItemTags.LOGS), nbtIngredient))
.unlockedBy("has_planks", has(Items.CRIMSON_PLANKS))
.save(consumer, new ResourceLocation("data_gen_test", "compound_ingredient_custom_types"));
}
}
*/
public static class SoundDefinitions extends SoundDefinitionsProvider
{