diff options
| author | shedaniel <daniel@shedaniel.me> | 2020-12-06 19:47:10 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2020-12-06 19:47:10 +0800 |
| commit | 1db55469d98948dbffedeaf94d21df5dd58c7496 (patch) | |
| tree | 156ac1353b1ed08bcdcaf39008ba4b2adbcb1ea3 /RoughlyEnoughItems-runtime/src/main/java/me | |
| parent | d27702349f1ee0dd4222e08dbd133ad7a80589b5 (diff) | |
| download | RoughlyEnoughItems-1db55469d98948dbffedeaf94d21df5dd58c7496.tar.gz RoughlyEnoughItems-1db55469d98948dbffedeaf94d21df5dd58c7496.tar.bz2 RoughlyEnoughItems-1db55469d98948dbffedeaf94d21df5dd58c7496.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/java/me')
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 9d1d572b6..60ff88f70 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.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() { 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 ebe5c1080..bcc21caa7 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 @@ -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 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 cda292f4c..36a18ac78 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 (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++; 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 4456a0ead..b977551e2 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 @@ -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 @@ -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 a57af0f7b..767ef019b 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 @@ -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; 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 e0328f0df..fe47d9290 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 - 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); } } |
