Skip to content

Commit 3a1352e

Browse files
committed
Merge branch 'master' into feature/packetmine-rewrite
# Conflicts: # common/src/main/java/com/lambda/mixin/MinecraftClientMixin.java
2 parents 3aebf1e + f84fcd5 commit 3a1352e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1864
-143
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,26 @@ name: Build Lambda
33
on:
44
push:
55
branches:
6-
- '**'
6+
- 'master'
7+
pull_request:
78

89
jobs:
9-
check-runner:
10-
name: Check Runner Availability
11-
runs-on: ubuntu-latest
12-
13-
outputs:
14-
runner-label: ${{ steps.set-runner.outputs.runner-label }}
15-
16-
steps:
17-
- name: Set runner
18-
id: set-runner
19-
run: |
20-
runners=$(curl -v -s -H "Accept: application/vnd.github+json" -H "Authorization: token ${{ secrets.REPO_ACCESS_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/actions/runners" --http1.1)
21-
if [ $? -ne 0 ]; then
22-
echo "Error: Failed to fetch runners from GitHub API" >&2
23-
exit 1
24-
fi
25-
26-
runners_count=$(echo "$runners" | jq '.runners | length')
27-
if [ "$runners_count" -eq 0 ]; then
28-
echo "No runners available or failed to retrieve runners." >&2
29-
echo "runner-label=ubuntu-latest" >> $GITHUB_OUTPUT
30-
exit 0
31-
fi
32-
33-
available=$(echo "$runners" | jq '.runners[] | select(.status == "online" and .busy == false and .labels[] .name == "self-hosted")')
34-
if [ $? -ne 0 ]; then
35-
echo "Error: Failed to parse JSON response" >&2
36-
exit 1
37-
fi
38-
39-
if [ -n "$available" ]; then
40-
echo "runner-label=lambda-linux-runner" >> $GITHUB_OUTPUT
41-
else
42-
echo "runner-label=ubuntu-latest" >> $GITHUB_OUTPUT
43-
fi
4410
build:
4511
concurrency:
4612
group: ${{ github.workflow }}-${{ github.ref }}
4713
cancel-in-progress: true
48-
49-
needs: check-runner
50-
runs-on: ${{ needs.check-runner.outputs.runner-label }}
5114

5215
name: Build Lambda
16+
runs-on: ubuntu-latest
17+
5318
permissions:
5419
contents: write
20+
5521
env:
5622
SEGMENT_DOWNLOAD_TIMEOUT_MINS: '5'
5723
steps:
5824
- name: Checkout Repository
59-
uses: actions/checkout@v4.1.1
25+
uses: actions/checkout@v4
6026

6127
- name: Set current date as env variable
6228
run: echo "DATE=$(date +'%Y-%m-%dT%H:%M:%S')" >> $GITHUB_ENV
@@ -65,11 +31,11 @@ jobs:
6531
id: vars
6632
run: echo "COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
6733

68-
- name: Set-Up JDK 17
34+
- name: Set-Up JDK
6935
uses: actions/setup-java@v4
7036
with:
7137
distribution: 'temurin'
72-
java-version: '17'
38+
java-version: '21'
7339
architecture: x64
7440
cache: 'gradle'
7541

@@ -81,7 +47,7 @@ jobs:
8147
all: true
8248

8349
- name: Build Lambda
84-
run: ./gradlew build
50+
run: ./gradlew build --no-daemon
8551

8652
- name: Rename Files with Commit Hash
8753
run: |
@@ -111,8 +77,6 @@ jobs:
11177
### [Lambda Forge ${{ steps.all.outputs.modVersion }} ${{ steps.all.outputs.minecraftVersion }} (${{ env.COMMIT_HASH }})](https://r2-bucket.edouard127.christmas/${{ env.DATE }}-${{ env.COMMIT_HASH }}/lambda-forge-${{ steps.all.outputs.modVersion }}+${{ steps.all.outputs.minecraftVersion }}-${{ env.COMMIT_HASH }}.jar)
11278
11379
#### [API (Developer Dependency)](https://r2-bucket.edouard127.christmas/${{ env.DATE }}-${{ env.COMMIT_HASH }}/lambda-api-${{ steps.all.outputs.modVersion }}+${{ steps.all.outputs.minecraftVersion }}-${{ env.COMMIT_HASH }}.jar)
114-
115-
**Runner:** \`${{ needs.check-runner.outputs.runner-label }}\`
11680
EOF
11781
11882
- name: Failover Upload

.github/workflows/publish-docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: Publish Dokka Documentation
22

33
on:
44
push:
5-
branches:
6-
- 'master'
5+
tags:
6+
- '*'
77

88
jobs:
99
build:

common/build.gradle.kts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ val kotlinxCoroutinesVersion: String by project
2323
val discordIPCVersion: String by project
2424
val fuelVersion: String by project
2525
val resultVersion: String by project
26+
val mockitoKotlin: String by project
27+
val mockitoInline: String by project
28+
val mockkVersion: String by project
2629

2730
base.archivesName = "${base.archivesName.get()}-api"
2831

@@ -57,6 +60,10 @@ dependencies {
5760

5861
// Baritone
5962
modImplementation("baritone-api:baritone-unoptimized-fabric:1.10.2") { isTransitive = false }
63+
testImplementation(kotlin("test"))
64+
testImplementation("org.mockito.kotlin:mockito-kotlin:$mockitoKotlin")
65+
testImplementation("org.mockito:mockito-inline:$mockitoInline")
66+
testImplementation("io.mockk:mockk:${mockkVersion}")
6067
}
6168

6269
tasks {
@@ -66,5 +73,12 @@ tasks {
6673

6774
test {
6875
useJUnitPlatform()
76+
jvmArgs("-XX:+EnableDynamicAgentLoading", "-Xshare:off")
77+
}
78+
}
79+
80+
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
81+
kotlinOptions {
82+
jvmTarget = "17"
6983
}
7084
}

common/src/main/java/com/lambda/mixin/MinecraftClientMixin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider;
3030
import net.minecraft.client.network.ClientPlayerEntity;
3131
import net.minecraft.client.network.ClientPlayerInteractionManager;
32+
import net.minecraft.util.thread.ThreadExecutor;
3233
import net.minecraft.util.Hand;
3334
import net.minecraft.util.hit.HitResult;
3435
import org.jetbrains.annotations.Nullable;
@@ -74,7 +75,7 @@ private void onShutdown(CallbackInfo ci) {
7475
}
7576

7677
/**
77-
* Inject after the thread field is set so `ThreadExecutor#getThread` is available
78+
* Inject after the thread field is set so that {@link ThreadExecutor#getThread} is available
7879
*/
7980
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;thread:Ljava/lang/Thread;", shift = At.Shift.AFTER, ordinal = 0), method = "run")
8081
private void onStartup(CallbackInfo ci) {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import net.minecraft.entity.Entity;
2626
import net.minecraft.entity.player.PlayerEntity;
2727
import net.minecraft.entity.player.PlayerInventory;
28+
import net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket;
2829
import net.minecraft.screen.slot.SlotActionType;
2930
import net.minecraft.util.ActionResult;
3031
import net.minecraft.util.Hand;
@@ -86,6 +87,18 @@ public void clickSlotHead(int syncId, int slotId, int button, SlotActionType act
8687
if (EventFlow.post(click).isCanceled()) ci.cancel();
8788
}
8889

90+
/**
91+
* Posts {@link InventoryEvent.HotbarSlot.Update} and returns the event value as the selected slot
92+
* <pre>{@code
93+
* private void syncSelectedSlot() {
94+
* int i = this.client.player.getInventory().selectedSlot;
95+
* if (i != this.lastSelectedSlot) {
96+
* this.lastSelectedSlot = i;
97+
* this.networkHandler.sendPacket(new UpdateSelectedSlotC2SPacket(this.lastSelectedSlot));
98+
* }
99+
* }
100+
* }</pre>
101+
*/
89102
@Redirect(method = "syncSelectedSlot", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/PlayerInventory;selectedSlot:I"))
90103
public int overrideSelectedSlotSync(PlayerInventory instance) {
91104
return EventFlow.post(new InventoryEvent.HotbarSlot.Update(instance.selectedSlot)).getSlot();

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public abstract class ClientPlayerEntityMixin extends EntityMixin {
5050
@Shadow
5151
protected abstract void autoJump(float dx, float dz);
5252

53+
/**
54+
* Post movement events and applies the modified player velocity
55+
*/
5356
@Inject(method = "move", at = @At("HEAD"), cancellable = true)
5457
void onMove(MovementType movementType, Vec3d movement, CallbackInfo ci) {
5558
ClientPlayerEntity self = (ClientPlayerEntity) (Object) this;
@@ -78,6 +81,22 @@ void processMovement(Input input, boolean slowDown, float slowDownFactor) {
7881
EventFlow.post(new MovementEvent.InputUpdate(input, slowDown, slowDownFactor));
7982
}
8083

84+
/**
85+
* Posts the {@link MovementEvent.Sprint} event
86+
* <pre>{@code
87+
* if (this.isSprinting()) {
88+
* boolean bl8 = !this.input.hasForwardMovement() || !this.canSprint();
89+
* boolean bl9 = bl8 || this.horizontalCollision && !this.collidedSoftly || this.isTouchingWater() && !this.isSubmergedInWater();
90+
* if (this.isSwimming()) {
91+
* if (!this.isOnGround() && !this.input.sneaking && bl8 || !this.isTouchingWater()) {
92+
* this.setSprinting(false);
93+
* }
94+
* } else if (bl9) {
95+
* this.setSprinting(false);
96+
* }
97+
* }
98+
* }</pre>
99+
*/
81100
@Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isSprinting()Z"))
82101
boolean isSprinting(ClientPlayerEntity entity) {
83102
return EventFlow.post(new MovementEvent.Sprint(entity.isSprinting())).getSprint();
@@ -92,6 +111,9 @@ void redirectSneaking(CallbackInfoReturnable<Boolean> cir) {
92111
cir.setReturnValue(EventFlow.post(new MovementEvent.Sneak(self.input.sneaking)).getSneak());
93112
}
94113

114+
/**
115+
* Overwrites the movement packet update function to use our code
116+
*/
95117
@Inject(method = "sendMovementPackets", at = @At(value = "HEAD"), cancellable = true)
96118
void sendBegin(CallbackInfo ci) {
97119
ci.cancel();
@@ -121,8 +143,6 @@ float fixHeldItemPitch(ClientPlayerEntity instance) {
121143

122144
@Inject(method = "damage", at = @At("HEAD"), cancellable = true)
123145
public void damage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
124-
if (EventFlow.post(new PlayerEvent.Damage(source, amount)).isCanceled()) {
125-
cir.setReturnValue(false);
126-
}
146+
if (EventFlow.post(new PlayerEvent.Damage(source, amount)).isCanceled()) cir.setReturnValue(false);
127147
}
128148
}

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public void move(MovementType movementType, Vec3d movement) {
4545
@Shadow
4646
public abstract float getYaw();
4747

48+
/**
49+
* Modifies the player yaw when there is an active rotation to apply the player velocity correctly
50+
*/
4851
@Redirect(method = "updateVelocity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw()F"))
4952
public float velocityYaw(Entity entity) {
5053
if ((Object) this != Lambda.getMc().player) return getYaw();
@@ -55,6 +58,14 @@ public float velocityYaw(Entity entity) {
5558
return y;
5659
}
5760

61+
/**
62+
* Modifies the player yaw for the given tick delta for interpolation when there is an active rotation
63+
* <pre>{@code
64+
* public final Vec3d getRotationVec(float tickDelta) {
65+
* return this.getRotationVector(this.getPitch(tickDelta), this.getYaw(tickDelta));
66+
* }
67+
* }</pre>
68+
*/
5869
@Redirect(method = "getRotationVec", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw(F)F"))
5970
float fixDirectionYaw(Entity entity, float tickDelta) {
6071
Vec2d rot = RotationManager.getRotationForVector(tickDelta);
@@ -63,6 +74,14 @@ float fixDirectionYaw(Entity entity, float tickDelta) {
6374
return (float) rot.getX();
6475
}
6576

77+
/**
78+
* Modifies the player pitch for the given tick delta for interpolation when there is an active rotation
79+
* <pre>{@code
80+
* public final Vec3d getRotationVec(float tickDelta) {
81+
* return this.getRotationVector(this.getPitch(tickDelta), this.getYaw(tickDelta));
82+
* }
83+
* }</pre>
84+
*/
6685
@Redirect(method = "getRotationVec", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getPitch(F)F"))
6786
float fixDirectionPitch(Entity entity, float tickDelta) {
6887
Vec2d rot = RotationManager.getRotationForVector(tickDelta);
@@ -71,6 +90,14 @@ float fixDirectionPitch(Entity entity, float tickDelta) {
7190
return (float) rot.getY();
7291
}
7392

93+
/**
94+
* Modifies the player yaw for the current rotation yaw
95+
* <pre>{@code
96+
* public Vec3d getRotationVector() {
97+
* return this.getRotationVector(this.getPitch(), this.getYaw());
98+
* }
99+
* }</pre>
100+
*/
74101
@Redirect(method = "getRotationVector()Lnet/minecraft/util/math/Vec3d;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw()F"))
75102
float fixDirectionYaw2(Entity entity) {
76103
Vec2d rot = RotationManager.getRotationForVector(1.0);
@@ -79,6 +106,14 @@ float fixDirectionYaw2(Entity entity) {
79106
return (float) rot.getX();
80107
}
81108

109+
/**
110+
* Modifies the player yaw for the current rotation pitch
111+
* <pre>{@code
112+
* public Vec3d getRotationVector() {
113+
* return this.getRotationVector(this.getPitch(), this.getYaw());
114+
* }
115+
* }</pre>
116+
*/
82117
@Redirect(method = "getRotationVector()Lnet/minecraft/util/math/Vec3d;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getPitch()F"))
83118
float fixDirectionPitch2(Entity entity) {
84119
Vec2d rot = RotationManager.getRotationForVector(1.0);
@@ -95,7 +130,6 @@ private void changeLookDirection(double cursorDeltaX, double cursorDeltaY, Callb
95130
@Inject(method = "onTrackedDataSet(Lnet/minecraft/entity/data/TrackedData;)V", at = @At("TAIL"))
96131
public void onTrackedDataSet(TrackedData<?> data, CallbackInfo ci) {
97132
Entity entity = (Entity) (Object) this;
98-
99133
EventFlow.post(new EntityEvent.EntityUpdate(entity, data));
100134
}
101135

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,10 @@
2727

2828
@Mixin(FireworkRocketEntity.class)
2929
public class FireworkRocketEntityMixin {
30-
@Redirect(
31-
method = "tick",
32-
at = @At(
33-
value = "INVOKE",
34-
target = "Lnet/minecraft/entity/LivingEntity;setVelocity(Lnet/minecraft/util/math/Vec3d;)V"
35-
)
36-
)
30+
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;setVelocity(Lnet/minecraft/util/math/Vec3d;)V"))
3731
private void redirectSetVelocity(LivingEntity shooter, Vec3d vec3d) {
3832
if (ElytraFly.getDoBoost()) {
39-
ElytraFly.boostRocket(shooter);
33+
ElytraFly.boostRocket();
4034
} else shooter.setVelocity(vec3d);
4135
}
4236
}

0 commit comments

Comments
 (0)