Skip to content

Commit a78c937

Browse files
committed
still fixes and refactors
1 parent 11e5930 commit a78c937

27 files changed

+319
-265
lines changed

build.gradle.kts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ dependencies {
6363
}
6464

6565
loom {
66-
accessWidenerPath = rootProject.file("src/main/resources/customcursor.accesswidener")
66+
//if there is no aw_version property for version it defaults to 1.20.1
67+
//added because i did not want to add this property for almost 20 versions
68+
//since 1.21.9 it is defined
69+
val awVersion = (findProperty("mod.aw_version") as String?) ?: "1.20.1"
70+
71+
accessWidenerPath = rootProject.file("src/main/resources/aw/customcursor.${awVersion}.accesswidener")
6772

6873
decompilers {
6974
get("vineflower").apply { // Adds names to lambdas - useful for mixins

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

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
import io.github.jumperonjava.customcursor.util.VersionFunctions;
44
import net.minecraft.client.MinecraftClient;
55
//? if >= 1.21.6 {
6-
import net.minecraft.client.gl.RenderPipelines;
7-
//?} else {
8-
/*import net.minecraft.client.render.RenderLayer;
6+
/*import net.minecraft.client.gl.RenderPipelines;
7+
*///?} else {
8+
import net.minecraft.client.render.RenderLayer;
99
import com.mojang.blaze3d.systems.RenderSystem;
10-
*///?}
10+
//?}
1111
import net.minecraft.client.gui.DrawContext;
1212
import org.lwjgl.glfw.GLFW;
1313
import org.lwjgl.opengl.GL11;
1414

1515
public class CursorRenderer {
16-
public static void render(DrawContext context, int mouseX, int mouseY, float donotuse_delta) {
16+
public static void render(DrawContext context, double mouseX, double mouseY, float donotuse_delta) {
1717
var config = CustomCursorInit.getConfig().settings;
1818
if (MinecraftClient.getInstance().currentScreen == null)
1919
return;
@@ -23,39 +23,47 @@ public static void render(DrawContext context, int mouseX, int mouseY, float don
2323
}
2424
var scale = MinecraftClient.getInstance().getWindow().getScaleFactor();
2525
//? if < 1.21.5
26-
/*RenderSystem.depthFunc(GL11.GL_ALWAYS);*/
26+
RenderSystem.depthFunc(GL11.GL_ALWAYS);
2727

2828
var sprite = config.arrow;
2929

3030
//? if > 1.21.8 {
31-
var contextCursor = context.cursor;
31+
/*var contextCursor = context.cursor;
3232
sprite = config.cursorToSprite(contextCursor);
33-
//?}
33+
*///?}
3434

3535
var identifier = sprite.identifier;
3636

37-
var x = (int) Math.round(mouseX - config.size * sprite.x / scale);
38-
var y = (int) Math.round(mouseY - config.size * sprite.y / scale);
37+
38+
mouseX = (float) MinecraftClient.getInstance().mouse.getX();
39+
mouseY = (float) MinecraftClient.getInstance().mouse.getY();
40+
var x = (int) Math.round(mouseX - config.size * sprite.x);
41+
var y = (int) Math.round(mouseY - config.size * sprite.y);
3942
var u = (float) 0;
4043
var v = (float) 0;
41-
var width = (int) (config.size / scale);
42-
var height = (int) (config.size / scale);
43-
var textureWidth = (int) (config.size / scale);
44-
var textureHeight = (int) (config.size / scale);
44+
var width = config.size;
45+
var height = config.size;
46+
var textureWidth = config.size;
47+
var textureHeight = config.size;
4548

4649
VersionFunctions.pushMatrix(context);
47-
VersionFunctions.rotateAbout(context, (float) Math.toRadians(sprite.rotation), x+ (float) textureWidth /2, y+ (float) textureHeight /2);
50+
//? if < 1.21.6 {
51+
context.getMatrices().scale((float) (1f/scale), (float) (1f/scale),1f);
52+
//?} else {
53+
/*context.getMatrices().scale((float) (1f/scale), (float) (1f/scale));
54+
*///?}
55+
VersionFunctions.rotateAbout(context, (float) Math.toRadians(sprite.rotation), x+ (float) textureWidth /2f, y+ (float) textureHeight /2f);
4856
//? if < 1.21.3 {
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 {
57+
context.drawTexture(identifier,x,y,u,v,width,height,textureWidth * (sprite.mirroredX ? -1:1), textureHeight* (sprite.mirroredY ? -1:1));
58+
//?} else if < 1.21.6 {
5159
/*context.drawTexture(RenderLayer::getGuiTexturedOverlay, identifier, x, y, u, v, width, height, textureWidth * (sprite.mirroredX ? -1:1), textureHeight* (sprite.mirroredY ? -1:1));
5260
*///?} else {
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);
61+
/*context.drawTexture(RenderPipelines.GUI_TEXTURED, identifier, x, y, u, v, width, height, textureWidth * (sprite.mirroredX ? -1:1), textureHeight* (sprite.mirroredY ? -1:1));
62+
*///?}
5663

64+
VersionFunctions.popMatrix(context);
5765
//? if < 1.21.5
58-
/*RenderSystem.depthFunc(GL11.GL_LEQUAL);*/
66+
RenderSystem.depthFunc(GL11.GL_LEQUAL);
5967

6068
//for debugging
6169
//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/CustomCursorInit.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.google.gson.Gson;
44
import com.google.gson.GsonBuilder;
55
import io.github.jumperonjava.customcursor.util.FileReadWrite;
6-
import io.github.jumperonjava.customcursor.util.TextureFolder;
6+
import io.github.jumperonjava.customcursor.editor.TextureFolder;
77
import net.minecraft.client.MinecraftClient;
88
import org.slf4j.Logger;
99
import org.slf4j.LoggerFactory;
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package io.github.jumperonjava.customcursor.editor;
2+
3+
import com.mojang.blaze3d.systems.RenderSystem;
4+
import io.github.jumperonjava.customcursor.util.VersionFunctions;
5+
import net.minecraft.client.gui.DrawContext;
6+
import net.minecraft.client.gui.Drawable;
7+
import net.minecraft.util.Identifier;
8+
import net.minecraft.util.math.MathHelper;
9+
import net.minecraft.util.math.Vec2f;
10+
11+
12+
//? if <= 1.21.5 {
13+
import com.mojang.blaze3d.systems.RenderSystem;
14+
//?} else {
15+
/*import net.minecraft.client.gl.RenderPipelines;
16+
*///?}
17+
18+
class BackgroundCheckerboard implements Drawable {
19+
private final CursorEditScreen cursorEditScreen;
20+
private final int x;
21+
private final int y;
22+
private final int size;
23+
24+
public BackgroundCheckerboard(CursorEditScreen cursorEditScreen, int x, int y, int size) {
25+
this.cursorEditScreen = cursorEditScreen;
26+
this.x = x;
27+
this.y = y;
28+
this.size = size;
29+
}
30+
31+
private float bgx, bgy, color;
32+
33+
@Override
34+
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
35+
//generates slowly changing pastel colors for backround
36+
color += delta * 0.05f;
37+
var n = 2;
38+
var color1 = VersionFunctions.ColorHelper.getArgb(255,
39+
(int) (128 + 64 * Math.pow(Math.sin(color + 0 * Math.PI / 3), n)),
40+
(int) (128 + 64 * Math.pow(Math.sin(color + 2 * Math.PI / 3), n)),
41+
(int) (128 + 64 * Math.pow(Math.sin(color + 4 * Math.PI / 3), n))
42+
);
43+
var color2 = VersionFunctions.ColorHelper.getArgb(255,
44+
(int) ((192 + 63 * Math.pow(Math.cos(color + 0 * Math.PI / 3), n))),
45+
(int) ((192 + 63 * Math.pow(Math.cos(color + 2 * Math.PI / 3), n))),
46+
(int) ((192 + 63 * Math.pow(Math.cos(color + 4 * Math.PI / 3), n)))
47+
);
48+
49+
float r = VersionFunctions.ColorHelper.getRed(color1) / 255f;
50+
float g = VersionFunctions.ColorHelper.getGreen(color1) / 255f;
51+
float b = VersionFunctions.ColorHelper.getBlue(color1) / 255f;
52+
53+
54+
var vec = new Vec2f(mouseX - (x + size / 2f), mouseY - (y + size / 2f)).normalize().multiply(delta);
55+
bgx += vec.x;
56+
bgy += vec.y;
57+
58+
context.fill(x, y, x + size, y + size, color2);
59+
context.enableScissor(x, y, x + size, y + size);
60+
61+
62+
var cellsize = size / 8;
63+
64+
65+
//? if < 1.21.6 {
66+
67+
context.getMatrices().push();
68+
context.getMatrices().translate(
69+
(x + MathHelper.floorMod(bgx, cellsize) - cellsize),
70+
(y + MathHelper.floorMod(bgy, cellsize) - cellsize),
71+
0);
72+
RenderSystem.setShaderColor(r, g, b, 255);
73+
74+
int checkerRenderSize = size + cellsize;
75+
VersionFunctions.drawTexture(context, Identifier.of("customcursor", "textures/gui/backgroundcheckerboard.png"),
76+
0,
77+
0,
78+
0,
79+
0, checkerRenderSize, checkerRenderSize, checkerRenderSize, checkerRenderSize);
80+
RenderSystem.setShaderColor(1, 1, 1, 1);
81+
82+
context.getMatrices().pop();
83+
context.disableScissor();
84+
//?} else {
85+
86+
87+
/*context.getMatrices().pushMatrix();
88+
context.getMatrices().translate(
89+
(x + MathHelper.floorMod(bgx, cellsize) - cellsize),
90+
(y + MathHelper.floorMod(bgy, cellsize) - cellsize));
91+
92+
93+
int color3 = VersionFunctions.ColorHelper.getArgb(255, (int) (r * 255), (int) (g * 255), (int) (b * 255));
94+
95+
int checkerRenderSize = size + cellsize;
96+
context.drawTexture(RenderPipelines.GUI_TEXTURED, Identifier.of("customcursor", "textures/gui/backgroundcheckerboard.png"),
97+
0,
98+
0,
99+
0,
100+
0, checkerRenderSize, checkerRenderSize, checkerRenderSize, checkerRenderSize, color3);
101+
102+
context.getMatrices().popMatrix();
103+
context.disableScissor();
104+
105+
*///?}
106+
}
107+
}

0 commit comments

Comments
 (0)