11package anticope .esixtwoone ;
22
3+ import meteordevelopment .meteorclient .MeteorClient ;
34import meteordevelopment .meteorclient .events .world .TickEvent ;
45import meteordevelopment .meteorclient .renderer .Renderer2D ;
56import meteordevelopment .meteorclient .renderer .GL ;
2021import net .minecraft .client .texture .NativeImageBackedTexture ;
2122import net .minecraft .util .Identifier ;
2223
23- import anticope .esixtwoone .sources .ESixTwoOne ;
2424import anticope .esixtwoone .sources .Source ;
2525import anticope .esixtwoone .sources .Source .Size ;
2626import anticope .esixtwoone .sources .Source .SourceType ;
@@ -34,7 +34,7 @@ public class ImageHUD extends HudElement {
3434 private boolean locked = false ;
3535 private boolean empty = true ;
3636 private int ticks = 0 ;
37- private Source source = new ESixTwoOne () ;
37+ private Source source ;
3838
3939 private static final Identifier TEXID = new Identifier ("e621" , "tex" );
4040
@@ -46,6 +46,7 @@ public class ImageHUD extends HudElement {
4646 .defaultValue (100 )
4747 .min (10 )
4848 .sliderRange (70 , 1000 )
49+ .onChanged (o -> updateSize ())
4950 .build ()
5051 );
5152
@@ -55,40 +56,31 @@ public class ImageHUD extends HudElement {
5556 .defaultValue (100 )
5657 .min (10 )
5758 .sliderRange (70 , 1000 )
59+ .onChanged (o -> updateSize ())
5860 .build ()
5961 );
6062
6163 private final Setting <String > tags = sgGeneral .add (new StringSetting .Builder ()
6264 .name ("tags" )
6365 .description ("Tags" )
6466 .defaultValue ("femboy" )
65- .onChanged ((v ) -> {
66- source .reset ();
67- empty = true ;
68- })
67+ .onChanged ((v ) -> updateSource ())
6968 .build ()
7069 );
7170
7271 private final Setting <Size > size = sgGeneral .add (new EnumSetting .Builder <Size >()
7372 .name ("size" )
7473 .description ("Size mode." )
7574 .defaultValue (Size .preview )
76- .onChanged ((v ) -> {
77- source .reset ();
78- empty = true ;
79- })
75+ .onChanged ((v ) -> updateSource ())
8076 .build ()
8177 );
8278
8379 private final Setting <SourceType > sourceType = sgGeneral .add (new EnumSetting .Builder <SourceType >()
8480 .name ("source" )
8581 .description ("Source Type." )
8682 .defaultValue (SourceType .e621 )
87- .onChanged ((v ) -> {
88- source = Source .getSource (v );
89- source .reset ();
90- empty = true ;
91- })
83+ .onChanged (v -> updateSource ())
9284 .build ()
9385 );
9486
@@ -98,11 +90,20 @@ public class ImageHUD extends HudElement {
9890 .defaultValue (1200 )
9991 .max (3000 )
10092 .min (20 )
93+ .sliderRange (20 , 3000 )
10194 .build ()
10295 );
10396
10497 public ImageHUD () {
10598 super (INFO );
99+ updateSource ();
100+ MeteorClient .EVENT_BUS .subscribe (this );
101+ }
102+
103+ @ Override
104+ public void remove () {
105+ super .remove ();
106+ MeteorClient .EVENT_BUS .unsubscribe (this );
106107 }
107108
108109 private static ImageHUD create () {
@@ -111,7 +112,6 @@ private static ImageHUD create() {
111112
112113 @ EventHandler
113114 public void onTick (TickEvent .Post event ) {
114- if (mc .world == null ) return ;
115115 ticks ++;
116116 if (ticks >= refreshRate .get ()) {
117117 ticks = 0 ;
@@ -132,6 +132,16 @@ public void render(HudRenderer renderer) {
132132 Renderer2D .TEXTURE .render (null );
133133 }
134134
135+ private void updateSize () {
136+ setSize (imgWidth .get (), imgHeight .get ());
137+ }
138+
139+ private void updateSource () {
140+ source = Source .getSource (sourceType .get ());
141+ source .reset ();
142+ empty = true ;
143+ }
144+
135145 private void loadImage () {
136146 if (locked || source == null )
137147 return ;
@@ -152,6 +162,6 @@ private void loadImage() {
152162 }
153163 locked = false ;
154164 }).start ();
155- setSize ( imgWidth . get (), imgHeight . get () );
165+ updateSize ( );
156166 }
157167}
0 commit comments