From 649d28d63c629b5c6476f05c06ed8f4c331c3dff Mon Sep 17 00:00:00 2001 From: Meredith Espinosa Date: Mon, 9 Dec 2019 23:31:32 -0800 Subject: [PATCH] update to new libcd! (#1902) --- build.gradle | 4 +- src/main/java/techreborn/TechReborn.java | 4 - .../techreborn/compat/libcd/LibCDPlugin.java | 22 +++ .../compat/libcd/TRRecipeParser.java | 18 +- .../techreborn/compat/libcd/TRTweaker.java | 185 +++++++++++------- .../data/techreborn/tweakers/tweaker_test.js | 45 +++-- src/main/resources/fabric.mod.json | 3 + 7 files changed, 175 insertions(+), 106 deletions(-) create mode 100644 src/main/java/techreborn/compat/libcd/LibCDPlugin.java diff --git a/build.gradle b/build.gradle index 8f180f0d5..1de07ac24 100644 --- a/build.gradle +++ b/build.gradle @@ -82,10 +82,10 @@ dependencies { modCompileOnly "io.github.prospector:modmenu:1.7.9-unstable.19w34a+build.1" modCompileOnly ("me.shedaniel:RoughlyEnoughItems:3.2.7-unstable.201911150440") - modCompile ('io.github.cottonmc:LibCD:1.5.0+1.14.4') { + modCompile ('io.github.cottonmc:LibCD:2.0.1+1.15') { transitive = false } - modRuntime ("io.github.cottonmc:Jankson:1.0.0+j1.1.2") { + modRuntime ("io.github.cottonmc:Jankson-Fabric:2.0.0+j1.2.0") { transitive = false } diff --git a/src/main/java/techreborn/TechReborn.java b/src/main/java/techreborn/TechReborn.java index a29ae3691..df224299d 100644 --- a/src/main/java/techreborn/TechReborn.java +++ b/src/main/java/techreborn/TechReborn.java @@ -91,10 +91,6 @@ public class TechReborn implements ModInitializer { DataAttachment.REGISTRY.register(IDSUManager.class, IDSUManager::new); - if (FabricLoader.getInstance().isModLoaded("libcd")) { - TRTweaker.init(); - } - LOGGER.info("TechReborn setup done!"); } diff --git a/src/main/java/techreborn/compat/libcd/LibCDPlugin.java b/src/main/java/techreborn/compat/libcd/LibCDPlugin.java new file mode 100644 index 000000000..d9487b569 --- /dev/null +++ b/src/main/java/techreborn/compat/libcd/LibCDPlugin.java @@ -0,0 +1,22 @@ +package techreborn.compat.libcd; + +import io.github.cottonmc.libcd.api.LibCDInitializer; +import io.github.cottonmc.libcd.api.condition.ConditionManager; +import io.github.cottonmc.libcd.api.tweaker.TweakerManager; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; +import techreborn.TechReborn; +import techreborn.items.ItemDynamicCell; + +public class LibCDPlugin implements LibCDInitializer { + @Override + public void initTweakers(TweakerManager manager) { + manager.addTweaker("techreborn.TRTweaker", TRTweaker.INSTANCE); + manager.addStackFactory(new Identifier(TechReborn.MOD_ID, "cell"), (id) -> ItemDynamicCell.getCellWithFluid(Registry.FLUID.get(id))); + } + + @Override + public void initConditions(ConditionManager manager) { + + } +} diff --git a/src/main/java/techreborn/compat/libcd/TRRecipeParser.java b/src/main/java/techreborn/compat/libcd/TRRecipeParser.java index f24cdfb63..1279f759f 100644 --- a/src/main/java/techreborn/compat/libcd/TRRecipeParser.java +++ b/src/main/java/techreborn/compat/libcd/TRRecipeParser.java @@ -2,8 +2,8 @@ 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 io.github.cottonmc.libcd.api.CDSyntaxError; +import io.github.cottonmc.libcd.api.tweaker.util.TweakerUtils; import net.minecraft.fluid.Fluid; import net.minecraft.fluid.Fluids; import net.minecraft.item.Item; @@ -24,7 +24,7 @@ import java.util.Optional; public class TRRecipeParser { - public static RebornIngredient processIngredient(Object input) throws TweakerSyntaxException { + public static RebornIngredient processIngredient(Object input) throws CDSyntaxError { if (input instanceof RebornIngredient) { return (RebornIngredient) input; } else if (input instanceof Ingredient) { @@ -42,12 +42,12 @@ public class TRRecipeParser { //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); + if (fluid == Fluids.EMPTY) throw new CDSyntaxError("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 itemTag = ItemTags.getContainer().get(id); - if (itemTag == null) throw new TweakerSyntaxException("Failed to get item tag for input: " + in); + if (itemTag == null) throw new CDSyntaxError("Failed to get item tag for input: " + in); return new TagIngredient(id, ItemTags.getContainer().get(id), amount); } else { ItemStack stack; @@ -56,7 +56,7 @@ public class TRRecipeParser { if (in.contains("->")) { ItemStack readStack = TweakerUtils.INSTANCE.getSpecialStack(in); if (readStack.isEmpty()) - throw new TweakerSyntaxException("Failed to get special stack for input: " + in); + throw new CDSyntaxError("Failed to get special stack for input: " + in); if (readStack.hasTag()) { tag = Optional.of(readStack.getTag()); } else { @@ -74,18 +74,18 @@ public class TRRecipeParser { if (parsedTag.isEmpty()) requireEmpty = true; else tag = Optional.of(reader.parseCompoundTag()); } catch (CommandSyntaxException e) { - throw new TweakerSyntaxException(e.getMessage()); + throw new CDSyntaxError(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); + if (item == Items.AIR) throw new CDSyntaxError("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()); + else throw new CDSyntaxError("Illegal object passed to TechReborn ingredient parser of type " + input.getClass().getName()); } public static FluidInstance parseFluid(String fluid) { diff --git a/src/main/java/techreborn/compat/libcd/TRTweaker.java b/src/main/java/techreborn/compat/libcd/TRTweaker.java index f77d83c0b..45d9d1bf8 100644 --- a/src/main/java/techreborn/compat/libcd/TRTweaker.java +++ b/src/main/java/techreborn/compat/libcd/TRTweaker.java @@ -1,6 +1,12 @@ package techreborn.compat.libcd; -import io.github.cottonmc.libcd.tweaker.*; +import blue.endless.jankson.JsonArray; +import blue.endless.jankson.JsonObject; +import blue.endless.jankson.JsonPrimitive; +import io.github.cottonmc.libcd.api.tweaker.Tweaker; +import io.github.cottonmc.libcd.api.tweaker.recipe.RecipeParser; +import io.github.cottonmc.libcd.api.tweaker.recipe.RecipeTweaker; +import io.github.cottonmc.libcd.api.tweaker.util.TweakerUtils; import net.minecraft.fluid.Fluid; import net.minecraft.fluid.Fluids; import net.minecraft.item.Item; @@ -17,14 +23,12 @@ 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; @@ -32,12 +36,14 @@ import java.util.concurrent.Executor; public class TRTweaker implements Tweaker { public static final TRTweaker INSTANCE = new TRTweaker(); private RecipeTweaker tweaker = RecipeTweaker.INSTANCE; + private JsonObject debug; List added = new ArrayList<>(); List toAdd = new ArrayList<>(); @Override public void prepareReload(ResourceManager resourceManager) { + debug = new JsonObject(); for (FluidGeneratorRecipe recipe : added) { GeneratorRecipeHelper.removeFluidRecipe(recipe.getGeneratorType(), recipe.getFluid()); } @@ -49,8 +55,17 @@ public class TRTweaker implements Tweaker { for (FluidGeneratorRecipe recipe : toAdd) { if (GeneratorRecipeHelper.getFluidRecipesForGenerator(recipe.getGeneratorType()).addRecipe(recipe)) { added.add(recipe); + String genID = recipe.getGeneratorType().getRecipeID(); + if (!debug.containsKey(genID)) { + debug.put(genID, new JsonArray()); + } + JsonArray array = (JsonArray) debug.get(genID); + JsonObject recipeInfo = new JsonObject(); + recipeInfo.put("fluid", new JsonPrimitive(Registry.FLUID.getId(recipe.getFluid()).toString())); + recipeInfo.put("energy_per_mb", new JsonPrimitive(recipe.getEnergyPerMb())); + array.add(recipeInfo); } else { - TechReborn.LOGGER.error("Could not add recipe to TechReborn generator " + recipe.getGeneratorType().getRecipeID() + tweaker.getLogger().error("Could not add recipe to TechReborn generator " + recipe.getGeneratorType().getRecipeID() + ": a recipe for fluid " + Registry.FLUID.getId(recipe.getFluid()) + " already exists"); } } @@ -63,6 +78,11 @@ public class TRTweaker implements Tweaker { return recipeCount + " TechReborn fluid generator " + (recipeCount == 1? "recipe" : "recipes"); } + @Override + public JsonObject getDebugInfo() { + return debug; + } + /** * Create a fluid ingredient * @param fluid The fluid required. @@ -95,20 +115,24 @@ public class TRTweaker implements Tweaker { * @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) { + public void add(RebornRecipeType type, Object[] inputs, Object[] outputs, int power, int time) { try { - Identifier id = tweaker.getRecipeId(outputs[0]); + ItemStack[] parsedOut = new ItemStack[outputs.length]; + for (int i = 0; i < outputs.length; i++) { + parsedOut[i] = RecipeParser.processItemStack(outputs[i]); + } + Identifier id = tweaker.getRecipeId(parsedOut[0]); DefaultedList 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)); + tweaker.addRecipe(new RebornRecipe(type, id, ingredients, DefaultedList.copyOf(ItemStack.EMPTY, parsedOut), power, time)); } catch (Exception e) { - TechReborn.LOGGER.error("Error parsing TechReborn " + type.getName().getPath().replace('_', ' ') + " recipe - " + e.getMessage()); + tweaker.getLogger().error("Error parsing TechReborn " + type.getName().getPath().replace('_', ' ') + " recipe - " + e.getMessage()); } } - public void add(String type, Object[] inputs, ItemStack[] outputs, int power, int time) { + public void add(String type, Object[] inputs, Object[] outputs, int power, int time) { Identifier id; if (type.contains(":")) id = new Identifier(type); else id = new Identifier("techreborn", type); @@ -123,7 +147,7 @@ public class TRTweaker implements Tweaker { * @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) { + public void addAlloySmelter(Object[] inputs, Object[] outputs, int power, int time) { add(ModRecipes.ALLOY_SMELTER, inputs, outputs, power, time); } @@ -134,7 +158,7 @@ public class TRTweaker implements Tweaker { * @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) { + public void addAssemblingMachine(Object[] inputs, Object[] outputs, int power, int time) { add(ModRecipes.ASSEMBLING_MACHINE, inputs, outputs, power, time); } @@ -146,16 +170,20 @@ public class TRTweaker implements Tweaker { * @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) { + public void addBlastFurnace(Object[] inputs, Object[] outputs, int power, int time, int heat) { try { - Identifier id = tweaker.getRecipeId(outputs[0]); + ItemStack[] parsedOut = new ItemStack[outputs.length]; + for (int i = 0; i < outputs.length; i++) { + parsedOut[i] = RecipeParser.processItemStack(outputs[i]); + } + Identifier id = tweaker.getRecipeId(parsedOut[0]); DefaultedList 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)); + tweaker.addRecipe(new BlastFurnaceRecipe(ModRecipes.BLAST_FURNACE, id, ingredients, DefaultedList.copyOf(ItemStack.EMPTY, parsedOut), power, time, heat)); } catch (Exception e) { - TechReborn.LOGGER.error("Error parsing TechReborn blast furnace recipe - " + e.getMessage()); + tweaker.getLogger().error("Error parsing TechReborn blast furnace recipe - " + e.getMessage()); } } @@ -166,7 +194,7 @@ public class TRTweaker implements Tweaker { * @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) { + public void addCentrifuge(Object[] inputs, Object[] outputs, int power, int time) { add(ModRecipes.CENTRIFUGE, inputs, outputs, power, time); } @@ -177,7 +205,7 @@ public class TRTweaker implements Tweaker { * @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) { + public void addChemicalReactor(Object[] inputs, Object[] outputs, int power, int time) { add(ModRecipes.CHEMICAL_REACTOR, inputs, outputs, power, time); } @@ -188,7 +216,7 @@ public class TRTweaker implements Tweaker { * @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) { + public void addCompressor(Object[] inputs, Object[] outputs, int power, int time) { add(ModRecipes.COMPRESSOR, inputs, outputs, power, time); } @@ -199,7 +227,7 @@ public class TRTweaker implements Tweaker { * @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) { + public void addDistillationTower(Object[] inputs, Object[] outputs, int power, int time) { add(ModRecipes.DISTILLATION_TOWER, inputs, outputs, power, time); } @@ -210,7 +238,7 @@ public class TRTweaker implements Tweaker { * @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) { + public void addExtractor(Object[] inputs, Object[] outputs, int power, int time) { add(ModRecipes.EXTRACTOR, inputs, outputs, power, time); } @@ -221,7 +249,7 @@ public class TRTweaker implements Tweaker { * @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) { + public void addGrinder(Object[] inputs, Object[] outputs, int power, int time) { add(ModRecipes.GRINDER, inputs, outputs, power, time); } @@ -232,7 +260,7 @@ public class TRTweaker implements Tweaker { * @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) { + public void addImplosionCompressor(Object[] inputs, Object[] outputs, int power, int time) { add(ModRecipes.IMPLOSION_COMPRESSOR, inputs, outputs, power, time); } @@ -243,7 +271,7 @@ public class TRTweaker implements Tweaker { * @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) { + public void addIndustrialElectrolyzer(Object[] inputs, Object[] outputs, int power, int time) { add(ModRecipes.INDUSTRIAL_ELECTROLYZER, inputs, outputs, power, time); } @@ -254,16 +282,20 @@ public class TRTweaker implements Tweaker { * @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) { + public void addIndustrialGrinder(Object[] inputs, Object[] outputs, int power, int time) { try { - Identifier id = tweaker.getRecipeId(outputs[0]); + ItemStack[] parsedOut = new ItemStack[outputs.length]; + for (int i = 0; i < outputs.length; i++) { + parsedOut[i] = RecipeParser.processItemStack(outputs[i]); + } + Identifier id = tweaker.getRecipeId(parsedOut[0]); DefaultedList 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)); + tweaker.addRecipe(new IndustrialGrinderRecipe(ModRecipes.INDUSTRIAL_GRINDER, id, ingredients, DefaultedList.copyOf(ItemStack.EMPTY, parsedOut), power, time)); } catch (Exception e) { - TechReborn.LOGGER.error("Error parsing TechReborn industrial grinder recipe - " + e.getMessage()); + tweaker.getLogger().error("Error parsing TechReborn industrial grinder recipe - " + e.getMessage()); } } @@ -275,17 +307,21 @@ public class TRTweaker implements Tweaker { * @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) { + public void addIndustrialGrinder(Object[] inputs, Object[] outputs, int power, int time, String fluid) { try { - Identifier id = tweaker.getRecipeId(outputs[0]); + ItemStack[] parsedOut = new ItemStack[outputs.length]; + for (int i = 0; i < outputs.length; i++) { + parsedOut[i] = RecipeParser.processItemStack(outputs[i]); + } + Identifier id = tweaker.getRecipeId(parsedOut[0]); DefaultedList 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)); + tweaker.addRecipe(new IndustrialGrinderRecipe(ModRecipes.INDUSTRIAL_GRINDER, id, ingredients, DefaultedList.copyOf(ItemStack.EMPTY, parsedOut), power, time, fluidInst)); } catch (Exception e) { - TechReborn.LOGGER.error("Error parsing TechReborn industrial grinder recipe - " + e.getMessage()); + tweaker.getLogger().error("Error parsing TechReborn industrial grinder recipe - " + e.getMessage()); } } @@ -296,16 +332,20 @@ public class TRTweaker implements Tweaker { * @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) { + public void addIndustrialSawmill(Object[] inputs, Object[] outputs, int power, int time) { try { - Identifier id = tweaker.getRecipeId(outputs[0]); + ItemStack[] parsedOut = new ItemStack[outputs.length]; + for (int i = 0; i < outputs.length; i++) { + parsedOut[i] = RecipeParser.processItemStack(outputs[i]); + } + Identifier id = tweaker.getRecipeId(parsedOut[0]); DefaultedList 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)); + tweaker.addRecipe(new IndustrialSawmillRecipe(ModRecipes.INDUSTRIAL_SAWMILL, id, ingredients, DefaultedList.copyOf(ItemStack.EMPTY, parsedOut), power, time)); } catch (Exception e) { - TechReborn.LOGGER.error("Error parsing TechReborn industrial sawmill recipe - " + e.getMessage()); + tweaker.getLogger().error("Error parsing TechReborn industrial sawmill recipe - " + e.getMessage()); } } @@ -317,17 +357,21 @@ public class TRTweaker implements Tweaker { * @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) { + public void addIndustrialSawmill(Object[] inputs, Object[] outputs, int power, int time, String fluid) { try { - Identifier id = tweaker.getRecipeId(outputs[0]); + ItemStack[] parsedOut = new ItemStack[outputs.length]; + for (int i = 0; i < outputs.length; i++) { + parsedOut[i] = RecipeParser.processItemStack(outputs[i]); + } + Identifier id = tweaker.getRecipeId(parsedOut[0]); DefaultedList 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)); + tweaker.addRecipe(new IndustrialSawmillRecipe(ModRecipes.INDUSTRIAL_SAWMILL, id, ingredients, DefaultedList.copyOf(ItemStack.EMPTY, parsedOut), power, time, fluidInst)); } catch (Exception e) { - TechReborn.LOGGER.error("Error parsing TechReborn industrial sawmill recipe - " + e.getMessage()); + tweaker.getLogger().error("Error parsing TechReborn industrial sawmill recipe - " + e.getMessage()); } } @@ -338,7 +382,7 @@ public class TRTweaker implements Tweaker { * @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) { + public void addRecycler(Object[] inputs, Object[] outputs, int power, int time) { add(ModRecipes.RECYCLER, inputs, outputs, power, time); } @@ -348,8 +392,8 @@ public class TRTweaker implements Tweaker { * @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); + public void addScrapbox(Object output, int power, int time) { + add(ModRecipes.SCRAPBOX, new String[]{"techreborn:scrap_box"}, new Object[]{output}, power, time); } /** @@ -359,7 +403,7 @@ public class TRTweaker implements Tweaker { * @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) { + public void addVacuumFreezer(Object[] inputs, Object[] outputs, int power, int time) { add(ModRecipes.VACUUM_FREEZER, inputs, outputs, power, time); } @@ -380,7 +424,7 @@ public class TRTweaker implements Tweaker { 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()); + tweaker.getLogger().error("Error parsing TechReborn fluid replicator recipe - " + e.getMessage()); } } @@ -393,16 +437,20 @@ public class TRTweaker implements Tweaker { * @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) { + public void addFusionReactor(Object[] inputs, Object[] outputs, int power, int time, int startE, int minSize) { try { - Identifier id = tweaker.getRecipeId(outputs[0]); + ItemStack[] parsedOut = new ItemStack[outputs.length]; + for (int i = 0; i < outputs.length; i++) { + parsedOut[i] = RecipeParser.processItemStack(outputs[i]); + } + Identifier id = tweaker.getRecipeId(parsedOut[0]); DefaultedList 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)); + tweaker.addRecipe(new FusionReactorRecipe(ModRecipes.FUSION_REACTOR, id, ingredients, DefaultedList.copyOf(ItemStack.EMPTY, parsedOut), power, time, startE, minSize)); } catch (Exception e) { - TechReborn.LOGGER.error("Error parsing TechReborn fusion reactor recipe - " + e.getMessage()); + tweaker.getLogger().error("Error parsing TechReborn fusion reactor recipe - " + e.getMessage()); } } @@ -411,14 +459,14 @@ public class TRTweaker implements Tweaker { * @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) { + public void addRollingMachine(Object[][] inputs, Object 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()); + tweaker.getLogger().error("Error parsing TechReborn 2D array rolling machine recipe - " + e.getMessage()); } } @@ -429,18 +477,19 @@ public class TRTweaker implements Tweaker { * @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); + public void addRollingMachine(Object[] inputs, Object output, int width, int height) { try { - DefaultedList ingredients = DefaultedList.of(); + ItemStack out = RecipeParser.processItemStack(output); + Identifier recipeId = tweaker.getRecipeId(out); + DefaultedList ingredients = DefaultedList.ofSize(width * height, Ingredient.EMPTY); 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)); + if (id == null || id.equals("") || id.equals("minecraft:air")) continue; + ingredients.set(i, RecipeParser.processIngredient(id)); } - tweaker.addRecipe(new RollingMachineRecipe(ModRecipes.ROLLING_MACHINE, recipeId, new ShapedRecipe(recipeId, "", width, height, ingredients, output))); + tweaker.addRecipe(new RollingMachineRecipe(ModRecipes.ROLLING_MACHINE, recipeId, new ShapedRecipe(recipeId, "", width, height, ingredients, out))); } catch (Exception e) { - TechReborn.LOGGER.error("Error parsing TechReborn rolling machine recipe - " + e.getMessage()); + tweaker.getLogger().error("Error parsing TechReborn 1D array rolling machine recipe - " + e.getMessage()); } } @@ -450,17 +499,18 @@ public class TRTweaker implements Tweaker { * @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 dictionary, ItemStack output) { - Identifier recipeId = tweaker.getRecipeId(output); + public void addDictRollingMachine(String[] pattern, Map dictionary, Object output) { try { + ItemStack out = RecipeParser.processItemStack(output); + Identifier recipeId = tweaker.getRecipeId(out); pattern = RecipeParser.processPattern(pattern); Map map = RecipeParser.processDictionary(dictionary); int x = pattern[0].length(); int y = pattern.length; DefaultedList ingredients = RecipeParser.getIngredients(pattern, map, x, y); - tweaker.addRecipe(new RollingMachineRecipe(ModRecipes.ROLLING_MACHINE, recipeId, new ShapedRecipe(recipeId, "", x, y, ingredients, output))); + tweaker.addRecipe(new RollingMachineRecipe(ModRecipes.ROLLING_MACHINE, recipeId, new ShapedRecipe(recipeId, "", x, y, ingredients, out))); } catch (Exception e) { - TechReborn.LOGGER.error("Error parsing TechReborn rolling machine recipe - " + e.getMessage()); + tweaker.getLogger().error("Error parsing TechReborn dictionary rolling machine recipe - " + e.getMessage()); } } @@ -471,7 +521,7 @@ public class TRTweaker implements Tweaker { * @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) { + public void addSolidCanningMachine(Object[] inputs, Object[] outputs, int power, int time) { add(ModRecipes.SOLID_CANNING_MACHINE, inputs, outputs, power, time); } @@ -482,7 +532,7 @@ public class TRTweaker implements Tweaker { * @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) { + public void addWireMill(Object[] inputs, Object[] outputs, int power, int time) { add(ModRecipes.WIRE_MILL, inputs, outputs, power, time); } @@ -516,19 +566,14 @@ public class TRTweaker implements Tweaker { type = EFluidGenerator.PLASMA; break; default: - TechReborn.LOGGER.error("Error parsing TechReborn fluid generator recipe - could not find generator: " + generator); + tweaker.getLogger().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); + tweaker.getLogger().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))); - } } diff --git a/src/main/resources/data/techreborn/tweakers/tweaker_test.js b/src/main/resources/data/techreborn/tweakers/tweaker_test.js index 181562d9a..176adfe6c 100644 --- a/src/main/resources/data/techreborn/tweakers/tweaker_test.js +++ b/src/main/resources/data/techreborn/tweakers/tweaker_test.js @@ -1,15 +1,18 @@ //Warn that the sample script is running -print("WARNING! The TechReborn tweaker sample script is running!"); -print("If you're seeing this and aren't in dev mode, please report it!"); +log.warn("WARNING! The TechReborn tweaker sample script is running!"); +log.warn("If you're seeing this and aren't in dev mode, please report it!"); + +var TRTweaker = libcd.require("techreborn.TRTweaker"); +var TweakerUtils = libcd.require("libcd.util.TweakerUtils"); //Add an alloy smelter recipe that takes 8 coal and 2 obsidian -> 2 diamonds -TRTweaker.addAlloySmelter(["minecraft:coal@8", "minecraft:obsidian@2"], [TweakerUtils.createItemStack("minecraft:diamond", 2)], 6, 200); +TRTweaker.addAlloySmelter(["minecraft:coal@8", "minecraft:obsidian@2"], ["minecraft:diamond@2"], 6, 200); //Add an assembling machine recipe that takes 3 diamonds and 2 sticks -> 1 diamond pickaxe -TRTweaker.addAssemblingMachine(["minecraft:diamond@3", "minecraft:stick@2"], [TweakerUtils.createItemStack("minecraft:diamond_pickaxe", 1)], 20, 200); +TRTweaker.addAssemblingMachine(["minecraft:diamond@3", "minecraft:stick@2"], ["minecraft:diamond_pickaxe"], 20, 200); //Add a blast furnace recipe that takes 64 of any item in the minecraft:coals tag -> 8 diamonds -TRTweaker.addBlastFurnace(["#minecraft:coals@64"], [TweakerUtils.createItemStack("minecraft:diamond", 8)], 128, 200, 1300); +TRTweaker.addBlastFurnace(["#minecraft:coals@64"], ["minecraft:diamond@8"], 128, 200, 1300); //Add a centrifuge recipe that takes any potion -> a water bottle TRTweaker.addCentrifuge(["minecraft:potion"], [TweakerUtils.getSpecialStack("minecraft:potion->minecraft:water")], 5, 1000); @@ -19,53 +22,53 @@ TRTweaker.addCentrifuge(["minecraft:potion"], [TweakerUtils.getSpecialStack("min TRTweaker.addChemicalReactor(["minecraft:potion->minecraft:water", TRTweaker.createFluidIngredient("techreborn:methane", ["techreborn:cell"], -1)], [TweakerUtils.getSpecialStack("minecraft:potion->minecraft:fire_resistance")], 30, 800); //Add a compressor recipe that takes 9 coal blocks -> 3 pieces of obsidian -TRTweaker.addCompressor(["minecraft:coal_ore@9"], [TweakerUtils.createItemStack("minecraft:coal_block", 3)], 10, 300); +TRTweaker.addCompressor(["minecraft:coal_ore@9"], ["minecraft:coal_block@3"], 10, 300); //Add a distillation tower recipe that takes a potion of regneration -> a strong potion of regeneration TRTweaker.addDistillationTower(["minecraft:potion->minecraft:regeneration"], [TweakerUtils.getSpecialStack("minecraft:potion->minecraft:strong_regeneration")], 20, 400); //Add an extractor recipe that takes 4 coal -> 1 gunpowder -TRTweaker.addExtractor(["minecraft:coal@4"], [TweakerUtils.createItemStack("minecraft:gunpowder", 1)], 10, 300); +TRTweaker.addExtractor(["minecraft:coal@4"], ["minecraft:gunpowder"], 10, 300); //Add a grinder recipe of 1 sugar cane -> 3 sugar -TRTweaker.addGrinder(["minecraft:sugar_cane"], [TweakerUtils.createItemStack("minecraft:sugar", 3)], 4, 270); +TRTweaker.addGrinder(["minecraft:sugar_cane"], ["minecraft:sugar@3"], 4, 270); //Add an implosion compressor recipe of 32 coal and 16 flint -> 16 diamonds -TRTweaker.addImplosionCompressor(["minecraft:coal@32", "minecraft:flint@16"], [TweakerUtils.createItemStack("minecraft:diamond", 16)], 30, 2000); +TRTweaker.addImplosionCompressor(["minecraft:coal@32", "minecraft:flint@16"], ["minecraft:diamond@16"], 30, 2000); //Add an industrial electrolyzer recipe of 1 skeleton skull -> 1 wither skeleton skull -TRTweaker.addIndustrialElectrolyzer(["minecraft:skeleton_skull"], [TweakerUtils.createItemStack("minecraft:wither_skeleton_skull", 1)], 50, 1400); +TRTweaker.addIndustrialElectrolyzer(["minecraft:skeleton_skull"], ["minecraft:wither_skeleton_skull"], 50, 1400); //Add an industrial electrolyzer recipe of 1 sea lantern -> 5 prismarine crystals and 4 prismarine shards -TRTweaker.addIndustrialGrinder(["minecraft:sea_lantern"], [TweakerUtils.createItemStack("minecraft:prismarine_crystals", 5), TweakerUtils.createItemStack("minecraft:prismarine_shard", 4)], 64, 100); +TRTweaker.addIndustrialGrinder(["minecraft:sea_lantern"], ["minecraft:prismarine_crystals@5", "minecraft:prismarine_shard@4"], 64, 100); //Add an industrial electrolyzer recipe of 1 sea lantern and 1 bucket of electrolyzed water -> 9 prismarine crystals -TRTweaker.addIndustrialGrinder(["minecraft:sea_lantern"], [TweakerUtils.createItemStack("minecraft:prismarine_crystals", 9)], 64, 100, "techreborn:electrolyzed_water@1000"); +TRTweaker.addIndustrialGrinder(["minecraft:sea_lantern"], ["minecraft:prismarine_crystals@9"], 64, 100, "techreborn:electrolyzed_water@1000"); //Add an industrial sawmill recipe of 3 sugar cane -> 18 paper -TRTweaker.addIndustrialSawmill(["minecraft:sugar_cane@3"], [TweakerUtils.createItemStack("minecraft:paper", 18)], 40, 200); +TRTweaker.addIndustrialSawmill(["minecraft:sugar_cane@3"], ["minecraft:paper@18"], 40, 200); //Add an industrial sawmill recipe of 1 heart of the sea and 1/2 bucket of water -> 16 nautilus shells -TRTweaker.addIndustrialSawmill(["minecraft:heart_of_the_sea"], [TweakerUtils.createItemStack("minecraft:nautilus_shell", 16)], 40, 200, "minecraft:water@500"); +TRTweaker.addIndustrialSawmill(["minecraft:heart_of_the_sea"], ["minecraft:nautilus_shell@16"], 40, 200, "minecraft:water@500"); //Add a recycler recipe of 1 water bucket -> 1 empty bucket -TRTweaker.addRecycler(["minecraft:water_bucket"], [TweakerUtils.createItemStack("minecraft:bucket", 1)], 5, 40); +TRTweaker.addRecycler(["minecraft:water_bucket"], ["minecraft:bucket"], 5, 40); //Add a scrapbox recipe of 1 scrap box -> 1 shulker box -TRTweaker.addScrapbox(TweakerUtils.createItemStack("minecraft:shulker_box", 1), 10, 20); +TRTweaker.addScrapbox("minecraft:shulker_box", 10, 20); //Add a scrapbox recipe of 1 cell of water -> 1 blue ice -TRTweaker.addVacuumFreezer([TRTweaker.createFluidIngredient("minecraft:water", ["techreborn:cell"], -1)], [TweakerUtils.createItemStack("minecraft:blue_ice", 1)], 60, 440); +TRTweaker.addVacuumFreezer([TRTweaker.createFluidIngredient("minecraft:water", ["techreborn:cell"], -1)], ["minecraft:blue_ice"], 60, 440); //Add a fluid replicator recipe of 2 uu matter and 1 bucket of wulframium -> 2 buckets of wolframium TRTweaker.addFluidReplicator(["techreborn:uu_matter@2"], 40, 100, "techreborn:wolframium@1000"); //Add a fusion reactor recipe of 3 wither skeleton skulls and 4 soul sand -> 1 nether star -TRTweaker.addFusionReactor(["minecraft:wither_skeleton_skull@3", "minecraft:soul_sand@4"], [TweakerUtils.createItemStack("minecraft:nether_star", 1)], -2048, 1024, 90000, 1); +TRTweaker.addFusionReactor(["minecraft:wither_skeleton_skull@3", "minecraft:soul_sand@4"], ["minecraft:nether_star"], -2048, 1024, 90000, 1); //Add a rolling machine recipe for 5 popped chorus fruit in a helmet shape -> a shulker shell var chorus = "minecraft:popped_chorus_fruit"; -TRTweaker.addRollingMachine([[chorus, chorus, chorus], [chorus, "", chorus]], TweakerUtils.createItemStack("minecraft:shulker_shell", 1)); +TRTweaker.addRollingMachine([[chorus, chorus, chorus], [chorus, "", chorus]], "minecraft:shulker_shell"); //Create a pattern/dictionary set for a shaped recipe var pattern = [ '/ /', @@ -77,13 +80,13 @@ var dict = { }; //Add a rolling machine recipe for sticks on the sides and any wooden slab in the middle -> six ladders -TRTweaker.addRollingMachine(pattern, dict, TweakerUtils.createItemStack("minecraft:ladder", 12)); +TRTweaker.addDictRollingMachine(pattern, dict, "minecraft:ladder@12"); //Add a solid canning machine recipe for 1 empty cell and 1 blue ice -> a cell full of water TRTweaker.addSolidCanningMachine(["techreborn:cell{}", "minecraft:blue_ice"], [TweakerUtils.getSpecialStack("techreborn:cell->minecraft:water")], 1, 100); //Add a wire mill recipe for 1 woll -> 4 string -TRTweaker.addWireMill(["#minecraft:wool"], [TweakerUtils.createItemStack("minecraft:string", 4)], 2, 200); +TRTweaker.addWireMill(["#minecraft:wool"], ["minecraft:string@4"], 2, 200); //Add a plasma fluid generator recipe for 1 mB of wolframium -> 300 EU TRTweaker.addFluidGenerator("plasma", "techreborn:wolframium", 300); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 17fbd9e12..fc0ced5bb 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -24,6 +24,9 @@ ], "towelette": [ "techreborn.compat.towelette.TowelettePlugin" + ], + "libcd": [ + "techreborn.compat.libcd.LibCDPlugin" ] }, "depends": {