Skip to content

Commit

Permalink
refactor recipe provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheaterpaul committed Jan 14, 2025
1 parent e1612a3 commit 1cbdcfd
Show file tree
Hide file tree
Showing 12 changed files with 346 additions and 264 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"conditions": {
"items": [
{
"items": "#c:leathers"
"items": "#c:crops/garlic"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"category": "equipment",
"key": {
"X": "#c:ingots/iron",
"Y": "minecraft:string",
"Y": "#c:strings",
"Z": "#minecraft:planks"
},
"lava": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"category": "equipment",
"key": {
"X": "#c:ingots/iron",
"Y": "minecraft:string",
"Y": "#c:strings",
"Z": "#minecraft:planks"
},
"lava": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"category": "equipment",
"key": {
"X": "#c:ingots/iron",
"Y": "minecraft:string",
"Y": "#c:strings",
"Z": "#c:gems/diamond"
},
"lava": 5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"category": "equipment",
"key": {
"X": "#c:ingots/iron",
"Y": "minecraft:string"
"Y": "#c:strings"
},
"lava": 2,
"pattern": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"category": "equipment",
"key": {
"X": "#c:ingots/iron",
"Y": "minecraft:string"
"Y": "#c:strings"
},
"lava": 3,
"pattern": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"category": "equipment",
"key": {
"X": "#c:ingots/iron",
"Y": "minecraft:string",
"Y": "#c:strings",
"Z": "#c:gems/diamond"
},
"lava": 5,
Expand Down
443 changes: 210 additions & 233 deletions src/main/java/de/teamlapen/vampirism/data/provider/RecipesProvider.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,11 @@ public void run() {
createAlchemicalFire();
createPlants();
createWood();
createCursedEarthPath();


ResourceLocation pathModel = ModelTemplates.DIRT_PATH.create(ModBlocks.CURSED_EARTH_PATH.get(), new TextureMapping().put(TextureSlot.PARTICLE, mod("block/cursed_earth")).put(TextureSlot.DOWN, mod("block/cursed_earth")).put(TextureSlot.SIDE, mod("block/cursed_earth_path_side")).put(TextureSlot.UP, mod("block/cursed_earth_path_top")), this.modelOutput);
this.blockStateOutput.accept(createRotatedVariant(ModBlocks.CURSED_EARTH_PATH.get(), pathModel));
createDefaultBlockItem(ModBlocks.CURSED_EARTH_PATH.get(), pathModel);
createLantern(ModBlocks.VAMPIRE_SOUL_LANTERN.get());
createCropBlock(ModBlocks.GARLIC.get(), BlockStateProperties.AGE_7, 0,0,1,1,2,2,2,3);

createTintedLeaves(ModBlocks.DARK_SPRUCE_LEAVES.get(), TexturedModel.LEAVES, -1);
ResourceLocation sunscreenModel = ModelTemplates.BEACON_MODEL.create(ModBlocks.SUNSCREEN_BEACON.get(), new TextureMapping().put(TextureSlots.BEACON, mod("block/cursed_earth")), this.modelOutput);
this.blockStateOutput.accept(createSimpleBlock(ModBlocks.SUNSCREEN_BEACON.get(), sunscreenModel));
Expand All @@ -89,6 +87,12 @@ public void run() {
createDefaultBlockItem(ModBlocks.ALTAR_INSPIRATION.get(), inspirationModel);
}

protected void createCursedEarthPath() {
ResourceLocation pathModel = ModelTemplates.DIRT_PATH.create(ModBlocks.CURSED_EARTH_PATH.get(), new TextureMapping().put(TextureSlot.PARTICLE, mod("block/cursed_earth")).put(TextureSlot.DOWN, mod("block/cursed_earth")).put(TextureSlot.SIDE, mod("block/cursed_earth_path_side")).put(TextureSlot.UP, mod("block/cursed_earth_path_top")), this.modelOutput);
this.blockStateOutput.accept(createRotatedVariant(ModBlocks.CURSED_EARTH_PATH.get(), pathModel));
createDefaultBlockItem(ModBlocks.CURSED_EARTH_PATH.get(), pathModel);
}

protected void createPlants() {
createPlantWithDefaultItem(ModBlocks.VAMPIRE_ORCHID.get(),ModBlocks.POTTED_VAMPIRE_ORCHID.get(), PlantType.NOT_TINTED);
createPlantWithDefaultItem(ModBlocks.CURSED_SPRUCE_SAPLING.get(), ModBlocks.POTTED_CURSED_SPRUCE_SAPLING.get(), PlantType.NOT_TINTED);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package de.teamlapen.vampirism.data.provider.parent;

import de.teamlapen.vampirism.api.items.oil.IOil;
import de.teamlapen.vampirism.api.util.VResourceLocation;
import de.teamlapen.vampirism.core.ModBlocks;
import de.teamlapen.vampirism.data.recipebuilder.AlchemicalCauldronRecipeBuilder;
import de.teamlapen.vampirism.data.recipebuilder.AlchemyTableRecipeBuilder;
import de.teamlapen.vampirism.data.recipebuilder.ShapedWeaponTableRecipeBuilder;
import de.teamlapen.vampirism.data.recipebuilder.ShapelessWeaponTableRecipeBuilder;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.data.recipes.RecipeOutput;
import net.minecraft.data.recipes.RecipeProvider;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionContents;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.level.ItemLike;
import net.neoforged.neoforge.common.crafting.CompoundIngredient;
import net.neoforged.neoforge.common.crafting.DataComponentIngredient;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;

public abstract class RecipesProvider extends RecipeProvider {

protected HolderLookup.RegistryLookup<Item> itemLookup = this.registries.lookupOrThrow(Registries.ITEM);

public RecipesProvider(HolderLookup.Provider registries, RecipeOutput output) {
super(registries, output);
}

@SafeVarargs
protected final @NotNull Ingredient potion(Holder<Potion> @NotNull ... potion) {
return CompoundIngredient.of(Arrays.stream(potion).map(PotionContents::new).map(s -> DataComponentIngredient.of(false, DataComponents.POTION_CONTENTS, s, Items.POTION)).toArray(Ingredient[]::new));
}

protected @NotNull Ingredient potion(@NotNull Holder<Potion> potion) {
return DataComponentIngredient.of(false, DataComponents.POTION_CONTENTS, new PotionContents(potion), Items.POTION);
}

protected void coffinFromWoolOrDye(RecipeOutput consumer, ItemLike coffin, ItemLike wool, ItemLike dye, String path) {
coffinFromWool(consumer, coffin, wool, path);
shapeless(RecipeCategory.DECORATIONS, coffin).requires(ModBlocks.COFFIN_WHITE.get()).requires(dye).unlockedBy("has_coffin", has(ModBlocks.COFFIN_WHITE.get())).unlockedBy("has_dye", has(dye)).save(consumer, path + "_from_white");
}

protected void coffinFromWool(RecipeOutput consumer, ItemLike coffin, ItemLike wool, String path) {
shaped(RecipeCategory.DECORATIONS, coffin).pattern("XXX").pattern("YYY").pattern("XXX").define('X', ItemTags.PLANKS).define('Y', wool).unlockedBy("has_wool", has(wool)).save(consumer, path);
}

private void enchantment(ItemStack stack, int level, @NotNull Holder<Enchantment> enchantment) {
stack.enchant(enchantment, level);
}


protected AlchemyTableRecipeBuilder alchemyTable(@NotNull Holder<IOil> oilStack) {
return AlchemyTableRecipeBuilder.builder(this.itemLookup, oilStack);
}

protected AlchemicalCauldronRecipeBuilder cauldronRecipe(ItemLike item) {
return AlchemicalCauldronRecipeBuilder.cauldronRecipe(this.itemLookup, item.asItem());
}

protected AlchemicalCauldronRecipeBuilder cauldronRecipe(ItemLike item, int count) {
return AlchemicalCauldronRecipeBuilder.cauldronRecipe(this.itemLookup, item.asItem(), count);
}

protected ShapedWeaponTableRecipeBuilder shapedWeaponTable(RecipeCategory category, ItemLike item) {
return ShapedWeaponTableRecipeBuilder.shapedWeaponTable(this.itemLookup, category, item);
}

protected ShapedWeaponTableRecipeBuilder shapedWeaponTable(RecipeCategory category, ItemStack stack) {
return ShapedWeaponTableRecipeBuilder.shapedWeaponTable(this.itemLookup, category, stack);
}

protected ShapedWeaponTableRecipeBuilder shapedWeaponTable(RecipeCategory category, ItemLike item, int count) {
return ShapedWeaponTableRecipeBuilder.shapedWeaponTable(this.itemLookup, category, item, count);
}

protected ShapelessWeaponTableRecipeBuilder shapelessWeaponTable(RecipeCategory category, ItemLike item) {
return ShapelessWeaponTableRecipeBuilder.shapelessWeaponTable(this.itemLookup, category, item);
}

protected ShapelessWeaponTableRecipeBuilder shapelessWeaponTable(RecipeCategory category, ItemLike item, int count) {
return ShapelessWeaponTableRecipeBuilder.shapelessWeaponTable(this.itemLookup, category, item, count);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.advancements.critereon.RecipeUnlockedTrigger;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderGetter;
import net.minecraft.core.HolderLookup;
import net.minecraft.data.recipes.RecipeBuilder;
import net.minecraft.data.recipes.RecipeOutput;
import net.minecraft.resources.ResourceKey;
Expand All @@ -26,14 +27,16 @@
import java.util.*;

public class AlchemicalCauldronRecipeBuilder implements RecipeBuilder {
public static @NotNull AlchemicalCauldronRecipeBuilder cauldronRecipe(@NotNull Item item) {
return AlchemicalCauldronRecipeBuilder.cauldronRecipe(item, 1);

public static @NotNull AlchemicalCauldronRecipeBuilder cauldronRecipe(HolderLookup.RegistryLookup<Item> itemLookup, @NotNull Item item) {
return AlchemicalCauldronRecipeBuilder.cauldronRecipe(itemLookup, item, 1);
}

public static @NotNull AlchemicalCauldronRecipeBuilder cauldronRecipe(@NotNull Item item, int count) {
return new AlchemicalCauldronRecipeBuilder(item, count);
public static @NotNull AlchemicalCauldronRecipeBuilder cauldronRecipe(HolderLookup.RegistryLookup<Item> itemLookup, @NotNull Item item, int count) {
return new AlchemicalCauldronRecipeBuilder(itemLookup, item, count);
}

private final HolderLookup.RegistryLookup<Item> itemLookup;
protected final @NotNull ItemStack result;
protected String group;
protected Ingredient ingredient;
Expand All @@ -44,7 +47,8 @@ public class AlchemicalCauldronRecipeBuilder implements RecipeBuilder {
protected float exp = 0.2f;
protected final Map<String, Criterion<?>> criteria = new LinkedHashMap<>();

public AlchemicalCauldronRecipeBuilder(@NotNull Item result, int count) {
public AlchemicalCauldronRecipeBuilder(HolderLookup.RegistryLookup<Item> itemLookup, @NotNull Item result, int count) {
this.itemLookup = itemLookup;
this.result = new ItemStack(result, count);
}

Expand Down Expand Up @@ -90,8 +94,8 @@ public void save(RecipeOutput recipeOutput, @NotNull ResourceKey<Recipe<?>> reso
return this;
}

public @NotNull AlchemicalCauldronRecipeBuilder withFluid(HolderGetter<Item> lookup, @NotNull TagKey<Item> tag) {
this.fluid = Either.left(Ingredient.of(lookup.getOrThrow(tag)));
public @NotNull AlchemicalCauldronRecipeBuilder withFluid(@NotNull TagKey<Item> tag) {
this.fluid = Either.left(Ingredient.of(this.itemLookup.getOrThrow(tag)));
return this;
}

Expand All @@ -110,13 +114,13 @@ public void save(RecipeOutput recipeOutput, @NotNull ResourceKey<Recipe<?>> reso
return this;
}

public @NotNull AlchemicalCauldronRecipeBuilder withIngredient(HolderGetter<Item> lookup, @NotNull TagKey<Item> tag) {
this.ingredient = Ingredient.of(lookup.getOrThrow(tag));
public @NotNull AlchemicalCauldronRecipeBuilder withIngredient(@NotNull TagKey<Item> tag) {
this.ingredient = Ingredient.of(this.itemLookup.getOrThrow(tag));
return this;
}

@SuppressWarnings("unchecked")
public @NotNull AlchemicalCauldronRecipeBuilder withSkills(@NotNull Holder<ISkill<?>>... skills) {
@SafeVarargs
public final @NotNull AlchemicalCauldronRecipeBuilder withSkills(@NotNull Holder<ISkill<?>>... skills) {
this.skills.addAll(Arrays.asList(skills));
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.advancements.critereon.RecipeUnlockedTrigger;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderGetter;
import net.minecraft.core.HolderLookup;
import net.minecraft.data.recipes.RecipeBuilder;
import net.minecraft.data.recipes.RecipeOutput;
import net.minecraft.resources.ResourceKey;
Expand All @@ -32,14 +33,15 @@

public class AlchemyTableRecipeBuilder implements RecipeBuilder {

public static @NotNull AlchemyTableRecipeBuilder builder(@NotNull ItemStack stack) {
return new AlchemyTableRecipeBuilder(stack);
public static @NotNull AlchemyTableRecipeBuilder builder(HolderLookup.RegistryLookup<Item> itemLookup, @NotNull ItemStack stack) {
return new AlchemyTableRecipeBuilder(itemLookup, stack);
}

public static @NotNull AlchemyTableRecipeBuilder builder(@NotNull Holder<IOil> oilStack) {
return new AlchemyTableRecipeBuilder(OilContent.createItemStack(ModItems.OIL_BOTTLE.get(), oilStack));
public static @NotNull AlchemyTableRecipeBuilder builder(HolderLookup.RegistryLookup<Item> itemLookup, @NotNull Holder<IOil> oilStack) {
return new AlchemyTableRecipeBuilder(itemLookup, OilContent.createItemStack(ModItems.OIL_BOTTLE.get(), oilStack));
}

protected HolderLookup.RegistryLookup<Item> itemLookup;
protected final @NotNull ItemStack result;
protected String group;
protected Ingredient ingredient;
Expand All @@ -48,7 +50,8 @@ public class AlchemyTableRecipeBuilder implements RecipeBuilder {
protected final List<ISkill<?>> skills = new LinkedList<>();
protected final Map<String, Criterion<?>> criteria = new LinkedHashMap<>();

public AlchemyTableRecipeBuilder(@NotNull ItemStack result) {
public AlchemyTableRecipeBuilder(HolderLookup.RegistryLookup<Item> itemLookup, @NotNull ItemStack result) {
this.itemLookup = itemLookup;
this.result = result;
}

Expand All @@ -67,12 +70,12 @@ public AlchemyTableRecipeBuilder(@NotNull ItemStack result) {
return this;
}

public AlchemyTableRecipeBuilder plantOilIngredient(HolderGetter<Item> holderGetter) {
return ingredient(DataComponentIngredient.of(false, ModDataComponents.OIL, new OilContent(ModOils.PLANT), ModItems.OIL_BOTTLE.get())).unlockedBy("has_bottles", has(holderGetter, ModItems.OIL_BOTTLE.get()));
public AlchemyTableRecipeBuilder plantOilIngredient() {
return ingredient(DataComponentIngredient.of(false, ModDataComponents.OIL, new OilContent(ModOils.PLANT), ModItems.OIL_BOTTLE.get())).unlockedBy("has_bottles", has(this.itemLookup, ModItems.OIL_BOTTLE.get()));
}

public AlchemyTableRecipeBuilder bloodOilIngredient(HolderGetter<Item> holderGetter) {
return ingredient(DataComponentIngredient.of(false, ModDataComponents.OIL, new OilContent(ModOils.VAMPIRE_BLOOD), ModItems.OIL_BOTTLE.get())).unlockedBy("has_bottles", has(holderGetter, ModItems.OIL_BOTTLE.get()));
public AlchemyTableRecipeBuilder bloodOilIngredient() {
return ingredient(DataComponentIngredient.of(false, ModDataComponents.OIL, new OilContent(ModOils.VAMPIRE_BLOOD), ModItems.OIL_BOTTLE.get())).unlockedBy("has_bottles", has(this.itemLookup, ModItems.OIL_BOTTLE.get()));
}

public @NotNull AlchemyTableRecipeBuilder input(@NotNull Ingredient input) {
Expand Down

0 comments on commit 1cbdcfd

Please sign in to comment.