Bläddra i källkod

Slow down stack rotating, and allowing users to scroll through the stacks.

Signed-off-by: shedaniel <daniel@shedaniel.me>
shedaniel 4 år sedan
förälder
incheckning
00464520ca

+ 6 - 9
RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java

@@ -23,8 +23,9 @@
 
 package me.shedaniel.rei;
 
+import com.google.common.collect.BiMap;
+import com.google.common.collect.HashBiMap;
 import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
 import me.shedaniel.cloth.api.client.events.v0.ClothClientHooks;
@@ -104,9 +105,8 @@ import static me.shedaniel.rei.impl.Internals.attachInstance;
 @ApiStatus.Internal
 @Environment(EnvType.CLIENT)
 public class RoughlyEnoughItemsCore implements ClientModInitializer {
-    
     @ApiStatus.Internal public static final Logger LOGGER = LogManager.getFormatterLogger("REI");
-    private static final Map<ResourceLocation, REIPluginEntry> plugins = Maps.newHashMap();
+    private static final BiMap<ResourceLocation, REIPluginEntry> PLUGINS = HashBiMap.create();
     private static final ExecutorService SYNC_RECIPES = Executors.newSingleThreadScheduledExecutor(r -> new Thread(r, "REI-SyncRecipes"));
     @ApiStatus.Experimental
     public static boolean isLeftModePressed = false;
@@ -307,20 +307,17 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer {
      */
     @ApiStatus.Internal
     public static REIPluginEntry registerPlugin(REIPluginEntry plugin) {
-        plugins.put(plugin.getPluginIdentifier(), plugin);
+        PLUGINS.put(plugin.getPluginIdentifier(), plugin);
         RoughlyEnoughItemsCore.LOGGER.debug("Registered plugin %s from %s", plugin.getPluginIdentifier().toString(), plugin.getClass().getSimpleName());
         return plugin;
     }
     
     public static List<REIPluginEntry> getPlugins() {
-        return new LinkedList<>(plugins.values());
+        return new ArrayList<>(PLUGINS.values());
     }
     
     public static Optional<ResourceLocation> getPluginIdentifier(REIPluginEntry plugin) {
-        for (ResourceLocation identifier : plugins.keySet())
-            if (identifier != null && plugins.get(identifier).equals(plugin))
-                return Optional.of(identifier);
-        return Optional.empty();
+        return Optional.ofNullable(PLUGINS.inverse().get(plugin));
     }
     
     public static boolean hasPermissionToUsePackets() {

+ 9 - 5
RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java

@@ -71,7 +71,6 @@ import java.util.function.Supplier;
 
 @ApiStatus.Internal
 public class RecipeViewingScreen extends Screen implements RecipeScreen {
-    
     public static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/recipecontainer.png");
     private final List<Widget> preWidgets = Lists.newArrayList();
     private final List<Widget> widgets = Lists.newArrayList();
@@ -518,10 +517,15 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen {
     }
     
     @Override
-    public boolean mouseScrolled(double i, double j, double amount) {
-        for (GuiEventListener listener : children())
-            if (listener.mouseScrolled(i, j, amount))
+    public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
+        ScreenHelper.isWithinRecipeViewingScreen = true;
+        for (GuiEventListener listener : children()) {
+            if (listener.mouseScrolled(mouseX, mouseY, amount)) {
+                ScreenHelper.isWithinRecipeViewingScreen = false;
                 return true;
+            }
+        }
+        ScreenHelper.isWithinRecipeViewingScreen = false;
         if (getBounds().contains(PointHelper.ofMouse())) {
             if (amount > 0 && recipeBack.isEnabled())
                 recipeBack.onClick();
@@ -534,7 +538,7 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen {
             else if (amount < 0 && categoryNext.isEnabled())
                 categoryNext.onClick();
         }
-        return super.mouseScrolled(i, j, amount);
+        return super.mouseScrolled(mouseX, mouseY, amount);
     }
     
     @Override

+ 7 - 3
RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java

@@ -62,7 +62,6 @@ import java.util.Optional;
 
 @ApiStatus.Internal
 public class VillagerRecipeViewingScreen extends Screen implements RecipeScreen {
-    
     private final Map<RecipeCategory<?>, List<RecipeDisplay>> categoryMap;
     private final List<RecipeCategory<?>> categories;
     private final List<Widget> widgets = Lists.newArrayList();
@@ -298,9 +297,14 @@ public class VillagerRecipeViewingScreen extends Screen implements RecipeScreen
                 scrollBarAlphaFutureTime = System.currentTimeMillis();
             return true;
         }
-        for (GuiEventListener listener : children())
-            if (listener.mouseScrolled(mouseX, mouseY, amount))
+        ScreenHelper.isWithinRecipeViewingScreen = true;
+        for (GuiEventListener listener : children()) {
+            if (listener.mouseScrolled(mouseX, mouseY, amount)) {
+                ScreenHelper.isWithinRecipeViewingScreen = false;
                 return true;
+            }
+        }
+        ScreenHelper.isWithinRecipeViewingScreen = false;
         int tabSize = ConfigObject.getInstance().isUsingCompactTabs() ? 24 : 28;
         if (mouseX >= bounds.x && mouseX <= bounds.getMaxX() && mouseY >= bounds.y - tabSize && mouseY < bounds.y) {
             if (amount < 0) selectedCategoryIndex++;

+ 17 - 3
RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryWidget.java

@@ -36,7 +36,6 @@ import me.shedaniel.rei.api.widgets.Slot;
 import me.shedaniel.rei.api.widgets.Tooltip;
 import me.shedaniel.rei.gui.ContainerScreenOverlay;
 import me.shedaniel.rei.impl.ScreenHelper;
-import me.shedaniel.rei.utils.CollectionUtils;
 import net.minecraft.client.gui.components.events.GuiEventListener;
 import net.minecraft.client.resources.language.I18n;
 import net.minecraft.network.chat.TextComponent;
@@ -54,7 +53,8 @@ import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
 public class EntryWidget extends Slot {
-    
+    @ApiStatus.Internal
+    public static long stackDisplayOffset = 0;
     protected static final ResourceLocation RECIPE_GUI = new ResourceLocation("roughlyenoughitems", "textures/gui/recipecontainer.png");
     protected static final ResourceLocation RECIPE_GUI_DARK = new ResourceLocation("roughlyenoughitems", "textures/gui/recipecontainer_dark.png");
     
@@ -255,7 +255,7 @@ public class EntryWidget extends Slot {
             return EntryStack.empty();
         if (entryStacks.size() == 1)
             return entryStacks.get(0);
-        return entryStacks.get(Mth.floor((System.currentTimeMillis() / 500 % (double) entryStacks.size()) / 1f));
+        return entryStacks.get(Mth.floor(((System.currentTimeMillis() + stackDisplayOffset) / 1000 % (double) entryStacks.size())));
     }
     
     @NotNull
@@ -364,6 +364,20 @@ public class EntryWidget extends Slot {
         return super.mouseClicked(mouseX, mouseY, button);
     }
     
+    @Override
+    public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
+        if (ScreenHelper.isWithinRecipeViewingScreen && entryStacks.size() > 1 && containsMouse(mouseX, mouseY)) {
+            if (amount < 0) {
+                EntryWidget.stackDisplayOffset += 500;
+                return true;
+            } else if (amount > 0) {
+                EntryWidget.stackDisplayOffset -= 500;
+                return true;
+            }
+        }
+        return false;
+    }
+    
     @Override
     public boolean mouseReleased(double mouseX, double mouseY, int button) {
         if (!interactable)

+ 2 - 0
RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java

@@ -64,6 +64,8 @@ import static me.shedaniel.rei.impl.Internals.attachInstance;
 @ApiStatus.Internal
 @Environment(EnvType.CLIENT)
 public class ScreenHelper implements ClientModInitializer, REIHelper {
+    @ApiStatus.Internal
+    public static boolean isWithinRecipeViewingScreen = false;
     private static final ResourceLocation DISPLAY_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/display.png");
     private static final ResourceLocation DISPLAY_TEXTURE_DARK = new ResourceLocation("roughlyenoughitems", "textures/gui/display_dark.png");
     private OverlaySearchField searchField;

+ 1 - 1
RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/widgets/BurningFireWidget.java

@@ -68,7 +68,7 @@ public final class BurningFireWidget extends BurningFire {
         Minecraft.getInstance().getTextureManager().bind(REIHelper.getInstance().getDefaultDisplayTexture());
         blit(matrices, getX(), getY(), 1, 74, 14, 14);
         if (getAnimationDuration() > 0) {
-            int height = 14 - Mth.ceil((System.currentTimeMillis() / (animationDuration / 14) % 14d) / 1f);
+            int height = 14 - Mth.ceil((System.currentTimeMillis() / (animationDuration / 14) % 14d));
             blit(matrices, getX(), getY() + 14 - height, 82, 77 + (14 - height), 14, height);
         }
     }

+ 1 - 1
gradle.properties

@@ -1,5 +1,5 @@
 org.gradle.jvmargs=-Xmx3G
-mod_version=5.8.7
+mod_version=5.8.8
 supported_version=1.16.2/3/4
 minecraft_version=1.16.4
 fabricloader_version=0.10.6+build.214