Some REI Compat Changes (#1882)

* Update REi

* Update to 3.2.6
This commit is contained in:
shedaniel 2019-11-07 22:46:19 +08:00 committed by modmuss50
parent 201785b674
commit 8ecfa4207a
7 changed files with 124 additions and 113 deletions

View file

@ -81,10 +81,7 @@ dependencies {
modCompile "net.fabricmc.fabric-api:fabric-api:0.4.1+build.245-1.14"
modCompile "io.github.prospector:modmenu:1.7.9+build.118"
modCompile ("me.shedaniel:RoughlyEnoughItems:3.1.8+build.35") {
//Thanks for moving the project breaking gradle...
exclude group: 'io.github.prospector.modmenu', module: 'ModMenu'
}
modCompile ("me.shedaniel:RoughlyEnoughItems:3.2.6+build.49")
modCompile ('io.github.cottonmc:LibCD:1.5.0+1.14.4') {
transitive = false
}

View file

@ -26,6 +26,7 @@ package techreborn.compat.rei;
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.api.Renderer;
import me.shedaniel.rei.gui.renderers.RecipeRenderer;
@ -71,12 +72,13 @@ public class MachineRecipeCategory<R extends RebornRecipe> implements RecipeCate
}
@Override
public Renderer getIcon() {
return Renderer.fromItemStack(new ItemStack(ReiPlugin.iconMap.getOrDefault(rebornRecipeType, () -> Items.DIAMOND_SHOVEL).asItem()));
public EntryStack getLogo() {
return EntryStack.create(ReiPlugin.iconMap.getOrDefault(rebornRecipeType, () -> Items.DIAMOND_SHOVEL));
}
@Override
public RecipeRenderer getSimpleRenderer(MachineRecipeDisplay<R> recipe) {
// There is currently no replacement for Renderer in the 1.14 version of REI
return Renderer.fromRecipe(() -> Collections.singletonList(recipe.getInput().get(0)), recipe::getOutput);
}
@ -92,37 +94,28 @@ public class MachineRecipeCategory<R extends RebornRecipe> implements RecipeCate
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));
}
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));
for (List<EntryStack> inputs : machineRecipe.getInputEntries()){
widgets.add(EntryWidget.create(startPoint.x + 1, startPoint.y + 1 + (i++ * 20)).entries(inputs));
}
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);
}
});
LabelWidget costLabel;
widgets.add(costLabel = new LabelWidget(startPoint.x + 1, startPoint.y + 1 + (i++ * 20), energyPerTick.asFormattedString()));
costLabel.setHasShadows(false);
costLabel.setDefaultColor(ScreenHelper.isDarkModeEnabled() ? 0xFFBBBBBB : 0xFF404040);
i = 0;
for (ItemStack outputs : machineRecipe.getOutput()){
widgets.add(new SlotWidget(startPoint.x + 61, startPoint.y + 1 + (i++ * 20), Renderer.fromItemStack(outputs), true, true, true));
for (EntryStack outputs : machineRecipe.getOutputEntries()){
widgets.add(EntryWidget.create(startPoint.x + 61, startPoint.y + 1 + (i++ * 20)).entry(outputs));
}
int heat = machineRecipe.getHeat();
if (heat > 0) {
String neededHeat = heat + " " + StringUtils.t("techreborn.jei.recipe.heat");
widgets.add(new LabelWidget(startPoint.x + 61, startPoint.y + 1 + (i++ * 20), neededHeat){
@Override
public void render(int mouseX, int mouseY, float delta) {
font.draw(text, x - font.getStringWidth(text) / 2, y, ScreenHelper.isDarkModeEnabled() ? 0xFFBBBBBB : 0xFF404040);
}
});
LabelWidget heatLabel;
widgets.add(heatLabel = new LabelWidget(startPoint.x + 61, startPoint.y + 1 + (i++ * 20), neededHeat));
heatLabel.setHasShadows(false);
heatLabel.setDefaultColor(ScreenHelper.isDarkModeEnabled() ? 0xFFBBBBBB : 0xFF404040);
}
return widgets;

View file

@ -24,38 +24,39 @@
package techreborn.compat.rei;
import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.api.RecipeDisplay;
import net.minecraft.item.ItemStack;
import me.shedaniel.rei.utils.CollectionUtils;
import net.minecraft.util.Identifier;
import reborncore.common.crafting.ingredient.RebornIngredient;
import reborncore.common.fluid.container.FluidInstance;
import techreborn.api.recipe.recipes.BlastFurnaceRecipe;
import reborncore.common.crafting.RebornFluidRecipe;
import reborncore.common.crafting.RebornRecipe;
import reborncore.common.fluid.container.FluidInstance;
import techreborn.api.recipe.recipes.BlastFurnaceRecipe;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
public class MachineRecipeDisplay<R extends RebornRecipe> implements RecipeDisplay {
private final R recipe;
private List<List<ItemStack>> inputs;
private List<ItemStack> outputs;
private List<List<EntryStack>> inputs;
private List<EntryStack> outputs;
private int energy = 0;
private int heat = 0;
private FluidInstance fluidInstance = null;
public MachineRecipeDisplay(R recipe) {
this.recipe = recipe;
this.inputs = recipe.getRebornIngredients().stream().map(RebornIngredient::getPreviewStacks).collect(Collectors.toList());
this.outputs = recipe.getOutputs();
this.inputs = CollectionUtils.map(recipe.getRebornIngredients(), ing -> CollectionUtils.map(ing.getPreviewStacks(), EntryStack::create));
this.outputs = CollectionUtils.map(recipe.getOutputs(), stack -> EntryStack.create(stack));
this.energy = recipe.getPower();
if (recipe instanceof BlastFurnaceRecipe) {
this.heat = ((BlastFurnaceRecipe) recipe).getHeat();
}
if (recipe instanceof RebornFluidRecipe) {
this.fluidInstance = ((RebornFluidRecipe) recipe).getFluidInstance();
inputs.add(Collections.singletonList(EntryStack.create(fluidInstance.getFluid(), fluidInstance.getAmount())));
}
}
@ -77,17 +78,17 @@ public class MachineRecipeDisplay<R extends RebornRecipe> implements RecipeDispl
}
@Override
public List<List<ItemStack>> getInput() {
public List<List<EntryStack>> getInputEntries() {
return inputs;
}
@Override
public List<List<ItemStack>> getRequiredItems() {
public List<List<EntryStack>> getRequiredEntries() {
return inputs;
}
@Override
public List<ItemStack> getOutput() {
public List<EntryStack> getOutputEntries() {
return outputs;
}

View file

@ -24,6 +24,8 @@
package techreborn.compat.rei;
import me.shedaniel.rei.RoughlyEnoughItemsCore;
import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.api.RecipeDisplay;
import me.shedaniel.rei.api.RecipeHelper;
import me.shedaniel.rei.api.plugins.REIPluginV0;
@ -48,6 +50,7 @@ import techreborn.init.TRContent;
import techreborn.init.TRContent.Machine;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
@ -89,7 +92,7 @@ public class ReiPlugin implements REIPluginV0 {
@Override
public SemanticVersion getMinimumVersion() throws VersionParsingException {
return SemanticVersion.parse("3.0-pre");
return SemanticVersion.parse("3.2.5");
}
@Override
@ -143,6 +146,29 @@ public class ReiPlugin implements REIPluginV0 {
recipeHelper.registerWorkingStations(ModRecipes.WIRE_MILL.getName(), new ItemStack(Machine.WIRE_MILL.asItem()));
}
@Override
public void postRegister() {
// Alright we are going to apply check tags to cells, this should not take long at all.
// Check Tags will not check the amount of the ItemStack, but will enable checking their tags.
for (EntryStack stack : RoughlyEnoughItemsCore.getEntryRegistry().getStacksList())
applyCellEntry(stack);
for (List<RecipeDisplay> displays : RecipeHelper.getInstance().getAllRecipes().values()) {
for (RecipeDisplay display : displays) {
for (List<EntryStack> entries : display.getInputEntries())
for (EntryStack stack : entries)
applyCellEntry(stack);
for (EntryStack stack : display.getOutputEntries())
applyCellEntry(stack);
}
}
}
private void applyCellEntry(EntryStack stack) {
// getItem can be null but this works
if (stack.getItem() == TRContent.CELL)
stack.addSetting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE);
}
private <R extends RebornRecipe> void registerMachineRecipe(RecipeHelper recipeHelper, RebornRecipeType<R> recipeType){
Function<R, RecipeDisplay> recipeDisplay = r -> new MachineRecipeDisplay<>((RebornRecipe) r);

View file

@ -24,31 +24,25 @@
package techreborn.compat.rei.fluidreplicator;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Supplier;
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.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.gui.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.fluid.container.FluidInstance;
import reborncore.common.util.StringUtils;
import techreborn.api.recipe.recipes.FluidReplicatorRecipe;
import techreborn.compat.rei.ReiPlugin;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Supplier;
public class FluidReplicatorRecipeCategory implements RecipeCategory<FluidReplicatorRecipeDisplay> {
private final RebornRecipeType<FluidReplicatorRecipe> rebornRecipeType;
@ -69,8 +63,8 @@ public class FluidReplicatorRecipeCategory implements RecipeCategory<FluidReplic
}
@Override
public Renderer getIcon() {
return Renderer.fromItemStack(new ItemStack(ReiPlugin.iconMap.getOrDefault(rebornRecipeType, () -> Items.DIAMOND_SHOVEL).asItem()));
public EntryStack getLogo() {
return EntryStack.create(ReiPlugin.iconMap.getOrDefault(rebornRecipeType, () -> Items.DIAMOND_SHOVEL));
}
@Override
@ -78,29 +72,25 @@ public class FluidReplicatorRecipeCategory implements RecipeCategory<FluidReplic
FluidReplicatorRecipeDisplay machineRecipe = recipeDisplaySupplier.get();
Point startPoint = new Point( bounds.getCenterX() - 41, bounds.getCenterY() - 13);
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));
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));
for (List<EntryStack> inputs : machineRecipe.getInputEntries()) {
widgets.add(EntryWidget.create(startPoint.x + 1, startPoint.y + 1 + (i++ * 20)).entries(inputs));
}
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);
}
});
LabelWidget costLabel;
widgets.add(costLabel = new LabelWidget(startPoint.x + 1, startPoint.y + 1 + (i++ * 20), energyPerTick.asFormattedString()));
costLabel.setHasShadows(false);
costLabel.setDefaultColor(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));
}
if (!machineRecipe.getOutputEntries().isEmpty())
widgets.add(EntryWidget.create(startPoint.x + 61, startPoint.y + 1).entries(machineRecipe.getOutputEntries()));
return widgets;
}

View file

@ -24,32 +24,32 @@
package techreborn.compat.rei.fluidreplicator;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import reborncore.common.fluid.container.FluidInstance;
import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.api.RecipeDisplay;
import net.minecraft.item.ItemStack;
import me.shedaniel.rei.utils.CollectionUtils;
import net.minecraft.util.Identifier;
import reborncore.common.crafting.ingredient.RebornIngredient;
import reborncore.common.fluid.container.FluidInstance;
import techreborn.api.recipe.recipes.FluidReplicatorRecipe;
import java.util.Collections;
import java.util.List;
/**
* @author drcrazy
*
*/
public class FluidReplicatorRecipeDisplay implements RecipeDisplay {
private final FluidReplicatorRecipe recipe;
private List<List<ItemStack>> inputs;
private List<List<EntryStack>> inputs;
private List<EntryStack> output;
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.inputs = CollectionUtils.map(recipe.getRebornIngredients(), ing -> CollectionUtils.map(ing.getPreviewStacks(), EntryStack::create));
this.fluidInstance = recipe.getFluidInstance();
this.output = fluidInstance == null ? Collections.emptyList() : Collections.singletonList(EntryStack.create(fluidInstance.getFluid(), fluidInstance.getAmount()));
this.energy = recipe.getPower();
}
@ -62,13 +62,18 @@ public class FluidReplicatorRecipeDisplay implements RecipeDisplay {
}
@Override
public List<List<ItemStack>> getInput() {
public List<List<EntryStack>> getInputEntries() {
return inputs;
}
@Override
public List<ItemStack> getOutput() {
return new ArrayList<ItemStack>();
public List<EntryStack> getOutputEntries() {
return output;
}
@Override
public List<List<EntryStack>> getRequiredEntries() {
return inputs;
}
@Override

View file

@ -24,9 +24,8 @@
package techreborn.compat.rei.rollingmachine;
import me.shedaniel.rei.api.Renderer;
import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.plugin.crafting.DefaultCraftingCategory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.Identifier;
import reborncore.common.crafting.RebornRecipeType;
@ -53,8 +52,8 @@ public class RollingMachineCategory extends DefaultCraftingCategory {
}
@Override
public Renderer getIcon() {
return Renderer.fromItemStack(new ItemStack(ReiPlugin.iconMap.getOrDefault(rebornRecipeType, () -> Items.DIAMOND_SHOVEL).asItem()));
public EntryStack getLogo() {
return EntryStack.create(ReiPlugin.iconMap.getOrDefault(rebornRecipeType, () -> Items.DIAMOND_SHOVEL));
}
}