4
4
import anticope .rejects .gui .screens .InteractionScreen ;
5
5
import it .unimi .dsi .fastutil .objects .Object2BooleanMap ;
6
6
import meteordevelopment .meteorclient .gui .GuiTheme ;
7
- import meteordevelopment .meteorclient .gui .utils .CharFilter ;
8
7
import meteordevelopment .meteorclient .gui .utils .StarscriptTextBoxRenderer ;
9
8
import meteordevelopment .meteorclient .gui .widgets .WWidget ;
10
9
import meteordevelopment .meteorclient .gui .widgets .containers .WTable ;
19
18
import meteordevelopment .meteorclient .utils .render .color .SettingColor ;
20
19
import meteordevelopment .starscript .value .Value ;
21
20
import meteordevelopment .starscript .value .ValueMap ;
22
-
23
21
import net .minecraft .client .render .debug .DebugRenderer ;
24
22
import net .minecraft .entity .Entity ;
25
23
import net .minecraft .entity .EntityType ;
26
24
import net .minecraft .entity .LivingEntity ;
27
25
import net .minecraft .nbt .NbtCompound ;
28
26
import net .minecraft .nbt .NbtString ;
29
27
30
- import java .util .*;
28
+ import java .util .HashMap ;
29
+ import java .util .Optional ;
31
30
32
31
public class InteractionMenu extends Module {
33
-
32
+
34
33
private final SettingGroup sgGeneral = settings .getDefaultGroup ();
35
34
private final SettingGroup sgStyle = settings .createGroup ("Style" );
36
-
35
+
37
36
private final Setting <Object2BooleanMap <EntityType <?>>> entities = sgGeneral .add (new EntityTypeListSetting .Builder ()
38
37
.name ("entities" )
39
38
.description ("Entities" )
@@ -47,6 +46,12 @@ public class InteractionMenu extends Module {
47
46
.action (this ::onKey )
48
47
.build ()
49
48
);
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
+ );
50
55
51
56
// Style
52
57
public final Setting <SettingColor > selectedDotColor = sgStyle .add (new ColorSetting .Builder ()
@@ -70,33 +75,40 @@ public class InteractionMenu extends Module {
70
75
public final Setting <SettingColor > borderColor = sgStyle .add (new ColorSetting .Builder ()
71
76
.name ("border-color" )
72
77
.description ("Color of the border." )
73
- .defaultValue (new SettingColor (0 ,0 , 0 ))
78
+ .defaultValue (new SettingColor (0 , 0 , 0 ))
74
79
.build ()
75
80
);
76
81
public final Setting <SettingColor > textColor = sgStyle .add (new ColorSetting .Builder ()
77
82
.name ("text-color" )
78
83
.description ("Color of the text." )
79
- .defaultValue (new SettingColor (255 ,255 ,255 ))
84
+ .defaultValue (new SettingColor (255 , 255 , 255 ))
80
85
.build ()
81
86
);
82
-
83
- public final HashMap <String ,String > messages = new HashMap <>();
87
+
88
+ public final HashMap <String , String > messages = new HashMap <>();
84
89
private String currMsgK = "" , currMsgV = "" ;
85
-
90
+
86
91
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." );
88
93
MeteorStarscript .ss .set ("entity" , () -> wrap (InteractionScreen .interactionMenuEntity ));
89
94
}
90
95
91
96
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 ();
98
105
}
99
106
}
107
+
108
+ if (e == null ) return ;
109
+ if (entities .get ().getBoolean (e .getType ())) {
110
+ mc .setScreen (new InteractionScreen (e , this ));
111
+ }
100
112
}
101
113
102
114
@ Override
@@ -114,24 +126,21 @@ private void fillTable(GuiTheme theme, WTable table) {
114
126
WMinus delete = table .add (theme .minus ()).widget ();
115
127
delete .action = () -> {
116
128
messages .remove (key );
117
- fillTable (theme ,table );
129
+ fillTable (theme , table );
118
130
};
119
131
table .row ();
120
132
});
121
133
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 ();
125
135
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 ();
129
137
WPlus add = table .add (theme .plus ()).widget ();
130
138
add .action = () -> {
131
- if (currMsgK != "" && currMsgV != "" ) {
139
+ if (! currMsgK . equals ( "" ) && ! currMsgV . equals ( "" ) ) {
132
140
messages .put (currMsgK , currMsgV );
133
- currMsgK = "" ; currMsgV = "" ;
134
- fillTable (theme ,table );
141
+ currMsgK = "" ;
142
+ currMsgV = "" ;
143
+ fillTable (theme , table );
135
144
}
136
145
};
137
146
table .row ();
@@ -140,25 +149,21 @@ private void fillTable(GuiTheme theme, WTable table) {
140
149
@ Override
141
150
public NbtCompound toTag () {
142
151
NbtCompound tag = super .toTag ();
143
-
152
+
144
153
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 ))));
148
155
149
156
tag .put ("messages" , messTag );
150
157
return tag ;
151
158
}
152
159
153
160
@ Override
154
161
public Module fromTag (NbtCompound tag ) {
155
-
162
+
156
163
messages .clear ();
157
164
if (tag .contains ("messages" )) {
158
165
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 )));
162
167
}
163
168
164
169
return super .fromTag (tag );
@@ -179,15 +184,15 @@ private static Value wrap(Entity entity) {
179
184
);
180
185
}
181
186
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 ()))
191
196
);
192
197
}
193
198
0 commit comments