diff --git a/build.gradle b/build.gradle index 4bdb6e9..44986b9 100644 --- a/build.gradle +++ b/build.gradle @@ -122,8 +122,9 @@ dependencies { // localRuntime "mezz.jei:jei-${mc_version}-neoforge:${jei_version}" // REI API for Forge (Architectury Loom) - compileOnly "me.shedaniel:RoughlyEnoughItems-api-neoforge:${rei_version}" - compileOnly "me.shedaniel:RoughlyEnoughItems-default-plugin-neoforge:${rei_version}" + //compileOnly "me.shedaniel:RoughlyEnoughItems-api-neoforge:${rei_version}" + //compileOnly "me.shedaniel:RoughlyEnoughItems-default-plugin-neoforge:${rei_version}" + compileOnly "me.shedaniel:RoughlyEnoughItems-neoforge:${rei_version}" // REI Runtime for Forge (Architectury Loom) localRuntime "me.shedaniel:RoughlyEnoughItems-neoforge:${rei_version}" diff --git a/src/main/java/com/leetftw/tech_mod/compat/REICommonCompat.java b/src/main/java/com/leetftw/tech_mod/compat/REICommonCompat.java index 11c057b..1e8e803 100644 --- a/src/main/java/com/leetftw/tech_mod/compat/REICommonCompat.java +++ b/src/main/java/com/leetftw/tech_mod/compat/REICommonCompat.java @@ -12,6 +12,7 @@ public class REICommonCompat implements REICommonPlugin @Override public void registerItemComparators(ItemComparatorRegistry registry) { - registry.register((context, stack) -> stack.hashCode(), ModItems.MACHINE_UPGRADE.get()); + registry.register((context, stack) -> + context.isExact() ? stack.hashCode() : stack.get(ModDataComponents.MACHINE_UPGRADE.get()).hashCode(), ModItems.MACHINE_UPGRADE.get()); } } diff --git a/src/main/java/com/leetftw/tech_mod/datagen/MachineUpgradeRecipe.java b/src/main/java/com/leetftw/tech_mod/datagen/MachineUpgradeRecipe.java deleted file mode 100644 index eedfc63..0000000 --- a/src/main/java/com/leetftw/tech_mod/datagen/MachineUpgradeRecipe.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.leetftw.tech_mod.datagen; - -import com.mojang.serialization.MapCodec; -import net.minecraft.core.HolderLookup; -import net.minecraft.network.RegistryFriendlyByteBuf; -import net.minecraft.network.codec.StreamCodec; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.CraftingBookCategory; -import net.minecraft.world.item.crafting.CraftingInput; -import net.minecraft.world.item.crafting.CustomRecipe; -import net.minecraft.world.item.crafting.RecipeSerializer; -import net.minecraft.world.level.Level; - -/* -public class MachineUpgradeRecipe extends CustomRecipe -{ - public MachineUpgradeRecipe(CraftingBookCategory category) - { - super(category); - } - - @Override - public boolean matches(CraftingInput craftingInput, Level level) - { - if (craftingInput) - return false; - } - - @Override - public ItemStack assemble(CraftingInput craftingInput, HolderLookup.Provider provider) - { - return null; - } - - @Override - public RecipeSerializer getSerializer() - { - return new Serializer(); - } - - public class Serializer implements RecipeSerializer - { - @Override - public MapCodec codec() - { - return null; - } - - @Override - public StreamCodec streamCodec() - { - return null; - } - } -} -*/ \ No newline at end of file diff --git a/src/main/java/com/leetftw/tech_mod/datagen/ModDataGenerators.java b/src/main/java/com/leetftw/tech_mod/datagen/ModDataGenerators.java index 1ea4a88..5c161b8 100644 --- a/src/main/java/com/leetftw/tech_mod/datagen/ModDataGenerators.java +++ b/src/main/java/com/leetftw/tech_mod/datagen/ModDataGenerators.java @@ -26,7 +26,7 @@ public static void onGatherData(GatherDataEvent.Client event) throws ExecutionEx CompletableFuture lookupProvider = event.getLookupProvider(); generator.addProvider(true, new ModModelProvider(packOutput)); - generator.addProvider(true, new ModRecipeProvider(packOutput, lookupProvider)); + generator.addProvider(true, new ModRecipeProvider.Runner(packOutput, lookupProvider)); generator.addProvider(true, new LootTableProvider(packOutput, Set.of(), List.of(new LootTableProvider.SubProviderEntry( ModBlockLootTableProvider::new, LootContextParamSets.BLOCK // it makes sense to use BLOCK here diff --git a/src/main/java/com/leetftw/tech_mod/datagen/ModRecipeProvider.java b/src/main/java/com/leetftw/tech_mod/datagen/ModRecipeProvider.java index 644a12e..7c96c95 100644 --- a/src/main/java/com/leetftw/tech_mod/datagen/ModRecipeProvider.java +++ b/src/main/java/com/leetftw/tech_mod/datagen/ModRecipeProvider.java @@ -5,92 +5,130 @@ import com.leetftw.tech_mod.item.ModDataComponents; import com.leetftw.tech_mod.item.ModItems; import com.leetftw.tech_mod.item.upgrade.MachineUpgrade; +import net.minecraft.advancements.critereon.ItemPredicate; import net.minecraft.core.HolderLookup; import net.minecraft.core.component.DataComponentPatch; import net.minecraft.core.component.DataComponentPredicate; +import net.minecraft.core.component.DataComponentType; import net.minecraft.core.registries.Registries; import net.minecraft.data.PackOutput; import net.minecraft.data.recipes.*; -import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.*; +import net.minecraft.world.level.ItemLike; import net.neoforged.neoforge.common.crafting.DataComponentIngredient; import org.jetbrains.annotations.NotNull; import java.util.List; -import java.util.Map; import java.util.concurrent.CompletableFuture; -public class ModRecipeProvider extends RecipeProvider.Runner +public class ModRecipeProvider extends RecipeProvider { - protected ModRecipeProvider(PackOutput packOutput, CompletableFuture registries) + protected ModRecipeProvider(HolderLookup.Provider registries, RecipeOutput packOutput) { - super(packOutput, registries); + super(registries, packOutput); } - private ResourceLocation modLoc(String path) + protected ShapedRecipeBuilder shaped(RecipeCategory category, ItemStack result) { - return ResourceLocation.fromNamespaceAndPath(LeetTechMod.MOD_ID, path); + return ShapedRecipeBuilder.shaped(registries.lookupOrThrow(Registries.ITEM), category, result); } - @Override - protected @NotNull RecipeProvider createRecipeProvider(HolderLookup.@NotNull Provider registries, @NotNull RecipeOutput output) + protected DataComponentPredicate componentPredicate(DataComponentType component, T value) { - return new RecipeProvider(registries, output) - { - @Override - protected void buildRecipes() - { - shaped(RecipeCategory.MISC, ModItems.AESTHETIC_DUST) - .define('T', ModItems.TINY_AESTHETIC_DUST_PILE) - .pattern("TT") - .pattern("TT") - .unlockedBy("has_tiny_aesthetic_dust_pile", has(ModItems.TINY_AESTHETIC_DUST_PILE)) - .save(output); - - shaped(RecipeCategory.MISC, ModItems.AESTHETIC_HAMMER) - .define('S', Items.STICK) - .define('I', ModItems.AESTHETIC_CRYSTAL) - .pattern("III") - .pattern("ISI") - .pattern(" S ") - .unlockedBy("has_aesthetic_crystal", has(ModItems.AESTHETIC_CRYSTAL)) - .save(output); - - shaped(RecipeCategory.MISC, ModBlocks.GEM_REFINERY_ITEM) - .define('F', Items.FURNACE) - .define('D', Items.DIAMOND) - .define('A', ModItems.AESTHETIC_DUST) - .pattern("DAD") - .pattern("AFA") - .pattern("DAD") - .unlockedBy("has_aesthetic_dust", has(ModItems.AESTHETIC_DUST)) - .save(output); - - // TODO: Create helper class for Shaped Recipe with DataComponentIngredients instead of Items - output.accept(ResourceKey.create(Registries.RECIPE, modLoc("machine_upgrade_speed_tier_1")), - new ShapedRecipe("", CraftingBookCategory.MISC, ShapedRecipePattern.of(Map.of( - 'B', DataComponentIngredient.of(true, DataComponentPredicate.builder().expect(ModDataComponents.MACHINE_UPGRADE.get(), - MachineUpgrade.BLANK_KEY).build(), ModItems.MACHINE_UPGRADE.get()), - 'C', Ingredient.of(ModItems.AESTHETIC_CRYSTAL), - 'S', Ingredient.of(Items.SUGAR)), - "SCS", - "CBC", - "SCS"), new ItemStack(ModItems.MACHINE_UPGRADE, 1, - DataComponentPatch.builder().set(ModDataComponents.MACHINE_UPGRADE.get(), modLoc("speed_tier_1")).build())), - output.advancement().addCriterion("has_machine_upgrade", has(ModItems.MACHINE_UPGRADE)).build(modLoc("has_machine_upgrade"))); - - oreCooking(RecipeSerializer.SMELTING_RECIPE, SmeltingRecipe::new, List.of(Items.DIAMOND), RecipeCategory.MISC, ModItems.TINY_AESTHETIC_DUST_PILE, 0.25f, 1600, "tiny_aesthetic_dust_pile", "_from_smelting"); - oreCooking(RecipeSerializer.BLASTING_RECIPE, BlastingRecipe::new, List.of(Items.DIAMOND), RecipeCategory.MISC, ModItems.TINY_AESTHETIC_DUST_PILE, 0.25f, 1600, "tiny_aesthetic_dust_pile", "_from_blasting"); - } - }; + return DataComponentPredicate.builder().expect(component, value).build(); + } + + protected Ingredient predicateIngredient(ItemLike item, DataComponentType component, T value) + { + return DataComponentIngredient.of(true, componentPredicate(component, value), item); + } + + protected ItemPredicate itemPredicate(ItemLike item, DataComponentType component, T value) + { + return ItemPredicate.Builder.item().of(registries.lookupOrThrow(Registries.ITEM), item) + .hasComponents(componentPredicate(component, value)).build(); } @Override - public @NotNull String getName() + protected void buildRecipes() + { + shaped(RecipeCategory.MISC, ModItems.AESTHETIC_DUST) + .define('T', ModItems.TINY_AESTHETIC_DUST_PILE) + .pattern("TT") + .pattern("TT") + .unlockedBy("has_tiny_aesthetic_dust_pile", has(ModItems.TINY_AESTHETIC_DUST_PILE)) + .save(output); + + shaped(RecipeCategory.MISC, ModItems.AESTHETIC_HAMMER) + .define('S', Items.STICK) + .define('I', ModItems.AESTHETIC_CRYSTAL) + .pattern("III") + .pattern("ISI") + .pattern(" S ") + .unlockedBy("has_aesthetic_crystal", has(ModItems.AESTHETIC_CRYSTAL)) + .save(output); + + shaped(RecipeCategory.MISC, ModBlocks.GEM_REFINERY_ITEM) + .define('F', Items.FURNACE) + .define('D', Items.DIAMOND) + .define('A', ModItems.AESTHETIC_DUST) + .pattern("DAD") + .pattern("AFA") + .pattern("DAD") + .unlockedBy("has_aesthetic_dust", has(ModItems.AESTHETIC_DUST)) + .save(output); + + shaped(RecipeCategory.MISC, new ItemStack(ModItems.MACHINE_UPGRADE, 1, + DataComponentPatch.builder().set(ModDataComponents.MACHINE_UPGRADE.get(), modLoc("speed_tier_1")).build())) + .define('U', predicateIngredient(ModItems.MACHINE_UPGRADE, ModDataComponents.MACHINE_UPGRADE.get(), MachineUpgrade.BLANK_KEY)) + .define('C', ModItems.AESTHETIC_CRYSTAL) + .define('S', Items.SUGAR) + .pattern("SCS") + .pattern("CUC") + .pattern("SCS") + .unlockedBy("has_machine_upgrade", has(ModItems.MACHINE_UPGRADE)) + .save(output, "leet_tech:machine_upgrade_speed_tier_1"); + + shaped(RecipeCategory.MISC, new ItemStack(ModItems.MACHINE_UPGRADE, 1, + DataComponentPatch.builder().set(ModDataComponents.MACHINE_UPGRADE.get(), modLoc("speed_tier_2")).build())) + .define('U', predicateIngredient(ModItems.MACHINE_UPGRADE, ModDataComponents.MACHINE_UPGRADE.get(), modLoc("speed_tier_1"))) + .define('C', ModItems.AESTHETIC_CRYSTAL) + .define('E', Items.EMERALD) + .pattern("ECE") + .pattern("UCU") + .pattern("ECE") + .unlockedBy("has_machine_upgrade", inventoryTrigger(itemPredicate(ModItems.MACHINE_UPGRADE, ModDataComponents.MACHINE_UPGRADE.get(), modLoc("speed_tier_1")))) + .save(output, "leet_tech:machine_upgrade_speed_tier_2"); + + oreCooking(RecipeSerializer.SMELTING_RECIPE, SmeltingRecipe::new, List.of(Items.DIAMOND), RecipeCategory.MISC, ModItems.TINY_AESTHETIC_DUST_PILE, 0.25f, 1600, "tiny_aesthetic_dust_pile", "_from_smelting"); + oreCooking(RecipeSerializer.BLASTING_RECIPE, BlastingRecipe::new, List.of(Items.DIAMOND), RecipeCategory.MISC, ModItems.TINY_AESTHETIC_DUST_PILE, 0.25f, 1600, "tiny_aesthetic_dust_pile", "_from_blasting"); + } + + private ResourceLocation modLoc(String path) + { + return ResourceLocation.fromNamespaceAndPath(LeetTechMod.MOD_ID, path); + } + + public static class Runner extends RecipeProvider.Runner { - return "Recipe Provider (LeetTech)"; + public Runner(PackOutput packOutput, CompletableFuture registries) + { + super(packOutput, registries); + } + + @Override + protected @NotNull RecipeProvider createRecipeProvider(HolderLookup.@NotNull Provider registries, @NotNull RecipeOutput output) + { + return new ModRecipeProvider(registries, output); + } + + @Override + public @NotNull String getName() + { + return "Recipe Provider (LeetTech)"; + } } } diff --git a/src/main/java/com/leetftw/tech_mod/datagen/texture/ITextureGenerator.java b/src/main/java/com/leetftw/tech_mod/datagen/texture/ITextureGenerator.java deleted file mode 100644 index 9511b82..0000000 --- a/src/main/java/com/leetftw/tech_mod/datagen/texture/ITextureGenerator.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.leetftw.tech_mod.datagen.texture; - -public interface ITextureGenerator -{ - void generateTextures(TextureProvider output); -} diff --git a/src/main/java/com/leetftw/tech_mod/datagen/texture/TextureProvider.java b/src/main/java/com/leetftw/tech_mod/datagen/texture/TextureProvider.java index 0d24151..d38dfdc 100644 --- a/src/main/java/com/leetftw/tech_mod/datagen/texture/TextureProvider.java +++ b/src/main/java/com/leetftw/tech_mod/datagen/texture/TextureProvider.java @@ -22,7 +22,7 @@ public abstract class TextureProvider implements DataProvider { - private class Entry + private static class Entry { public List sourceTextures; public ResourceLocation destinationTexture; diff --git a/src/main/resources/data/leet_tech/recipe/test_recipe.json b/src/main/resources/data/leet_tech/recipe/test_recipe.json new file mode 100644 index 0000000..3de9c2c --- /dev/null +++ b/src/main/resources/data/leet_tech/recipe/test_recipe.json @@ -0,0 +1,27 @@ +{ + "type": "minecraft:crafting_shaped", + "category": "misc", + "key": { + "B": { + "neoforge:ingredient_type": "neoforge:components", + "components": { + "minecraft:stored_enchantments": { + "levels": { + "minecraft:sharpness": 4 + } + } + }, + "items": "minecraft:enchanted_book", + "strict": false + } + }, + "pattern": [ + " ", + " ", + " B" + ], + "result": { + "count": 1, + "id": "minecraft:dirt" + } +} \ No newline at end of file