Add LibCD Support (#1851)
* First ugly commit for LibCD support * fix all the ugly hacks, add rolling machine + fluid gen recipes * be a bit more lenient with fluid generator names * add test script, fix a few bugs * get rid of ShapedRecipeSerializer stuff that's no longer needed * Add a warning to the sample script
This commit is contained in:
parent
bfce163c99
commit
989e4601af
12 changed files with 801 additions and 0 deletions
|
@ -26,6 +26,7 @@ package techreborn;
|
|||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.block.DispenserBlock;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -39,6 +40,7 @@ import reborncore.common.util.Torus;
|
|||
import reborncore.common.world.DataAttachment;
|
||||
import techreborn.blockentity.storage.idsu.IDSUManager;
|
||||
import techreborn.client.GuiHandler;
|
||||
import techreborn.compat.libcd.TRTweaker;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.events.ModRegistry;
|
||||
import techreborn.init.*;
|
||||
|
@ -89,6 +91,10 @@ public class TechReborn implements ModInitializer {
|
|||
|
||||
DataAttachment.REGISTRY.register(IDSUManager.class, IDSUManager::new);
|
||||
|
||||
if (FabricLoader.getInstance().isModLoaded("libcd")) {
|
||||
TRTweaker.init();
|
||||
}
|
||||
|
||||
LOGGER.info("TechReborn setup done!");
|
||||
|
||||
}
|
||||
|
|
|
@ -26,10 +26,13 @@ package techreborn.api.recipe.recipes;
|
|||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.DefaultedList;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.JsonHelper;
|
||||
import reborncore.common.crafting.RebornRecipe;
|
||||
import reborncore.common.crafting.RebornRecipeType;
|
||||
import reborncore.common.crafting.ingredient.RebornIngredient;
|
||||
import techreborn.blockentity.machine.multiblock.IndustrialBlastFurnaceBlockEntity;
|
||||
|
||||
public class BlastFurnaceRecipe extends RebornRecipe {
|
||||
|
@ -39,6 +42,11 @@ public class BlastFurnaceRecipe extends RebornRecipe {
|
|||
public BlastFurnaceRecipe(RebornRecipeType<?> type, Identifier name) {
|
||||
super(type, name);
|
||||
}
|
||||
|
||||
public BlastFurnaceRecipe(RebornRecipeType<?> type, Identifier name, DefaultedList<RebornIngredient> ingredients, DefaultedList<ItemStack> outputs, int power, int time, int heat) {
|
||||
super(type, name, ingredients, outputs, power, time);
|
||||
this.heat = heat;
|
||||
}
|
||||
|
||||
public int getHeat() {
|
||||
return heat;
|
||||
|
|
|
@ -27,10 +27,14 @@ package techreborn.api.recipe.recipes;
|
|||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.DefaultedList;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import reborncore.common.crafting.RebornFluidRecipe;
|
||||
import reborncore.common.crafting.RebornRecipeType;
|
||||
import reborncore.common.crafting.ingredient.RebornIngredient;
|
||||
import reborncore.common.fluid.container.FluidInstance;
|
||||
import reborncore.common.util.Tank;
|
||||
import techreborn.blockentity.machine.multiblock.FluidReplicatorBlockEntity;
|
||||
import techreborn.utils.FluidUtils;
|
||||
|
@ -41,6 +45,14 @@ public class FluidReplicatorRecipe extends RebornFluidRecipe {
|
|||
super(type, name);
|
||||
}
|
||||
|
||||
public FluidReplicatorRecipe(RebornRecipeType<?> type, Identifier name, DefaultedList<RebornIngredient> ingredients, DefaultedList<ItemStack> outputs, int power, int time) {
|
||||
super(type, name, ingredients, outputs, power, time);
|
||||
}
|
||||
|
||||
public FluidReplicatorRecipe(RebornRecipeType<?> type, Identifier name, DefaultedList<RebornIngredient> ingredients, DefaultedList<ItemStack> outputs, int power, int time, FluidInstance fluid) {
|
||||
super(type, name, ingredients, outputs, power, time, fluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tank getTank(BlockEntity be) {
|
||||
FluidReplicatorBlockEntity blockEntity = (FluidReplicatorBlockEntity) be;
|
||||
|
|
|
@ -27,10 +27,13 @@ package techreborn.api.recipe.recipes;
|
|||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.DefaultedList;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.JsonHelper;
|
||||
import reborncore.common.crafting.RebornRecipe;
|
||||
import reborncore.common.crafting.RebornRecipeType;
|
||||
import reborncore.common.crafting.ingredient.RebornIngredient;
|
||||
import techreborn.blockentity.fusionReactor.FusionControlComputerBlockEntity;
|
||||
|
||||
/**
|
||||
|
@ -45,6 +48,12 @@ public class FusionReactorRecipe extends RebornRecipe {
|
|||
public FusionReactorRecipe(RebornRecipeType<?> type, Identifier name) {
|
||||
super(type, name);
|
||||
}
|
||||
|
||||
public FusionReactorRecipe(RebornRecipeType<?> type, Identifier name, DefaultedList<RebornIngredient> ingredients, DefaultedList<ItemStack> outputs, int power, int time, int startE, int minSize) {
|
||||
super(type, name, ingredients, outputs, power, time);
|
||||
this.startE = startE;
|
||||
this.minSize = minSize;
|
||||
}
|
||||
|
||||
public int getStartEnergy () {
|
||||
return startE;
|
||||
|
|
|
@ -25,9 +25,13 @@
|
|||
package techreborn.api.recipe.recipes;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.DefaultedList;
|
||||
import net.minecraft.util.Identifier;
|
||||
import reborncore.common.crafting.RebornFluidRecipe;
|
||||
import reborncore.common.crafting.RebornRecipeType;
|
||||
import reborncore.common.crafting.ingredient.RebornIngredient;
|
||||
import reborncore.common.fluid.container.FluidInstance;
|
||||
import reborncore.common.util.Tank;
|
||||
import techreborn.blockentity.machine.multiblock.IndustrialGrinderBlockEntity;
|
||||
|
||||
|
@ -37,6 +41,14 @@ public class IndustrialGrinderRecipe extends RebornFluidRecipe {
|
|||
super(type, name);
|
||||
}
|
||||
|
||||
public IndustrialGrinderRecipe(RebornRecipeType<?> type, Identifier name, DefaultedList<RebornIngredient> ingredients, DefaultedList<ItemStack> outputs, int power, int time) {
|
||||
super(type, name, ingredients, outputs, power, time);
|
||||
}
|
||||
|
||||
public IndustrialGrinderRecipe(RebornRecipeType<?> type, Identifier name, DefaultedList<RebornIngredient> ingredients, DefaultedList<ItemStack> outputs, int power, int time, FluidInstance fluid) {
|
||||
super(type, name, ingredients, outputs, power, time, fluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tank getTank(BlockEntity be) {
|
||||
IndustrialGrinderBlockEntity blockEntity = (IndustrialGrinderBlockEntity) be;
|
||||
|
|
|
@ -25,9 +25,13 @@
|
|||
package techreborn.api.recipe.recipes;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.DefaultedList;
|
||||
import net.minecraft.util.Identifier;
|
||||
import reborncore.common.crafting.RebornFluidRecipe;
|
||||
import reborncore.common.crafting.RebornRecipeType;
|
||||
import reborncore.common.crafting.ingredient.RebornIngredient;
|
||||
import reborncore.common.fluid.container.FluidInstance;
|
||||
import reborncore.common.util.Tank;
|
||||
import techreborn.blockentity.machine.multiblock.IndustrialSawmillBlockEntity;
|
||||
|
||||
|
@ -37,6 +41,14 @@ public class IndustrialSawmillRecipe extends RebornFluidRecipe {
|
|||
super(type, name);
|
||||
}
|
||||
|
||||
public IndustrialSawmillRecipe(RebornRecipeType<?> type, Identifier name, DefaultedList<RebornIngredient> ingredients, DefaultedList<ItemStack> outputs, int power, int time) {
|
||||
super(type, name, ingredients, outputs, power, time);
|
||||
}
|
||||
|
||||
public IndustrialSawmillRecipe(RebornRecipeType<?> type, Identifier name, DefaultedList<RebornIngredient> ingredients, DefaultedList<ItemStack> outputs, int power, int time, FluidInstance fluid) {
|
||||
super(type, name, ingredients, outputs, power, time, fluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tank getTank(BlockEntity be) {
|
||||
IndustrialSawmillBlockEntity blockEntity = (IndustrialSawmillBlockEntity) be;
|
||||
|
|
|
@ -51,6 +51,11 @@ public class RollingMachineRecipe extends RebornRecipe {
|
|||
super(type, name);
|
||||
}
|
||||
|
||||
public RollingMachineRecipe(RebornRecipeType<?> type, Identifier name, ShapedRecipe recipe) {
|
||||
super(type, name);
|
||||
this.shapedRecipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(JsonObject jsonObject) {
|
||||
if(jsonObject.has("shaped")) {
|
||||
|
@ -69,6 +74,7 @@ public class RollingMachineRecipe extends RebornRecipe {
|
|||
RecipeSerializer.SHAPED.write(byteBuf, shapedRecipe);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deserialize(PacketByteBuf byteBuf) {
|
||||
Identifier identifier = new Identifier(byteBuf.readString(byteBuf.readInt()));
|
||||
|
|
102
src/main/java/techreborn/compat/libcd/TRRecipeParser.java
Normal file
102
src/main/java/techreborn/compat/libcd/TRRecipeParser.java
Normal file
|
@ -0,0 +1,102 @@
|
|||
package techreborn.compat.libcd;
|
||||
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import io.github.cottonmc.libcd.tweaker.TweakerSyntaxException;
|
||||
import io.github.cottonmc.libcd.tweaker.TweakerUtils;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.StringNbtReader;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import net.minecraft.tag.ItemTags;
|
||||
import net.minecraft.tag.Tag;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import reborncore.common.crafting.ingredient.*;
|
||||
import reborncore.common.fluid.container.FluidInstance;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
|
||||
public class TRRecipeParser {
|
||||
|
||||
public static RebornIngredient processIngredient(Object input) throws TweakerSyntaxException {
|
||||
if (input instanceof RebornIngredient) {
|
||||
return (RebornIngredient) input;
|
||||
} else if (input instanceof Ingredient) {
|
||||
return new WrappedIngredient((Ingredient) input);
|
||||
} else if (input instanceof String) {
|
||||
String in = (String) input;
|
||||
Optional<Integer> amount = Optional.empty();
|
||||
int atIndex = in.lastIndexOf('@');
|
||||
if (atIndex != -1 && in.lastIndexOf('}') < atIndex) {
|
||||
String count = in.substring(atIndex + 1);
|
||||
amount = Optional.of(Integer.parseInt(count));
|
||||
in = in.substring(0, atIndex);
|
||||
}
|
||||
if (in.indexOf('~') == 0) {
|
||||
//fluids
|
||||
Identifier id = new Identifier(in.substring(1));
|
||||
Fluid fluid = Registry.FLUID.get(id);
|
||||
if (fluid == Fluids.EMPTY) throw new TweakerSyntaxException("Failed to get fluid for input: " + in);
|
||||
return new FluidIngredient(fluid, Optional.empty(), amount);
|
||||
} else if (in.indexOf('#') == 0) {
|
||||
Identifier id = new Identifier(in.substring(1));
|
||||
Tag<Item> itemTag = ItemTags.getContainer().get(id);
|
||||
if (itemTag == null) throw new TweakerSyntaxException("Failed to get item tag for input: " + in);
|
||||
return new TagIngredient(id, ItemTags.getContainer().get(id), amount);
|
||||
} else {
|
||||
ItemStack stack;
|
||||
Optional<CompoundTag> tag = Optional.empty();
|
||||
boolean requireEmpty = false;
|
||||
if (in.contains("->")) {
|
||||
ItemStack readStack = TweakerUtils.INSTANCE.getSpecialStack(in);
|
||||
if (readStack.isEmpty())
|
||||
throw new TweakerSyntaxException("Failed to get special stack for input: " + in);
|
||||
if (readStack.hasTag()) {
|
||||
tag = Optional.of(readStack.getTag());
|
||||
} else {
|
||||
requireEmpty = true;
|
||||
}
|
||||
stack = readStack;
|
||||
} else {
|
||||
int nbtIndex = in.indexOf('{');
|
||||
if (nbtIndex != -1) {
|
||||
try {
|
||||
String nbt = in.substring(nbtIndex);
|
||||
in = in.substring(0, nbtIndex);
|
||||
StringNbtReader reader = new StringNbtReader(new StringReader(nbt));
|
||||
CompoundTag parsedTag = reader.parseCompoundTag();
|
||||
if (parsedTag.isEmpty()) requireEmpty = true;
|
||||
else tag = Optional.of(reader.parseCompoundTag());
|
||||
} catch (CommandSyntaxException e) {
|
||||
throw new TweakerSyntaxException(e.getMessage());
|
||||
}
|
||||
}
|
||||
Identifier id = new Identifier(in);
|
||||
Item item = Registry.ITEM.get(id);
|
||||
if (item == Items.AIR) throw new TweakerSyntaxException("Failed to get item for input: " + in);
|
||||
stack = new ItemStack(item);
|
||||
}
|
||||
return new StackIngredient(Collections.singletonList(stack), amount, tag, requireEmpty);
|
||||
}
|
||||
}
|
||||
else throw new TweakerSyntaxException("Illegal object passed to TechReborn of type " + input.getClass().getName());
|
||||
}
|
||||
|
||||
public static FluidInstance parseFluid(String fluid) {
|
||||
int amount = 1000;
|
||||
int amtIndex = fluid.indexOf('@');
|
||||
if (amtIndex != -1) {
|
||||
String amtStr = fluid.substring(amtIndex + 1);
|
||||
fluid = fluid.substring(0, amtIndex);
|
||||
amount = Integer.parseInt(amtStr);
|
||||
}
|
||||
Identifier id = new Identifier(fluid);
|
||||
return new FluidInstance(Registry.FLUID.get(id), amount);
|
||||
}
|
||||
}
|
534
src/main/java/techreborn/compat/libcd/TRTweaker.java
Normal file
534
src/main/java/techreborn/compat/libcd/TRTweaker.java
Normal file
|
@ -0,0 +1,534 @@
|
|||
package techreborn.compat.libcd;
|
||||
|
||||
import io.github.cottonmc.libcd.tweaker.*;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import net.minecraft.recipe.ShapedRecipe;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.util.DefaultedList;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import reborncore.common.crafting.RebornRecipe;
|
||||
import reborncore.common.crafting.RebornRecipeType;
|
||||
import reborncore.common.crafting.RecipeManager;
|
||||
import reborncore.common.crafting.ingredient.FluidIngredient;
|
||||
import reborncore.common.crafting.ingredient.RebornIngredient;
|
||||
import reborncore.common.fluid.container.FluidInstance;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.api.generator.EFluidGenerator;
|
||||
import techreborn.api.generator.FluidGeneratorRecipe;
|
||||
import techreborn.api.generator.GeneratorRecipeHelper;
|
||||
import techreborn.api.recipe.recipes.*;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.items.ItemDynamicCell;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class TRTweaker implements Tweaker {
|
||||
public static final TRTweaker INSTANCE = new TRTweaker();
|
||||
private RecipeTweaker tweaker = RecipeTweaker.INSTANCE;
|
||||
|
||||
List<FluidGeneratorRecipe> added = new ArrayList<>();
|
||||
List<FluidGeneratorRecipe> toAdd = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void prepareReload(ResourceManager resourceManager) {
|
||||
for (FluidGeneratorRecipe recipe : added) {
|
||||
GeneratorRecipeHelper.removeFluidRecipe(recipe.getGeneratorType(), recipe.getFluid());
|
||||
}
|
||||
added.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyReload(ResourceManager resourceManager, Executor executor) {
|
||||
for (FluidGeneratorRecipe recipe : toAdd) {
|
||||
if (GeneratorRecipeHelper.getFluidRecipesForGenerator(recipe.getGeneratorType()).addRecipe(recipe)) {
|
||||
added.add(recipe);
|
||||
} else {
|
||||
TechReborn.LOGGER.error("Could not add recipe to TechReborn generator " + recipe.getGeneratorType().getRecipeID()
|
||||
+ ": a recipe for fluid " + Registry.FLUID.getId(recipe.getFluid()) + " already exists");
|
||||
}
|
||||
}
|
||||
toAdd.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getApplyMessage() {
|
||||
int recipeCount = added.size();
|
||||
return recipeCount + " TechReborn fluid generator " + (recipeCount == 1? "recipe" : "recipes");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a fluid ingredient
|
||||
* @param fluid The fluid required.
|
||||
* @param holders The fluid-holding items the fluid can be in, or [] for any.
|
||||
* @param amount The amount of fluid needed, or -1 for any.
|
||||
* @return A prepared fluid ingredient.
|
||||
*/
|
||||
public FluidIngredient createFluidIngredient(String fluid, String[] holders, int amount) {
|
||||
Fluid parsedFluid = TweakerUtils.INSTANCE.getFluid(fluid);
|
||||
Optional<List<Item>> parsedHolders;
|
||||
Optional<Integer> count;
|
||||
if (holders.length == 0) parsedHolders = Optional.empty();
|
||||
else {
|
||||
List<Item> items = new ArrayList<>();
|
||||
for (String holder : holders) {
|
||||
items.add(TweakerUtils.INSTANCE.getItem(holder));
|
||||
}
|
||||
parsedHolders = Optional.of(items);
|
||||
}
|
||||
if (amount == -1) count = Optional.empty();
|
||||
else count = Optional.of(amount);
|
||||
return new FluidIngredient(parsedFluid, parsedHolders, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a generic TechReborn recipe.
|
||||
* @param type The type of RebornRecipe to add.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param outputs The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to process for.
|
||||
*/
|
||||
public void add(RebornRecipeType type, Object[] inputs, ItemStack[] outputs, int power, int time) {
|
||||
try {
|
||||
Identifier id = tweaker.getRecipeId(outputs[0]);
|
||||
DefaultedList<RebornIngredient> ingredients = DefaultedList.of();
|
||||
for (Object input : inputs) {
|
||||
ingredients.add(TRRecipeParser.processIngredient(input));
|
||||
}
|
||||
tweaker.addRecipe(new RebornRecipe(type, id, ingredients, DefaultedList.copyOf(ItemStack.EMPTY, outputs), power, time));
|
||||
} catch (Exception e) {
|
||||
TechReborn.LOGGER.error("Error parsing TechReborn " + type.getName().getPath().replace('_', ' ') + " recipe - " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void add(String type, Object[] inputs, ItemStack[] outputs, int power, int time) {
|
||||
Identifier id;
|
||||
if (type.contains(":")) id = new Identifier(type);
|
||||
else id = new Identifier("techreborn", type);
|
||||
RebornRecipeType<?> recipeType = RecipeManager.getRecipeType(id);
|
||||
add(recipeType, inputs, outputs, power, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to smelt in an alloy smelter.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param outputs The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to smelt for.
|
||||
*/
|
||||
public void addAlloySmelter(Object[] inputs, ItemStack[] outputs, int power, int time) {
|
||||
add(ModRecipes.ALLOY_SMELTER, inputs, outputs, power, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to assemble in an assembling machine.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param outputs The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to process for.
|
||||
*/
|
||||
public void addAssemblingMachine(Object[] inputs, ItemStack[] outputs, int power, int time) {
|
||||
add(ModRecipes.ASSEMBLING_MACHINE, inputs, outputs, power, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to smelt in a TechReborn blast furnace.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param outputs The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to smelt for.
|
||||
* @param heat How hot the blast furnace needs to be.
|
||||
*/
|
||||
public void addBlastFurnace(Object[] inputs, ItemStack[] outputs, int power, int time, int heat) {
|
||||
try {
|
||||
Identifier id = tweaker.getRecipeId(outputs[0]);
|
||||
DefaultedList<RebornIngredient> ingredients = DefaultedList.of();
|
||||
for (Object input : inputs) {
|
||||
ingredients.add(TRRecipeParser.processIngredient(input));
|
||||
}
|
||||
tweaker.addRecipe(new BlastFurnaceRecipe(ModRecipes.BLAST_FURNACE, id, ingredients, DefaultedList.copyOf(ItemStack.EMPTY, outputs), power, time, heat));
|
||||
} catch (Exception e) {
|
||||
TechReborn.LOGGER.error("Error parsing TechReborn blast furnace recipe - " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to process in a centrifuge.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param outputs The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to process for.
|
||||
*/
|
||||
public void addCentrifuge(Object[] inputs, ItemStack[] outputs, int power, int time) {
|
||||
add(ModRecipes.CENTRIFUGE, inputs, outputs, power, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to process in a chemical reactor.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param outputs The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to process for.
|
||||
*/
|
||||
public void addChemicalReactor(Object[] inputs, ItemStack[] outputs, int power, int time) {
|
||||
add(ModRecipes.CHEMICAL_REACTOR, inputs, outputs, power, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to compress in a compressor.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param outputs The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to process for.
|
||||
*/
|
||||
public void addCompressor(Object[] inputs, ItemStack[] outputs, int power, int time) {
|
||||
add(ModRecipes.COMPRESSOR, inputs, outputs, power, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to distil in a distillation tower.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param outputs The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to process for.
|
||||
*/
|
||||
public void addDistillationTower(Object[] inputs, ItemStack[] outputs, int power, int time) {
|
||||
add(ModRecipes.DISTILLATION_TOWER, inputs, outputs, power, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to extract in an extractor.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param outputs The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to process for.
|
||||
*/
|
||||
public void addExtractor(Object[] inputs, ItemStack[] outputs, int power, int time) {
|
||||
add(ModRecipes.EXTRACTOR, inputs, outputs, power, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to process in a grinder.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param outputs The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to process for.
|
||||
*/
|
||||
public void addGrinder(Object[] inputs, ItemStack[] outputs, int power, int time) {
|
||||
add(ModRecipes.GRINDER, inputs, outputs, power, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to process in an implosion compressor.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param outputs The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to process for.
|
||||
*/
|
||||
public void addImplosionCompressor(Object[] inputs, ItemStack[] outputs, int power, int time) {
|
||||
add(ModRecipes.IMPLOSION_COMPRESSOR, inputs, outputs, power, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to process in an industrial electrolyzer.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param outputs The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to process for.
|
||||
*/
|
||||
public void addIndustrialElectrolyzer(Object[] inputs, ItemStack[] outputs, int power, int time) {
|
||||
add(ModRecipes.INDUSTRIAL_ELECTROLYZER, inputs, outputs, power, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to process in an industrial grinder.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param outputs The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to process for.
|
||||
*/
|
||||
public void addIndustrialGrinder(Object[] inputs, ItemStack[] outputs, int power, int time) {
|
||||
try {
|
||||
Identifier id = tweaker.getRecipeId(outputs[0]);
|
||||
DefaultedList<RebornIngredient> ingredients = DefaultedList.of();
|
||||
for (Object input : inputs) {
|
||||
ingredients.add(TRRecipeParser.processIngredient(input));
|
||||
}
|
||||
tweaker.addRecipe(new IndustrialGrinderRecipe(ModRecipes.INDUSTRIAL_GRINDER, id, ingredients, DefaultedList.copyOf(ItemStack.EMPTY, outputs), power, time));
|
||||
} catch (Exception e) {
|
||||
TechReborn.LOGGER.error("Error parsing TechReborn industrial grinder recipe - " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to process in an industrial grinder.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param outputs The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to process for.
|
||||
* @param fluid The fluid required for the operation, including an amount.
|
||||
*/
|
||||
public void addIndustrialGrinder(Object[] inputs, ItemStack[] outputs, int power, int time, String fluid) {
|
||||
try {
|
||||
Identifier id = tweaker.getRecipeId(outputs[0]);
|
||||
DefaultedList<RebornIngredient> ingredients = DefaultedList.of();
|
||||
for (Object input : inputs) {
|
||||
ingredients.add(TRRecipeParser.processIngredient(input));
|
||||
}
|
||||
FluidInstance fluidInst = TRRecipeParser.parseFluid(fluid);
|
||||
tweaker.addRecipe(new IndustrialGrinderRecipe(ModRecipes.INDUSTRIAL_GRINDER, id, ingredients, DefaultedList.copyOf(ItemStack.EMPTY, outputs), power, time, fluidInst));
|
||||
} catch (Exception e) {
|
||||
TechReborn.LOGGER.error("Error parsing TechReborn industrial grinder recipe - " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to process in an industria sawmilll.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param outputs The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to process for.
|
||||
*/
|
||||
public void addIndustrialSawmill(Object[] inputs, ItemStack[] outputs, int power, int time) {
|
||||
try {
|
||||
Identifier id = tweaker.getRecipeId(outputs[0]);
|
||||
DefaultedList<RebornIngredient> ingredients = DefaultedList.of();
|
||||
for (Object input : inputs) {
|
||||
ingredients.add(TRRecipeParser.processIngredient(input));
|
||||
}
|
||||
tweaker.addRecipe(new IndustrialSawmillRecipe(ModRecipes.INDUSTRIAL_SAWMILL, id, ingredients, DefaultedList.copyOf(ItemStack.EMPTY, outputs), power, time));
|
||||
} catch (Exception e) {
|
||||
TechReborn.LOGGER.error("Error parsing TechReborn industrial sawmill recipe - " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to process in an industrial sawmill.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param outputs The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to process for.
|
||||
* @param fluid The fluid required for this operation, including an amount.
|
||||
*/
|
||||
public void addIndustrialSawmill(Object[] inputs, ItemStack[] outputs, int power, int time, String fluid) {
|
||||
try {
|
||||
Identifier id = tweaker.getRecipeId(outputs[0]);
|
||||
DefaultedList<RebornIngredient> ingredients = DefaultedList.of();
|
||||
for (Object input : inputs) {
|
||||
ingredients.add(TRRecipeParser.processIngredient(input));
|
||||
}
|
||||
FluidInstance fluidInst = TRRecipeParser.parseFluid(fluid);
|
||||
tweaker.addRecipe(new IndustrialSawmillRecipe(ModRecipes.INDUSTRIAL_SAWMILL, id, ingredients, DefaultedList.copyOf(ItemStack.EMPTY, outputs), power, time, fluidInst));
|
||||
} catch (Exception e) {
|
||||
TechReborn.LOGGER.error("Error parsing TechReborn industrial sawmill recipe - " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to process in a recycler.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param outputs The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to process for.
|
||||
*/
|
||||
public void addRecycler(Object[] inputs, ItemStack[] outputs, int power, int time) {
|
||||
add(ModRecipes.RECYCLER, inputs, outputs, power, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to get from a scrapbox. Input is always a scrap box.
|
||||
* @param output The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to process for.
|
||||
*/
|
||||
public void addScrapbox(ItemStack output, int power, int time) {
|
||||
add(ModRecipes.SCRAPBOX, new String[]{"techreborn:scrap_box"}, new ItemStack[]{output}, power, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to process in a vacuum freezer.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param outputs The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to process for.
|
||||
*/
|
||||
public void addVacuumFreezer(Object[] inputs, ItemStack[] outputs, int power, int time) {
|
||||
add(ModRecipes.VACUUM_FREEZER, inputs, outputs, power, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to process in a fluid replicator.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to process for.
|
||||
* @param fluid The fluid required for this operation, including an amount.
|
||||
*/
|
||||
public void addFluidReplicator(Object[] inputs, int power, int time, String fluid) {
|
||||
try {
|
||||
Identifier id = tweaker.getRecipeId(new ItemStack(TRContent.Parts.UU_MATTER));
|
||||
DefaultedList<RebornIngredient> ingredients = DefaultedList.of();
|
||||
for (Object input : inputs) {
|
||||
ingredients.add(TRRecipeParser.processIngredient(input));
|
||||
}
|
||||
FluidInstance fluidInst = TRRecipeParser.parseFluid(fluid);
|
||||
tweaker.addRecipe(new FluidReplicatorRecipe(ModRecipes.FLUID_REPLICATOR, id, ingredients, DefaultedList.of(), power, time, fluidInst));
|
||||
} catch (Exception e) {
|
||||
TechReborn.LOGGER.error("Error parsing TechReborn fluid replicator recipe - " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to process in a fusion reactor.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param outputs The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to process for.
|
||||
* @param startE The energy requried to start the reaction.
|
||||
* @param minSize The minimum size of the reactor coil ring for this reaction.
|
||||
*/
|
||||
public void addFusionReactor(Object[] inputs, ItemStack[] outputs, int power, int time, int startE, int minSize) {
|
||||
try {
|
||||
Identifier id = tweaker.getRecipeId(outputs[0]);
|
||||
DefaultedList<RebornIngredient> ingredients = DefaultedList.of();
|
||||
for (Object input : inputs) {
|
||||
ingredients.add(TRRecipeParser.processIngredient(input));
|
||||
}
|
||||
tweaker.addRecipe(new FusionReactorRecipe(ModRecipes.FUSION_REACTOR, id, ingredients, DefaultedList.copyOf(ItemStack.EMPTY, outputs), power, time, startE, minSize));
|
||||
} catch (Exception e) {
|
||||
TechReborn.LOGGER.error("Error parsing TechReborn fusion reactor recipe - " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a rolling machine recipe from a 2D array of inputs, like a standard CraftTweaker recipe.
|
||||
* @param inputs the 2D array (array of arrays) of inputs to use.
|
||||
* @param output The output of the recipe.
|
||||
*/
|
||||
public void addRollingMachine(Object[][] inputs, ItemStack output) {
|
||||
try {
|
||||
Object[] processed = RecipeParser.processGrid(inputs);
|
||||
int width = inputs[0].length;
|
||||
int height = inputs.length;
|
||||
addRollingMachine(processed, output, width, height);
|
||||
} catch (Exception e) {
|
||||
TechReborn.LOGGER.error("Error parsing TechReborn rolling machine recipe - " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a rolling machine recipe from a 1D array of inputs.
|
||||
* @param inputs The input item or tag ids required in order: left to right, top to bottom.
|
||||
* @param output The output of the recipe.
|
||||
* @param width How many rows the recipe needs.
|
||||
* @param height How many columns the recipe needs.
|
||||
*/
|
||||
public void addRollingMachine(Object[] inputs, ItemStack output, int width, int height) {
|
||||
Identifier recipeId = tweaker.getRecipeId(output);
|
||||
try {
|
||||
DefaultedList<Ingredient> ingredients = DefaultedList.of();
|
||||
for (int i = 0; i < Math.min(inputs.length, width * height); i++) {
|
||||
Object id = inputs[i];
|
||||
if (id.equals("")) continue;
|
||||
ingredients.add(i, RecipeParser.processIngredient(id));
|
||||
}
|
||||
tweaker.addRecipe(new RollingMachineRecipe(ModRecipes.ROLLING_MACHINE, recipeId, new ShapedRecipe(recipeId, "", width, height, ingredients, output)));
|
||||
} catch (Exception e) {
|
||||
TechReborn.LOGGER.error("Error parsing TechReborn rolling machine recipe - " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a rolling machine recipe from a pattern and dictionary.
|
||||
* @param pattern A crafting pattern like one you'd find in a vanilla recipe JSON.
|
||||
* @param dictionary A map of single characters to item or tag ids.
|
||||
* @param output The output of the recipe.
|
||||
*/
|
||||
public void addRollingMachine(String[] pattern, Map<String, Object> dictionary, ItemStack output) {
|
||||
Identifier recipeId = tweaker.getRecipeId(output);
|
||||
try {
|
||||
pattern = RecipeParser.processPattern(pattern);
|
||||
Map<String, Ingredient> map = RecipeParser.processDictionary(dictionary);
|
||||
int x = pattern[0].length();
|
||||
int y = pattern.length;
|
||||
DefaultedList<Ingredient> ingredients = RecipeParser.getIngredients(pattern, map, x, y);
|
||||
tweaker.addRecipe(new RollingMachineRecipe(ModRecipes.ROLLING_MACHINE, recipeId, new ShapedRecipe(recipeId, "", x, y, ingredients, output)));
|
||||
} catch (Exception e) {
|
||||
TechReborn.LOGGER.error("Error parsing TechReborn rolling machine recipe - " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to process in a solid canning machine.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param outputs The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to process for.
|
||||
*/
|
||||
public void addSolidCanningMachine(Object[] inputs, ItemStack[] outputs, int power, int time) {
|
||||
add(ModRecipes.SOLID_CANNING_MACHINE, inputs, outputs, power, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a recipe to process in a wire mill.
|
||||
* @param inputs The input ingredients for the recipe.
|
||||
* @param outputs The outputs of the recipe.
|
||||
* @param power How much power the recipe consumes per tick.
|
||||
* @param time How many ticks (1/20 of a second) to process for.
|
||||
*/
|
||||
public void addWireMill(Object[] inputs, ItemStack[] outputs, int power, int time) {
|
||||
add(ModRecipes.WIRE_MILL, inputs, outputs, power, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a fluid to process in a fluid generator.
|
||||
* @param generator The type of generator: thermal, gas, diesel, semifluid, or plasma.
|
||||
* @param fluid The fluid to add a recipe for.
|
||||
* @param euPerMB How much EU should be generated per millibucket of fluid.
|
||||
*/
|
||||
public void addFluidGenerator(String generator, String fluid, int euPerMB) {
|
||||
EFluidGenerator type;
|
||||
switch(generator.toLowerCase()) {
|
||||
case "thermal":
|
||||
case "techreborn.thermalgenerator":
|
||||
type = EFluidGenerator.THERMAL;
|
||||
break;
|
||||
case "gas":
|
||||
case "techreborn.gasgenerator":
|
||||
type = EFluidGenerator.GAS;
|
||||
break;
|
||||
case "diesel":
|
||||
case "techreborn.dieselgenerator":
|
||||
type = EFluidGenerator.DIESEL;
|
||||
break;
|
||||
case "semifluid":
|
||||
case "techreborn.semifluidgenerator":
|
||||
type = EFluidGenerator.SEMIFLUID;
|
||||
break;
|
||||
case "plasma":
|
||||
case "techreborn.plasmagenerator":
|
||||
type = EFluidGenerator.PLASMA;
|
||||
break;
|
||||
default:
|
||||
TechReborn.LOGGER.error("Error parsing TechReborn fluid generator recipe - could not find generator: " + generator);
|
||||
return;
|
||||
}
|
||||
Fluid parsedFluid = TweakerUtils.INSTANCE.getFluid(fluid);
|
||||
if (parsedFluid == Fluids.EMPTY) {
|
||||
TechReborn.LOGGER.error("Error parsing TechReborn fluid generator recipe - could not find fluid: " + fluid);
|
||||
return;
|
||||
}
|
||||
toAdd.add(new FluidGeneratorRecipe(parsedFluid, euPerMB, type));
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
Tweaker.addTweaker("TRTweaker", TRTweaker.INSTANCE);
|
||||
TweakerStackGetter.registerGetter(new Identifier("techreborn:cell"), (id) -> ItemDynamicCell.getCellWithFluid(Registry.FLUID.get(id)));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue