Danielshe 5 gadi atpakaļ
vecāks
revīzija
834eac11d0

+ 1 - 1
gradle.properties

@@ -1,4 +1,4 @@
-mod_version=3.1
+mod_version=3.1.1
 minecraft_version=1.14.4
 yarn_version=1.14.4+build.1
 fabricloader_version=0.6.1+build.164

+ 30 - 15
src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java

@@ -5,6 +5,7 @@
 
 package me.shedaniel.rei.gui.widget;
 
+import com.google.common.collect.Lists;
 import it.unimi.dsi.fastutil.ints.IntList;
 import me.shedaniel.math.api.Point;
 import me.shedaniel.math.api.Rectangle;
@@ -20,12 +21,13 @@ import net.minecraft.util.math.MathHelper;
 import java.util.List;
 import java.util.Optional;
 import java.util.function.Supplier;
+import java.util.stream.Collectors;
 
 public class AutoCraftingButtonWidget extends ButtonWidget {
     
     private final Supplier<RecipeDisplay> displaySupplier;
     private String extraTooltip;
-    private String errorTooltip;
+    private List<String> errorTooltip;
     private List<Widget> setupDisplay;
     private AbstractContainerScreen<?> containerScreen;
     private boolean visible = false;
@@ -61,7 +63,7 @@ public class AutoCraftingButtonWidget extends ButtonWidget {
     @Override
     public void render(int mouseX, int mouseY, float delta) {
         this.enabled = false;
-        String error = null;
+        List<String> error = null;
         int color = 0;
         visible = false;
         IntList redSlots = null;
@@ -74,9 +76,14 @@ public class AutoCraftingButtonWidget extends ButtonWidget {
                 if (result.isSuccessful()) {
                     enabled = true;
                     error = null;
+                    color = 0;
+                    redSlots = null;
                     break;
-                } else if (error == null) {
-                    error = result.getErrorKey();
+                } else if (result.isApplicable()) {
+                    if (error == null) {
+                        error = Lists.newArrayList();
+                    }
+                    error.add(result.getErrorKey());
                     color = result.getColor();
                     redSlots = result.getIntegers();
                 }
@@ -86,12 +93,17 @@ public class AutoCraftingButtonWidget extends ButtonWidget {
         }
         if (!visible) {
             enabled = false;
-            error = "error.rei.no.handlers.applicable";
+            if (error == null) {
+                error = Lists.newArrayList();
+            } else {
+                error.clear();
+            }
+            error.add("error.rei.no.handlers.applicable");
         }
         if (isHovered(mouseX, mouseY) && category instanceof TransferRecipeCategory && redSlots != null) {
             ((TransferRecipeCategory<RecipeDisplay>) category).renderRedSlots(setupDisplay, displayBounds, displaySupplier.get(), redSlots);
         }
-        errorTooltip = error;
+        errorTooltip = error == null || error.isEmpty() ? null : error;
         int x = getBounds().x, y = getBounds().y, width = getBounds().width, height = getBounds().height;
         minecraft.getTextureManager().bindTexture(ScreenHelper.isDarkModeEnabled() ? BUTTON_LOCATION_DARK : BUTTON_LOCATION);
         RenderHelper.color4f(1.0F, 1.0F, 1.0F, 1.0F);
@@ -139,14 +151,17 @@ public class AutoCraftingButtonWidget extends ButtonWidget {
     
     @Override
     public Optional<String> getTooltips() {
-        if (this.minecraft.options.advancedItemTooltips)
-            if (errorTooltip == null)
-                return Optional.ofNullable(I18n.translate("text.auto_craft.move_items") + extraTooltip);
-            else
-                return Optional.ofNullable(Formatting.RED.toString() + I18n.translate(errorTooltip) + extraTooltip);
-        if (errorTooltip == null)
-            return Optional.ofNullable(I18n.translate("text.auto_craft.move_items"));
-        else
-            return Optional.ofNullable(Formatting.RED.toString() + I18n.translate(errorTooltip));
+        String str = "";
+        if (errorTooltip == null) {
+            str += I18n.translate("text.auto_craft.move_items");
+        } else {
+            if (errorTooltip.size() > 1)
+                str += Formatting.RED.toString() + I18n.translate("error.rei.multi.errors") + "\n";
+            str += errorTooltip.stream().map(s -> Formatting.RED.toString() + (errorTooltip.size() > 1 ? "- " : "") + I18n.translate(s)).collect(Collectors.joining("\n"));
+        }
+        if (this.minecraft.options.advancedItemTooltips) {
+            str += extraTooltip;
+        }
+        return Optional.of(str);
     }
 }

+ 2 - 0
src/main/java/me/shedaniel/rei/plugin/DefaultAutoCraftingPlugin.java

@@ -9,6 +9,7 @@ import me.shedaniel.rei.RoughlyEnoughItemsCore;
 import me.shedaniel.rei.api.RecipeHelper;
 import me.shedaniel.rei.api.plugins.REIPluginV0;
 import me.shedaniel.rei.plugin.autocrafting.DefaultCategoryHandler;
+import me.shedaniel.rei.plugin.autocrafting.DefaultRecipeBookHandler;
 import net.fabricmc.loader.api.SemanticVersion;
 import net.fabricmc.loader.util.version.VersionParsingException;
 import net.minecraft.util.Identifier;
@@ -33,5 +34,6 @@ public class DefaultAutoCraftingPlugin implements REIPluginV0 {
             return;
         }
         recipeHelper.registerAutoCraftingHandler(new DefaultCategoryHandler());
+        recipeHelper.registerAutoCraftingHandler(new DefaultRecipeBookHandler());
     }
 }

+ 102 - 0
src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultRecipeBookHandler.java

@@ -0,0 +1,102 @@
+package me.shedaniel.rei.plugin.autocrafting;
+
+import me.shedaniel.rei.api.AutoTransferHandler;
+import me.shedaniel.rei.api.RecipeDisplay;
+import me.shedaniel.rei.impl.ScreenHelper;
+import me.shedaniel.rei.listeners.RecipeBookGuiHooks;
+import me.shedaniel.rei.plugin.blasting.DefaultBlastingDisplay;
+import me.shedaniel.rei.plugin.crafting.DefaultCraftingDisplay;
+import me.shedaniel.rei.plugin.smelting.DefaultSmeltingDisplay;
+import me.shedaniel.rei.plugin.smoking.DefaultSmokingDisplay;
+import net.minecraft.client.gui.screen.Screen;
+import net.minecraft.client.gui.screen.recipebook.RecipeBookProvider;
+import net.minecraft.client.resource.language.I18n;
+import net.minecraft.container.CraftingContainer;
+import net.minecraft.container.CraftingTableContainer;
+import net.minecraft.container.PlayerContainer;
+import net.minecraft.recipe.Recipe;
+
+public class DefaultRecipeBookHandler implements AutoTransferHandler {
+    @Override
+    public Result handle(Context context) {
+        RecipeDisplay display = context.getRecipe();
+        if (!(context.getContainer() instanceof CraftingContainer))
+            return Result.createNotApplicable();
+        CraftingContainer<?> container = (CraftingContainer<?>) context.getContainer();
+        if (display instanceof DefaultCraftingDisplay) {
+            DefaultCraftingDisplay craftingDisplay = (DefaultCraftingDisplay) display;
+            if (craftingDisplay.getOptionalRecipe().isPresent()) {
+                int h = -1, w = -1;
+                if (container instanceof CraftingTableContainer) {
+                    h = 3;
+                    w = 3;
+                } else if (container instanceof PlayerContainer) {
+                    h = 2;
+                    w = 2;
+                }
+                if (h == -1 || w == -1)
+                    return Result.createNotApplicable();
+                Recipe<?> recipe = (craftingDisplay).getOptionalRecipe().get();
+                if (craftingDisplay.getHeight() > h || craftingDisplay.getWidth() > w)
+                    return Result.createFailed(I18n.translate("error.rei.transfer.too_small", h, w));
+                if (!context.getMinecraft().player.getRecipeBook().contains(recipe))
+                    return Result.createFailed(I18n.translate("error.rei.recipe.not.unlocked"));
+                if (!context.isActuallyCrafting())
+                    return Result.createSuccessful();
+                context.getMinecraft().openScreen(context.getContainerScreen());
+                if (context.getContainerScreen() instanceof RecipeBookProvider)
+                    ((RecipeBookGuiHooks) ((RecipeBookProvider) context.getContainerScreen()).getRecipeBookGui()).rei_getGhostSlots().reset();
+                context.getMinecraft().interactionManager.clickRecipe(container.syncId, recipe, Screen.hasShiftDown());
+                ScreenHelper.getLastOverlay().init();
+            }
+        } else if (display instanceof DefaultSmeltingDisplay) {
+            DefaultSmeltingDisplay defaultDisplay = (DefaultSmeltingDisplay) display;
+            if (defaultDisplay.getOptionalRecipe().isPresent()) {
+                Recipe<?> recipe = (defaultDisplay).getOptionalRecipe().get();
+                if (!context.getMinecraft().player.getRecipeBook().contains(recipe))
+                    return Result.createFailed(I18n.translate("error.rei.recipe.not.unlocked"));
+                if (!context.isActuallyCrafting())
+                    return Result.createSuccessful();
+                context.getMinecraft().openScreen(context.getContainerScreen());
+                if (context.getContainerScreen() instanceof RecipeBookProvider)
+                    ((RecipeBookGuiHooks) ((RecipeBookProvider) context.getContainerScreen()).getRecipeBookGui()).rei_getGhostSlots().reset();
+                context.getMinecraft().interactionManager.clickRecipe(container.syncId, recipe, Screen.hasShiftDown());
+                ScreenHelper.getLastOverlay().init();
+            }
+        } else if (display instanceof DefaultSmokingDisplay) {
+            DefaultSmokingDisplay defaultDisplay = (DefaultSmokingDisplay) display;
+            if (defaultDisplay.getOptionalRecipe().isPresent()) {
+                Recipe<?> recipe = (defaultDisplay).getOptionalRecipe().get();
+                if (!context.getMinecraft().player.getRecipeBook().contains(recipe))
+                    return Result.createFailed(I18n.translate("error.rei.recipe.not.unlocked"));
+                if (!context.isActuallyCrafting())
+                    return Result.createSuccessful();
+                context.getMinecraft().openScreen(context.getContainerScreen());
+                if (context.getContainerScreen() instanceof RecipeBookProvider)
+                    ((RecipeBookGuiHooks) ((RecipeBookProvider) context.getContainerScreen()).getRecipeBookGui()).rei_getGhostSlots().reset();
+                context.getMinecraft().interactionManager.clickRecipe(container.syncId, recipe, Screen.hasShiftDown());
+                ScreenHelper.getLastOverlay().init();
+            }
+        } else if (display instanceof DefaultBlastingDisplay) {
+            DefaultBlastingDisplay defaultDisplay = (DefaultBlastingDisplay) display;
+            if (defaultDisplay.getOptionalRecipe().isPresent()) {
+                Recipe<?> recipe = (defaultDisplay).getOptionalRecipe().get();
+                if (!context.getMinecraft().player.getRecipeBook().contains(recipe))
+                    return Result.createFailed(I18n.translate("error.rei.recipe.not.unlocked"));
+                if (!context.isActuallyCrafting())
+                    return Result.createSuccessful();
+                context.getMinecraft().openScreen(context.getContainerScreen());
+                if (context.getContainerScreen() instanceof RecipeBookProvider)
+                    ((RecipeBookGuiHooks) ((RecipeBookProvider) context.getContainerScreen()).getRecipeBookGui()).rei_getGhostSlots().reset();
+                context.getMinecraft().interactionManager.clickRecipe(container.syncId, recipe, Screen.hasShiftDown());
+                ScreenHelper.getLastOverlay().init();
+            }
+        }
+        return Result.createNotApplicable();
+    }
+    
+    @Override
+    public double getPriority() {
+        return -20;
+    }
+}

+ 0 - 2
src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java

@@ -61,12 +61,10 @@ public class InputSlotCrafter<C extends Inventory> implements RecipeGridAligner<
             } else {
                 this.returnInputs();
                 craftingContainer.sendContentUpdates();
-                player.inventory.markDirty();
                 throw new NullPointerException();
             }
             
             craftingContainer.sendContentUpdates();
-            player.inventory.markDirty();
         }
     }
     

+ 2 - 0
src/main/resources/assets/roughlyenoughitems/lang/en_us.json

@@ -43,7 +43,9 @@
   "error.rei.not.on.server": "REI is not on the server.",
   "error.rei.not.enough.materials": "Not enough materials.",
   "error.rei.internal.error": "Internal Error: %s",
+  "error.rei.recipe.not.unlocked": "Recipe not unlocked in Recipe Book.",
   "error.rei.no.handlers.applicable": "No handlers are applicable.",
+  "error.rei.multi.errors": "Multiple Errors:",
   "rei.rei.no.slot.in.inv": "Can't find any space for item in the inventory",
   "text.rei.showing_craftable": "Showing Craftable",
   "text.rei.showing_all": "Showing All",