aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorUnknown <shekwancheung0528@gmail.com>2019-01-10 23:37:34 +0800
committerUnknown <shekwancheung0528@gmail.com>2019-01-10 23:37:34 +0800
commitff3c2799a766babb69d772f15958d7a0bf50868c (patch)
tree38d045d36135a79ca32011dfae7d011333ad7804 /src/main
parent9644c27ae7b344a6dbe3cc77cd6f567525f1c711 (diff)
downloadRoughlyEnoughItems-ff3c2799a766babb69d772f15958d7a0bf50868c.tar.gz
RoughlyEnoughItems-ff3c2799a766babb69d772f15958d7a0bf50868c.tar.bz2
RoughlyEnoughItems-ff3c2799a766babb69d772f15958d7a0bf50868c.zip
Basic Searching Works
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java22
-rw-r--r--src/main/java/me/shedaniel/rei/api/IRecipeCategory.java18
-rw-r--r--src/main/java/me/shedaniel/rei/api/IRecipeDisplay.java24
-rw-r--r--src/main/java/me/shedaniel/rei/api/IRecipePlugin.java11
-rw-r--r--src/main/java/me/shedaniel/rei/client/ClientHelper.java20
-rw-r--r--src/main/java/me/shedaniel/rei/client/ConfigManager.java75
-rw-r--r--src/main/java/me/shedaniel/rei/client/REIConfig.java22
-rw-r--r--src/main/java/me/shedaniel/rei/client/REIItemListOrdering.java21
-rw-r--r--src/main/java/me/shedaniel/rei/client/RecipeHelper.java100
-rw-r--r--src/main/java/me/shedaniel/rei/client/SearchArgument.java36
-rw-r--r--src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java105
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/ButtonWidget.java115
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java117
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidget.java161
-rw-r--r--src/main/java/me/shedaniel/rei/listeners/RecipeSync.java9
-rw-r--r--src/main/java/me/shedaniel/rei/mixin/MixinClientPlayNetworkHandler.java26
-rw-r--r--src/main/java/me/shedaniel/rei/mixin/MixinContainerGui.java23
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/DefaultCraftingCategory.java26
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/DefaultCraftingDisplay.java15
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java28
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/DefaultShapedDisplay.java45
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/DefaultShapelessDisplay.java45
-rwxr-xr-xsrc/main/resources/assets/roughlyenoughitems/textures/gui/recipecontainer.pngbin5886 -> 6214 bytes
-rwxr-xr-xsrc/main/resources/roughlyenoughitems.client.json3
24 files changed, 1029 insertions, 38 deletions
diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
index 5431b3232..765ef4e64 100644
--- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
+++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
@@ -1,14 +1,17 @@
package me.shedaniel.rei;
+import me.shedaniel.rei.api.IRecipePlugin;
import me.shedaniel.rei.client.ClientHelper;
+import me.shedaniel.rei.client.ConfigManager;
+import me.shedaniel.rei.client.RecipeHelper;
import me.shedaniel.rei.listeners.ClientTick;
import me.shedaniel.rei.listeners.IListener;
+import me.shedaniel.rei.plugin.DefaultPlugin;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.events.client.ClientTickEvent;
import net.fabricmc.fabric.networking.CustomPayloadPacketRegistry;
import net.minecraft.item.ItemStack;
-import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sortme.ChatMessageType;
import net.minecraft.text.TranslatableTextComponent;
@@ -26,6 +29,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer, ModInitiali
public static final Identifier DELETE_ITEMS_PACKET = new Identifier("roughlyenoughitems", "deleteitem");
public static final Identifier CREATE_ITEMS_PACKET = new Identifier("roughlyenoughitems", "createitem");
private static final List<IListener> listeners = new ArrayList<>();
+ private static ConfigManager configManager;
public static <T> List<T> getListeners(Class<T> listenerClass) {
return listeners.stream().filter(listener -> {
@@ -35,14 +39,25 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer, ModInitiali
}).collect(Collectors.toList());
}
+ public static ConfigManager getConfigManager() {
+ return configManager;
+ }
+
@Override
public void onInitializeClient() {
registerREIListeners();
registerFabricEvents();
+ registerDefaultPlugin();
+ configManager = new ConfigManager();
+ }
+
+ private void registerDefaultPlugin() {
+ registerPlugin(new DefaultPlugin());
}
private void registerREIListeners() {
registerListener(new ClientHelper());
+ registerListener(new RecipeHelper());
}
private IListener registerListener(IListener listener) {
@@ -50,6 +65,11 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer, ModInitiali
return listener;
}
+ private IRecipePlugin registerPlugin(IRecipePlugin plugin) {
+ registerListener(plugin);
+ return plugin;
+ }
+
private boolean removeListener(IListener listener) {
if (!listeners.contains(listener))
return false;
diff --git a/src/main/java/me/shedaniel/rei/api/IRecipeCategory.java b/src/main/java/me/shedaniel/rei/api/IRecipeCategory.java
new file mode 100644
index 000000000..e4d357dee
--- /dev/null
+++ b/src/main/java/me/shedaniel/rei/api/IRecipeCategory.java
@@ -0,0 +1,18 @@
+package me.shedaniel.rei.api;
+
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.Identifier;
+
+public interface IRecipeCategory<T extends IRecipeDisplay> {
+
+ public Identifier getIdentifier();
+
+ public ItemStack getCategoryIcon();
+
+ public String getCategoryName();
+
+ default public boolean usesFullPage() {
+ return false;
+ }
+
+}
diff --git a/src/main/java/me/shedaniel/rei/api/IRecipeDisplay.java b/src/main/java/me/shedaniel/rei/api/IRecipeDisplay.java
new file mode 100644
index 000000000..1a19b21c5
--- /dev/null
+++ b/src/main/java/me/shedaniel/rei/api/IRecipeDisplay.java
@@ -0,0 +1,24 @@
+package me.shedaniel.rei.api;
+
+import com.google.common.collect.Lists;
+import net.minecraft.item.ItemStack;
+import net.minecraft.recipe.Recipe;
+import net.minecraft.util.Identifier;
+
+import java.util.List;
+
+public interface IRecipeDisplay<T extends Recipe> {
+
+ public abstract T getRecipe();
+
+ public List<List<ItemStack>> getInput();
+
+ public List<ItemStack> getOutput();
+
+ default public List<List<ItemStack>> getRequiredItems() {
+ return Lists.newArrayList();
+ }
+
+ public Identifier getRecipeCategory();
+
+}
diff --git a/src/main/java/me/shedaniel/rei/api/IRecipePlugin.java b/src/main/java/me/shedaniel/rei/api/IRecipePlugin.java
new file mode 100644
index 000000000..870691e6d
--- /dev/null
+++ b/src/main/java/me/shedaniel/rei/api/IRecipePlugin.java
@@ -0,0 +1,11 @@
+package me.shedaniel.rei.api;
+
+import me.shedaniel.rei.listeners.IListener;
+
+public interface IRecipePlugin extends IListener {
+
+ public void registerPluginCategories();
+
+ public void registerRecipes();
+
+}
diff --git a/src/main/java/me/shedaniel/rei/client/ClientHelper.java b/src/main/java/me/shedaniel/rei/client/ClientHelper.java
index b0bc64a98..8c1cd472e 100644
--- a/src/main/java/me/shedaniel/rei/client/ClientHelper.java
+++ b/src/main/java/me/shedaniel/rei/client/ClientHelper.java
@@ -3,7 +3,12 @@ package me.shedaniel.rei.client;
import com.google.common.collect.Lists;
import io.netty.buffer.Unpooled;
import me.shedaniel.rei.RoughlyEnoughItemsCore;
+import me.shedaniel.rei.api.IRecipeCategory;
+import me.shedaniel.rei.api.IRecipeDisplay;
+import me.shedaniel.rei.gui.ContainerGuiOverlay;
+import me.shedaniel.rei.gui.widget.RecipeViewingWidget;
import me.shedaniel.rei.listeners.ClientLoaded;
+import me.shedaniel.rei.listeners.IMixinContainerGui;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.loader.FabricLoader;
import net.minecraft.client.MinecraftClient;
@@ -19,9 +24,11 @@ import net.minecraft.util.PacketByteBuf;
import net.minecraft.util.registry.Registry;
import java.awt.*;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
public class ClientHelper implements ClientLoaded, ClientModInitializer {
@@ -69,6 +76,10 @@ public class ClientHelper implements ClientLoaded, ClientModInitializer {
return cheating;
}
+ public static void setCheating(boolean cheating) {
+ ClientHelper.cheating = cheating;
+ }
+
public static void sendDeletePacket() {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
MinecraftClient.getInstance().getNetworkHandler().sendPacket(new CustomPayloadServerPacket(RoughlyEnoughItemsCore.DELETE_ITEMS_PACKET, buf));
@@ -85,8 +96,11 @@ public class ClientHelper implements ClientLoaded, ClientModInitializer {
}
}
- public static boolean executeRecipeKeyBind() {
- return false;
+ public static boolean executeRecipeKeyBind(ContainerGuiOverlay overlay, ItemStack stack, IMixinContainerGui parent) {
+ Map<IRecipeCategory, List<IRecipeDisplay>> map = RecipeHelper.getRecipesFor(stack);
+ if (map.keySet().size() > 0)
+ MinecraftClient.getInstance().openGui(new RecipeViewingWidget(overlay, MinecraftClient.getInstance().window, parent, map));
+ return map.keySet().size() > 0;
}
public static boolean executeUsageKeyBind() {
@@ -118,7 +132,7 @@ public class ClientHelper implements ClientLoaded, ClientModInitializer {
@Override
public void onInitializeClient() {
- this.cheating = true;
+ this.cheating = false;
}
}
diff --git a/src/main/java/me/shedaniel/rei/client/ConfigManager.java b/src/main/java/me/shedaniel/rei/client/ConfigManager.java
new file mode 100644
index 000000000..a2d4d9890
--- /dev/null
+++ b/src/main/java/me/shedaniel/rei/client/ConfigManager.java
@@ -0,0 +1,75 @@
+package me.shedaniel.rei.client;
+
+import me.shedaniel.rei.RoughlyEnoughItemsCore;
+import net.fabricmc.loader.FabricLoader;
+import org.apache.logging.log4j.core.Core;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.nio.file.Files;
+
+public class ConfigManager {
+
+ private final File configFile;
+ private REIConfig config;
+ private boolean craftableOnly;
+
+ public ConfigManager() {
+ this.configFile = new File(FabricLoader.INSTANCE.getConfigDirectory(), "rei.json");
+ this.craftableOnly = false;
+ try {
+ loadConfig();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void saveConfig() throws IOException {
+ configFile.getParentFile().mkdirs();
+ if (!configFile.exists() && !configFile.createNewFile()) {
+ RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to save config! Overwriting with default config.");
+ config = new REIConfig();
+ return;
+ }
+ FileWriter writer = new FileWriter(configFile, false);
+ try {
+ REIConfig.GSON.toJson(config, writer);
+ } finally {
+ writer.close();
+ }
+ }
+
+ public void loadConfig() throws IOException {
+ if (!configFile.exists() || !configFile.canRead()) {
+ config = new REIConfig();
+ saveConfig();
+ return;
+ }
+ boolean failed = false;
+ try {
+ config = REIConfig.GSON.fromJson(new InputStreamReader(Files.newInputStream(configFile.toPath())), REIConfig.class);
+ } catch (Exception e) {
+ failed = true;
+ }
+ if (failed || config == null) {
+ RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to load config! Overwriting with default config.");
+ config = new REIConfig();
+ }
+ saveConfig();
+ }
+
+ public REIItemListOrdering getItemListOrdering() {
+ return config.itemListOrdering;
+ }
+
+ public boolean isAscending() {
+ return config.isAscending;
+ }
+
+ public boolean craftableOnly() {
+ return craftableOnly && config.enableCraftableOnlyButton;
+ }
+
+}
diff --git a/src/main/java/me/shedaniel/rei/client/REIConfig.java b/src/main/java/me/shedaniel/rei/client/REIConfig.java
new file mode 100644
index 000000000..dfc961f28
--- /dev/null
+++ b/src/main/java/me/shedaniel/rei/client/REIConfig.java
@@ -0,0 +1,22 @@
+package me.shedaniel.rei.client;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import java.awt.event.KeyEvent;
+
+public class REIConfig {
+
+ public static Gson GSON = new GsonBuilder()
+ .setPrettyPrinting()
+ .create();
+
+ public int recipeKeyBind = KeyEvent.VK_R;
+ public int usageKeyBind = KeyEvent.VK_U;
+ public int hideKeyBind = KeyEvent.VK_O;
+ public boolean centreSearchBox = false;
+ public REIItemListOrdering itemListOrdering = REIItemListOrdering.REGISTRY;
+ public boolean isAscending = true;
+ public boolean enableCraftableOnlyButton = true;
+
+}
diff --git a/src/main/java/me/shedaniel/rei/client/REIItemListOrdering.java b/src/main/java/me/shedaniel/rei/client/REIItemListOrdering.java
new file mode 100644
index 000000000..b0167d352
--- /dev/null
+++ b/src/main/java/me/shedaniel/rei/client/REIItemListOrdering.java
@@ -0,0 +1,21 @@
+package me.shedaniel.rei.client;
+
+import com.google.gson.annotations.SerializedName;
+
+public enum REIItemListOrdering {
+
+ @SerializedName("registry") REGISTRY("ordering.rei.registry"),
+ @SerializedName("name") NAME("ordering.rei.name"),
+ @SerializedName("item_groups") ITEM_GROUPS("ordering.rei.item_groups");
+
+ private String nameTranslationKey;
+
+ REIItemListOrdering(String nameTranslationKey) {
+ this.nameTranslationKey = nameTranslationKey;
+ }
+
+ public String getNameTranslationKey() {
+ return nameTranslationKey;
+ }
+
+}
diff --git a/src/main/java/me/shedaniel/rei/client/RecipeHelper.java b/src/main/java/me/shedaniel/rei/client/RecipeHelper.java
new file mode 100644
index 000000000..74780846c
--- /dev/null
+++ b/src/main/java/me/shedaniel/rei/client/RecipeHelper.java
@@ -0,0 +1,100 @@
+package me.shedaniel.rei.client;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import me.shedaniel.rei.RoughlyEnoughItemsCore;
+import me.shedaniel.rei.api.IRecipeCategory;
+import me.shedaniel.rei.api.IRecipeDisplay;
+import me.shedaniel.rei.api.IRecipePlugin;
+import me.shedaniel.rei.listeners.RecipeSync;
+import net.minecraft.item.ItemStack;
+import net.minecraft.recipe.RecipeManager;
+import net.minecraft.util.Identifier;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+public class RecipeHelper implements RecipeSync {
+
+ private static Map<Identifier, List<IRecipeDisplay>> recipeCategoryListMap;
+ private static List<IRecipeCategory> categories;
+ private static RecipeManager recipeManager;
+
+ public RecipeHelper() {
+ this.recipeCategoryListMap = Maps.newHashMap();
+ this.categories = Lists.newArrayList();
+ }
+
+ public static List<ItemStack> findCraftableByItems(List<ItemStack> inventoryItems) {
+ List<ItemStack> craftables = new ArrayList<>();
+ for(List<IRecipeDisplay> value : recipeCategoryListMap.values())
+ for(IRecipeDisplay recipeDisplay : value) {
+ int slotsCraftable = 0;
+ List<List<ItemStack>> requiredInput = (List<List<ItemStack>>) recipeDisplay.getRequiredItems();
+ for(List<ItemStack> slot : requiredInput) {
+ if (slot.isEmpty()) {
+ slotsCraftable++;
+ continue;
+ }
+ boolean slotDone = false;
+ for(ItemStack possibleType : inventoryItems) {
+ for(ItemStack slotPossible : slot)
+ if (ItemStack.areEqualIgnoreTags(slotPossible, possibleType)) {
+ slotsCraftable++;
+ slotDone = true;
+ break;
+ }
+ if (slotDone)
+ break;
+ }
+ }
+ if (slotsCraftable == recipeDisplay.getRequiredItems().size())
+ craftables.addAll((List<ItemStack>) recipeDisplay.getOutput());
+ }
+ return craftables.stream().distinct().collect(Collectors.toList());
+ }
+
+ public static void registerCategory(IRecipeCategory category) {
+ categories.add(category);
+ recipeCategoryListMap.put(category.getIdentifier(), Lists.newArrayList());
+ }
+
+ public static void registerRecipe(Identifier categoryIdentifier, IRecipeDisplay display) {
+ if (!recipeCategoryListMap.containsKey(categoryIdentifier))
+ return;
+ recipeCategoryListMap.get(categoryIdentifier).add(display);
+ }
+
+ public static Map<IRecipeCategory, List<IRecipeDisplay>> getRecipesFor(ItemStack stack) {
+ Map<Identifier, List<IRecipeDisplay>> categoriesMap = new HashMap<>();
+ categories.forEach(f -> categoriesMap.put(f.getIdentifier(), new LinkedList<>()));
+ for(List<IRecipeDisplay> value : recipeCategoryListMap.values())
+ for(IRecipeDisplay recipeDisplay : value)
+ for(ItemStack outputStack : (List<ItemStack>) recipeDisplay.getOutput())
+ if (ItemStack.areEqualIgnoreTags(stack, outputStack))
+ categoriesMap.get(recipeDisplay.getRecipeCategory()).add(recipeDisplay);
+ categoriesMap.keySet().removeIf(f -> categoriesMap.get(f).isEmpty());
+ Map<IRecipeCategory, List<IRecipeDisplay>> recipeCategoryListMap = Maps.newHashMap();
+ categories.forEach(category -> {
+ if (categoriesMap.containsKey(category.getIdentifier()))
+ recipeCategoryListMap.put(category, categoriesMap.get(category.getIdentifier()));
+ });
+ return recipeCategoryListMap;
+ }
+
+ public static RecipeManager getRecipeManager() {
+ return recipeManager;
+ }
+
+ @Override
+ public void recipesLoaded(RecipeManager recipeManager) {
+ this.recipeManager = recipeManager;
+ this.recipeCategoryListMap.clear();
+ this.categories.clear();
+ RoughlyEnoughItemsCore.getListeners(IRecipePlugin.class).forEach(plugin -> {
+ plugin.registerPluginCategories();
+ plugin.registerRecipes();
+ });
+ }
+
+}
diff --git a/src/main/java/me/shedaniel/rei/client/SearchArgument.java b/src/main/java/me/shedaniel/rei/client/SearchArgument.java
new file mode 100644
index 000000000..445214871
--- /dev/null
+++ b/src/main/java/me/shedaniel/rei/client/SearchArgument.java
@@ -0,0 +1,36 @@
+package me.shedaniel.rei.client;
+
+public class SearchArgument {
+
+ public enum ArgumentType {
+ TEXT, MOD, TOOLTIP
+ }
+
+ private ArgumentType argumentType;
+ private String text;
+ private boolean include;
+
+ public SearchArgument(ArgumentType argumentType, String text, boolean include) {
+ this.argumentType = argumentType;
+ this.text = text;
+ this.include = include;
+ }
+
+ public ArgumentType getArgumentType() {
+ return argumentType;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public boolean isInclude() {
+ return include;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("Argument[%s]: name = %s, include = %b", argumentType.name(), text, include);
+ }
+
+}
diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java
index 42bd77bf5..3ffd95238 100644
--- a/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java
+++ b/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java
@@ -1,16 +1,16 @@
package me.shedaniel.rei.gui;
-import me.shedaniel.rei.RoughlyEnoughItemsCore;
+import com.mojang.blaze3d.platform.GlStateManager;
import me.shedaniel.rei.client.ClientHelper;
-import me.shedaniel.rei.gui.widget.IWidget;
-import me.shedaniel.rei.gui.widget.ItemListOverlay;
-import me.shedaniel.rei.gui.widget.LabelWidget;
-import me.shedaniel.rei.gui.widget.QueuedTooltip;
+import me.shedaniel.rei.gui.widget.*;
import me.shedaniel.rei.listeners.IMixinContainerGui;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.ContainerGui;
import net.minecraft.client.gui.Gui;
-import net.minecraft.client.gui.widget.ButtonWidget;
+import net.minecraft.client.gui.GuiEventListener;
+import net.minecraft.client.gui.widget.TextFieldWidget;
+import net.minecraft.client.render.GuiLighting;
+import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.util.Window;
import net.minecraft.util.math.MathHelper;
@@ -20,14 +20,15 @@ import java.util.List;
public class ContainerGuiOverlay extends Gui {
+ private static int page = 0;
+ private final List<IWidget> widgets;
+ private final List<QueuedTooltip> queuedTooltips;
private Rectangle rectangle;
private IMixinContainerGui containerGui;
private Window window;
- private static int page = 0;
- private final List<IWidget> widgets;
private ItemListOverlay itemListOverlay;
private ButtonWidget buttonLeft, buttonRight;
- private final List<QueuedTooltip> queuedTooltips;
+ private TextFieldWidget searchField;
public ContainerGuiOverlay(ContainerGui containerGui) {
this.queuedTooltips = new ArrayList<>();
@@ -36,6 +37,7 @@ public class ContainerGuiOverlay extends Gui {
}
public void onInitialized() {
+ String searchTerm = searchField != null ? searchField.getText() : "";
//Update Variables
this.widgets.clear();
this.window = MinecraftClient.getInstance().window;
@@ -44,23 +46,36 @@ public class ContainerGuiOverlay extends Gui {
this.rectangle = calculateBoundary();
widgets.add(this.itemListOverlay = new ItemListOverlay(this, containerGui, page));
- this.itemListOverlay.updateList(getItemListArea(), page);
- addButton(buttonLeft = new ButtonWidget(-1, rectangle.x, rectangle.y + 3, 16, 20, "<") {
+ this.itemListOverlay.updateList(getItemListArea(), page, searchTerm);
+ widgets.add(buttonLeft = new ButtonWidget(rectangle.x, rectangle.y + 5, 16, 16, "<") {
@Override
- public void onPressed(double double_1, double double_2) {
+ public void onPressed(int button, double mouseX, double mouseY) {
page--;
if (page < 0)
page = getTotalPage();
- itemListOverlay.updateList(getItemListArea(), page);
+ itemListOverlay.updateList(getItemListArea(), page, searchField.getText());
}
});
- addButton(buttonRight = new ButtonWidget(-1, rectangle.x + rectangle.width - 18, rectangle.y + 3, 16, 20, ">") {
+ widgets.add(buttonRight = new ButtonWidget(rectangle.x + rectangle.width - 18, rectangle.y + 5, 16, 16, ">") {
@Override
- public void onPressed(double double_1, double double_2) {
+ public void onPressed(int button, double mouseX, double mouseY) {
page++;
if (page > getTotalPage())
page = 0;
- itemListOverlay.updateList(getItemListArea(), page);
+ itemListOverlay.updateList(getItemListArea(), page, searchField.getText());
+ }
+ });
+ page = MathHelper.clamp(page, 0, getTotalPage());
+ widgets.add(new ButtonWidget(10, 10, 40, 20, "") {
+ @Override
+ public void draw(int int_1, int int_2, float float_1) {
+ this.text = getCheatModeText();
+ super.draw(int_1, int_2, float_1);
+ }
+
+ @Override
+ public void onPressed(int button, double mouseX, double mouseY) {
+ ClientHelper.setCheating(!ClientHelper.isCheating());
}
});
this.widgets.add(new LabelWidget(rectangle.x + (rectangle.width / 2), rectangle.y + 10, "") {
@@ -70,10 +85,29 @@ public class ContainerGuiOverlay extends Gui {
super.draw(mouseX, mouseY, partialTicks);
}
});
+ Rectangle textFieldArea = getTextFieldArea();
+ this.listeners.add(searchField = new TextFieldWidget(-1, MinecraftClient.getInstance().fontRenderer,
+ (int) textFieldArea.getX(), (int) textFieldArea.getY(), (int) textFieldArea.getWidth(), (int) textFieldArea.getHeight()));
+ searchField.setChangedListener((id, text) -> {
+ itemListOverlay.updateList(page, text);
+ });
+ searchField.setText(searchTerm);
this.listeners.addAll(widgets);
}
+ private Rectangle getTextFieldArea() {
+ if (MinecraftClient.getInstance().currentGui instanceof RecipeViewingWidget) {
+ RecipeViewingWidget widget = (RecipeViewingWidget) MinecraftClient.getInstance().currentGui;
+ return new Rectangle(widget.getBounds().x, window.getScaledHeight() - 22, widget.getBounds().width, 18);
+ }
+ return new Rectangle(containerGui.getContainerLeft(), window.getScaledHeight() - 22, containerGui.getContainerWidth(), 18);
+ }
+
+ private String getCheatModeText() {
+ return I18n.translate(String.format("%s%s", "text.rei.", ClientHelper.isCheating() ? "cheat" : "nocheat"));
+ }
+
private Rectangle getItemListArea() {
return new Rectangle(rectangle.x + 2, rectangle.y + 24, rectangle.width - 4, rectangle.height - 27);
}
@@ -83,9 +117,14 @@ public class ContainerGuiOverlay extends Gui {
}
public void render(int mouseX, int mouseY, float partialTicks) {
- draw(mouseX, mouseY, partialTicks);
+ GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
+ GuiLighting.disable();
+ this.draw(mouseX, mouseY, partialTicks);
+ GuiLighting.disable();
queuedTooltips.forEach(queuedTooltip -> containerGui.getContainerGui().drawTooltip(queuedTooltip.text, queuedTooltip.mouse.x, queuedTooltip.mouse.y));
queuedTooltips.clear();
+ GuiLighting.disable();
+ searchField.render(mouseX, mouseY, partialTicks);
}
public void addTooltip(QueuedTooltip queuedTooltip) {
@@ -94,28 +133,37 @@ public class ContainerGuiOverlay extends Gui {
@Override
public void draw(int int_1, int int_2, float float_1) {
- widgets.forEach(widget -> widget.draw(int_1, int_2, float_1));
+ widgets.forEach(widget -> {
+ GuiLighting.disable();
+ widget.draw(int_1, int_2, float_1);
+ });
+ GuiLighting.disable();
itemListOverlay.draw(int_1, int_2, float_1);
+ GuiLighting.disable();
super.draw(int_1, int_2, float_1);
}
private Rectangle calculateBoundary() {
int startX = containerGui.getContainerLeft() + containerGui.getContainerWidth() + 10;
int width = window.getScaledWidth() - startX;
+ if (MinecraftClient.getInstance().currentGui instanceof RecipeViewingWidget) {
+ RecipeViewingWidget widget = (RecipeViewingWidget) MinecraftClient.getInstance().currentGui;
+ width = window.getScaledWidth() - (widget.getBounds().x + widget.getBounds().width + 10);
+ }
return new Rectangle(startX, 0, width, window.getScaledHeight());
}
private int getTotalPage() {
- return MathHelper.ceil(ClientHelper.getItemList().size() / itemListOverlay.getTotalSlotsPerPage());
+ return MathHelper.ceil(itemListOverlay.getCurrentDisplayed().size() / itemListOverlay.getTotalSlotsPerPage());
}
@Override
public boolean mouseScrolled(double amount) {
if (rectangle.contains(ClientHelper.getMouseLocation())) {
if (amount > 0 && buttonLeft.enabled)
- buttonLeft.onPressed(0, 0);
+ buttonLeft.onPressed(0, 0, 0);
else if (amount < 0 && buttonRight.enabled)
- buttonRight.onPressed(0, 0);
+ buttonRight.onPressed(0, 0, 0);
else return false;
return true;
}
@@ -126,10 +174,19 @@ public class ContainerGuiOverlay extends Gui {
}
@Override
- public boolean mouseClicked(double double_1, double double_2, int int_1) {
- for(IWidget widget : widgets)
- if (widget.mouseClicked(double_1, double_2, int_1))
+ public boolean keyPressed(int int_1, int int_2, int int_3) {
+ for(GuiEventListener listener : listeners)
+ if (listener.keyPressed(int_1, int_2, int_3))
return true;
return false;
}
+
+ @Override
+ public boolean char