Skip to content

Change compat datagen from enum to interface #8895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: mc1.20.1/dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import com.simibubi.create.AllRecipeTypes;

import com.simibubi.create.foundation.data.recipe.Mods;

import net.minecraft.data.PackOutput;
import net.minecraft.world.level.block.Block;

import java.util.Objects;

/**
* The base class for Cutting recipe generation.
* Addons should extend this and use the {@link ProcessingRecipeGen#create} methods
Expand All @@ -25,6 +29,76 @@ protected GeneratedRecipe stripAndMakePlanks(Block wood, Block stripped, Block p
.output(planks, planksAmount));
}

protected GeneratedRecipe cuttingCompat(DatagenMod mod, String... woodtypes) {
for (String type : woodtypes) {
String planks = type + "_planks";

if (mod == Mods.ARS_N && type.contains("archwood"))
planks = "archwood_planks";

String strippedPre = mod.strippedIsSuffix() ? "" : "stripped_";
String strippedPost = mod.strippedIsSuffix() ? "_stripped" : "";
stripAndMakePlanks(mod, type + "_log", strippedPre + type + "_log" + strippedPost, planks);

String wood = type + (mod.omitWoodSuffix() ? "" : "_wood");
stripAndMakePlanks(mod, wood, strippedPre + wood + strippedPost, planks);
}
return null;
}

protected GeneratedRecipe cuttingCompatLogOnly(DatagenMod mod, String... woodtypes) {
for (String type : woodtypes) {
String planks = type + "_planks";
String strippedPre = mod.strippedIsSuffix() ? "" : "stripped_";
String strippedPost = mod.strippedIsSuffix() ? "_stripped" : "";
stripAndMakePlanks(mod, type + "_log", strippedPre + type + "_log" + strippedPost, planks);
}
return null;
}

protected GeneratedRecipe stripOnlyDiffModId(DatagenMod mod1, String wood, DatagenMod mod2, String stripped) {
create("compat/" + mod1.getId() + "/" + wood, b -> b.duration(50)
.require(mod1, wood)
.output(1, mod2, stripped, 1)
.whenModLoaded(mod1.getId()));
return null;
}

protected GeneratedRecipe stripAndMakePlanksDiffPlanksModId(DatagenMod mod1, String log, String stripped, DatagenMod mod2, String planks) {
if (log != null)
create("compat/" + mod1.getId() + "/" + log, b -> b.duration(50)
.require(mod1, log)
.output(1, mod1, stripped, 1)
.whenModLoaded(mod1.getId()));
if (planks != null) // Shouldn't be needed as stripAndMakePlanks can already do what this method does if planks is null
create("compat/" + mod1.getId() + "/" + stripped, b -> b.duration(50)
.require(mod1, stripped)
.output(1, mod2, planks, 6)
.whenModLoaded(mod1.getId()));
return null;
}

protected GeneratedRecipe stripAndMakePlanks(DatagenMod mod, String wood, String stripped, String planks) {
if (wood != null)
create("compat/" + mod.getId() + "/" + wood, b -> b.duration(50)
.require(mod, wood)
.output(1, mod, stripped, 1)
.whenModLoaded(mod.getId()));
if (planks != null)
if (!Objects.equals(mod.getId(), Mods.VH.getId())) {
create("compat/" + mod.getId() + "/" + stripped, b -> b.duration(50)
.require(mod, stripped)
.output(1, mod, planks, 6)
.whenModLoaded(mod.getId()));
} else {
create("compat/" + mod.getId() + "/" + stripped, b -> b.duration(50)
.require(mod, stripped)
.output(1, mod, planks, 4)
.whenModLoaded(mod.getId()));
}
return null;
}

public CuttingRecipeGen(PackOutput output, String defaultNamespace) {
super(output, defaultNamespace);
}
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/com/simibubi/create/api/data/recipe/DatagenMod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.simibubi.create.api.data.recipe;

import net.minecraft.resources.ResourceLocation;

public interface DatagenMod {
default ResourceLocation asResource(String id) {
return new ResourceLocation(getId(), id);
}

default String recipeId(String id) {
return "compat/" + getId() + "/" + id;
}

String getId();

default ResourceLocation ingotOf(String type) {
return new ResourceLocation(getId(), reversedMetalPrefix() ? "ingot_" + type : type + "_ingot");
}

default ResourceLocation nuggetOf(String type) {
return new ResourceLocation(getId(), reversedMetalPrefix() ? "nugget_" + type : type + "_nugget");
}

default ResourceLocation oreOf(String type) {
return new ResourceLocation(getId(), reversedMetalPrefix() ? "ore_" + type : type + "_ore");
}

default ResourceLocation deepslateOreOf(String type) {
return new ResourceLocation(getId(), reversedMetalPrefix() ? "deepslate_ore_" + type : "deepslate_" + type + "_ore");
}

/**
* @return Whether the resource locations of this mod's metal-derived entries have the metal named appended.
*/
default boolean reversedMetalPrefix() { return false; }

/**
* @return Whether the resource locations of this mod's stripped logs/wood have '_stripped' appended to the normal log/wood RL.
*/
default boolean strippedIsSuffix() {
return false;
}

/**
* @return Whether wood blocks from this mod omit the '_wood' part of their resource locations.
*/
default boolean omitWoodSuffix() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.simibubi.create.AllRecipeTypes;

import net.minecraft.data.PackOutput;
import net.minecraft.world.level.material.Fluids;

/**
* The base class for Filling recipe generation.
Expand All @@ -13,6 +14,14 @@
*/
public abstract class FillingRecipeGen extends ProcessingRecipeGen {

protected GeneratedRecipe moddedGrass(DatagenMod mod, String name) {
String grass = name + "_grass_block";
return create(mod.recipeId(grass), b -> b.require(Fluids.WATER, 500)
.require(mod, name + "_dirt")
.output(mod, grass)
.whenModLoaded(mod.getId()));
}

public FillingRecipeGen(PackOutput output, String defaultNamespace) {
super(output, defaultNamespace);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public GeneratedRecipe convert(Supplier<Ingredient> input, Supplier<ItemLike> re
.output(result.get()));
}

protected GeneratedRecipe moddedConversion(DatagenMod mod, String input, String output) {
return create("compat/" + mod.getId() + "/" + output, p -> p.require(mod, input)
.output(mod, output)
.whenModLoaded(mod.getId()));
}

public HauntingRecipeGen(PackOutput output, String defaultNamespace) {
super(output, defaultNamespace);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.simibubi.create.AllRecipeTypes;


import net.minecraft.data.PackOutput;
import net.minecraft.world.level.material.Fluids;

/**
* The base class for Mixing recipe generation.
Expand All @@ -13,6 +15,14 @@
*/
public abstract class MixingRecipeGen extends ProcessingRecipeGen {

protected GeneratedRecipe moddedMud(DatagenMod mod, String name) {
String mud = name + "_mud";
return create(mod.recipeId(mud), b -> b.require(Fluids.WATER, 250)
.require(mod, name + "_dirt")
.output(mod, mud)
.whenModLoaded(mod.getId()));
}

public MixingRecipeGen(PackOutput output, String defaultNamespace) {
super(output, defaultNamespace);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
*/
public abstract class PressingRecipeGen extends ProcessingRecipeGen {

protected GeneratedRecipe moddedCompacting(DatagenMod mod, String input, String output) {
return create("compat/" + mod.getId() + "/" + output, b -> b.require(mod, input)
.output(mod, output)
.whenModLoaded(mod.getId()));
}

protected GeneratedRecipe moddedPaths(DatagenMod mod, String... blocks) {
for(String block : blocks) {
moddedCompacting(mod, block, block + "_path");
}
return null;
}

public PressingRecipeGen(PackOutput output, String defaultNamespace) {
super(output, defaultNamespace);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import java.util.function.Supplier;

import com.simibubi.create.AllRecipeTypes;
import com.simibubi.create.foundation.data.recipe.CompatMetals;
import com.simibubi.create.foundation.data.recipe.Mods;
import com.tterrag.registrate.util.entry.ItemEntry;

import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.Block;

Expand All @@ -29,6 +33,24 @@ public GeneratedRecipe crushedOre(ItemEntry<Item> crushed, Supplier<ItemLike> nu
.output(secondaryChance, secondary.get(), 1));
}

protected GeneratedRecipe moddedCrushedOre(ItemEntry<? extends Item> crushed, CompatMetals metal) {
for (Mods mod : metal.getMods()) {
String metalName = metal.getName(mod);
ResourceLocation nugget = mod.nuggetOf(metalName);
create(mod.getId() + "/" + crushed.getId()
.getPath(),
b -> b.withItemIngredients(Ingredient.of(crushed::get))
.output(1, nugget, 9)
.whenModLoaded(mod.getId()));
}
return null;
}

protected GeneratedRecipe simpleModded(DatagenMod mod, String input, String output) {
return create(mod.getId() + "/" + output, b -> b.require(mod, input)
.output(mod, output).whenModLoaded(mod.getId()));
}

public WashingRecipeGen(PackOutput output, String defaultNamespace) {
super(output, defaultNamespace);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.simibubi.create.api.data.recipe.DatagenMod;
import com.simibubi.create.foundation.data.SimpleDatagenIngredient;
import com.simibubi.create.foundation.data.recipe.Mods;
import com.simibubi.create.foundation.fluid.FluidHelper;
import com.simibubi.create.foundation.fluid.FluidIngredient;
import com.simibubi.create.foundation.recipe.IRecipeTypeInfo;
Expand Down Expand Up @@ -120,7 +120,7 @@ public ProcessingRecipeBuilder<T> require(Ingredient ingredient) {
return this;
}

public ProcessingRecipeBuilder<T> require(Mods mod, String id) {
public ProcessingRecipeBuilder<T> require(DatagenMod mod, String id) {
params.ingredients.add(new SimpleDatagenIngredient(mod, id));
return this;
}
Expand Down Expand Up @@ -167,15 +167,15 @@ public ProcessingRecipeBuilder<T> output(float chance, ItemStack output) {
return output(new ProcessingOutput(output, chance));
}

public ProcessingRecipeBuilder<T> output(float chance, Mods mod, String id, int amount) {
public ProcessingRecipeBuilder<T> output(float chance, DatagenMod mod, String id, int amount) {
return output(new ProcessingOutput(Pair.of(mod.asResource(id), amount), chance));
}

public ProcessingRecipeBuilder<T> output(ResourceLocation id) {
return output(1, id, 1);
}

public ProcessingRecipeBuilder<T> output(Mods mod, String id) {
public ProcessingRecipeBuilder<T> output(DatagenMod mod, String id) {
return output(1, mod.asResource(id), 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.simibubi.create.foundation.data.recipe.Mods;
import com.simibubi.create.api.data.recipe.DatagenMod;

import net.minecraft.world.item.crafting.Ingredient;

public class SimpleDatagenIngredient extends Ingredient {

private Mods mod;
private DatagenMod mod;
private String id;

public SimpleDatagenIngredient(Mods mod, String id) {
public SimpleDatagenIngredient(DatagenMod mod, String id) {
super(Stream.empty());
this.mod = mod;
this.id = id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import com.simibubi.create.Create;
import com.simibubi.create.api.data.recipe.CompactingRecipeGen;

import com.simibubi.create.api.data.recipe.SequencedAssemblyRecipeGen;

import net.minecraft.data.PackOutput;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Blocks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.simibubi.create.Create;
import com.simibubi.create.api.data.recipe.CrushingRecipeGen;

import com.simibubi.create.api.data.recipe.SequencedAssemblyRecipeGen;
import com.simibubi.create.content.decoration.palettes.AllPaletteStoneTypes;

import com.simibubi.create.content.processing.recipe.ProcessingRecipe;
Expand Down
Loading