1
1
package com .kevinthegreat .skyblockmod .waypoint ;
2
2
3
3
import com .kevinthegreat .skyblockmod .mixins .CheckboxWidgetAccessor ;
4
+ import it .unimi .dsi .fastutil .ints .Int2ObjectFunction ;
4
5
import net .minecraft .client .MinecraftClient ;
5
6
import net .minecraft .client .gui .DrawContext ;
6
7
import net .minecraft .client .gui .Element ;
7
8
import net .minecraft .client .gui .Selectable ;
8
9
import net .minecraft .client .gui .widget .*;
9
10
import net .minecraft .text .Text ;
10
11
import net .minecraft .util .math .BlockPos ;
11
- import org .apache .commons .lang3 .math .NumberUtils ;
12
12
13
13
import java .util .ArrayList ;
14
14
import java .util .Arrays ;
@@ -227,35 +227,28 @@ public void updateName(String name) {
227
227
}
228
228
229
229
public void updateX (String xString ) {
230
- if (!NumberUtils .isParsable (xString )) return ;
231
- int index = category .category .waypoints ().indexOf (waypoint );
232
- int x = Integer .parseInt (xString );
233
- if (waypoint .pos .getX () == x ) return ;
234
- waypoint = waypoint .withX (x );
235
- if (index >= 0 ) {
236
- category .category .waypoints ().set (index , waypoint );
237
- }
230
+ updateInt (xString , waypoint .pos .getX (), waypoint ::withX );
238
231
}
239
232
240
233
public void updateY (String yString ) {
241
- if (!NumberUtils .isParsable (yString )) return ;
242
- int index = category .category .waypoints ().indexOf (waypoint );
243
- int y = Integer .parseInt (yString );
244
- if (waypoint .pos .getY () == y ) return ;
245
- waypoint = waypoint .withY (y );
246
- if (index >= 0 ) {
247
- category .category .waypoints ().set (index , waypoint );
248
- }
234
+ updateInt (yString , waypoint .pos .getY (), waypoint ::withY );
249
235
}
250
236
251
237
public void updateZ (String zString ) {
252
- if (!NumberUtils .isParsable (zString )) return ;
253
- int index = category .category .waypoints ().indexOf (waypoint );
254
- int z = Integer .parseInt (zString );
255
- if (waypoint .pos .getZ () == z ) return ;
256
- waypoint = waypoint .withZ (z );
257
- if (index >= 0 ) {
258
- category .category .waypoints ().set (index , waypoint );
238
+ updateInt (zString , waypoint .pos .getZ (), waypoint ::withZ );
239
+ }
240
+
241
+ public void updateInt (String newValueString , int currentValue , Int2ObjectFunction <NamedWaypoint > wither ) {
242
+ try {
243
+ int index = category .category .waypoints ().indexOf (waypoint );
244
+ int newValue = Integer .parseInt (newValueString );
245
+ if (newValue == currentValue ) return ;
246
+ waypoint = wither .apply (newValue );
247
+ if (index >= 0 ) {
248
+ category .category .waypoints ().set (index , waypoint );
249
+ }
250
+ } catch (NumberFormatException e ) {
251
+ Waypoints .LOGGER .warn ("[Skyblocker Waypoints] Failed to parse integer: {}" , newValueString , e );
259
252
}
260
253
}
261
254
@@ -270,7 +263,8 @@ public void updateColor(String colorString) {
270
263
if (index >= 0 ) {
271
264
category .category .waypoints ().set (index , waypoint );
272
265
}
273
- } catch (NumberFormatException ignored ) {
266
+ } catch (NumberFormatException e ) {
267
+ Waypoints .LOGGER .warn ("[Skyblocker Waypoints] Failed to parse color: {}" , colorString , e );
274
268
}
275
269
}
276
270
0 commit comments