aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/ftbsc/bscv/modules/hud/Highlighter.java35
-rw-r--r--src/main/java/ftbsc/bscv/tools/Inventory.java46
2 files changed, 48 insertions, 33 deletions
diff --git a/src/main/java/ftbsc/bscv/modules/hud/Highlighter.java b/src/main/java/ftbsc/bscv/modules/hud/Highlighter.java
index a5fa0e5..f5cc542 100644
--- a/src/main/java/ftbsc/bscv/modules/hud/Highlighter.java
+++ b/src/main/java/ftbsc/bscv/modules/hud/Highlighter.java
@@ -4,6 +4,7 @@ import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import ftbsc.bscv.modules.AbstractModule;
+import ftbsc.bscv.tools.Inventory;
import ftbsc.bscv.tools.Setting;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.inventory.container.Slot;
@@ -48,38 +49,6 @@ public class Highlighter extends AbstractModule {
this.pattern = Pattern.compile(this.query.get());
}
- private List<String> enchantments(ItemStack stack) {
- final ListNBT tags;
- if (Items.ENCHANTED_BOOK.equals(stack.getItem())) {
- tags = EnchantedBookItem.getEnchantments(stack); // special case to also search book enchants
- } else {
- tags = stack.getEnchantmentTags();
- }
-
- List<String> out = new ArrayList<>();
- for (int i = 0; i < tags.size(); i++) {
- CompoundNBT tag = tags.getCompound(i);
- out.add(String.format("%s %s", tag.getString("id"), tag.getInt("lvl")));
- }
-
- return out;
- }
-
- private boolean matches(ItemStack stack) {
- if (stack.isEmpty()) return false;
-
- String displayName = stack.getDisplayName().getString();
- if (this.pattern.matcher(displayName).find()) return true;
-
- if (Items.ENCHANTED_BOOK.equals(stack.getItem()) || stack.isEnchanted()) {
- for (String ench : this.enchantments(stack)) {
- if (this.pattern.matcher(ench).find()) return true;
- }
- }
-
- return false;
- }
-
@SubscribeEvent
public void onGuiContainerDraw(GuiContainerEvent.DrawBackground event) {
MatrixStack matrix = event.getMatrixStack();
@@ -91,7 +60,7 @@ public class Highlighter extends AbstractModule {
for (Slot slot : screen.getMenu().slots) {
ItemStack stack = slot.getItem();
- if (this.matches(stack)) {
+ if (Inventory.matchItem(this.pattern, stack)) {
GuiUtils.drawGradientRect(
matrix.last().pose(), 0,
slot.x, slot.y, slot.x + 16, slot.y + 16,
diff --git a/src/main/java/ftbsc/bscv/tools/Inventory.java b/src/main/java/ftbsc/bscv/tools/Inventory.java
index 8f1e2f5..f044be8 100644
--- a/src/main/java/ftbsc/bscv/tools/Inventory.java
+++ b/src/main/java/ftbsc/bscv/tools/Inventory.java
@@ -7,13 +7,19 @@ import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraft.inventory.EquipmentSlotType;
+import net.minecraft.inventory.container.ClickType;
import net.minecraft.inventory.container.Slot;
+import net.minecraft.item.EnchantedBookItem;
import net.minecraft.item.ItemStack;
+import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT;
+import net.minecraft.nbt.ListNBT;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.regex.Pattern;
public class Inventory implements ICommons {
@@ -68,4 +74,44 @@ public class Inventory implements ICommons {
return damage / (1. + speed);
}
+
+ public static List<String> itemEnchantments(ItemStack stack) {
+ final ListNBT tags;
+ if (Items.ENCHANTED_BOOK.equals(stack.getItem())) {
+ tags = EnchantedBookItem.getEnchantments(stack); // special case to also search book enchants
+ } else {
+ tags = stack.getEnchantmentTags();
+ }
+
+ List<String> out = new ArrayList<>();
+ for (int i = 0; i < tags.size(); i++) {
+ CompoundNBT tag = tags.getCompound(i);
+ out.add(String.format("%s %s", tag.getString("id"), tag.getInt("lvl")));
+ }
+
+ return out;
+ }
+
+ public static void clickSLot(Slot slot, ClickType click) { clickSlot(0, slot, 0, click); }
+ public static void clickSLot(Slot slot, int button, ClickType click) { clickSlot(0, slot, button, click); }
+ public static void clickSLot(int container, Slot slot, ClickType click) { clickSlot(container, slot, 0, click); }
+
+ public static void clickSlot(int container, Slot slot, int button, ClickType click) {
+ MC.gameMode.handleInventoryMouseClick(container, slot.index, button, click, MC.player);
+ }
+
+ public static boolean matchItem(Pattern pattern, ItemStack stack) {
+ if (stack.isEmpty()) return false;
+
+ String displayName = stack.getDisplayName().getString();
+ if (pattern.matcher(displayName).find()) return true;
+
+ if (Items.ENCHANTED_BOOK.equals(stack.getItem()) || stack.isEnchanted()) {
+ for (String ench : itemEnchantments(stack)) {
+ if (pattern.matcher(ench).find()) return true;
+ }
+ }
+
+ return false;
+ }
}