Show fluids in REI. Why water is so weird?

This commit is contained in:
drcrazy 2019-08-23 01:40:14 +03:00
parent 9f22ddf686
commit f3cdd131a0
5 changed files with 192 additions and 1 deletions

View file

@ -45,6 +45,8 @@ import java.util.LinkedList;
import java.util.List;
import java.util.function.Supplier;
import io.github.prospector.silk.fluid.FluidInstance;
public class MachineRecipeCategory<R extends RebornRecipe> implements RecipeCategory<MachineRecipeDisplay<R>> {
private final RebornRecipeType<R> rebornRecipeType;
@ -95,6 +97,11 @@ public class MachineRecipeCategory<R extends RebornRecipe> implements RecipeCate
widgets.add(new SlotWidget(startPoint.x + 1, startPoint.y + 1 + (i++ * 20), Renderer.fromItemStacks(inputs), true, true, true));
}
FluidInstance fluidInstance = machineRecipe.getFluidInstance();
if (fluidInstance != null) {
widgets.add(new SlotWidget(startPoint.x + 1, startPoint.y + 1 + (i++ * 20), Renderer.fromFluid(fluidInstance.getFluid()), true, true, true));
}
Text energyPerTick = new TranslatableText("techreborn.jei.recipe.running.cost", "E", machineRecipe.getEnergy());
widgets.add(new LabelWidget(startPoint.x + 1, startPoint.y + 1 + (i++ * 20), energyPerTick.asFormattedString()){
@Override

View file

@ -29,12 +29,15 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import reborncore.common.crafting.ingredient.RebornIngredient;
import techreborn.api.recipe.recipes.BlastFurnaceRecipe;
import reborncore.common.crafting.RebornFluidRecipe;
import reborncore.common.crafting.RebornRecipe;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import io.github.prospector.silk.fluid.FluidInstance;
public class MachineRecipeDisplay<R extends RebornRecipe> implements RecipeDisplay {
private final R recipe;
@ -42,6 +45,7 @@ public class MachineRecipeDisplay<R extends RebornRecipe> implements RecipeDispl
private List<ItemStack> outputs;
private int energy = 0;
private int heat = 0;
private FluidInstance fluidInstance = null;
public MachineRecipeDisplay(R recipe) {
this.recipe = recipe;
@ -51,6 +55,9 @@ public class MachineRecipeDisplay<R extends RebornRecipe> implements RecipeDispl
if (recipe instanceof BlastFurnaceRecipe) {
this.heat = ((BlastFurnaceRecipe) recipe).getHeat();
}
if (recipe instanceof RebornFluidRecipe) {
this.fluidInstance = ((RebornFluidRecipe) recipe).getFluidInstance();
}
}
public int getEnergy() {
@ -60,6 +67,10 @@ public class MachineRecipeDisplay<R extends RebornRecipe> implements RecipeDispl
public int getHeat() {
return heat;
}
public FluidInstance getFluidInstance() {
return fluidInstance;
}
@Override
public Optional<Identifier> getRecipeLocation() {

View file

@ -37,7 +37,10 @@ import reborncore.common.crafting.RebornRecipe;
import reborncore.common.crafting.RebornRecipeType;
import reborncore.common.crafting.RecipeManager;
import techreborn.TechReborn;
import techreborn.api.recipe.recipes.FluidReplicatorRecipe;
import techreborn.api.recipe.recipes.RollingMachineRecipe;
import techreborn.compat.rei.fluidreplicator.FluidReplicatorRecipeCategory;
import techreborn.compat.rei.fluidreplicator.FluidReplicatorRecipeDisplay;
import techreborn.compat.rei.rollingmachine.RollingMachineCategory;
import techreborn.compat.rei.rollingmachine.RollingMachineDisplay;
import techreborn.init.ModRecipes;
@ -97,7 +100,7 @@ public class ReiPlugin implements REIPluginV0 {
recipeHelper.registerCategory(new MachineRecipeCategory<>(ModRecipes.COMPRESSOR, 1));
recipeHelper.registerCategory(new MachineRecipeCategory<>(ModRecipes.DISTILLATION_TOWER, 3));
recipeHelper.registerCategory(new MachineRecipeCategory<>(ModRecipes.EXTRACTOR, 1));
recipeHelper.registerCategory(new MachineRecipeCategory<>(ModRecipes.FLUID_REPLICATOR, 1));
recipeHelper.registerCategory(new FluidReplicatorRecipeCategory(ModRecipes.FLUID_REPLICATOR));
recipeHelper.registerCategory(new MachineRecipeCategory<>(ModRecipes.FUSION_REACTOR, 2));
recipeHelper.registerCategory(new MachineRecipeCategory<>(ModRecipes.GRINDER, 1));
recipeHelper.registerCategory(new MachineRecipeCategory<>(ModRecipes.IMPLOSION_COMPRESSOR));
@ -143,6 +146,14 @@ public class ReiPlugin implements REIPluginV0 {
return new RollingMachineDisplay(rollingMachineRecipe.getShapedRecipe());
};
}
if(recipeType == ModRecipes.FLUID_REPLICATOR){
recipeDisplay = r -> {
FluidReplicatorRecipe recipe = (FluidReplicatorRecipe) r;
return new FluidReplicatorRecipeDisplay(recipe);
};
}
recipeHelper.registerRecipes(recipeType.getName(), (Predicate<Recipe>) recipe -> {
if (recipe instanceof RebornRecipe) {

View file

@ -0,0 +1,84 @@
package techreborn.compat.rei.fluidreplicator;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Supplier;
import io.github.prospector.silk.fluid.FluidInstance;
import me.shedaniel.math.api.Point;
import me.shedaniel.math.api.Rectangle;
import me.shedaniel.rei.api.RecipeCategory;
import me.shedaniel.rei.api.Renderer;
import me.shedaniel.rei.gui.widget.LabelWidget;
import me.shedaniel.rei.gui.widget.RecipeArrowWidget;
import me.shedaniel.rei.gui.widget.RecipeBaseWidget;
import me.shedaniel.rei.gui.widget.SlotWidget;
import me.shedaniel.rei.gui.widget.Widget;
import me.shedaniel.rei.impl.ScreenHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
import reborncore.common.crafting.RebornRecipeType;
import reborncore.common.util.StringUtils;
import techreborn.api.recipe.recipes.FluidReplicatorRecipe;
import techreborn.compat.rei.ReiPlugin;
public class FluidReplicatorRecipeCategory implements RecipeCategory<FluidReplicatorRecipeDisplay> {
private final RebornRecipeType<FluidReplicatorRecipe> rebornRecipeType;
public FluidReplicatorRecipeCategory(RebornRecipeType<FluidReplicatorRecipe> recipeType) {
this.rebornRecipeType = recipeType;
}
@Override
public Identifier getIdentifier() {
return rebornRecipeType.getName();
}
@Override
public String getCategoryName() {
return StringUtils.t(rebornRecipeType.getName().toString());
}
@Override
public Renderer getIcon() {
return Renderer.fromItemStack(new ItemStack(ReiPlugin.iconMap.getOrDefault(rebornRecipeType, () -> Items.DIAMOND_SHOVEL).asItem()));
}
@Override
public List<Widget> setupDisplay(Supplier<FluidReplicatorRecipeDisplay> recipeDisplaySupplier, Rectangle bounds) {
FluidReplicatorRecipeDisplay 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));
int i = 0;
for (List<ItemStack> inputs : machineRecipe.getInput()){
widgets.add(new SlotWidget(startPoint.x + 1, startPoint.y + 1 + (i++ * 20), Renderer.fromItemStacks(inputs), true, true, true));
}
Text energyPerTick = new TranslatableText("techreborn.jei.recipe.running.cost", "E", machineRecipe.getEnergy());
widgets.add(new LabelWidget(startPoint.x + 1, startPoint.y + 1 + (i++ * 20), energyPerTick.asFormattedString()){
@Override
public void render(int mouseX, int mouseY, float delta) {
font.draw(text, x - font.getStringWidth(text) / 2, y, ScreenHelper.isDarkModeEnabled() ? 0xFFBBBBBB : 0xFF404040);
}
});
FluidInstance fluidInstance = machineRecipe.getFluidInstance();
if (fluidInstance != null) {
widgets.add(new SlotWidget(startPoint.x + 61, startPoint.y + 1, Renderer.fromFluid(fluidInstance.getFluid()), true, true, true));
}
return widgets;
}
}

View file

@ -0,0 +1,78 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2018 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.compat.rei.fluidreplicator;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import io.github.prospector.silk.fluid.FluidInstance;
import me.shedaniel.rei.api.RecipeDisplay;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import reborncore.common.crafting.ingredient.RebornIngredient;
import techreborn.api.recipe.recipes.FluidReplicatorRecipe;
/**
* @author drcrazy
*
*/
public class FluidReplicatorRecipeDisplay implements RecipeDisplay {
private final FluidReplicatorRecipe recipe;
private List<List<ItemStack>> inputs;
private FluidInstance fluidInstance;
private int energy = 0;
public FluidReplicatorRecipeDisplay(FluidReplicatorRecipe recipe) {
this.recipe = recipe;
this.inputs = recipe.getRebornIngredients().stream().map(RebornIngredient::getPreviewStacks).collect(Collectors.toList());
this.fluidInstance = recipe.getFluidInstance();
this.energy = recipe.getPower();
}
public FluidInstance getFluidInstance() {
return fluidInstance;
}
public int getEnergy() {
return energy;
}
@Override
public List<List<ItemStack>> getInput() {
return inputs;
}
@Override
public List<ItemStack> getOutput() {
return new ArrayList<ItemStack>();
}
@Override
public Identifier getRecipeCategory() {
return recipe.getRebornRecipeType().getName();
}
}