aboutsummaryrefslogtreecommitdiff
path: root/RoughlyEnoughItems-runtime/src/main
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2020-12-06 19:47:10 +0800
committershedaniel <daniel@shedaniel.me>2021-01-21 09:17:44 +0800
commit261367a968c01ad287d0ba6bdd5e242bde5c55de (patch)
treee86c1bd736336de26594be976b16398564780e96 /RoughlyEnoughItems-runtime/src/main
parent69b212314d50f3b3e031a81a85d3becfc877c76a (diff)
downloadRoughlyEnoughItems-261367a968c01ad287d0ba6bdd5e242bde5c55de.tar.gz
RoughlyEnoughItems-261367a968c01ad287d0ba6bdd5e242bde5c55de.tar.bz2
RoughlyEnoughItems-261367a968c01ad287d0ba6bdd5e242bde5c55de.zip
Slow down stack rotating, and allowing users to scroll through the stacks.
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'RoughlyEnoughItems-runtime/src/main')
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java15
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java14
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java10
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryWidget.java20
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java2
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/widgets/BurningFireWidget.java2
6 files changed, 42 insertions, 21 deletions
diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
index 17a861146..9571f0bc0 100644
--- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
+++ b/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.clothconfig2.forge.api.LazyResettable;
@@ -99,9 +100,8 @@ import static me.shedaniel.rei.impl.Internals.attachInstance;
@ApiStatus.Internal
@OnlyIn(Dist.CLIENT)
public class RoughlyEnoughItemsCore {
-
@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;
@@ -298,20 +298,17 @@ public class RoughlyEnoughItemsCore {
*/
@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() {
diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java
index 4c6f302c3..82e0ad46f 100644
--- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java
+++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java
@@ -72,7 +72,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();
@@ -519,10 +518,15 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen {
}
@Override
- public boolean mouseScrolled(double i, double j, double amount) {
- for (IGuiEventListener listener : children())
- if (listener.mouseScrolled(i, j, amount))
+ public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
+ ScreenHelper.isWithinRecipeViewingScreen = true;
+ for (IGuiEventListener 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();
@@ -535,7 +539,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
diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java
index c3133d362..d02677b50 100644
--- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java
+++ b/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 (IGuiEventListener listener : children())
- if (listener.mouseScrolled(mouseX, mouseY, amount))
+ ScreenHelper.isWithinRecipeViewingScreen = true;
+ for (IGuiEventListener 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++;
diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryWidget.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryWidget.java
index 355b62832..471c19606 100644
--- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryWidget.java
+++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryWidget.java
@@ -35,7 +35,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.IGuiEventListener;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.InputMappings;
@@ -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(MathHelper.floor((System.currentTimeMillis() / 500 % (double) entryStacks.size()) / 1f));
+ return entryStacks.get(MathHelper.floor(((System.currentTimeMillis() + stackDisplayOffset) / 1000 % (double) entryStacks.size())));
}
@NotNull
@@ -365,6 +365,20 @@ public class EntryWidget extends Slot {
}
@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)
return false;
diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java
index 9ebc8dfb1..478b87afd 100644
--- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java
+++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java
@@ -62,6 +62,8 @@ import static me.shedaniel.rei.impl.Internals.attachInstance;
@ApiStatus.Internal
@OnlyIn(Dist.CLIENT)
public class ScreenHelper implements 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;
diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/widgets/BurningFireWidget.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/widgets/BurningFireWidget.java
index 6a27993bd..6ec680c06 100644
--- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/widgets/BurningFireWidget.java
+++ b/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 - MathHelper.ceil((System.currentTimeMillis() / (animationDuration / 14) % 14d) / 1f);
+ int height = 14 - MathHelper.ceil((System.currentTimeMillis() / (animationDuration / 14) % 14d));
blit(matrices, getX(), getY() + 14 - height, 82, 77 + (14 - height), 14, height);
}
}