Danielshe 5 years ago
parent
commit
98a84387b0

+ 1 - 1
gradle.properties

@@ -1,4 +1,4 @@
-mod_version=3.1.5-unstable
+mod_version=3.1.6-unstable
 minecraft_version=19w41a
 yarn_version=19w41a+build.3
 fabricloader_version=0.6.3+build.167

+ 2 - 0
src/main/java/me/shedaniel/rei/api/ClientHelper.java

@@ -80,6 +80,8 @@ public interface ClientHelper {
     
     FabricKeyBinding getFocusSearchFieldKeyBinding();
     
+    FabricKeyBinding getCopyRecipeIdentifierKeyBinding();
+    
     /**
      * Gets the mod from an item
      *

+ 2 - 0
src/main/java/me/shedaniel/rei/api/ConfigObject.java

@@ -28,6 +28,8 @@ public interface ConfigObject {
     
     boolean isUsingDarkTheme();
     
+    boolean isToastDisplayedOnCopyIdentifier();
+    
     boolean doesRenderEntryExtraOverlay();
     
     boolean isEntryListWidgetScrolled();

+ 52 - 0
src/main/java/me/shedaniel/rei/gui/toast/CopyRecipeIdentifierToast.java

@@ -0,0 +1,52 @@
+package me.shedaniel.rei.gui.toast;
+
+import com.mojang.blaze3d.platform.GlStateManager;
+import com.mojang.blaze3d.systems.RenderSystem;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.toast.Toast;
+import net.minecraft.client.toast.ToastManager;
+import net.minecraft.util.Identifier;
+
+import javax.annotation.Nullable;
+
+public class CopyRecipeIdentifierToast implements Toast {
+    
+    protected static final Identifier TOASTS_TEX = new Identifier("roughlyenoughitems", "textures/gui/toasts.png");
+    private String title;
+    private String subtitle;
+    private long startTime;
+    
+    public CopyRecipeIdentifierToast(String title, @Nullable String subtitleNullable) {
+        this.title = title;
+        this.subtitle = subtitleNullable;
+    }
+    
+    public static void addToast(String title, @Nullable String subtitleNullable) {
+        MinecraftClient.getInstance().getToastManager().add(new CopyRecipeIdentifierToast(title, subtitleNullable));
+    }
+    
+    @Override
+    public Visibility draw(ToastManager toastManager, long var2) {
+        toastManager.getGame().getTextureManager().bindTexture(TOASTS_TEX);
+        RenderSystem.color3f(1.0F, 1.0F, 1.0F);
+        toastManager.blit(0, 0, 0, 0, 160, 32);
+        if (this.subtitle == null) {
+            toastManager.getGame().textRenderer.draw(this.title, 18.0F, 12.0F, 11141120);
+        } else {
+            toastManager.getGame().textRenderer.draw(this.title, 18.0F, 7.0F, 11141120);
+            toastManager.getGame().textRenderer.draw(this.subtitle, 18.0F, 18.0F, -16777216);
+        }
+        
+        return var2 - this.startTime < 5000L ? Visibility.SHOW : Visibility.HIDE;
+    }
+    
+    @Override
+    public Object getType() {
+        return Type.THIS_IS_SURE_A_TYPE;
+    }
+    
+    public enum Type {
+        THIS_IS_SURE_A_TYPE
+    }
+    
+}

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

@@ -10,7 +10,10 @@ import com.mojang.blaze3d.systems.RenderSystem;
 import it.unimi.dsi.fastutil.ints.IntList;
 import me.shedaniel.math.api.Point;
 import me.shedaniel.math.api.Rectangle;
+import me.shedaniel.math.impl.PointHelper;
+import me.shedaniel.rei.RoughlyEnoughItemsCore;
 import me.shedaniel.rei.api.*;
+import me.shedaniel.rei.gui.toast.CopyRecipeIdentifierToast;
 import me.shedaniel.rei.impl.ScreenHelper;
 import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen;
 import net.minecraft.client.resource.language.I18n;
@@ -170,4 +173,16 @@ public class AutoCraftingButtonWidget extends ButtonWidget {
         }
         return Optional.of(str);
     }
+    
+    @Override
+    public boolean keyPressed(int int_1, int int_2, int int_3) {
+        if (displaySupplier.get().getRecipeLocation().isPresent() && ClientHelper.getInstance().getCopyRecipeIdentifierKeyBinding().matchesKey(int_1, int_2) && containsMouse(PointHelper.fromMouse())) {
+            minecraft.keyboard.setClipboard(displaySupplier.get().getRecipeLocation().get().toString());
+            if (RoughlyEnoughItemsCore.getConfigManager().getConfig().isToastDisplayedOnCopyIdentifier()) {
+                CopyRecipeIdentifierToast.addToast(I18n.translate("msg.rei.copied_recipe_id"), I18n.translate("msg.rei.recipe_id_details", displaySupplier.get().getRecipeLocation().get().toString()));
+            }
+            return true;
+        }
+        return super.keyPressed(int_1, int_2, int_3);
+    }
 }

+ 8 - 1
src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java

@@ -55,8 +55,9 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer {
     private final Identifier previousPageKeybind = new Identifier("roughlyenoughitems", "previous_page");
     private final Identifier nextPageKeybind = new Identifier("roughlyenoughitems", "next_page");
     private final Identifier focusSearchFieldKeybind = new Identifier("roughlyenoughitems", "focus_search");
+    private final Identifier copyRecipeIdentifierKeybind = new Identifier("roughlyenoughitems", "copy_recipe_id");
     private final Map<String, String> modNameCache = Maps.newHashMap();
-    public FabricKeyBinding recipe, usage, hide, previousPage, nextPage, focusSearchField;
+    public FabricKeyBinding recipe, usage, hide, previousPage, nextPage, focusSearchField, copyRecipeIdentifier;
     
     @Override
     public String getFormattedModFromItem(Item item) {
@@ -104,6 +105,11 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer {
         return focusSearchField;
     }
     
+    @Override
+    public FabricKeyBinding getCopyRecipeIdentifierKeyBinding() {
+        return copyRecipeIdentifier;
+    }
+    
     @Override
     public String getModFromItem(Item item) {
         if (item.equals(Items.AIR))
@@ -265,6 +271,7 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer {
         KeyBindingRegistryImpl.INSTANCE.register(previousPage = FabricKeyBinding.Builder.create(previousPageKeybind, InputUtil.Type.KEYSYM, -1, category).build());
         KeyBindingRegistryImpl.INSTANCE.register(nextPage = FabricKeyBinding.Builder.create(nextPageKeybind, InputUtil.Type.KEYSYM, -1, category).build());
         KeyBindingRegistryImpl.INSTANCE.register(focusSearchField = FabricKeyBinding.Builder.create(focusSearchFieldKeybind, InputUtil.Type.KEYSYM, -1, category).build());
+        KeyBindingRegistryImpl.INSTANCE.register(copyRecipeIdentifier = FabricKeyBinding.Builder.create(copyRecipeIdentifierKeybind, InputUtil.Type.KEYSYM, -1, category).build());
     }
     
 }

+ 11 - 0
src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java

@@ -84,6 +84,12 @@ public class ConfigObjectImpl implements ConfigObject {
             .withName("enableCraftableOnlyButton")
             .build();
     
+    private ConfigValue<Boolean> toastDisplayedOnCopyIdentifier = ConfigValue.builder(Boolean.class)
+            .withParent(modules)
+            .withDefaultValue(true)
+            .withName("toastDisplayedOnCopyIdentifier")
+            .build();
+    
     private ConfigValue<String> gamemodeCommand = ConfigValue.builder(String.class)
             .withParent(technical)
             .withDefaultValue("/gamemode {gamemode}")
@@ -228,6 +234,11 @@ public class ConfigObjectImpl implements ConfigObject {
         return darkTheme.getValue().booleanValue();
     }
     
+    @Override
+    public boolean isToastDisplayedOnCopyIdentifier() {
+        return toastDisplayedOnCopyIdentifier.getValue();
+    }
+    
     @Override
     public boolean doesRenderEntryExtraOverlay() {
         return renderEntryExtraOverlay.getValue().booleanValue();

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

@@ -6,6 +6,7 @@
   "key.roughlyenoughitems.next_page": "Next Page",
   "key.roughlyenoughitems.previous_page": "Previous Page",
   "key.roughlyenoughitems.focus_search": "Focus Search Field",
+  "key.roughlyenoughitems.copy_recipe_id": "Copy Recipe Identifier",
   "text.rei.cheating": "Cheating",
   "text.rei.cheating_disabled": "§7Cheating Disabled",
   "text.rei.cheating_enabled": "§cCheating Enabled",
@@ -78,6 +79,8 @@
   "text.rei.recipe_screen_type.selection": "Recipe Screen Type Selection",
   "text.rei.recipe_screen_type.selection.sub": "You can always edit this setting again via the config screen.",
   "text.rei.view_recipes_for": "View Recipes for %s",
+  "msg.rei.copied_recipe_id": "Copied Recipe Identifier",
+  "msg.rei.recipe_id_details": "Recipe ID: %s",
   "_comment": "Config Tooltips",
   "config.roughlyenoughitems.title": "Roughly Enough Items Config",
   "config.roughlyenoughitems.!general": "General",
@@ -134,6 +137,7 @@
   "config.roughlyenoughitems.itemCheatingMode.rei_like": "Normal",
   "config.roughlyenoughitems.itemCheatingMode.jei_like": "Inverted",
   "config.roughlyenoughitems.appendModNames": "Append Mod Names:",
+  "config.roughlyenoughitems.toastDisplayedOnCopyIdentifier": "Copy Identifier Toast:",
   "config.roughlyenoughitems.scrollingEntryListWidget": "Entry List Action:",
   "config.roughlyenoughitems.scrollingEntryListWidget.boolean.true": "Scrolled",
   "config.roughlyenoughitems.scrollingEntryListWidget.boolean.false": "Paginated",

BIN
src/main/resources/assets/roughlyenoughitems/textures/gui/toasts.png