Skip to content

Commit

Permalink
Project temporarily compiles against full REI for code browsing
Browse files Browse the repository at this point in the history
Removed redundant ITextureGenerator.java
Removed redundant MachineUpgradeRecipe.java
Reworked ModRecipeProvider to support various predicate types
Created new recipe for tier 2 speed upgrade
REI item comparator for machine upgrade now takes into account fuzzy matching
TextureProvider.Entry is now static
Added a temporary testing recipe (see shedaniel/RoughlyEnoughItems#1798 for more info)
  • Loading branch information
leet committed Jan 19, 2025
1 parent be116e3 commit 26114c4
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 126 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static void onGatherData(GatherDataEvent.Client event) throws ExecutionEx
CompletableFuture<HolderLookup.Provider> 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
Expand Down
156 changes: 97 additions & 59 deletions src/main/java/com/leetftw/tech_mod/datagen/ModRecipeProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<HolderLookup.Provider> 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 <T> DataComponentPredicate componentPredicate(DataComponentType<T> 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 <T> Ingredient predicateIngredient(ItemLike item, DataComponentType<T> component, T value)
{
return DataComponentIngredient.of(true, componentPredicate(component, value), item);
}

protected <T> ItemPredicate itemPredicate(ItemLike item, DataComponentType<T> 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<HolderLookup.Provider> 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)";
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

public abstract class TextureProvider implements DataProvider
{
private class Entry
private static class Entry
{
public List<ResourceLocation> sourceTextures;
public ResourceLocation destinationTexture;
Expand Down
27 changes: 27 additions & 0 deletions src/main/resources/data/leet_tech/recipe/test_recipe.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit 26114c4

Please sign in to comment.