REI integration for fluid generators (#1916)

This commit is contained in:
vhd 2019-12-22 19:58:58 +02:00 committed by modmuss50
parent 5e9e0f3c2b
commit 6918f8dd60
4 changed files with 153 additions and 2 deletions

View file

@ -38,8 +38,12 @@ import reborncore.common.crafting.RebornRecipe;
import reborncore.common.crafting.RebornRecipeType;
import reborncore.common.crafting.RecipeManager;
import techreborn.TechReborn;
import techreborn.api.generator.EFluidGenerator;
import techreborn.api.generator.GeneratorRecipeHelper;
import techreborn.api.recipe.recipes.FluidReplicatorRecipe;
import techreborn.api.recipe.recipes.RollingMachineRecipe;
import techreborn.compat.rei.fluidgenerator.FluidGeneratorRecipeCategory;
import techreborn.compat.rei.fluidgenerator.FluidGeneratorRecipeDisplay;
import techreborn.compat.rei.fluidreplicator.FluidReplicatorRecipeCategory;
import techreborn.compat.rei.fluidreplicator.FluidReplicatorRecipeDisplay;
import techreborn.compat.rei.rollingmachine.RollingMachineCategory;
@ -81,7 +85,6 @@ public class ReiPlugin implements REIPluginV0 {
iconMap.put(ModRecipes.SOLID_CANNING_MACHINE, Machine.SOLID_CANNING_MACHINE);
iconMap.put(ModRecipes.VACUUM_FREEZER, Machine.VACUUM_FREEZER);
iconMap.put(ModRecipes.WIRE_MILL, Machine.WIRE_MILL);
}
@Override
@ -116,11 +119,23 @@ public class ReiPlugin implements REIPluginV0 {
recipeHelper.registerCategory(new MachineRecipeCategory<>(ModRecipes.SOLID_CANNING_MACHINE));
recipeHelper.registerCategory(new MachineRecipeCategory<>(ModRecipes.VACUUM_FREEZER, 1));
recipeHelper.registerCategory(new MachineRecipeCategory<>(ModRecipes.WIRE_MILL, 1));
recipeHelper.registerCategory(new FluidGeneratorRecipeCategory(Machine.THERMAL_GENERATOR));
recipeHelper.registerCategory(new FluidGeneratorRecipeCategory(Machine.GAS_TURBINE));
recipeHelper.registerCategory(new FluidGeneratorRecipeCategory(Machine.DIESEL_GENERATOR));
recipeHelper.registerCategory(new FluidGeneratorRecipeCategory(Machine.SEMI_FLUID_GENERATOR));
recipeHelper.registerCategory(new FluidGeneratorRecipeCategory(Machine.PLASMA_GENERATOR));
}
@Override
public void registerRecipeDisplays(RecipeHelper recipeHelper) {
RecipeManager.getRecipeTypes("techreborn").forEach(rebornRecipeType -> registerMachineRecipe(recipeHelper, rebornRecipeType));
registerFluidGeneratorDisplays(recipeHelper, EFluidGenerator.THERMAL, Machine.THERMAL_GENERATOR);
registerFluidGeneratorDisplays(recipeHelper, EFluidGenerator.GAS, Machine.GAS_TURBINE);
registerFluidGeneratorDisplays(recipeHelper, EFluidGenerator.DIESEL, Machine.DIESEL_GENERATOR);
registerFluidGeneratorDisplays(recipeHelper, EFluidGenerator.SEMIFLUID, Machine.SEMI_FLUID_GENERATOR);
registerFluidGeneratorDisplays(recipeHelper, EFluidGenerator.PLASMA, Machine.PLASMA_GENERATOR);
}
@Override
@ -143,6 +158,11 @@ public class ReiPlugin implements REIPluginV0 {
recipeHelper.registerWorkingStations(ModRecipes.SOLID_CANNING_MACHINE.getName(), EntryStack.create(Machine.SOLID_CANNING_MACHINE));
recipeHelper.registerWorkingStations(ModRecipes.VACUUM_FREEZER.getName(), EntryStack.create(Machine.VACUUM_FREEZER));
recipeHelper.registerWorkingStations(ModRecipes.WIRE_MILL.getName(), EntryStack.create(Machine.WIRE_MILL));
recipeHelper.registerWorkingStations(new Identifier(TechReborn.MOD_ID, Machine.THERMAL_GENERATOR.name), EntryStack.create(Machine.THERMAL_GENERATOR));
recipeHelper.registerWorkingStations(new Identifier(TechReborn.MOD_ID, Machine.GAS_TURBINE.name), EntryStack.create(Machine.GAS_TURBINE));
recipeHelper.registerWorkingStations(new Identifier(TechReborn.MOD_ID, Machine.DIESEL_GENERATOR.name), EntryStack.create(Machine.DIESEL_GENERATOR));
recipeHelper.registerWorkingStations(new Identifier(TechReborn.MOD_ID, Machine.SEMI_FLUID_GENERATOR.name), EntryStack.create(Machine.SEMI_FLUID_GENERATOR));
recipeHelper.registerWorkingStations(new Identifier(TechReborn.MOD_ID, Machine.PLASMA_GENERATOR.name), EntryStack.create(Machine.PLASMA_GENERATOR));
}
@Override
@ -168,6 +188,13 @@ public class ReiPlugin implements REIPluginV0 {
stack.addSetting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE);
}
private void registerFluidGeneratorDisplays(RecipeHelper recipeHelper, EFluidGenerator generator, Machine machine) {
Identifier identifier = new Identifier(TechReborn.MOD_ID, machine.name);
GeneratorRecipeHelper.getFluidRecipesForGenerator(generator).getRecipes().forEach(recipe -> {
recipeHelper.registerDisplay(identifier, new FluidGeneratorRecipeDisplay(recipe, identifier));
});
}
private <R extends RebornRecipe> void registerMachineRecipe(RecipeHelper recipeHelper, RebornRecipeType<R> recipeType) {
Function<R, RecipeDisplay> recipeDisplay = r -> new MachineRecipeDisplay<>((RebornRecipe) r);

View file

@ -0,0 +1,74 @@
package techreborn.compat.rei.fluidgenerator;
import me.shedaniel.math.api.Point;
import me.shedaniel.math.api.Rectangle;
import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.api.RecipeCategory;
import me.shedaniel.rei.gui.widget.*;
import me.shedaniel.rei.impl.ScreenHelper;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
import reborncore.common.util.StringUtils;
import techreborn.TechReborn;
import techreborn.init.TRContent;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Supplier;
public class FluidGeneratorRecipeCategory implements RecipeCategory<FluidGeneratorRecipeDisplay> {
private TRContent.Machine generator;
private Identifier identifier;
public FluidGeneratorRecipeCategory(TRContent.Machine generator) {
this.generator = generator;
this.identifier = new Identifier(TechReborn.MOD_ID, generator.name);
}
@Override
public Identifier getIdentifier() {
return identifier;
}
@Override
public String getCategoryName() {
return StringUtils.t(identifier.toString());
}
@Override
public EntryStack getLogo() {
return EntryStack.create(generator);
}
@Override
public List<Widget> setupDisplay(Supplier<FluidGeneratorRecipeDisplay> recipeDisplaySupplier, Rectangle bounds) {
FluidGeneratorRecipeDisplay machineRecipe = recipeDisplaySupplier.get();
Point startPoint = new Point(bounds.getCenterX() - 41, bounds.getCenterY() - 13);
List<Widget> widgets = new LinkedList<>();
widgets.add(new RecipeBaseWidget(bounds));
widgets.add(new RecipeArrowWidget(startPoint.x + 24, startPoint.y + 1, true));
for (List<EntryStack> inputs : machineRecipe.getInputEntries()) {
widgets.add(EntryWidget.create(startPoint.x + 1, startPoint.y + 1).entries(inputs));
}
Text energyPerTick = new TranslatableText("techreborn.jei.recipe.generator.total", machineRecipe.getTotalEnergy());
LabelWidget costLabel;
widgets.add(costLabel = new LabelWidget(bounds.getCenterX(), startPoint.y + 20, energyPerTick.asFormattedString()));
costLabel.setHasShadows(false);
costLabel.setDefaultColor(ScreenHelper.isDarkModeEnabled() ? 0xFFBBBBBB : 0xFF404040);
return widgets;
}
@Override
public int getDisplayHeight() {
return 37;
}
}

View file

@ -0,0 +1,44 @@
package techreborn.compat.rei.fluidgenerator;
import com.google.common.collect.Lists;
import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.api.RecipeDisplay;
import net.minecraft.util.Identifier;
import techreborn.api.generator.FluidGeneratorRecipe;
import java.util.Collections;
import java.util.List;
public class FluidGeneratorRecipeDisplay implements RecipeDisplay {
private List<List<EntryStack>> inputs;
private Identifier category;
private int totalEnergy;
public FluidGeneratorRecipeDisplay(FluidGeneratorRecipe recipe, Identifier category) {
this.category = category;
this.inputs = Lists.newArrayList();
this.totalEnergy = recipe.getEnergyPerBucket();
inputs.add(Collections.singletonList(EntryStack.create(recipe.getFluid(), 1000)));
}
@Override
public List<List<EntryStack>> getInputEntries() {
return inputs;
}
@Override
public List<EntryStack> getOutputEntries() {
return Lists.newArrayList();
}
@Override
public Identifier getRecipeCategory() {
return category;
}
public int getTotalEnergy() {
return totalEnergy;
}
}

View file

@ -614,6 +614,7 @@
"techreborn.jei.recipe.processing.time.1": "Time: %s ticks",
"techreborn.jei.recipe.processing.time.2": "(%s sec)",
"techreborn.jei.recipe.heat": "Heat",
"techreborn.jei.recipe.generator.total": "E total: %s",
"techreborn.jei.desc.rubberSap": "In order to get sap, you need to find a rubber tree or obtain a rubber tree sapling and proceed to grow it. Once you have obtained a rubber tree, search around for little yellowish spots on the tree. If you don't see any, just wait a bit and eventually these yellow \"sap\" spots. To harvest the sap, use a treetap and use it on the log.",
"techreborn.jei.desc.scrapBox": "Scrapboxes can be opened by either a simple use in hand, or by dispensers. That's right, just throw your scrapboxes into dispensers and give them a redstone signal, and boom! Random item!",
@ -680,7 +681,12 @@
"techreborn:rolling_machine": "Rolling Machine",
"techreborn:solid_canning_machine": "Solid Canning Machine",
"techreborn:wire_mill": "Wire Mill",
"techreborn:gas_turbine": "Gas Generator",
"techreborn:semi_fluid_generator": "Semifluid Generator",
"techreborn:diesel_generator": "Diesel Generator",
"techreborn:thermal_generator": "Thermal Generator",
"techreborn:plasma_generator": "Plasma Generator",
"_comment26": "Fluid buckets",
"item.techreborn.beryllium_bucket": "Beryllium",
"item.techreborn.calcium_bucket": "Calcium",