22
33
44import com .google .gson .Gson ;
5+ import net .minecraft .client .gui .cursor .Cursor ;
6+ import net .minecraft .client .gui .cursor .StandardCursors ;
57import net .minecraft .util .Identifier ;
68
9+ import java .util .List ;
10+ import java .util .Map ;
711import java .util .Objects ;
812
9- public class CursorSettings implements Cloneable {
10- public int size =32 ;
11- public boolean enabled =false ;
13+ public class CursorSettings implements Cloneable {
14+ public static Cursor globalCursor ;
1215
13- CursorSprite pointer = new CursorSprite (1 ,9 , 0 , false ,Identifier .of ("minecraft" , "textures/item/diamond_sword.png" ));
14- CursorSprite arrow = new CursorSprite (0 ,0 , 0 , false ,Identifier .of ("minecraft" , "textures/item/arrow.png" ));
15- CursorSprite ibeam = new CursorSprite (0 ,0 , 0 , false ,Identifier .of ("minecraft" , "textures/item/ink_sac.png" ));
16- CursorSprite crosshair = new CursorSprite (0 ,0 , 0 , false ,Identifier .of ("minecraft" , "textures/item/lead.png" ));
17- CursorSprite pointing_hand = new CursorSprite (0 ,0 , 0 , false ,Identifier .of ("minecraft" , "textures/item/rabbit_foot.png" ));
18- CursorSprite resize_ns = new CursorSprite (0 ,0 , 0 , false ,Identifier .of ("minecraft" , "textures/item/golden_hoe.png" ));
19- CursorSprite resize_ew = new CursorSprite (0 ,0 , 0 , false ,Identifier .of ("minecraft" , "textures/item/copper_hoe.png" ));
20- CursorSprite resize_all = new CursorSprite (0 ,0 , 0 , false ,Identifier .of ("minecraft" , "textures/item/nether_star.png" ));
21- CursorSprite not_allowed = new CursorSprite (0 ,0 , 0 , false ,Identifier .of ("minecraft" , "textures/item/barrier.png" ));
16+ public int size = 32 ;
17+ public boolean enabled = false ;
18+ public boolean dynamicEnabled = true ;
2219
23- public CursorSettings clone () {
24- return new Gson ().fromJson (new Gson ().toJson (this ), CursorSettings .class );
20+
21+ public final CursorSprite arrow = new CursorSprite (0.0625f , 0.0625f , 0 , false , Identifier .of ("customcursor" , "cursors/arrow.png" ));
22+ public final CursorSprite ibeam = new CursorSprite (0.5f , 0.5f , 0 , false , Identifier .of ("customcursor" , "cursors/ibeam.png" ));
23+ public final CursorSprite crosshair = new CursorSprite (0.5f , 0.5f , 0 , false , Identifier .of ("customcursor" , "cursors/crosshair.png" ));
24+ public final CursorSprite pointing_hand = new CursorSprite (0.375f , 0 , 0 , false , Identifier .of ("customcursor" , "cursors/pointing_hand.png" ));
25+ public final CursorSprite resize_ns = new CursorSprite (0.5f , 0.5f , 0 , false , Identifier .of ("customcursor" , "cursors/resize_ns.png" ));
26+ public final CursorSprite resize_ew = new CursorSprite (0.5f , 0.5f , 0 , false , Identifier .of ("customcursor" , "cursors/resize_ew.png" ));
27+ public final CursorSprite resize_all = new CursorSprite (0.5f , 0.5f , 0 , false , Identifier .of ("customcursor" , "cursors/resize_all.png" ));
28+ public final CursorSprite not_allowed = new CursorSprite (0.5f , 0.5f , 0 , false , Identifier .of ("minecraft" , "textures/item/barrier.png" ));
29+
30+ public Map <String , CursorSprite > allCursors () {
31+ return Map .of (
32+ "arrow" , arrow ,
33+ "ibeam" , ibeam ,
34+ "crosshair" , crosshair ,
35+ "pointing_hand" , pointing_hand ,
36+ "resize_ns" , resize_ns ,
37+ "resize_ew" , resize_ew ,
38+ "resize_all" , resize_all ,
39+ "not_allowed" , not_allowed
40+ );
2541 }
2642
27- public CursorSprite currentCursor () {
28- return pointer ;
43+ public static Map <String , Cursor > cursors () {
44+ return Map .of (
45+ "arrow" , StandardCursors .ARROW ,
46+ "ibeam" , StandardCursors .IBEAM ,
47+ "crosshair" , StandardCursors .CROSSHAIR ,
48+ "pointing_hand" , StandardCursors .POINTING_HAND ,
49+ "resize_ns" , StandardCursors .RESIZE_NS ,
50+ "resize_ew" , StandardCursors .RESIZE_EW ,
51+ "resize_all" , StandardCursors .RESIZE_ALL ,
52+ "not_allowed" , StandardCursors .NOT_ALLOWED
53+ );
54+ }
55+
56+ public static final List <String > cursorOrder = List .of (
57+ "arrow" ,
58+ "ibeam" ,
59+ "crosshair" ,
60+ "pointing_hand" ,
61+ "resize_ns" ,
62+ "resize_ew" ,
63+ "resize_all" ,
64+ "not_allowed"
65+ );
66+
67+ public CursorSprite cursorToSprite (Cursor cursor ) {
68+ if (!this .dynamicEnabled ){
69+ return this .arrow ;
70+ }
71+ var map = Map .of (
72+ Cursor .DEFAULT , arrow ,
73+ StandardCursors .ARROW , arrow ,
74+ StandardCursors .IBEAM , ibeam ,
75+ StandardCursors .CROSSHAIR , crosshair ,
76+ StandardCursors .POINTING_HAND , pointing_hand ,
77+ StandardCursors .RESIZE_NS , resize_ns ,
78+ StandardCursors .RESIZE_EW , resize_ew ,
79+ StandardCursors .RESIZE_ALL , resize_all ,
80+ StandardCursors .NOT_ALLOWED , not_allowed
81+ );
82+ return map .get (cursor );
83+ }
84+
85+ public CursorSettings clone () {
86+ return new Gson ().fromJson (new Gson ().toJson (this ), CursorSettings .class );
2987 }
3088
3189 public static final class CursorSprite {
3290 public float x ;
3391 public float y ;
3492 public float rotation ;
35- public boolean mirror ;
93+ public boolean mirroredX ;
94+ public boolean mirroredY ;
3695 public Identifier identifier ;
3796
3897 public CursorSprite (float x , float y , float rotation , boolean mirror , Identifier identifier ) {
3998 this .x = x ;
4099 this .y = y ;
41100 this .rotation = rotation ;
42- this .mirror = mirror ;
101+ this .mirroredX = mirror ;
43102 this .identifier = identifier ;
44103 }
104+
45105 @ Override
46106 public boolean equals (Object obj ) {
47107 if (obj == this ) return true ;
@@ -50,13 +110,13 @@ public boolean equals(Object obj) {
50110 return Float .floatToIntBits (this .x ) == Float .floatToIntBits (that .x ) &&
51111 Float .floatToIntBits (this .y ) == Float .floatToIntBits (that .y ) &&
52112 Float .floatToIntBits (this .rotation ) == Float .floatToIntBits (that .rotation ) &&
53- this .mirror == that .mirror &&
113+ this .mirroredX == that .mirroredX &&
54114 Objects .equals (this .identifier , that .identifier );
55115 }
56116
57117 @ Override
58118 public int hashCode () {
59- return Objects .hash (x , y , rotation , mirror , identifier );
119+ return Objects .hash (x , y , rotation , mirroredX , identifier );
60120 }
61121
62122 @ Override
@@ -65,10 +125,10 @@ public String toString() {
65125 "x=" + x + ", " +
66126 "y=" + y + ", " +
67127 "rotation=" + rotation + ", " +
68- "mirror=" + mirror + ", " +
128+ "mirror=" + mirroredX + ", " +
69129 "identifier=" + identifier + ']' ;
70130 }
71131
72- }
132+ }
73133
74134}
0 commit comments