From c4f4539a871180ca928d309a99277c5f6a650b85 Mon Sep 17 00:00:00 2001 From: ThebestkillerTBK <2593828650@qq.com> Date: Sat, 12 Nov 2022 17:36:59 +0800 Subject: [PATCH] InteractionMenu updates --- .../rejects/modules/InteractionMenu.java | 93 ++++++++++--------- 1 file changed, 49 insertions(+), 44 deletions(-) diff --git a/src/main/java/anticope/rejects/modules/InteractionMenu.java b/src/main/java/anticope/rejects/modules/InteractionMenu.java index 42b9c720..c624d55c 100644 --- a/src/main/java/anticope/rejects/modules/InteractionMenu.java +++ b/src/main/java/anticope/rejects/modules/InteractionMenu.java @@ -4,7 +4,6 @@ import anticope.rejects.gui.screens.InteractionScreen; import it.unimi.dsi.fastutil.objects.Object2BooleanMap; import meteordevelopment.meteorclient.gui.GuiTheme; -import meteordevelopment.meteorclient.gui.utils.CharFilter; import meteordevelopment.meteorclient.gui.utils.StarscriptTextBoxRenderer; import meteordevelopment.meteorclient.gui.widgets.WWidget; import meteordevelopment.meteorclient.gui.widgets.containers.WTable; @@ -19,7 +18,6 @@ import meteordevelopment.meteorclient.utils.render.color.SettingColor; import meteordevelopment.starscript.value.Value; import meteordevelopment.starscript.value.ValueMap; - import net.minecraft.client.render.debug.DebugRenderer; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; @@ -27,13 +25,14 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtString; -import java.util.*; +import java.util.HashMap; +import java.util.Optional; public class InteractionMenu extends Module { - + private final SettingGroup sgGeneral = settings.getDefaultGroup(); private final SettingGroup sgStyle = settings.createGroup("Style"); - + private final Setting>> entities = sgGeneral.add(new EntityTypeListSetting.Builder() .name("entities") .description("Entities") @@ -47,6 +46,12 @@ public class InteractionMenu extends Module { .action(this::onKey) .build() ); + public final Setting useCrosshairTarget = sgGeneral.add(new BoolSetting.Builder() + .name("use-crosshair-target") + .description("Use crosshair target.") + .defaultValue(false) + .build() + ); // Style public final Setting selectedDotColor = sgStyle.add(new ColorSetting.Builder() @@ -70,33 +75,40 @@ public class InteractionMenu extends Module { public final Setting borderColor = sgStyle.add(new ColorSetting.Builder() .name("border-color") .description("Color of the border.") - .defaultValue(new SettingColor(0,0,0)) + .defaultValue(new SettingColor(0, 0, 0)) .build() ); public final Setting textColor = sgStyle.add(new ColorSetting.Builder() .name("text-color") .description("Color of the text.") - .defaultValue(new SettingColor(255,255,255)) + .defaultValue(new SettingColor(255, 255, 255)) .build() ); - - public final HashMap messages = new HashMap<>(); + + public final HashMap messages = new HashMap<>(); private String currMsgK = "", currMsgV = ""; - + public InteractionMenu() { - super(MeteorRejectsAddon.CATEGORY,"interaction-menu","An interaction screen when looking at an entity."); + super(MeteorRejectsAddon.CATEGORY, "interaction-menu", "An interaction screen when looking at an entity."); MeteorStarscript.ss.set("entity", () -> wrap(InteractionScreen.interactionMenuEntity)); } public void onKey() { - if (mc.currentScreen != null) return; - Optional lookingAt = DebugRenderer.getTargetedEntity(mc.player, 20); - if (lookingAt.isPresent()) { - Entity e = lookingAt.get(); - if (entities.get().getBoolean(e.getType())) { - mc.setScreen(new InteractionScreen(e, this)); + if (mc.player == null || mc.currentScreen != null) return; + Entity e = null; + if (useCrosshairTarget.get()) { + e = mc.targetedEntity; + } else { + Optional lookingAt = DebugRenderer.getTargetedEntity(mc.player, 20); + if (lookingAt.isPresent()) { + e = lookingAt.get(); } } + + if (e == null) return; + if (entities.get().getBoolean(e.getType())) { + mc.setScreen(new InteractionScreen(e, this)); + } } @Override @@ -114,24 +126,21 @@ private void fillTable(GuiTheme theme, WTable table) { WMinus delete = table.add(theme.minus()).widget(); delete.action = () -> { messages.remove(key); - fillTable(theme,table); + fillTable(theme, table); }; table.row(); }); WTextBox textBoxK = table.add(theme.textBox(currMsgK)).minWidth(100).expandX().widget(); - textBoxK.action = () -> { - currMsgK = textBoxK.get(); - }; + textBoxK.action = () -> currMsgK = textBoxK.get(); WTextBox textBoxV = table.add(theme.textBox(currMsgV, (text1, c) -> true, StarscriptTextBoxRenderer.class)).minWidth(100).expandX().widget(); - textBoxV.action = () -> { - currMsgV = textBoxV.get(); - }; + textBoxV.action = () -> currMsgV = textBoxV.get(); WPlus add = table.add(theme.plus()).widget(); add.action = () -> { - if (currMsgK != "" && currMsgV != "") { + if (!currMsgK.equals("") && !currMsgV.equals("")) { messages.put(currMsgK, currMsgV); - currMsgK = ""; currMsgV = ""; - fillTable(theme,table); + currMsgK = ""; + currMsgV = ""; + fillTable(theme, table); } }; table.row(); @@ -140,11 +149,9 @@ private void fillTable(GuiTheme theme, WTable table) { @Override public NbtCompound toTag() { NbtCompound tag = super.toTag(); - + NbtCompound messTag = new NbtCompound(); - messages.keySet().forEach((key) -> { - messTag.put(key, NbtString.of(messages.get(key))); - }); + messages.keySet().forEach((key) -> messTag.put(key, NbtString.of(messages.get(key)))); tag.put("messages", messTag); return tag; @@ -152,13 +159,11 @@ public NbtCompound toTag() { @Override public Module fromTag(NbtCompound tag) { - + messages.clear(); if (tag.contains("messages")) { NbtCompound msgs = tag.getCompound("messages"); - msgs.getKeys().forEach((key) -> { - messages.put(key, msgs.getString(key)); - }); + msgs.getKeys().forEach((key) -> messages.put(key, msgs.getString(key))); } return super.fromTag(tag); @@ -179,15 +184,15 @@ private static Value wrap(Entity entity) { ); } return Value.map(new ValueMap() - .set("_toString", Value.string(entity.getName().getString())) - .set("health", Value.number(entity instanceof LivingEntity e ? e.getHealth() : 0)) - .set("pos", Value.map(new ValueMap() - .set("_toString", posString(entity.getX(), entity.getY(), entity.getZ())) - .set("x", Value.number(entity.getX())) - .set("y", Value.number(entity.getY())) - .set("z", Value.number(entity.getZ())) - )) - .set("uuid", Value.string(entity.getUuidAsString())) + .set("_toString", Value.string(entity.getName().getString())) + .set("health", Value.number(entity instanceof LivingEntity e ? e.getHealth() : 0)) + .set("pos", Value.map(new ValueMap() + .set("_toString", posString(entity.getX(), entity.getY(), entity.getZ())) + .set("x", Value.number(entity.getX())) + .set("y", Value.number(entity.getY())) + .set("z", Value.number(entity.getZ())) + )) + .set("uuid", Value.string(entity.getUuidAsString())) ); }