Skip to content

Commit c4f4539

Browse files
hexadecimal233C10udburst
authored andcommitted
InteractionMenu updates
1 parent bb7c6f0 commit c4f4539

File tree

1 file changed

+49
-44
lines changed

1 file changed

+49
-44
lines changed

src/main/java/anticope/rejects/modules/InteractionMenu.java

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import anticope.rejects.gui.screens.InteractionScreen;
55
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
66
import meteordevelopment.meteorclient.gui.GuiTheme;
7-
import meteordevelopment.meteorclient.gui.utils.CharFilter;
87
import meteordevelopment.meteorclient.gui.utils.StarscriptTextBoxRenderer;
98
import meteordevelopment.meteorclient.gui.widgets.WWidget;
109
import meteordevelopment.meteorclient.gui.widgets.containers.WTable;
@@ -19,21 +18,21 @@
1918
import meteordevelopment.meteorclient.utils.render.color.SettingColor;
2019
import meteordevelopment.starscript.value.Value;
2120
import meteordevelopment.starscript.value.ValueMap;
22-
2321
import net.minecraft.client.render.debug.DebugRenderer;
2422
import net.minecraft.entity.Entity;
2523
import net.minecraft.entity.EntityType;
2624
import net.minecraft.entity.LivingEntity;
2725
import net.minecraft.nbt.NbtCompound;
2826
import net.minecraft.nbt.NbtString;
2927

30-
import java.util.*;
28+
import java.util.HashMap;
29+
import java.util.Optional;
3130

3231
public class InteractionMenu extends Module {
33-
32+
3433
private final SettingGroup sgGeneral = settings.getDefaultGroup();
3534
private final SettingGroup sgStyle = settings.createGroup("Style");
36-
35+
3736
private final Setting<Object2BooleanMap<EntityType<?>>> entities = sgGeneral.add(new EntityTypeListSetting.Builder()
3837
.name("entities")
3938
.description("Entities")
@@ -47,6 +46,12 @@ public class InteractionMenu extends Module {
4746
.action(this::onKey)
4847
.build()
4948
);
49+
public final Setting<Boolean> useCrosshairTarget = sgGeneral.add(new BoolSetting.Builder()
50+
.name("use-crosshair-target")
51+
.description("Use crosshair target.")
52+
.defaultValue(false)
53+
.build()
54+
);
5055

5156
// Style
5257
public final Setting<SettingColor> selectedDotColor = sgStyle.add(new ColorSetting.Builder()
@@ -70,33 +75,40 @@ public class InteractionMenu extends Module {
7075
public final Setting<SettingColor> borderColor = sgStyle.add(new ColorSetting.Builder()
7176
.name("border-color")
7277
.description("Color of the border.")
73-
.defaultValue(new SettingColor(0,0,0))
78+
.defaultValue(new SettingColor(0, 0, 0))
7479
.build()
7580
);
7681
public final Setting<SettingColor> textColor = sgStyle.add(new ColorSetting.Builder()
7782
.name("text-color")
7883
.description("Color of the text.")
79-
.defaultValue(new SettingColor(255,255,255))
84+
.defaultValue(new SettingColor(255, 255, 255))
8085
.build()
8186
);
82-
83-
public final HashMap<String,String> messages = new HashMap<>();
87+
88+
public final HashMap<String, String> messages = new HashMap<>();
8489
private String currMsgK = "", currMsgV = "";
85-
90+
8691
public InteractionMenu() {
87-
super(MeteorRejectsAddon.CATEGORY,"interaction-menu","An interaction screen when looking at an entity.");
92+
super(MeteorRejectsAddon.CATEGORY, "interaction-menu", "An interaction screen when looking at an entity.");
8893
MeteorStarscript.ss.set("entity", () -> wrap(InteractionScreen.interactionMenuEntity));
8994
}
9095

9196
public void onKey() {
92-
if (mc.currentScreen != null) return;
93-
Optional<Entity> lookingAt = DebugRenderer.getTargetedEntity(mc.player, 20);
94-
if (lookingAt.isPresent()) {
95-
Entity e = lookingAt.get();
96-
if (entities.get().getBoolean(e.getType())) {
97-
mc.setScreen(new InteractionScreen(e, this));
97+
if (mc.player == null || mc.currentScreen != null) return;
98+
Entity e = null;
99+
if (useCrosshairTarget.get()) {
100+
e = mc.targetedEntity;
101+
} else {
102+
Optional<Entity> lookingAt = DebugRenderer.getTargetedEntity(mc.player, 20);
103+
if (lookingAt.isPresent()) {
104+
e = lookingAt.get();
98105
}
99106
}
107+
108+
if (e == null) return;
109+
if (entities.get().getBoolean(e.getType())) {
110+
mc.setScreen(new InteractionScreen(e, this));
111+
}
100112
}
101113

102114
@Override
@@ -114,24 +126,21 @@ private void fillTable(GuiTheme theme, WTable table) {
114126
WMinus delete = table.add(theme.minus()).widget();
115127
delete.action = () -> {
116128
messages.remove(key);
117-
fillTable(theme,table);
129+
fillTable(theme, table);
118130
};
119131
table.row();
120132
});
121133
WTextBox textBoxK = table.add(theme.textBox(currMsgK)).minWidth(100).expandX().widget();
122-
textBoxK.action = () -> {
123-
currMsgK = textBoxK.get();
124-
};
134+
textBoxK.action = () -> currMsgK = textBoxK.get();
125135
WTextBox textBoxV = table.add(theme.textBox(currMsgV, (text1, c) -> true, StarscriptTextBoxRenderer.class)).minWidth(100).expandX().widget();
126-
textBoxV.action = () -> {
127-
currMsgV = textBoxV.get();
128-
};
136+
textBoxV.action = () -> currMsgV = textBoxV.get();
129137
WPlus add = table.add(theme.plus()).widget();
130138
add.action = () -> {
131-
if (currMsgK != "" && currMsgV != "") {
139+
if (!currMsgK.equals("") && !currMsgV.equals("")) {
132140
messages.put(currMsgK, currMsgV);
133-
currMsgK = ""; currMsgV = "";
134-
fillTable(theme,table);
141+
currMsgK = "";
142+
currMsgV = "";
143+
fillTable(theme, table);
135144
}
136145
};
137146
table.row();
@@ -140,25 +149,21 @@ private void fillTable(GuiTheme theme, WTable table) {
140149
@Override
141150
public NbtCompound toTag() {
142151
NbtCompound tag = super.toTag();
143-
152+
144153
NbtCompound messTag = new NbtCompound();
145-
messages.keySet().forEach((key) -> {
146-
messTag.put(key, NbtString.of(messages.get(key)));
147-
});
154+
messages.keySet().forEach((key) -> messTag.put(key, NbtString.of(messages.get(key))));
148155

149156
tag.put("messages", messTag);
150157
return tag;
151158
}
152159

153160
@Override
154161
public Module fromTag(NbtCompound tag) {
155-
162+
156163
messages.clear();
157164
if (tag.contains("messages")) {
158165
NbtCompound msgs = tag.getCompound("messages");
159-
msgs.getKeys().forEach((key) -> {
160-
messages.put(key, msgs.getString(key));
161-
});
166+
msgs.getKeys().forEach((key) -> messages.put(key, msgs.getString(key)));
162167
}
163168

164169
return super.fromTag(tag);
@@ -179,15 +184,15 @@ private static Value wrap(Entity entity) {
179184
);
180185
}
181186
return Value.map(new ValueMap()
182-
.set("_toString", Value.string(entity.getName().getString()))
183-
.set("health", Value.number(entity instanceof LivingEntity e ? e.getHealth() : 0))
184-
.set("pos", Value.map(new ValueMap()
185-
.set("_toString", posString(entity.getX(), entity.getY(), entity.getZ()))
186-
.set("x", Value.number(entity.getX()))
187-
.set("y", Value.number(entity.getY()))
188-
.set("z", Value.number(entity.getZ()))
189-
))
190-
.set("uuid", Value.string(entity.getUuidAsString()))
187+
.set("_toString", Value.string(entity.getName().getString()))
188+
.set("health", Value.number(entity instanceof LivingEntity e ? e.getHealth() : 0))
189+
.set("pos", Value.map(new ValueMap()
190+
.set("_toString", posString(entity.getX(), entity.getY(), entity.getZ()))
191+
.set("x", Value.number(entity.getX()))
192+
.set("y", Value.number(entity.getY()))
193+
.set("z", Value.number(entity.getZ()))
194+
))
195+
.set("uuid", Value.string(entity.getUuidAsString()))
191196
);
192197
}
193198

0 commit comments

Comments
 (0)