Skip to content

Commit 47929ff

Browse files
committed
Projection, Particles, Speed fixes
1 parent 1392101 commit 47929ff

File tree

14 files changed

+273
-35
lines changed

14 files changed

+273
-35
lines changed

common/src/main/java/com/lambda/mixin/entity/ClientPlayInteractionManagerMixin.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.lambda.mixin.entity;
22

33
import com.lambda.event.EventFlow;
4+
import com.lambda.event.events.AttackEvent;
45
import com.lambda.event.events.InteractionEvent;
56
import net.minecraft.client.MinecraftClient;
67
import net.minecraft.client.network.ClientPlayerEntity;
78
import net.minecraft.client.network.ClientPlayerInteractionManager;
9+
import net.minecraft.entity.Entity;
10+
import net.minecraft.entity.player.PlayerEntity;
811
import net.minecraft.util.ActionResult;
912
import net.minecraft.util.Hand;
1013
import net.minecraft.util.hit.BlockHitResult;
@@ -13,6 +16,7 @@
1316
import org.spongepowered.asm.mixin.Shadow;
1417
import org.spongepowered.asm.mixin.injection.At;
1518
import org.spongepowered.asm.mixin.injection.Inject;
19+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1620
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1721

1822
@Mixin(ClientPlayerInteractionManager.class)
@@ -27,4 +31,14 @@ public void interactBlockHead(final ClientPlayerEntity player, final Hand hand,
2731
if (client.world == null) return;
2832
EventFlow.post(new InteractionEvent.Block(client.world, hitResult));
2933
}
34+
35+
@Inject(method = "attackEntity", at = @At("HEAD"), cancellable = true)
36+
void onAttackPre(PlayerEntity player, Entity target, CallbackInfo ci) {
37+
if (EventFlow.post(new AttackEvent.Pre(target)).isCanceled()) ci.cancel();
38+
}
39+
40+
@Inject(method = "attackEntity", at = @At("TAIL"))
41+
void onAttackPost(PlayerEntity player, Entity target, CallbackInfo ci) {
42+
EventFlow.post(new AttackEvent.Post(target));
43+
}
3044
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.lambda.event.events
2+
3+
import com.lambda.event.Event
4+
import com.lambda.event.callback.Cancellable
5+
import com.lambda.event.callback.ICancellable
6+
import net.minecraft.entity.Entity
7+
8+
abstract class AttackEvent(val entity: Entity) : Event {
9+
class Pre(entity: Entity) : AttackEvent(entity), ICancellable by Cancellable()
10+
class Post(entity: Entity) : AttackEvent(entity)
11+
}

common/src/main/kotlin/com/lambda/graphics/buffer/vao/IRenderContext.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package com.lambda.graphics.buffer.vao
22

3-
import com.lambda.graphics.gl.Matrices
4-
import org.joml.Matrix4f
53
import java.awt.Color
64

75
interface IRenderContext {
86
fun vec3(x: Double, y: Double, z: Double): IRenderContext
97
fun vec2(x: Double, y: Double): IRenderContext
108

11-
fun vec3m(x: Double, y: Double, z: Double, matrix4f: Matrix4f = Matrices.peek()): IRenderContext
12-
fun vec2m(x: Double, y: Double, matrix4f: Matrix4f = Matrices.peek()): IRenderContext
9+
fun vec3m(x: Double, y: Double, z: Double): IRenderContext
10+
fun vec2m(x: Double, y: Double): IRenderContext
1311

1412
fun float(v: Double): IRenderContext
1513
fun color(color: Color): IRenderContext

common/src/main/kotlin/com/lambda/graphics/buffer/vao/VAO.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.lambda.graphics.buffer.vao
33
import com.lambda.graphics.buffer.vao.vertex.BufferUsage
44
import com.lambda.graphics.buffer.vao.vertex.VertexAttrib
55
import com.lambda.graphics.buffer.vao.vertex.VertexMode
6+
import com.lambda.graphics.gl.Matrices
67
import com.lambda.graphics.gl.Memory.address
78
import com.lambda.graphics.gl.Memory.byteBuffer
89
import com.lambda.graphics.gl.Memory.capacity
@@ -89,16 +90,20 @@ class VAO(
8990
return this
9091
}
9192

92-
override fun vec3m(x: Double, y: Double, z: Double, matrix4f: Matrix4f): IRenderContext {
93-
// ToDo: optimize at runtime
94-
val vec = Vector4d(x, y, z, 1.0).apply(Matrix4d(matrix4f)::transform)
95-
verticesPosition += vec3(verticesPosition, vec.x, vec.y, vec.z)
93+
override fun vec3m(x: Double, y: Double, z: Double): IRenderContext {
94+
Matrices.vertexTransformer?.let { mat ->
95+
val vec = Vector4d(x, y, z, 1.0).apply(mat::transform)
96+
vec3(vec.x, vec.y, vec.z)
97+
} ?: vec3(x, y, z)
98+
9699
return this
97100
}
98101

99-
override fun vec2m(x: Double, y: Double, matrix4f: Matrix4f): IRenderContext {
100-
val vec = Vector4d(x, y, 0.0, 1.0).apply(Matrix4d(matrix4f)::transform)
101-
verticesPosition += vec2(verticesPosition, vec.x, vec.y)
102+
override fun vec2m(x: Double, y: Double): IRenderContext {
103+
Matrices.vertexTransformer?.let { mat ->
104+
val vec = Vector4d(x, y, 0.0, 1.0).apply(mat::transform)
105+
vec2(vec.x, vec.y)
106+
} ?: vec2(x, y)
102107
return this
103108
}
104109

common/src/main/kotlin/com/lambda/graphics/buffer/vao/vertex/VertexAttrib.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ enum class VertexAttrib(val componentCount: Int, componentSize: Int, val normali
1616
POS_UV(Vec2, Vec2),
1717

1818
// GUI
19-
FONT(Vec2, Vec2, Color), // pos, uv, color
19+
FONT(Vec3, Vec2, Color), // pos, uv, color
2020
RECT_FILLED(Vec2, Vec2, Vec2, Float, Float, Color), // pos, uv, size, roundRadius, shade, color
2121
RECT_OUTLINE(Vec2, Float, Float, Color), // pos, alpha, shade, color
2222

2323
// WORLD
2424
DYNAMIC_RENDERER(Vec3, Vec3, Color), // prev pos, pos, color
25-
STATIC_RENDERER(Vec3, Color); // pos, color
25+
STATIC_RENDERER(Vec3, Color), // pos, color
26+
27+
PARTICLE(Vec3, Vec2, Color); // pos, uv, color
2628

2729
val stride = attributes.sumOf { attribute -> attribute.size }
2830
}

common/src/main/kotlin/com/lambda/graphics/gl/Matrices.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package com.lambda.graphics.gl
22

3+
import com.lambda.Lambda.mc
4+
import net.minecraft.util.math.Vec3d
5+
import org.joml.Matrix4d
36
import org.joml.Matrix4f
47
import org.joml.Quaternionf
58

69
object Matrices {
710
private val stack = ArrayDeque<Matrix4f>(1)
811

12+
var vertexTransformer: Matrix4d? = null
13+
914
fun translate(x: Double, y: Double, z: Double) {
1015
translate(x.toFloat(), y.toFloat(), z.toFloat())
1116
}
@@ -51,4 +56,18 @@ object Matrices {
5156
stack.clear()
5257
stack.add(entry)
5358
}
59+
60+
fun withVertexTransform(matrix: Matrix4f, block: () -> Unit) {
61+
vertexTransformer = Matrix4d(matrix)
62+
block()
63+
vertexTransformer = null
64+
}
65+
66+
fun buildWorldProjection(pos: Vec3d, scale: Double = 1.0) = Matrix4f().apply {
67+
val s = 0.025f * scale.toFloat()
68+
69+
translate(pos.x.toFloat(), pos.y.toFloat(), pos.z.toFloat())
70+
rotate(mc.gameRenderer.camera.rotation)
71+
scale(-s, -s, s)
72+
}
5473
}

common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/FontRenderer.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class FontRenderer(
3333
iterateText(text, scale, shadow, color) { char, pos1, pos2, color ->
3434
grow(4)
3535
putQuad(
36-
vec2(pos1.x + position.x, pos1.y + position.y).vec2(char.uv1.x, char.uv1.y).color(color).end(),
37-
vec2(pos1.x + position.x, pos2.y + position.y).vec2(char.uv1.x, char.uv2.y).color(color).end(),
38-
vec2(pos2.x + position.x, pos2.y + position.y).vec2(char.uv2.x, char.uv2.y).color(color).end(),
39-
vec2(pos2.x + position.x, pos1.y + position.y).vec2(char.uv2.x, char.uv1.y).color(color).end()
36+
vec3m(pos1.x + position.x, pos1.y + position.y, 0.0).vec2(char.uv1.x, char.uv1.y).color(color).end(),
37+
vec3m(pos1.x + position.x, pos2.y + position.y, 0.0).vec2(char.uv1.x, char.uv2.y).color(color).end(),
38+
vec3m(pos2.x + position.x, pos2.y + position.y, 0.0).vec2(char.uv2.x, char.uv2.y).color(color).end(),
39+
vec3m(pos2.x + position.x, pos1.y + position.y, 0.0).vec2(char.uv2.x, char.uv1.y).color(color).end()
4040
)
4141
}
4242
}

common/src/main/kotlin/com/lambda/graphics/renderer/gui/rect/FilledRectRenderer.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ class FilledRectRenderer : AbstractRectRenderer(
5050
grow(4)
5151

5252
putQuad(
53-
vec2(p1.x, p1.y).vec2(0.0, 0.0).vec2(size.x, size.y).float(round).float(s).color(leftTop).end(),
54-
vec2(p1.x, p2.y).vec2(0.0, 1.0).vec2(size.x, size.y).float(round).float(s).color(leftBottom).end(),
55-
vec2(p2.x, p2.y).vec2(1.0, 1.0).vec2(size.x, size.y).float(round).float(s).color(rightBottom).end(),
56-
vec2(p2.x, p1.y).vec2(1.0, 0.0).vec2(size.x, size.y).float(round).float(s).color(rightTop).end()
53+
vec2m(p1.x, p1.y).vec2(0.0, 0.0).vec2(size.x, size.y).float(round).float(s).color(leftTop).end(),
54+
vec2m(p1.x, p2.y).vec2(0.0, 1.0).vec2(size.x, size.y).float(round).float(s).color(leftBottom).end(),
55+
vec2m(p2.x, p2.y).vec2(1.0, 1.0).vec2(size.x, size.y).float(round).float(s).color(rightBottom).end(),
56+
vec2m(p2.x, p1.y).vec2(1.0, 0.0).vec2(size.x, size.y).float(round).float(s).color(rightTop).end()
5757
)
5858
}
5959

common/src/main/kotlin/com/lambda/graphics/renderer/gui/rect/OutlineRectRenderer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class OutlineRectRenderer : AbstractRectRenderer(
5757

5858
val pos = base + Vec2d(cos(angle), -sin(angle)) * round
5959
val s = shade.toInt().toDouble()
60-
add(vec2(pos.x, pos.y).float(a).float(s).color(c).end())
60+
add(vec2m(pos.x, pos.y).float(a).float(s).color(c).end())
6161
}
6262

6363
val rt = r.rightTop + Vec2d(-round, round)

common/src/main/kotlin/com/lambda/module/modules/movement/Speed.kt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,6 @@ object Speed : Module(
123123
event.context = RotationContext(rotation, rotationConfig)
124124
}
125125

126-
listener<MovementEvent.InputUpdate> { event ->
127-
if (mode != Mode.GRIM_STRAFE) return@listener
128-
if (!shouldWork() || !isInputting) return@listener
129-
if (player.input.handledByBaritone || TargetStrafe.isActive) return@listener
130-
131-
event.input.mergeFrom(
132-
buildMovementInput(
133-
1.0, 0.0, event.input.jumping, event.input.sneaking
134-
)
135-
)
136-
}
137-
138126
onEnable {
139127
reset()
140128
}

0 commit comments

Comments
 (0)