From f0b8d99853bc8b5c1d07c176d86bfcb71e58799b Mon Sep 17 00:00:00 2001
From: Daniel She <daniel@shedaniel.me>
Date: Mon, 19 Aug 2019 21:26:47 +0800
Subject: [PATCH] Update to REI 3.0-pre (#1793)

* Update to REI 3.0-pre

* Update fabric.mod.json
---
 build.gradle                                  |  2 +-
 .../compat/rei/MachineRecipeCategory.java     | 88 +++++++------------
 .../compat/rei/MachineRecipeDisplay.java      |  6 +-
 .../java/techreborn/compat/rei/ReiPlugin.java | 21 +++--
 .../RollingMachineCategory.java               |  5 +-
 .../rollingmachine/RollingMachineDisplay.java |  2 +-
 src/main/resources/fabric.mod.json            |  4 +-
 7 files changed, 56 insertions(+), 72 deletions(-)

diff --git a/build.gradle b/build.gradle
index 2170dfb17..994ce3223 100644
--- a/build.gradle
+++ b/build.gradle
@@ -93,7 +93,7 @@ dependencies {
 
 	modCompile "io.github.prospector:modmenu:1.7.7+build.116"
 	modCompile "io.github.prospector.silk:SilkAPI:1.2.4-43"
-	modCompile ("me.shedaniel:RoughlyEnoughItems:2.9.7+build.145") {
+	modCompile ("me.shedaniel:RoughlyEnoughItems:3.0-pre+build.1") {
 		//Thanks for moving the project breaking gradle...
 		exclude group: 'io.github.prospector.modmenu', module: 'ModMenu'
 	}
diff --git a/src/main/java/techreborn/compat/rei/MachineRecipeCategory.java b/src/main/java/techreborn/compat/rei/MachineRecipeCategory.java
index 81d7cab6f..ff818a0cc 100644
--- a/src/main/java/techreborn/compat/rei/MachineRecipeCategory.java
+++ b/src/main/java/techreborn/compat/rei/MachineRecipeCategory.java
@@ -25,12 +25,13 @@
 package techreborn.compat.rei;
 
 import com.mojang.blaze3d.platform.GlStateManager;
-import me.shedaniel.rei.api.*;
-import me.shedaniel.rei.gui.renderables.RecipeRenderer;
-import me.shedaniel.rei.gui.widget.LabelWidget;
-import me.shedaniel.rei.gui.widget.RecipeBaseWidget;
-import me.shedaniel.rei.gui.widget.SlotWidget;
-import me.shedaniel.rei.gui.widget.Widget;
+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.renderers.RecipeRenderer;
+import me.shedaniel.rei.gui.widget.*;
+import me.shedaniel.rei.impl.ScreenHelper;
 import me.shedaniel.rei.plugin.DefaultPlugin;
 import net.minecraft.client.MinecraftClient;
 import net.minecraft.client.render.GuiLighting;
@@ -43,7 +44,7 @@ import net.minecraft.util.math.MathHelper;
 import reborncore.common.crafting.RebornRecipe;
 import reborncore.common.crafting.RebornRecipeType;
 import reborncore.common.util.StringUtils;
-import java.awt.*;
+
 import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
@@ -75,12 +76,12 @@ public class MachineRecipeCategory<R extends RebornRecipe> implements RecipeCate
 
 	@Override
 	public Renderer getIcon() {
-		return Renderable.fromItemStack(new ItemStack(ReiPlugin.iconMap.getOrDefault(rebornRecipeType, () -> Items.DIAMOND_SHOVEL).asItem()));
+		return Renderer.fromItemStack(new ItemStack(ReiPlugin.iconMap.getOrDefault(rebornRecipeType, () -> Items.DIAMOND_SHOVEL).asItem()));
 	}
 
 	@Override
 	public RecipeRenderer getSimpleRenderer(MachineRecipeDisplay<R> recipe) {
-		return Renderable.fromRecipe(() -> Collections.singletonList(recipe.getInput().get(0)), recipe::getOutput);
+		return Renderer.fromRecipe(() -> Collections.singletonList(recipe.getInput().get(0)), recipe::getOutput);
 	}
 
 	@Override
@@ -88,66 +89,43 @@ public class MachineRecipeCategory<R extends RebornRecipe> implements RecipeCate
 
 		MachineRecipeDisplay<R> machineRecipe = recipeDisplaySupplier.get();
 
-		Point startPoint = new Point((int) bounds.getCenterX() - 41, (int) bounds.getCenterY() - recipeLines*12 -1);
+		Point startPoint = new Point( bounds.getCenterX() - 41, bounds.getCenterY() - recipeLines*12 -1);
 
-        class RecipeBackgroundWidget extends RecipeBaseWidget {
-            RecipeBackgroundWidget(Rectangle bounds) {
-                super(bounds);
-            }
-
-            public void render(int mouseX, int mouseY, float delta) {
-                super.render(mouseX, mouseY, delta);
-                GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
-                GuiLighting.disable();
-                MinecraftClient.getInstance().getTextureManager().bindTexture(DefaultPlugin.getDisplayTexture());
-                int width = MathHelper.ceil((double)(System.currentTimeMillis() / 50L) % 24.0D / 1.0D);
-                this.blit(startPoint.x + 24, startPoint.y + 1, 82, 91, width, 17);
-            }
-        }
         List<Widget> widgets = new LinkedList<>();
-        widgets.add(new RecipeBackgroundWidget(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), inputs, true, true, true));
+			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()));
+		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);
+			}
+		});
 
 		i = 0;
 		for (ItemStack outputs : machineRecipe.getOutput()){
-			widgets.add(new SlotWidget(startPoint.x + 61, startPoint.y + 1 + (i++ * 20), Collections.singletonList(outputs), true, true, true));
+			widgets.add(new SlotWidget(startPoint.x + 61, startPoint.y + 1 + (i++ * 20), Renderer.fromItemStack(outputs), true, true, true));
 		}
 
 		return widgets;
 	}
 
-    @Override
-    public DisplaySettings<MachineRecipeDisplay<R>> getDisplaySettings() {
-		return new DisplaySettings<MachineRecipeDisplay<R>>() {
-			
-            public int getDisplayHeight(RecipeCategory category) {
+	@Override
+	public int getDisplayHeight() {
+		if (recipeLines == 1) {
+			return 36;
+		}
+		else if (recipeLines == 3) {
+			return 90;
+		}
+		else if (recipeLines == 4) {
+			return 110;
+		}
+		return 66;
+	}
 
-                if (recipeLines == 1) {
-                    return 36;
-                }
-                else if (recipeLines == 3) {
-                    return 90;
-                }
-                else if (recipeLines == 4) {
-                    return 110;
-                }
-                return 66;
-            }
-
-            public int getDisplayWidth(RecipeCategory category, MachineRecipeDisplay<R> display) {
-                return 150;
-            }
-
-            public int getMaximumRecipePerPage(RecipeCategory category) {
-                return 99;
-            }
-
-        };
-    }
 }
diff --git a/src/main/java/techreborn/compat/rei/MachineRecipeDisplay.java b/src/main/java/techreborn/compat/rei/MachineRecipeDisplay.java
index 84c001916..31ef29459 100644
--- a/src/main/java/techreborn/compat/rei/MachineRecipeDisplay.java
+++ b/src/main/java/techreborn/compat/rei/MachineRecipeDisplay.java
@@ -34,7 +34,7 @@ import java.util.List;
 import java.util.Optional;
 import java.util.stream.Collectors;
 
-public class MachineRecipeDisplay<R extends RebornRecipe> implements RecipeDisplay<R> {
+public class MachineRecipeDisplay<R extends RebornRecipe> implements RecipeDisplay {
 
 	private final R recipe;
 	private List<List<ItemStack>> inputs;
@@ -53,8 +53,8 @@ public class MachineRecipeDisplay<R extends RebornRecipe> implements RecipeDispl
 	}
 
 	@Override
-	public Optional<R> getRecipe() {
-		return Optional.ofNullable(recipe);
+	public Optional<Identifier> getRecipeLocation() {
+		return Optional.ofNullable(recipe).map(RebornRecipe::getId);
 	}
 
 	@Override
diff --git a/src/main/java/techreborn/compat/rei/ReiPlugin.java b/src/main/java/techreborn/compat/rei/ReiPlugin.java
index dc61bdb6a..1a6c55d39 100644
--- a/src/main/java/techreborn/compat/rei/ReiPlugin.java
+++ b/src/main/java/techreborn/compat/rei/ReiPlugin.java
@@ -24,9 +24,11 @@
 
 package techreborn.compat.rei;
 
-import me.shedaniel.rei.api.REIPluginEntry;
 import me.shedaniel.rei.api.RecipeDisplay;
 import me.shedaniel.rei.api.RecipeHelper;
+import me.shedaniel.rei.api.plugins.REIPluginV0;
+import net.fabricmc.loader.api.SemanticVersion;
+import net.fabricmc.loader.util.version.VersionParsingException;
 import net.minecraft.item.ItemConvertible;
 import net.minecraft.item.ItemStack;
 import net.minecraft.recipe.Recipe;
@@ -35,19 +37,19 @@ import reborncore.common.crafting.RebornRecipe;
 import reborncore.common.crafting.RebornRecipeType;
 import reborncore.common.crafting.RecipeManager;
 import techreborn.TechReborn;
-import techreborn.api.recipe.recipes.*;
+import techreborn.api.recipe.recipes.RollingMachineRecipe;
+import techreborn.compat.rei.rollingmachine.RollingMachineCategory;
+import techreborn.compat.rei.rollingmachine.RollingMachineDisplay;
 import techreborn.init.ModRecipes;
 import techreborn.init.TRContent;
 import techreborn.init.TRContent.Machine;
-import techreborn.compat.rei.rollingmachine.RollingMachineCategory;
-import techreborn.compat.rei.rollingmachine.RollingMachineDisplay;
 
 import java.util.HashMap;
 import java.util.Map;
 import java.util.function.Function;
 import java.util.function.Predicate;
 
-public class ReiPlugin implements REIPluginEntry {
+public class ReiPlugin implements REIPluginV0 {
 
 	public static final Identifier PLUGIN = new Identifier(TechReborn.MOD_ID, "techreborn_plugin");
 
@@ -55,7 +57,7 @@ public class ReiPlugin implements REIPluginEntry {
 
 	public ReiPlugin() {
 		iconMap.put(ModRecipes.ALLOY_SMELTER, Machine.ALLOY_SMELTER);
-		iconMap.put(ModRecipes.ASSEMBLING_MACHINE,Machine.ASSEMBLY_MACHINE);
+		iconMap.put(ModRecipes.ASSEMBLING_MACHINE, Machine.ASSEMBLY_MACHINE);
 		iconMap.put(ModRecipes.BLAST_FURNACE, Machine.INDUSTRIAL_BLAST_FURNACE);
 		iconMap.put(ModRecipes.CENTRIFUGE, Machine.INDUSTRIAL_CENTRIFUGE);
 		iconMap.put(ModRecipes.CHEMICAL_REACTOR, Machine.CHEMICAL_REACTOR);
@@ -72,7 +74,7 @@ public class ReiPlugin implements REIPluginEntry {
 		iconMap.put(ModRecipes.ROLLING_MACHINE, Machine.ROLLING_MACHINE);
 		iconMap.put(ModRecipes.SCRAPBOX, TRContent.SCRAP_BOX);
 		iconMap.put(ModRecipes.VACUUM_FREEZER, Machine.VACUUM_FREEZER);
-		
+
 	}
 
 	@Override
@@ -80,6 +82,11 @@ public class ReiPlugin implements REIPluginEntry {
 		return PLUGIN;
 	}
 
+	@Override
+	public SemanticVersion getMinimumVersion() throws VersionParsingException {
+		return SemanticVersion.parse("3.0-pre");
+	}
+
 	@Override
 	public void registerPluginCategories(RecipeHelper recipeHelper) {
 	    recipeHelper.registerCategory(new MachineRecipeCategory<>(ModRecipes.ALLOY_SMELTER));
diff --git a/src/main/java/techreborn/compat/rei/rollingmachine/RollingMachineCategory.java b/src/main/java/techreborn/compat/rei/rollingmachine/RollingMachineCategory.java
index 42fedb96b..10b16b00d 100644
--- a/src/main/java/techreborn/compat/rei/rollingmachine/RollingMachineCategory.java
+++ b/src/main/java/techreborn/compat/rei/rollingmachine/RollingMachineCategory.java
@@ -24,9 +24,8 @@
 
 package techreborn.compat.rei.rollingmachine;
 
-import me.shedaniel.rei.api.Renderable;
 import me.shedaniel.rei.api.Renderer;
-import me.shedaniel.rei.plugin.DefaultCraftingCategory;
+import me.shedaniel.rei.plugin.crafting.DefaultCraftingCategory;
 import net.minecraft.item.ItemStack;
 import net.minecraft.item.Items;
 import net.minecraft.util.Identifier;
@@ -55,7 +54,7 @@ public class RollingMachineCategory extends DefaultCraftingCategory {
 
 	@Override
 	public Renderer getIcon() {
-		return Renderable.fromItemStack(new ItemStack(ReiPlugin.iconMap.getOrDefault(rebornRecipeType, () -> Items.DIAMOND_SHOVEL).asItem()));
+		return Renderer.fromItemStack(new ItemStack(ReiPlugin.iconMap.getOrDefault(rebornRecipeType, () -> Items.DIAMOND_SHOVEL).asItem()));
 	}
 
 }
diff --git a/src/main/java/techreborn/compat/rei/rollingmachine/RollingMachineDisplay.java b/src/main/java/techreborn/compat/rei/rollingmachine/RollingMachineDisplay.java
index c46a9ff61..8330a3109 100644
--- a/src/main/java/techreborn/compat/rei/rollingmachine/RollingMachineDisplay.java
+++ b/src/main/java/techreborn/compat/rei/rollingmachine/RollingMachineDisplay.java
@@ -1,6 +1,6 @@
 package techreborn.compat.rei.rollingmachine;
 
-import me.shedaniel.rei.plugin.DefaultShapedDisplay;
+import me.shedaniel.rei.plugin.crafting.DefaultShapedDisplay;
 import net.minecraft.recipe.ShapedRecipe;
 import net.minecraft.util.Identifier;
 import techreborn.init.ModRecipes;
diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json
index ca530a87d..7426f4322 100644
--- a/src/main/resources/fabric.mod.json
+++ b/src/main/resources/fabric.mod.json
@@ -19,7 +19,7 @@
     "client": [
       "techreborn.TechRebornClient"
     ],
-    "rei_plugins": [
+    "rei_plugins_v0": [
       "techreborn.compat.rei.ReiPlugin"
     ],
     "towelette": [
@@ -55,4 +55,4 @@
     "coderbot",
     "estebes"
   ]
-}
\ No newline at end of file
+}