Skip to content

Commit 11e5930

Browse files
committed
Pre release
1 parent 548be03 commit 11e5930

36 files changed

+682
-179
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ org.gradle.parallel=false
77
#org.gradle.configureondemand=true
88

99
# Mod properties
10-
mod.version=2.0.4
10+
mod.version=3.0.0
1111
mod.group=io.github.jumperonjava
1212
mod.id=customcursor
1313
mod.name=Custom cursor

src/main/java/io/github/jumperonjava/customcursor/CursorConfigStorage.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22

33

44
public class CursorConfigStorage {
5-
public CursorSettings pointer = new CursorSettings();
5+
public CursorSettings settings = new CursorSettings();
6+
public CursorConfigStorage() {
7+
}
68
}

src/main/java/io/github/jumperonjava/customcursor/CursorRenderer.java

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
package io.github.jumperonjava.customcursor;
22

3+
import io.github.jumperonjava.customcursor.util.VersionFunctions;
34
import net.minecraft.client.MinecraftClient;
45
//? if >= 1.21.6 {
5-
/*import net.minecraft.client.gl.RenderPipelines;
6-
*///?} else {
6+
import net.minecraft.client.gl.RenderPipelines;
7+
//?} else {
8+
/*import net.minecraft.client.render.RenderLayer;
79
import com.mojang.blaze3d.systems.RenderSystem;
8-
//?}
10+
*///?}
911
import net.minecraft.client.gui.DrawContext;
10-
import net.minecraft.client.render.RenderLayer;
1112
import org.lwjgl.glfw.GLFW;
1213
import org.lwjgl.opengl.GL11;
1314

1415
public class CursorRenderer {
1516
public static void render(DrawContext context, int mouseX, int mouseY, float donotuse_delta) {
16-
var config = CustomCursorInit.getConfig().pointer;
17+
var config = CustomCursorInit.getConfig().settings;
1718
if (MinecraftClient.getInstance().currentScreen == null)
1819
return;
1920
if (!config.enabled) {
@@ -22,26 +23,39 @@ public static void render(DrawContext context, int mouseX, int mouseY, float don
2223
}
2324
var scale = MinecraftClient.getInstance().getWindow().getScaleFactor();
2425
//? if < 1.21.5
25-
RenderSystem.depthFunc(GL11.GL_ALWAYS);
26-
var identifier = config.currentCursor().identifier;
27-
var x = (int) Math.round(mouseX - config.size * config.currentCursor().x / scale);
28-
var y = (int) Math.round(mouseY - config.size * config.currentCursor().y / scale);
26+
/*RenderSystem.depthFunc(GL11.GL_ALWAYS);*/
27+
28+
var sprite = config.arrow;
29+
30+
//? if > 1.21.8 {
31+
var contextCursor = context.cursor;
32+
sprite = config.cursorToSprite(contextCursor);
33+
//?}
34+
35+
var identifier = sprite.identifier;
36+
37+
var x = (int) Math.round(mouseX - config.size * sprite.x / scale);
38+
var y = (int) Math.round(mouseY - config.size * sprite.y / scale);
2939
var u = (float) 0;
3040
var v = (float) 0;
3141
var width = (int) (config.size / scale);
3242
var height = (int) (config.size / scale);
3343
var textureWidth = (int) (config.size / scale);
3444
var textureHeight = (int) (config.size / scale);
45+
46+
VersionFunctions.pushMatrix(context);
47+
VersionFunctions.rotateAbout(context, (float) Math.toRadians(sprite.rotation), x+ (float) textureWidth /2, y+ (float) textureHeight /2);
3548
//? if < 1.21.3 {
36-
context.drawTexture(identifier,x,y,u,v,width,height,textureWidth,textureHeight);
37-
//?} else if < 1.21.6 {
38-
/*context.drawTexture(RenderLayer::getGuiTexturedOverlay, identifier, x, y, u, v, width, height, textureWidth, textureHeight);
49+
/*context.drawTexture(identifier,x,y,u,v,width,height,textureWidth * (sprite.mirroredX ? -1:1), textureHeight* (sprite.mirroredY ? -1:1));
50+
*///?} else if < 1.21.6 {
51+
/*context.drawTexture(RenderLayer::getGuiTexturedOverlay, identifier, x, y, u, v, width, height, textureWidth * (sprite.mirroredX ? -1:1), textureHeight* (sprite.mirroredY ? -1:1));
3952
*///?} else {
40-
/*context.drawTexture(RenderPipelines.GUI_TEXTURED, identifier, x, y, u, v, width, height, textureWidth, textureHeight);
53+
context.drawTexture(RenderPipelines.GUI_TEXTURED, identifier, x, y, u, v, width, height, textureWidth * (sprite.mirroredX ? -1:1), textureHeight* (sprite.mirroredY ? -1:1));
54+
//?}
55+
VersionFunctions.popMatrix(context);
4156

42-
*///?}
4357
//? if < 1.21.5
44-
RenderSystem.depthFunc(GL11.GL_LEQUAL);
58+
/*RenderSystem.depthFunc(GL11.GL_LEQUAL);*/
4559

4660
//for debugging
4761
//context.drawTexture(new Identifier("customcursor","textures/gui/pointer.png"), (int) (mouseX-4), (int) (mouseY-4),0,0,8,8,8,8);

src/main/java/io/github/jumperonjava/customcursor/CursorSettings.java

Lines changed: 82 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,106 @@
22

33

44
import com.google.gson.Gson;
5+
import net.minecraft.client.gui.cursor.Cursor;
6+
import net.minecraft.client.gui.cursor.StandardCursors;
57
import net.minecraft.util.Identifier;
68

9+
import java.util.List;
10+
import java.util.Map;
711
import 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

Comments
 (0)