From 5357ec90f80768b69b197161e877e3ef884650a4 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 7 May 2019 18:30:54 +0800 Subject: 2.8.2 Build 104 Fixed #81 Close #82 Close #83 --- .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 2 +- .../java/me/shedaniel/rei/api/ClientHelper.java | 47 +++++ .../java/me/shedaniel/rei/api/DisplayHelper.java | 8 + .../me/shedaniel/rei/api/DisplayVisibility.java | 5 +- .../me/shedaniel/rei/api/ItemCheatingMode.java | 3 +- .../java/me/shedaniel/rei/api/PluginFunction.java | 7 +- .../java/me/shedaniel/rei/api/RecipeHelper.java | 3 + .../rei/client/BaseBoundsHandlerImpl.java | 29 ++- .../java/me/shedaniel/rei/client/ClientHelper.java | 162 ----------------- .../me/shedaniel/rei/client/ClientHelperImpl.java | 200 +++++++++++++++++++++ .../java/me/shedaniel/rei/client/ConfigObject.java | 27 ++- .../me/shedaniel/rei/client/DisplayHelperImpl.java | 40 +++-- .../me/shedaniel/rei/client/ItemListOrdering.java | 4 +- .../me/shedaniel/rei/client/RecipeHelperImpl.java | 37 ++-- .../me/shedaniel/rei/client/SearchArgument.java | 7 +- src/main/java/me/shedaniel/rei/client/Weather.java | 4 +- .../shedaniel/rei/gui/ContainerScreenOverlay.java | 50 ++++-- .../me/shedaniel/rei/gui/RecipeViewingScreen.java | 16 +- .../rei/gui/config/ItemListOrderingConfig.java | 7 +- .../shedaniel/rei/gui/widget/ItemListOverlay.java | 37 ++-- .../shedaniel/rei/gui/widget/ItemSlotWidget.java | 16 +- .../me/shedaniel/rei/gui/widget/LabelWidget.java | 1 - .../rei/gui/widget/SearchFieldWidget.java | 11 ++ .../shedaniel/rei/mixin/MixinContainerScreen.java | 15 +- .../mixin/MixinCreativePlayerInventoryScreen.java | 3 +- .../me/shedaniel/rei/mixin/MixinRecipeBookGui.java | 11 +- .../me/shedaniel/rei/plugin/DefaultPlugin.java | 9 +- .../shedaniel/rei/utils/ClothScreenRegistry.java | 3 +- 28 files changed, 460 insertions(+), 304 deletions(-) create mode 100644 src/main/java/me/shedaniel/rei/api/ClientHelper.java delete mode 100644 src/main/java/me/shedaniel/rei/client/ClientHelper.java create mode 100644 src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java (limited to 'src/main/java') diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index fbcf11103..657ec3018 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -208,7 +208,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { }); ClothClientHooks.SCREEN_MOUSE_SCROLLED.register((minecraftClient, screen, v, v1, v2) -> { if (screen instanceof ContainerScreen) - if (ScreenHelper.isOverlayVisible() && ScreenHelper.getLastOverlay().getRectangle().contains(ClientUtils.getMouseLocation()) && ScreenHelper.getLastOverlay().mouseScrolled(v, v1, v2)) + if (ScreenHelper.isOverlayVisible() && ScreenHelper.getLastOverlay().isInside(ClientUtils.getMouseLocation()) && ScreenHelper.getLastOverlay().mouseScrolled(v, v1, v2)) return ActionResult.SUCCESS; return ActionResult.PASS; }); diff --git a/src/main/java/me/shedaniel/rei/api/ClientHelper.java b/src/main/java/me/shedaniel/rei/api/ClientHelper.java new file mode 100644 index 000000000..86c234872 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/ClientHelper.java @@ -0,0 +1,47 @@ +package me.shedaniel.rei.api; + +import me.shedaniel.rei.client.ClientHelperImpl; +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +import java.util.List; + +public interface ClientHelper extends ClientModInitializer { + static ClientHelper getInstance() { + return ClientHelperImpl.instance; + } + + boolean isCheating(); + + void setCheating(boolean cheating); + + List getInventoryItemsTypes(); + + void registerFabricKeyBinds(); + + boolean tryCheatingStack(ItemStack stack); + + boolean executeRecipeKeyBind(ItemStack stack); + + boolean executeUsageKeyBind(ItemStack stack); + + String getModFromItem(Item item); + + void sendDeletePacket(); + + String getFormattedModFromItem(Item item); + + FabricKeyBinding getRecipeKeyBinding(); + + FabricKeyBinding getUsageKeyBinding(); + + FabricKeyBinding getHideKeyBinding(); + + FabricKeyBinding getPreviousPageKeyBinding(); + + FabricKeyBinding getNextPageKeyBinding(); + + boolean executeViewAllRecipesKeyBind(); +} diff --git a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java index 5d4fda8a4..8234c20b3 100644 --- a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java +++ b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java @@ -12,6 +12,8 @@ public interface DisplayHelper { List getSortedBoundsHandlers(Class screenClass); + List getAllBoundsHandlers(); + DisplayBoundsHandler getResponsibleBoundsHandler(Class screenClass); void registerBoundsHandler(DisplayBoundsHandler handler); @@ -19,6 +21,8 @@ public interface DisplayHelper { BaseBoundsHandler getBaseBoundsHandler(); public static interface DisplayBoundsHandler { + public static final Rectangle EMPTY = new Rectangle(); + Class getBaseSupportedClass(); Rectangle getLeftBounds(T screen); @@ -29,6 +33,10 @@ public interface DisplayHelper { return PASS; } + default ActionResult isInZone(boolean isOnRightSide, double mouseX, double mouseY) { + return PASS; + } + default Rectangle getItemListArea(Rectangle rectangle) { return new Rectangle(rectangle.x + 2, rectangle.y + 24, rectangle.width - 4, rectangle.height - (RoughlyEnoughItemsCore.getConfigManager().getConfig().sideSearchField ? 27 + 22 : 27)); } diff --git a/src/main/java/me/shedaniel/rei/api/DisplayVisibility.java b/src/main/java/me/shedaniel/rei/api/DisplayVisibility.java index 231f3efb5..8195d88a0 100644 --- a/src/main/java/me/shedaniel/rei/api/DisplayVisibility.java +++ b/src/main/java/me/shedaniel/rei/api/DisplayVisibility.java @@ -1,5 +1,8 @@ package me.shedaniel.rei.api; public enum DisplayVisibility { - ALWAYS_VISIBLE, CONFIG_OPTIONAL, NEVER_VISIBLE, PASS + ALWAYS_VISIBLE, + CONFIG_OPTIONAL, + NEVER_VISIBLE, + PASS } diff --git a/src/main/java/me/shedaniel/rei/api/ItemCheatingMode.java b/src/main/java/me/shedaniel/rei/api/ItemCheatingMode.java index ba9f73b77..41d5e5ead 100644 --- a/src/main/java/me/shedaniel/rei/api/ItemCheatingMode.java +++ b/src/main/java/me/shedaniel/rei/api/ItemCheatingMode.java @@ -1,5 +1,6 @@ package me.shedaniel.rei.api; public enum ItemCheatingMode { - REI_LIKE, JEI_LIKE; + REI_LIKE, + JEI_LIKE; } diff --git a/src/main/java/me/shedaniel/rei/api/PluginFunction.java b/src/main/java/me/shedaniel/rei/api/PluginFunction.java index f69f347d5..67e460a70 100644 --- a/src/main/java/me/shedaniel/rei/api/PluginFunction.java +++ b/src/main/java/me/shedaniel/rei/api/PluginFunction.java @@ -1,5 +1,10 @@ package me.shedaniel.rei.api; public enum PluginFunction { - REGISTER_ITEMS, REGISTER_CATEGORIES, REGISTER_RECIPE_DISPLAYS, REGISTER_SPEED_CRAFT, REGISTER_BOUNDS, REGISTER_OTHERS; + REGISTER_ITEMS, + REGISTER_CATEGORIES, + REGISTER_RECIPE_DISPLAYS, + REGISTER_SPEED_CRAFT, + REGISTER_BOUNDS, + REGISTER_OTHERS; } diff --git a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java index b7e3f2206..4b0fde018 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java @@ -2,6 +2,7 @@ package me.shedaniel.rei.api; import me.shedaniel.rei.RoughlyEnoughItemsCore; import net.minecraft.item.ItemStack; +import net.minecraft.recipe.Recipe; import net.minecraft.recipe.RecipeManager; import net.minecraft.util.Identifier; @@ -17,6 +18,8 @@ public interface RecipeHelper { int getRecipeCount(); + List getVanillaSortedRecipes(); + List findCraftableByItems(List inventoryItems); void registerCategory(RecipeCategory category); diff --git a/src/main/java/me/shedaniel/rei/client/BaseBoundsHandlerImpl.java b/src/main/java/me/shedaniel/rei/client/BaseBoundsHandlerImpl.java index 0567f6e16..9b64a5708 100644 --- a/src/main/java/me/shedaniel/rei/client/BaseBoundsHandlerImpl.java +++ b/src/main/java/me/shedaniel/rei/client/BaseBoundsHandlerImpl.java @@ -38,12 +38,12 @@ public class BaseBoundsHandlerImpl implements BaseBoundsHandler { @Override public Rectangle getLeftBounds(Screen screen) { - return new Rectangle(); + return DisplayHelper.DisplayBoundsHandler.EMPTY; } @Override public Rectangle getRightBounds(Screen screen) { - return new Rectangle(); + return DisplayHelper.DisplayBoundsHandler.EMPTY; } @Override @@ -51,21 +51,34 @@ public class BaseBoundsHandlerImpl implements BaseBoundsHandler { return -5f; } + @Override + public ActionResult isInZone(boolean isOnRightSide, double mouseX, double mouseY) { + for(Rectangle zone : getCurrentExclusionZones(MinecraftClient.getInstance().currentScreen.getClass(), isOnRightSide)) + if (zone.contains(mouseX, mouseY)) + return ActionResult.FAIL; + return ActionResult.PASS; + } + @Override public boolean shouldRecalculateArea(boolean isOnRightSide, Rectangle rectangle) { if (lastArea == null) { - DisplayHelper.DisplayBoundsHandler handler = RoughlyEnoughItemsCore.getDisplayHelper().getResponsibleBoundsHandler(MinecraftClient.getInstance().currentScreen.getClass()); - lastArea = getStringFromAreas(isOnRightSide ? handler.getRightBounds(MinecraftClient.getInstance().currentScreen) : handler.getLeftBounds(MinecraftClient.getInstance().currentScreen), getCurrentExclusionZones(MinecraftClient.getInstance().currentScreen.getClass(), isOnRightSide)); + lastArea = getStringFromCurrent(isOnRightSide); return false; } - DisplayHelper.DisplayBoundsHandler handler = RoughlyEnoughItemsCore.getDisplayHelper().getResponsibleBoundsHandler(MinecraftClient.getInstance().currentScreen.getClass()); - String fromAreas = getStringFromAreas(isOnRightSide ? handler.getRightBounds(MinecraftClient.getInstance().currentScreen) : handler.getLeftBounds(MinecraftClient.getInstance().currentScreen), getCurrentExclusionZones(MinecraftClient.getInstance().currentScreen.getClass(), isOnRightSide)); - if (lastArea.contentEquals(fromAreas)) + if (lastArea.contentEquals(getStringFromCurrent(isOnRightSide))) return false; - lastArea = fromAreas; + lastArea = getStringFromCurrent(isOnRightSide); return true; } + private DisplayHelper.DisplayBoundsHandler getHandler() { + return RoughlyEnoughItemsCore.getDisplayHelper().getResponsibleBoundsHandler(MinecraftClient.getInstance().currentScreen.getClass()); + } + + private String getStringFromCurrent(boolean isOnRightSide) { + return getStringFromAreas(isOnRightSide ? getHandler().getRightBounds(MinecraftClient.getInstance().currentScreen) : getHandler().getLeftBounds(MinecraftClient.getInstance().currentScreen), getCurrentExclusionZones(MinecraftClient.getInstance().currentScreen.getClass(), isOnRightSide)); + } + @Override public ActionResult canItemSlotWidgetFit(boolean isOnRightSide, int left, int top, Screen screen, Rectangle fullBounds) { List currentExclusionZones = getCurrentExclusionZones(MinecraftClient.getInstance().currentScreen.getClass(), isOnRightSide); diff --git a/src/main/java/me/shedaniel/rei/client/ClientHelper.java b/src/main/java/me/shedaniel/rei/client/ClientHelper.java deleted file mode 100644 index 0a3484786..000000000 --- a/src/main/java/me/shedaniel/rei/client/ClientHelper.java +++ /dev/null @@ -1,162 +0,0 @@ -package me.shedaniel.rei.client; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Maps; -import io.netty.buffer.Unpooled; -import me.shedaniel.rei.RoughlyEnoughItemsCore; -import me.shedaniel.rei.RoughlyEnoughItemsNetwork; -import me.shedaniel.rei.api.RecipeCategory; -import me.shedaniel.rei.api.RecipeDisplay; -import me.shedaniel.rei.api.RecipeHelper; -import me.shedaniel.rei.gui.RecipeViewingScreen; -import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; -import net.fabricmc.fabric.api.network.ClientSidePacketRegistry; -import net.fabricmc.fabric.impl.client.keybinding.KeyBindingRegistryImpl; -import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.api.ModContainer; -import net.fabricmc.loader.api.metadata.ModMetadata; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.ingame.CreativePlayerInventoryScreen; -import net.minecraft.client.util.InputUtil; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.text.TranslatableTextComponent; -import net.minecraft.util.DefaultedList; -import net.minecraft.util.Identifier; -import net.minecraft.util.PacketByteBuf; -import net.minecraft.util.registry.Registry; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -public class ClientHelper implements ClientModInitializer { - - private static final Identifier RECIPE_KEYBIND = new Identifier("roughlyenoughitems", "recipe_keybind"); - private static final Identifier USAGE_KEYBIND = new Identifier("roughlyenoughitems", "usage_keybind"); - private static final Identifier HIDE_KEYBIND = new Identifier("roughlyenoughitems", "hide_keybind"); - private static final Map MOD_NAME_CACHE = Maps.newHashMap(); - public static FabricKeyBinding RECIPE, USAGE, HIDE; - - static { - MOD_NAME_CACHE.put("minecraft", "Minecraft"); - MOD_NAME_CACHE.put("c", "Common"); - } - - public static String getFormattedModFromItem(Item item) { - String mod = getModFromItem(item); - if (mod.equalsIgnoreCase("")) - return ""; - return "§9§o" + mod; - } - - public static String getModFromItem(Item item) { - if (item.equals(Items.AIR)) - return ""; - return getModFromIdentifier(Registry.ITEM.getId(item)); - } - - public static String getModFromIdentifier(Identifier identifier) { - if (identifier == null) - return ""; - Optional any = Optional.ofNullable(MOD_NAME_CACHE.getOrDefault(identifier.getNamespace(), null)); - if (any.isPresent()) - return any.get(); - String modid = identifier.getNamespace(); - String s = FabricLoader.getInstance().getModContainer(modid).map(ModContainer::getMetadata).map(ModMetadata::getName).orElse(modid); - MOD_NAME_CACHE.put(modid, s); - return s; - } - - public static boolean isCheating() { - return RoughlyEnoughItemsCore.getConfigManager().getConfig().cheating; - } - - public static void setCheating(boolean cheating) { - RoughlyEnoughItemsCore.getConfigManager().getConfig().cheating = cheating; - try { - RoughlyEnoughItemsCore.getConfigManager().saveConfig(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public static void sendDeletePacket() { - if (ScreenHelper.getLastContainerScreen() instanceof CreativePlayerInventoryScreen) { - MinecraftClient.getInstance().player.inventory.setCursorStack(ItemStack.EMPTY); - return; - } - ClientSidePacketRegistry.INSTANCE.sendToServer(RoughlyEnoughItemsNetwork.DELETE_ITEMS_PACKET, new PacketByteBuf(Unpooled.buffer())); - } - - public static boolean tryCheatingStack(ItemStack cheatedStack) { - if (RoughlyEnoughItemsCore.canUsePackets()) { - try { - ClientSidePacketRegistry.INSTANCE.sendToServer(RoughlyEnoughItemsNetwork.CREATE_ITEMS_PACKET, new PacketByteBuf(Unpooled.buffer()).writeItemStack(cheatedStack.copy())); - return true; - } catch (Exception e) { - return false; - } - } else { - Identifier identifier = Registry.ITEM.getId(cheatedStack.getItem()); - String tagMessage = cheatedStack.copy().getTag() != null && !cheatedStack.copy().getTag().isEmpty() ? cheatedStack.copy().getTag().asString() : ""; - String og = cheatedStack.getAmount() != 1 ? RoughlyEnoughItemsCore.getConfigManager().getConfig().giveCommand.replaceAll(" \\{count}", "").replaceAll("\\{count}", "") : RoughlyEnoughItemsCore.getConfigManager().getConfig().giveCommand; - String madeUpCommand = og.replaceAll("\\{player_name}", MinecraftClient.getInstance().player.getEntityName()).replaceAll("\\{item_identifier}", identifier.toString()).replaceAll("\\{nbt}", tagMessage).replaceAll("\\{count}", String.valueOf(cheatedStack.getAmount())); - if (madeUpCommand.length() > 256) { - madeUpCommand = og.replaceAll("\\{player_name}", MinecraftClient.getInstance().player.getEntityName()).replaceAll("\\{item_identifier}", identifier.toString()).replaceAll("\\{nbt}", "").replaceAll("\\{count}", String.valueOf(cheatedStack.getAmount())); - MinecraftClient.getInstance().player.addChatMessage(new TranslatableTextComponent("text.rei.too_long_nbt"), false); - } - MinecraftClient.getInstance().player.sendChatMessage(madeUpCommand); - return true; - } - } - - public static boolean executeRecipeKeyBind(ItemStack stack) { - Map> map = RecipeHelper.getInstance().getRecipesFor(stack); - if (map.keySet().size() > 0) - MinecraftClient.getInstance().openScreen(new RecipeViewingScreen(MinecraftClient.getInstance().window, map)); - return map.keySet().size() > 0; - } - - public static boolean executeUsageKeyBind(ItemStack stack) { - Map> map = RecipeHelper.getInstance().getUsagesFor(stack); - if (map.keySet().size() > 0) - MinecraftClient.getInstance().openScreen(new RecipeViewingScreen(MinecraftClient.getInstance().window, map)); - return map.keySet().size() > 0; - } - - public static List getInventoryItemsTypes() { - List> field_7543 = ImmutableList.of(MinecraftClient.getInstance().player.inventory.main, MinecraftClient.getInstance().player.inventory.armor, MinecraftClient.getInstance().player.inventory.offHand); - List inventoryStacks = new ArrayList<>(); - field_7543.forEach(itemStacks -> itemStacks.forEach(itemStack -> { - if (!itemStack.isEmpty()) - inventoryStacks.add(itemStack); - })); - return inventoryStacks; - } - - public static boolean executeViewAllRecipesKeyBind() { - Map> map = RecipeHelper.getInstance().getAllRecipes(); - if (map.keySet().size() > 0) - MinecraftClient.getInstance().openScreen(new RecipeViewingScreen(MinecraftClient.getInstance().window, map)); - return map.keySet().size() > 0; - } - - @Override - public void onInitializeClient() { - registerFabricKeyBinds(); - } - - private void registerFabricKeyBinds() { - String category = "key.rei.category"; - KeyBindingRegistryImpl.INSTANCE.addCategory(category); - KeyBindingRegistryImpl.INSTANCE.register(RECIPE = FabricKeyBinding.Builder.create(RECIPE_KEYBIND, InputUtil.Type.KEYSYM, 82, category).build()); - KeyBindingRegistryImpl.INSTANCE.register(USAGE = FabricKeyBinding.Builder.create(USAGE_KEYBIND, InputUtil.Type.KEYSYM, 85, category).build()); - KeyBindingRegistryImpl.INSTANCE.register(HIDE = FabricKeyBinding.Builder.create(HIDE_KEYBIND, InputUtil.Type.KEYSYM, 79, category).build()); - } - -} diff --git a/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java b/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java new file mode 100644 index 000000000..febe35b4e --- /dev/null +++ b/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java @@ -0,0 +1,200 @@ +package me.shedaniel.rei.client; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Maps; +import io.netty.buffer.Unpooled; +import me.shedaniel.rei.RoughlyEnoughItemsCore; +import me.shedaniel.rei.RoughlyEnoughItemsNetwork; +import me.shedaniel.rei.api.ClientHelper; +import me.shedaniel.rei.api.RecipeCategory; +import me.shedaniel.rei.api.RecipeDisplay; +import me.shedaniel.rei.api.RecipeHelper; +import me.shedaniel.rei.gui.RecipeViewingScreen; +import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; +import net.fabricmc.fabric.api.network.ClientSidePacketRegistry; +import net.fabricmc.fabric.impl.client.keybinding.KeyBindingRegistryImpl; +import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.loader.api.ModContainer; +import net.fabricmc.loader.api.metadata.ModMetadata; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.ingame.CreativePlayerInventoryScreen; +import net.minecraft.client.util.InputUtil; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.text.TranslatableTextComponent; +import net.minecraft.util.DefaultedList; +import net.minecraft.util.Identifier; +import net.minecraft.util.PacketByteBuf; +import net.minecraft.util.registry.Registry; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +public class ClientHelperImpl implements ClientHelper { + + public static ClientHelperImpl instance; + private final Identifier recipeKeybind = new Identifier("roughlyenoughitems", "recipe_keybind"); + private final Identifier usageKeybind = new Identifier("roughlyenoughitems", "usage_keybind"); + private final Identifier hideKeybind = new Identifier("roughlyenoughitems", "hide_keybind"); + private final Identifier previousPageKeybind = new Identifier("roughlyenoughitems", "previous_page"); + private final Identifier nextPageKeybind = new Identifier("roughlyenoughitems", "next_page"); + private final Map modNameCache = Maps.newHashMap(); + public FabricKeyBinding recipe, usage, hide, previousPage, nextPage; + + @Override + public String getFormattedModFromItem(Item item) { + String mod = getModFromItem(item); + if (mod.equalsIgnoreCase("")) + return ""; + return "§9§o" + mod; + } + + @Override + public FabricKeyBinding getRecipeKeyBinding() { + return recipe; + } + + @Override + public FabricKeyBinding getUsageKeyBinding() { + return usage; + } + + @Override + public FabricKeyBinding getHideKeyBinding() { + return hide; + } + + @Override + public FabricKeyBinding getPreviousPageKeyBinding() { + return previousPage; + } + + @Override + public FabricKeyBinding getNextPageKeyBinding() { + return nextPage; + } + + public String getModFromItem(Item item) { + if (item.equals(Items.AIR)) + return ""; + return getModFromIdentifier(Registry.ITEM.getId(item)); + } + + public String getModFromIdentifier(Identifier identifier) { + if (identifier == null) + return ""; + Optional any = Optional.ofNullable(modNameCache.getOrDefault(identifier.getNamespace(), null)); + if (any.isPresent()) + return any.get(); + String modid = identifier.getNamespace(); + String s = FabricLoader.getInstance().getModContainer(modid).map(ModContainer::getMetadata).map(ModMetadata::getName).orElse(modid); + modNameCache.put(modid, s); + return s; + } + + @Override + public boolean isCheating() { + return RoughlyEnoughItemsCore.getConfigManager().getConfig().cheating; + } + + @Override + public void setCheating(boolean cheating) { + RoughlyEnoughItemsCore.getConfigManager().getConfig().cheating = cheating; + try { + RoughlyEnoughItemsCore.getConfigManager().saveConfig(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void sendDeletePacket() { + if (ScreenHelper.getLastContainerScreen() instanceof CreativePlayerInventoryScreen) { + MinecraftClient.getInstance().player.inventory.setCursorStack(ItemStack.EMPTY); + return; + } + ClientSidePacketRegistry.INSTANCE.sendToServer(RoughlyEnoughItemsNetwork.DELETE_ITEMS_PACKET, new PacketByteBuf(Unpooled.buffer())); + } + + @Override + public boolean tryCheatingStack(ItemStack cheatedStack) { + if (RoughlyEnoughItemsCore.canUsePackets()) { + try { + ClientSidePacketRegistry.INSTANCE.sendToServer(RoughlyEnoughItemsNetwork.CREATE_ITEMS_PACKET, new PacketByteBuf(Unpooled.buffer()).writeItemStack(cheatedStack.copy())); + return true; + } catch (Exception e) { + return false; + } + } else { + Identifier identifier = Registry.ITEM.getId(cheatedStack.getItem()); + String tagMessage = cheatedStack.copy().getTag() != null && !cheatedStack.copy().getTag().isEmpty() ? cheatedStack.copy().getTag().asString() : ""; + String og = cheatedStack.getAmount() != 1 ? RoughlyEnoughItemsCore.getConfigManager().getConfig().giveCommand.replaceAll(" \\{count}", "").replaceAll("\\{count}", "") : RoughlyEnoughItemsCore.getConfigManager().getConfig().giveCommand; + String madeUpCommand = og.replaceAll("\\{player_name}", MinecraftClient.getInstance().player.getEntityName()).replaceAll("\\{item_identifier}", identifier.toString()).replaceAll("\\{nbt}", tagMessage).replaceAll("\\{count}", String.valueOf(cheatedStack.getAmount())); + if (madeUpCommand.length() > 256) { + madeUpCommand = og.replaceAll("\\{player_name}", MinecraftClient.getInstance().player.getEntityName()).replaceAll("\\{item_identifier}", identifier.toString()).replaceAll("\\{nbt}", "").replaceAll("\\{count}", String.valueOf(cheatedStack.getAmount())); + MinecraftClient.getInstance().player.addChatMessage(new TranslatableTextComponent("text.rei" + ".too_long_nbt"), false); + } + MinecraftClient.getInstance().player.sendChatMessage(madeUpCommand); + return true; + } + } + + @Override + public boolean executeRecipeKeyBind(ItemStack stack) { + Map> map = RecipeHelper.getInstance().getRecipesFor(stack); + if (map.keySet().size() > 0) + MinecraftClient.getInstance().openScreen(new RecipeViewingScreen(MinecraftClient.getInstance().window, map)); + return map.keySet().size() > 0; + } + + @Override + public boolean executeUsageKeyBind(ItemStack stack) { + Map> map = RecipeHelper.getInstance().getUsagesFor(stack); + if (map.keySet().size() > 0) + MinecraftClient.getInstance().openScreen(new RecipeViewingScreen(MinecraftClient.getInstance().window, map)); + return map.keySet().size() > 0; + } + + @Override + public List getInventoryItemsTypes() { + List> field_7543 = ImmutableList.of(MinecraftClient.getInstance().player.inventory.main, MinecraftClient.getInstance().player.inventory.armor, MinecraftClient.getInstance().player.inventory.offHand); + List inventoryStacks = new ArrayList<>(); + field_7543.forEach(itemStacks -> itemStacks.forEach(itemStack -> { + if (!itemStack.isEmpty()) + inventoryStacks.add(itemStack); + })); + return inventoryStacks; + } + + @Override + public boolean executeViewAllRecipesKeyBind() { + Map> map = RecipeHelper.getInstance().getAllRecipes(); + if (map.keySet().size() > 0) + MinecraftClient.getInstance().openScreen(new RecipeViewingScreen(MinecraftClient.getInstance().window, map)); + return map.keySet().size() > 0; + } + + @Override + public void onInitializeClient() { + ClientHelperImpl.instance = (ClientHelperImpl) this; + registerFabricKeyBinds(); + modNameCache.put("minecraft", "Minecraft"); + modNameCache.put("c", "Common"); + } + + @Override + public void registerFabricKeyBinds() { + String category = "key.rei.category"; + KeyBindingRegistryImpl.INSTANCE.addCategory(category); + KeyBindingRegistryImpl.INSTANCE.register(recipe = FabricKeyBinding.Builder.create(recipeKeybind, InputUtil.Type.KEYSYM, 82, category).build()); + KeyBindingRegistryImpl.INSTANCE.register(usage = FabricKeyBinding.Builder.create(usageKeybind, InputUtil.Type.KEYSYM, 85, category).build()); + KeyBindingRegistryImpl.INSTANCE.register(hide = FabricKeyBinding.Builder.create(hideKeybind, InputUtil.Type.KEYSYM, 79, category).build()); + 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()); + } + +} diff --git a/src/main/java/me/shedaniel/rei/client/ConfigObject.java b/src/main/java/me/shedaniel/rei/client/ConfigObject.java index 7ee02b5fe..af100f3fc 100644 --- a/src/main/java/me/shedaniel/rei/client/ConfigObject.java +++ b/src/main/java/me/shedaniel/rei/client/ConfigObject.java @@ -11,8 +11,7 @@ public class ConfigObject { @Comment("The ordering of the items on the item panel.") public ItemListOrdering itemListOrdering = ItemListOrdering.registry; - @Comment("The ordering of the items on the item panel.") - public boolean isAscending = true; + @Comment("The ordering of the items on the item panel.") public boolean isAscending = true; @Comment("To toggle the craftable button next to the search field.") public boolean enableCraftableOnlyButton = true; @@ -23,40 +22,34 @@ public class ConfigObject { @Comment("The command used in servers to cheat items") public String giveCommand = "/give {player_name} {item_identifier}{nbt} {count}"; - @Comment("The command used to change gamemode") - public String gamemodeCommand = "/gamemode {gamemode}"; + @Comment("The command used to change gamemode") public String gamemodeCommand = "/gamemode {gamemode}"; - @Comment("The command used to change weather") - public String weatherCommand = "/weather {weather}"; + @Comment("The command used to change weather") public String weatherCommand = "/weather {weather}"; - @Comment("True: item panel on the left, false: on the right") - public boolean mirrorItemPanel = false; + @Comment("True: item panel on the left, false: on the right") public boolean mirrorItemPanel = false; @Comment("To disable REI's default plugin, don't change this unless you understand what you are doing") public boolean loadDefaultPlugin = true; - @Comment("Maximum recipes viewed at one time.") - public int maxRecipePerPage = 3; + @Comment("Maximum recipes viewed at one time.") public int maxRecipePerPage = 3; - @Comment("Toggle utils buttons") - public boolean showUtilsButtons = false; + @Comment("Toggle utils buttons") public boolean showUtilsButtons = false; - @Comment("Disable Recipe Book") - public boolean disableRecipeBook = false; + @Comment("Disable Recipe Book") public boolean disableRecipeBook = false; public boolean preferVisibleRecipes = false; // @Comment("Enable support for old REI plugins which uses registerSpeedCraft") // public boolean enableLegacySpeedCraftSupport = false; - @Comment("Force enable 2019 REI April Fools' joke") - public boolean aprilFoolsFish2019 = false; + @Comment("Force enable 2019 REI April Fools' joke") public boolean aprilFoolsFish2019 = false; public ItemCheatingMode itemCheatingMode = ItemCheatingMode.REI_LIKE; public boolean lightGrayRecipeBorder = false; - @Comment("The location of choose page dialog, will automatically be set to your last location so there is no need to change this.") + @Comment( + "The location of choose page dialog, will automatically be set to your last location so there is no need to change this.") public RelativePoint choosePageDialogPoint = new RelativePoint(.5, .5); } diff --git a/src/main/java/me/shedaniel/rei/client/DisplayHelperImpl.java b/src/main/java/me/shedaniel/rei/client/DisplayHelperImpl.java index 28c5f5e43..6ab47f79f 100644 --- a/src/main/java/me/shedaniel/rei/client/DisplayHelperImpl.java +++ b/src/main/java/me/shedaniel/rei/client/DisplayHelperImpl.java @@ -14,25 +14,21 @@ import java.util.stream.Collectors; public class DisplayHelperImpl implements DisplayHelper { - private static final Comparator BOUNDS_HANDLER_COMPARATOR = Comparator.comparingDouble(value -> { - if (value instanceof DisplayBoundsHandler) - return (double) ((DisplayBoundsHandler) value).getPriority(); - return -Double.MAX_VALUE; - }).reversed(); + private static final Comparator BOUNDS_HANDLER_COMPARATOR; private static final DisplayBoundsHandler EMPTY = new DisplayBoundsHandler() { @Override public Class getBaseSupportedClass() { - return null; + return Object.class; } @Override public Rectangle getLeftBounds(Object screen) { - return new Rectangle(); + return DisplayBoundsHandler.EMPTY; } @Override public Rectangle getRightBounds(Object screen) { - return new Rectangle(); + return DisplayBoundsHandler.EMPTY; } @Override @@ -40,30 +36,38 @@ public class DisplayHelperImpl implements DisplayHelper { return -10f; } }; - private List screenDisplayBoundsHandlerMap = Lists.newArrayList(); + + static { + Comparator comparator = Comparator.comparingDouble(DisplayBoundsHandler::getPriority); + BOUNDS_HANDLER_COMPARATOR = comparator.reversed(); + } + + private List screenDisplayBoundsHandlers = Lists.newArrayList(); private Map handlerCache = Maps.newHashMap(); private BaseBoundsHandler baseBoundsHandler; @Override public List getSortedBoundsHandlers(Class screenClass) { - List list = Lists.newArrayList(screenDisplayBoundsHandlerMap.stream().filter(handler -> handler.getBaseSupportedClass().isAssignableFrom(screenClass)).collect(Collectors.toList())); - list.sort(BOUNDS_HANDLER_COMPARATOR); - return list; + return screenDisplayBoundsHandlers.stream().filter(handler -> handler.getBaseSupportedClass().isAssignableFrom(screenClass)).sorted(BOUNDS_HANDLER_COMPARATOR).collect(Collectors.toList()); + } + + @Override + public List getAllBoundsHandlers() { + return screenDisplayBoundsHandlers; } @Override public DisplayBoundsHandler getResponsibleBoundsHandler(Class screenClass) { - Optional handler = handlerCache.entrySet().stream().filter(entry -> entry.getKey().equals(screenClass)).map(Map.Entry::getValue).findAny(); - if (handler.isPresent()) - return handler.get(); - List sortedBoundsHandlers = getSortedBoundsHandlers(screenClass); - handlerCache.put(screenClass, sortedBoundsHandlers.isEmpty() ? EMPTY : sortedBoundsHandlers.get(0)); + Optional any = handlerCache.entrySet().stream().filter(entry -> entry.getKey().equals(screenClass)).map(Map.Entry::getValue).findAny(); + if (any.isPresent()) + return any.get(); + handlerCache.put(screenClass, screenDisplayBoundsHandlers.stream().filter(handler -> handler.getBaseSupportedClass().isAssignableFrom(screenClass)).sorted(BOUNDS_HANDLER_COMPARATOR).findAny().orElse(EMPTY)); return handlerCache.get(screenClass); } @Override public void registerBoundsHandler(DisplayBoundsHandler handler) { - screenDisplayBoundsHandlerMap.add(handler); + screenDisplayBoundsHandlers.add(handler); } @Override diff --git a/src/main/java/me/shedaniel/rei/client/ItemListOrdering.java b/src/main/java/me/shedaniel/rei/client/ItemListOrdering.java index b9ef1f874..0c52c2f24 100644 --- a/src/main/java/me/shedaniel/rei/client/ItemListOrdering.java +++ b/src/main/java/me/shedaniel/rei/client/ItemListOrdering.java @@ -2,7 +2,9 @@ package me.shedaniel.rei.client; public enum ItemListOrdering { - registry("ordering.rei.registry"), name("ordering.rei.name"), item_groups("ordering.rei.item_groups"); + registry("ordering.rei.registry"), + name("ordering.rei.name"), + item_groups("ordering.rei.item_groups"); private String nameTranslationKey; diff --git a/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java b/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java index ec5b211d0..1f03ac8aa 100644 --- a/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java +++ b/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java @@ -5,6 +5,7 @@ import com.google.common.collect.Maps; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.*; import net.minecraft.item.ItemStack; +import net.minecraft.recipe.Recipe; import net.minecraft.recipe.RecipeManager; import net.minecraft.util.Identifier; @@ -16,11 +17,20 @@ import java.util.stream.Collectors; public class RecipeHelperImpl implements RecipeHelper { - private static final Comparator VISIBILITY_HANDLER_COMPARATOR = Comparator.comparingDouble(value -> { - if (value instanceof DisplayVisibilityHandler) - return (double) ((DisplayVisibilityHandler) value).getPriority(); - return -Double.MAX_VALUE; - }).reversed(); + private static final Comparator VISIBILITY_HANDLER_COMPARATOR; + private static final Comparator RECIPE_COMPARATOR = (o1, o2) -> { + int int_1 = o1.getId().getNamespace().compareTo(o2.getId().getNamespace()); + if (int_1 == 0) + int_1 = o1.getId().getPath().compareTo(o2.getId().getPath()); + return int_1; + }; + + static { + Comparator comparator = Comparator.comparingDouble(DisplayVisibilityHandler::getPriority); + VISIBILITY_HANDLER_COMPARATOR = comparator.reversed(); + } + + private final List sortedRecipes = new ArrayList<>(); private final AtomicInteger recipeCount = new AtomicInteger(); private final Map> recipeCategoryListMap = Maps.newHashMap(); private final Map categoryDisplaySettingsMap = Maps.newHashMap(); @@ -184,6 +194,7 @@ public class RecipeHelperImpl implements RecipeHelper { this.speedCraftFunctionalMap.clear(); this.categoryDisplaySettingsMap.clear(); this.displayVisibilityHandlers.clear(); + this.sortedRecipes.clear(); ((DisplayHelperImpl) RoughlyEnoughItemsCore.getDisplayHelper()).resetCache(); BaseBoundsHandler baseBoundsHandler = new BaseBoundsHandlerImpl(); RoughlyEnoughItemsCore.getDisplayHelper().registerBoundsHandler(baseBoundsHandler); @@ -214,7 +225,7 @@ public class RecipeHelperImpl implements RecipeHelper { RoughlyEnoughItemsCore.LOGGER.error("[REI] %s plugin failed to load: %s", identifier.toString(), e.getLocalizedMessage()); } }); - if (getDisplayVisibilityHandlers().size() == 0) + if (getDisplayVisibilityHandlers().isEmpty()) registerRecipeVisibilityHandler(new DisplayVisibilityHandler() { @Override public DisplayVisibility handleDisplay(RecipeCategory category, RecipeDisplay display) { @@ -227,7 +238,7 @@ public class RecipeHelperImpl implements RecipeHelper { } }); long usedTime = System.currentTimeMillis() - startTime; - RoughlyEnoughItemsCore.LOGGER.info("[REI] Registered %d recipes, %d categories (%s) in %d ms.", recipeCount.get(), categories.size(), String.join(", ", categories.stream().map(RecipeCategory::getCategoryName).collect(Collectors.toList())), usedTime); + RoughlyEnoughItemsCore.LOGGER.info("[REI] Registered %d recipes displays, %d bounds handler, %d visibility " + "handlers and %d categories (%s) in %d ms.", recipeCount.get(), RoughlyEnoughItemsCore.getDisplayHelper().getAllBoundsHandlers().size(), getDisplayVisibilityHandlers().size(), categories.size(), String.join(", ", categories.stream().map(RecipeCategory::getCategoryName).collect(Collectors.toList())), usedTime); } @Override @@ -235,6 +246,13 @@ public class RecipeHelperImpl implements RecipeHelper { return recipeCount.get(); } + @Override + public List getVanillaSortedRecipes() { + if (sortedRecipes.isEmpty()) + sortedRecipes.addAll(getRecipeManager().values().stream().sorted(RECIPE_COMPARATOR).collect(Collectors.toSet())); + return sortedRecipes; + } + @Override public Map> getAllRecipes() { Map> map = Maps.newLinkedHashMap(); @@ -244,7 +262,7 @@ public class RecipeHelperImpl implements RecipeHelper { if (tempMap.containsKey(category.getIdentifier())) map.put(category, tempMap.get(category.getIdentifier()).stream().filter(display -> isDisplayVisible(display, true)).collect(Collectors.toList())); }); - for(RecipeCategory category : Lists.newArrayList(map.keySet())) + for(RecipeCategory category : map.keySet()) if (map.get(category).isEmpty()) map.remove(category); return map; @@ -268,8 +286,7 @@ public class RecipeHelperImpl implements RecipeHelper { @Override public boolean isDisplayVisible(RecipeDisplay display, boolean respectConfig) { RecipeCategory category = getCategory(display.getRecipeCategory()); - List list = Lists.newArrayList(getDisplayVisibilityHandlers()); - list.sort((o1, o2) -> VISIBILITY_HANDLER_COMPARATOR.compare(o1, o2)); + List list = getDisplayVisibilityHandlers().stream().sorted(VISIBILITY_HANDLER_COMPARATOR).collect(Collectors.toList()); for(DisplayVisibilityHandler displayVisibilityHandler : list) { DisplayVisibility visibility = displayVisibilityHandler.handleDisplay(category, display); if (visibility != DisplayVisibility.PASS) { diff --git a/src/main/java/me/shedaniel/rei/client/SearchArgument.java b/src/main/java/me/shedaniel/rei/client/SearchArgument.java index 4d90848ca..4dbc39dce 100644 --- a/src/main/java/me/shedaniel/rei/client/SearchArgument.java +++ b/src/main/java/me/shedaniel/rei/client/SearchArgument.java @@ -1,5 +1,6 @@ package me.shedaniel.rei.client; +import java.util.Locale; import java.util.function.Function; import java.util.regex.Pattern; @@ -18,7 +19,7 @@ public class SearchArgument { public SearchArgument(ArgumentType argumentType, String text, boolean include, boolean autoLowerCase) { this.argumentType = argumentType; - this.text = autoLowerCase ? text.toLowerCase() : text; + this.text = autoLowerCase ? text.toLowerCase(Locale.ROOT) : text; this.include = include; } @@ -44,7 +45,9 @@ public class SearchArgument { } public enum ArgumentType { - TEXT, MOD, TOOLTIP + TEXT, + MOD, + TOOLTIP } } diff --git a/src/main/java/me/shedaniel/rei/client/Weather.java b/src/main/java/me/shedaniel/rei/client/Weather.java index f59cba7d4..e39cb37c9 100644 --- a/src/main/java/me/shedaniel/rei/client/Weather.java +++ b/src/main/java/me/shedaniel/rei/client/Weather.java @@ -1,7 +1,9 @@ package me.shedaniel.rei.client; public enum Weather { - CLEAR(0, "text.rei.weather.clear"), RAIN(1, "text.rei.weather.rain"), THUNDER(2, "text.rei.weather.thunder"); + CLEAR(0, "text.rei.weather.clear"), + RAIN(1, "text.rei.weather.rain"), + THUNDER(2, "text.rei.weather.thunder"); private final int id; private final String translateKey; diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java index 4e73fcaac..73bac395d 100644 --- a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java @@ -4,8 +4,8 @@ import com.google.common.collect.Lists; import com.mojang.blaze3d.platform.GlStateManager; import me.shedaniel.cloth.api.ClientUtils; import me.shedaniel.rei.RoughlyEnoughItemsCore; +import me.shedaniel.rei.api.ClientHelper; import me.shedaniel.rei.api.DisplayHelper; -import me.shedaniel.rei.client.ClientHelper; import me.shedaniel.rei.client.ScreenHelper; import me.shedaniel.rei.client.Weather; import me.shedaniel.rei.gui.widget.*; @@ -21,20 +21,19 @@ import net.minecraft.container.Slot; import net.minecraft.item.ItemStack; import net.minecraft.sound.SoundEvents; import net.minecraft.text.TranslatableTextComponent; +import net.minecraft.util.ActionResult; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; import net.minecraft.world.GameMode; import java.awt.*; -import java.util.LinkedList; +import java.util.*; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.stream.Collectors; public class ContainerScreenOverlay extends AbstractParentElement implements Drawable { - private static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png"); + private static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui" + "/recipecontainer.png"); private static final List QUEUED_TOOLTIPS = Lists.newArrayList(); public static String searchTerm = ""; private static int page = 0; @@ -110,7 +109,7 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra @Override public void onPressed() { if (Screen.hasShiftDown()) { - ClientHelper.setCheating(!ClientHelper.isCheating()); + ClientHelper.getInstance().setCheating(!ClientHelper.getInstance().isCheating()); return; } RoughlyEnoughItemsCore.getConfigManager().openConfigScreen(ScreenHelper.getLastContainerScreen()); @@ -120,7 +119,7 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra public void render(int mouseX, int mouseY, float delta) { super.render(mouseX, mouseY, delta); GuiLighting.disable(); - if (ClientHelper.isCheating() && RoughlyEnoughItemsCore.hasOperatorPermission()) { + if (ClientHelper.getInstance().isCheating() && RoughlyEnoughItemsCore.hasOperatorPermission()) { if (RoughlyEnoughItemsCore.hasPermissionToUsePackets()) fill(getBounds().x, getBounds().y, getBounds().x + 20, getBounds().y + 20, 721354752); else @@ -135,7 +134,7 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra public Optional getTooltips() { String tooltips = I18n.translate("text.rei.config_tooltip"); tooltips += "\n "; - if (!ClientHelper.isCheating()) + if (!ClientHelper.getInstance().isCheating()) tooltips += "\n" + I18n.translate("text.rei.cheating_disabled"); else if (!RoughlyEnoughItemsCore.hasOperatorPermission()) tooltips += "\n" + I18n.translate("text.rei.cheating_enabled_no_perms"); @@ -177,7 +176,7 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra widgets.add(new ButtonWidget(RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel ? window.getScaledWidth() - 80 : 60, 10, 20, 20, "") { @Override public void onPressed() { - MinecraftClient.getInstance().player.sendChatMessage(RoughlyEnoughItemsCore.getConfigManager().getConfig().weatherCommand.replaceAll("\\{weather}", getNextWeather().name().toLowerCase())); + MinecraftClient.getInstance().player.sendChatMessage(RoughlyEnoughItemsCore.getConfigManager().getConfig().weatherCommand.replaceAll("\\{weather}", getNextWeather().name().toLowerCase(Locale.ROOT))); } @Override @@ -318,7 +317,7 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra } private String getCheatModeText() { - return I18n.translate(String.format("%s%s", "text.rei.", ClientHelper.isCheating() ? "cheat" : "nocheat")); + return I18n.translate(String.format("%s%s", "text.rei.", ClientHelper.getInstance().isCheating() ? "cheat" : "nocheat")); } public Rectangle getRectangle() { @@ -327,11 +326,11 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra @Override public void render(int mouseX, int mouseY, float delta) { - List currentStacks = ClientHelper.getInventoryItemsTypes(); + List currentStacks = ClientHelper.getInstance().getInventoryItemsTypes(); if (RoughlyEnoughItemsCore.getDisplayHelper().getBaseBoundsHandler() != null && RoughlyEnoughItemsCore.getDisplayHelper().getBaseBoundsHandler().shouldRecalculateArea(!RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel, rectangle)) init(true); else if (RoughlyEnoughItemsCore.getConfigManager().isCraftableOnlyEnabled() && (!hasSameListContent(new LinkedList<>(ScreenHelper.inventoryStacks), currentStacks) || (currentStacks.size() != ScreenHelper.inventoryStacks.size()))) { - ScreenHelper.inventoryStacks = ClientHelper.getInventoryItemsTypes(); + ScreenHelper.inventoryStacks = ClientHelper.getInstance().getInventoryItemsTypes(); DisplayHelper.DisplayBoundsHandler boundsHandler = RoughlyEnoughItemsCore.getDisplayHelper().getResponsibleBoundsHandler(MinecraftClient.getInstance().currentScreen.getClass()); itemListOverlay.updateList(boundsHandler, boundsHandler.getItemListArea(rectangle), page, searchTerm, true); } @@ -446,7 +445,7 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra public boolean mouseScrolled(double i, double j, double amount) { if (!ScreenHelper.isOverlayVisible()) return false; - if (rectangle.contains(ClientUtils.getMouseLocation())) { + if (isInside(ClientUtils.getMouseLocation())) { if (amount > 0 && buttonLeft.enabled) buttonLeft.onPressed(); else if (amount < 0 && buttonRight.enabled) @@ -467,7 +466,7 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra for(Element listener : widgets) if (listener.keyPressed(int_1, int_2, int_3)) return true; - if (ClientHelper.HIDE.matchesKey(int_1, int_2)) { + if (ClientHelper.getInstance().getHideKeyBinding().matchesKey(int_1, int_2)) { ScreenHelper.toggleOverlayVisible(); return true; } @@ -478,10 +477,10 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra if (ScreenHelper.getLastContainerScreenHooks().rei_getHoveredSlot() != null && !ScreenHelper.getLastContainerScreenHooks().rei_getHoveredSlot().getStack().isEmpty()) itemStack = ScreenHelper.getLastContainerScreenHooks().rei_getHoveredSlot().getStack(); if (itemStack != null && !itemStack.isEmpty()) { - if (ClientHelper.RECIPE.matchesKey(int_1, int_2)) - return ClientHelper.executeRecipeKeyBind(itemStack); - else if (ClientHelper.USAGE.matchesKey(int_1, int_2)) - return ClientHelper.executeUsageKeyBind(itemStack); + if (ClientHelper.getInstance().getRecipeKeyBinding().matchesKey(int_1, int_2)) + return ClientHelper.getInstance().executeRecipeKeyBind(itemStack); + else if (ClientHelper.getInstance().getUsageKeyBinding().matchesKey(int_1, int_2)) + return ClientHelper.getInstance().executeUsageKeyBind(itemStack); } return false; } @@ -515,4 +514,19 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra return false; } + public boolean isInside(double mouseX, double mouseY) { + if (!rectangle.contains(mouseX, mouseY)) + return false; + for(DisplayHelper.DisplayBoundsHandler handler : RoughlyEnoughItemsCore.getDisplayHelper().getSortedBoundsHandlers(MinecraftClient.getInstance().currentScreen.getClass())) { + ActionResult in = handler.isInZone(!RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel, mouseX, mouseY); + if (in != ActionResult.PASS) + return in == ActionResult.SUCCESS; + } + return true; + } + + public boolean isInside(Point point) { + return isInside(point.getX(), point.getY()); + } + } diff --git a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java index 0f467f723..16af460f4 100644 --- a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java @@ -5,7 +5,6 @@ import com.mojang.blaze3d.platform.GlStateManager; import me.shedaniel.cloth.api.ClientUtils; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.*; -import me.shedaniel.rei.client.ClientHelper; import me.shedaniel.rei.client.ScreenHelper; import me.shedaniel.rei.gui.widget.*; import net.minecraft.client.MinecraftClient; @@ -31,9 +30,9 @@ import java.util.function.Supplier; public class RecipeViewingScreen extends Screen { - public static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png"); + public static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui" + "/recipecontainer.png"); public static final Color SUB_COLOR = new Color(159, 159, 159); - private static final Identifier CREATIVE_INVENTORY_TABS = new Identifier("textures/gui/container/creative_inventory/tabs.png"); + private static final Identifier CREATIVE_INVENTORY_TABS = new Identifier("textures/gui/container" + "/creative_inventory/tabs.png"); private final List widgets; private final List tabs; private final Map> categoriesMap; @@ -94,6 +93,15 @@ public class RecipeViewingScreen extends Screen { } if (choosePageActivated) return recipeChoosePageWidget.keyPressed(int_1, int_2, int_3); + else if (ClientHelper.getInstance().getNextPageKeyBinding().matchesKey(int_1, int_2)) { + if (recipeNext.enabled) + recipeNext.onPressed(); + return recipeNext.enabled; + } else if (ClientHelper.getInstance().getPreviousPageKeyBinding().matchesKey(int_1, int_2)) { + if (recipeBack.enabled) + recipeBack.onPressed(); + return recipeBack.enabled; + } for(Element element : children()) if (element.keyPressed(int_1, int_2, int_3)) return true; @@ -151,7 +159,7 @@ public class RecipeViewingScreen extends Screen { @Override public void onLabelClicked() { MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F)); - ClientHelper.executeViewAllRecipesKeyBind(); + ClientHelper.getInstance().executeViewAllRecipesKeyBind(); } }); widgets.add(categoryNext = new ButtonWidget((int) bounds.getMaxX() - 17, (int) bounds.getY() + 5, 12, 12, new TranslatableTextComponent("text.rei.right_arrow")) { diff --git a/src/main/java/me/shedaniel/rei/gui/config/ItemListOrderingConfig.java b/src/main/java/me/shedaniel/rei/gui/config/ItemListOrderingConfig.java index 7dbb40042..7e447007c 100644 --- a/src/main/java/me/shedaniel/rei/gui/config/ItemListOrderingConfig.java +++ b/src/main/java/me/shedaniel/rei/gui/config/ItemListOrderingConfig.java @@ -4,7 +4,12 @@ import me.shedaniel.rei.client.ItemListOrdering; import net.minecraft.client.resource.language.I18n; public enum ItemListOrderingConfig { - REGISTRY_ASCENDING(ItemListOrdering.registry, true), NAME_ASCENDING(ItemListOrdering.name, true), GROUPS_ASCENDING(ItemListOrdering.item_groups, true), REGISTRY_DESCENDING(ItemListOrdering.registry, false), NAME_DESCENDING(ItemListOrdering.name, false), GROUPS_DESCENDING(ItemListOrdering.item_groups, false); + REGISTRY_ASCENDING(ItemListOrdering.registry, true), + NAME_ASCENDING(ItemListOrdering.name, true), + GROUPS_ASCENDING(ItemListOrdering.item_groups, true), + REGISTRY_DESCENDING(ItemListOrdering.registry, false), + NAME_DESCENDING(ItemListOrdering.name, false), + GROUPS_DESCENDING(ItemListOrdering.item_groups, false); private ItemListOrdering ordering; private boolean isAscending; diff --git a/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java b/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java index e18b128e1..a04956e8d 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java @@ -3,10 +3,10 @@ package me.shedaniel.rei.gui.widget; import com.google.common.collect.Lists; import me.shedaniel.cloth.api.ClientUtils; import me.shedaniel.rei.RoughlyEnoughItemsCore; +import me.shedaniel.rei.api.ClientHelper; import me.shedaniel.rei.api.DisplayHelper; import me.shedaniel.rei.api.ItemCheatingMode; import me.shedaniel.rei.api.RecipeHelper; -import me.shedaniel.rei.client.ClientHelper; import me.shedaniel.rei.client.ItemListOrdering; import me.shedaniel.rei.client.ScreenHelper; import me.shedaniel.rei.client.SearchArgument; @@ -28,6 +28,7 @@ import java.awt.*; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.stream.Collectors; public class ItemListOverlay extends Widget { @@ -82,7 +83,7 @@ public class ItemListOverlay extends Widget { GuiLighting.disable(); widgets.forEach(widget -> widget.render(int_1, int_2, float_1)); ClientPlayerEntity player = minecraft.player; - if (rectangle.contains(ClientUtils.getMouseLocation()) && ClientHelper.isCheating() && !player.inventory.getCursorStack().isEmpty() && RoughlyEnoughItemsCore.hasPermissionToUsePackets()) + if (rectangle.contains(ClientUtils.getMouseLocation()) && ClientHelper.getInstance().isCheating() && !player.inventory.getCursorStack().isEmpty() && RoughlyEnoughItemsCore.hasPermissionToUsePackets()) ScreenHelper.getLastOverlay().addTooltip(QueuedTooltip.create(I18n.translate("text.rei.delete_items"))); } @@ -112,14 +113,14 @@ public class ItemListOverlay extends Widget { @Override protected void queueTooltip(ItemStack itemStack, float delta) { ClientPlayerEntity player = minecraft.player; - if (!ClientHelper.isCheating() || player.inventory.getCursorStack().isEmpty()) + if (!ClientHelper.getInstance().isCheating() || player.inventory.getCursorStack().isEmpty()) super.queueTooltip(itemStack, delta); } @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { if (isHighlighted(mouseX, mouseY)) { - if (ClientHelper.isCheating()) { + if (ClientHelper.getInstance().isCheating()) { if (getCurrentStack() != null && !getCurrentStack().isEmpty()) { ItemStack cheatedStack = getCurrentStack().copy(); if (RoughlyEnoughItemsCore.getConfigManager().getConfig().itemCheatingMode == ItemCheatingMode.REI_LIKE) @@ -128,12 +129,12 @@ public class ItemListOverlay extends Widget { cheatedStack.setAmount(button != 0 ? 1 : cheatedStack.getMaxAmount()); else cheatedStack.setAmount(1); - return ClientHelper.tryCheatingStack(cheatedStack); + return ClientHelper.getInstance().tryCheatingStack(cheatedStack); } } else if (button == 0) - return ClientHelper.executeRecipeKeyBind(getCurrentStack().copy()); + return ClientHelper.getInstance().executeRecipeKeyBind(getCurrentStack().copy()); else if (button == 1) - return ClientHelper.executeUsageKeyBind(getCurrentStack().copy()); + return ClientHelper.getInstance().executeUsageKeyBind(getCurrentStack().copy()); } return false; } @@ -161,16 +162,12 @@ public class ItemListOverlay extends Widget { } public boolean canBeFit(int left, int top, Rectangle listArea) { - List sortedBoundsHandlers = RoughlyEnoughItemsCore.getDisplayHelper().getSortedBoundsHandlers(minecraft.currentScreen.getClass()); - ActionResult result = ActionResult.SUCCESS; - for(DisplayHelper.DisplayBoundsHandler sortedBoundsHandler : sortedBoundsHandlers) { + for(DisplayHelper.DisplayBoundsHandler sortedBoundsHandler : RoughlyEnoughItemsCore.getDisplayHelper().getSortedBoundsHandlers(minecraft.currentScreen.getClass())) { ActionResult fit = sortedBoundsHandler.canItemSlotWidgetFit(!RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel, left, top, minecraft.currentScreen, listArea); - if (fit != ActionResult.PASS) { - result = fit; - break; - } + if (fit != ActionResult.PASS) + return fit == ActionResult.SUCCESS; } - return result == ActionResult.SUCCESS; + return true; } @Override @@ -247,9 +244,9 @@ public class ItemListOverlay extends Widget { private boolean filterItem(ItemStack itemS