Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ val discordIPCVersion: String by project
val classGraphVersion: String by project
val kotlinVersion: String by project
val ktorVersion: String by project
val mockitoKotlin: String by project
val mockitoInline: String by project
val mockkVersion: String by project
val spairVersion: String by project
val lwjglVersion: String by project
Expand All @@ -46,10 +44,10 @@ val replacements = file("gradle.properties").inputStream().use { stream ->
}.map { (k, v) -> k.toString() to v.toString() }.toMap()

plugins {
kotlin("jvm") version "2.2.0"
id("org.jetbrains.dokka") version "2.0.0"
id("fabric-loom") version "1.10-SNAPSHOT"
id("com.gradleup.shadow") version "9.0.0-rc1"
kotlin("jvm") version "2.3.0"
id("org.jetbrains.dokka") version "2.1.0"
id("fabric-loom") version "1.14-SNAPSHOT"
id("com.gradleup.shadow") version "9.3.0"
id("maven-publish")
}

Expand Down Expand Up @@ -151,6 +149,8 @@ dependencies {
// Fabric
modImplementation("net.fabricmc:fabric-loader:$fabricLoaderVersion")
modImplementation("net.fabricmc.fabric-api:fabric-api:$fabricApiVersion+$minecraftVersion")
// Explicit dependency on fabric-renderer-indigo for mixin access to internal classes
modCompileOnly("net.fabricmc.fabric-api:fabric-renderer-indigo:4.1.4+1af5c5a75f")
modImplementation("net.fabricmc:fabric-language-kotlin:$kotlinFabricVersion.$kotlinVersion")

// Add dependencies on the required Kotlin modules.
Expand All @@ -175,7 +175,7 @@ dependencies {
includeLib("io.ktor:ktor-serialization-gson:$ktorVersion")

// Add mods
modImplementation("com.github.rfresh2:baritone-fabric:$minecraftVersion")
modCompileOnly("com.github.rfresh2:baritone-fabric:$minecraftVersion-SNAPSHOT")
modCompileOnly("maven.modrinth:sodium:$sodiumVersion")
modCompileOnly("maven.modrinth:malilib:$maLiLibVersion")
modCompileOnly("maven.modrinth:litematica:$litematicaVersion")
Expand All @@ -185,8 +185,6 @@ dependencies {

// Test implementations
testImplementation(kotlin("test"))
testImplementation("org.mockito.kotlin:mockito-kotlin:$mockitoKotlin")
testImplementation("org.mockito:mockito-inline:$mockitoInline")
testImplementation("io.mockk:mockk:${mockkVersion}")

// Finish the configuration
Expand Down
32 changes: 15 additions & 17 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,29 @@ mavenGroup=com.lambda
modAuthors=Constructor (Avanatiker), Blade, beanbag44, Emy

# General
minecraftVersion=1.21.5
minecraftVersionMin=1.21.5
minecraftVersionMax=1.21.6
minecraftVersion=1.21.11
minecraftVersionMin=1.21.11
minecraftVersionMax=1.21.11
lwjglVersion=3.3.3
mixinExtrasVersion=0.5.0-rc.2
kotlinVersion=2.2.0
mixinExtrasVersion=0.5.0
kotlinVersion=2.3.0
pngEncoderVersion=0.16.0
javaVersion=21
baritoneVersion=1.14.0
discordIPCVersion=6f6b6cce17
classGraphVersion=4.8.179
ktorVersion=3.1.2
mockitoKotlin=5.4.0
mockitoInline=5.2.0
mockkVersion=1.13.17
classGraphVersion=4.8.184
ktorVersion=3.3.3
mockkVersion=1.14.7
spairVersion=1.90.0

# Fabric https://fabricmc.net/develop/
fabricLoaderVersion=0.16.13
yarnMappings=build.1
fabricApiVersion=0.124.0
kotlinFabricVersion=1.13.4+kotlin
sodiumVersion=mc1.21.5-0.6.13-fabric
litematicaVersion=0.22.2
maLiLibVersion=0.24.2
fabricLoaderVersion=0.18.3
yarnMappings=build.3
fabricApiVersion=0.139.5
kotlinFabricVersion=1.13.8+kotlin
sodiumVersion=mc1.21.11-0.8.0-fabric
litematicaVersion=0.25.1
maLiLibVersion=0.27.1

# Kotlin https://kotlinlang.org/
kotlin.code.style=official
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
27 changes: 14 additions & 13 deletions src/main/java/com/lambda/mixin/MinecraftClientMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.thread.ThreadExecutor;
import org.jetbrains.annotations.Nullable;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
Expand Down Expand Up @@ -106,18 +107,18 @@ void onInput(MinecraftClient instance, Operation<Void> original) {
this.lambda$inputHandledThisTick = true;
}

@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;tick()V"))
void onWorldRenderer(WorldRenderer instance, Operation<Void> original) {
if (!this.lambda$inputHandledThisTick) {
EventFlow.post(TickEvent.Input.Pre.INSTANCE);
EventFlow.post(TickEvent.Input.Post.INSTANCE);
this.lambda$inputHandledThisTick = true;
}

EventFlow.post(TickEvent.WorldRender.Pre.INSTANCE);
original.call(instance);
EventFlow.post(TickEvent.WorldRender.Post.INSTANCE);
}
// @WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;tick()V"))
// void onWorldRenderer(WorldRenderer instance, Operation<Void> original) {
// if (!this.lambda$inputHandledThisTick) {
// EventFlow.post(TickEvent.Input.Pre.INSTANCE);
// EventFlow.post(TickEvent.Input.Post.INSTANCE);
// this.lambda$inputHandledThisTick = true;
// }
//
// EventFlow.post(TickEvent.WorldRender.Pre.INSTANCE);
// original.call(instance);
// EventFlow.post(TickEvent.WorldRender.Post.INSTANCE);
// }

@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/sound/SoundManager;tick(Z)V"))
void onSound(SoundManager instance, boolean paused, Operation<Void> original) {
Expand All @@ -134,7 +135,7 @@ private void onShutdown(CallbackInfo ci) {
/**
* Inject after the thread field is set so that {@link ThreadExecutor#getThread} is available
*/
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;thread:Ljava/lang/Thread;", shift = At.Shift.AFTER, ordinal = 0), method = "run")
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;thread:Ljava/lang/Thread;", shift = At.Shift.AFTER, ordinal = 0, opcode = Opcodes.PUTFIELD), method = "run")
private void onStartup(CallbackInfo ci) {
EventFlow.post(new ClientEvent.Startup());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(SoundSystem.class)
public class SoundSystemMixin {
@Inject(method = "play(Lnet/minecraft/client/sound/SoundInstance;)V", at = @At("HEAD"), cancellable = true)
public void onPlay(SoundInstance sound, CallbackInfo ci) {
@Inject(method = "play(Lnet/minecraft/client/sound/SoundInstance;)Lnet/minecraft/client/sound/SoundSystem$PlayResult;", at = @At("HEAD"), cancellable = true)
public void onPlay(SoundInstance sound, CallbackInfoReturnable<SoundSystem.PlayResult> cir) {
if (EventFlow.post(new ClientEvent.Sound(sound)).isCanceled()) {
ci.cancel();
cir.setReturnValue(SoundSystem.PlayResult.NOT_STARTED);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ private void cancelBlockBreakingPre(CallbackInfo ci) {
if (EventFlow.post(new PlayerEvent.Breaking.Cancel(currentBreakingProgress)).isCanceled()) ci.cancel();
}

@WrapMethod(method = "createPlayer(Lnet/minecraft/client/world/ClientWorld;Lnet/minecraft/stat/StatHandler;Lnet/minecraft/client/recipebook/ClientRecipeBook;ZZ)Lnet/minecraft/client/network/ClientPlayerEntity;")
private ClientPlayerEntity injectCreatePlayer(ClientWorld world, StatHandler statHandler, ClientRecipeBook recipeBook, boolean lastSneaking, boolean lastSprinting, Operation<ClientPlayerEntity> original) {
var player = original.call(world, statHandler, recipeBook, lastSneaking, lastSprinting);
@WrapMethod(method = "createPlayer(Lnet/minecraft/client/world/ClientWorld;Lnet/minecraft/stat/StatHandler;Lnet/minecraft/client/recipebook/ClientRecipeBook;)Lnet/minecraft/client/network/ClientPlayerEntity;")
private ClientPlayerEntity wrapCreatePlayer(ClientWorld world, StatHandler statHandler, ClientRecipeBook recipeBook, Operation<ClientPlayerEntity> original) {
var player = original.call(world, statHandler, recipeBook);
InventoryManager.INSTANCE.setScreenHandler(player.playerScreenHandler);
return player;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ void sendLambdaMovement(CallbackInfo ci) {
autoJumpEnabled = Lambda.getMc().options.getAutoJump().getValue();
}

@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;sendSneakingPacket()V"))
void sendSneakingPacket(ClientPlayerEntity entity, Operation<Void> original) {
PlayerPacketHandler.sendSneakPackets();
}

@ModifyExpressionValue(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isSprinting()Z"))
boolean isSprinting(boolean original) {
return EventFlow.post(new MovementEvent.Sprint(original)).getSprint();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/lambda/mixin/entity/LivingEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ private float rotHead(LivingEntity entity, Operation<Float> original) {
return (yaw == null) ? original.call(entity) : yaw;
}

@ModifyConstant(method = "getHandSwingDuration", constant = @Constant(intValue = 6))
private int getHandSwingDuration(int constant) {
if (lambda$instance != Lambda.getMc().player || ViewModel.INSTANCE.isDisabled()) return constant;
@WrapMethod(method = "getHandSwingDuration")
private int getHandSwingDuration(Operation<Integer> original) {
if (lambda$instance != Lambda.getMc().player || ViewModel.INSTANCE.isDisabled()) return original.call();

return ViewModel.INSTANCE.getSwingDuration();
}
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/com/lambda/mixin/entity/PlayerEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ private float wrapHeadYaw(PlayerEntity instance, Operation<Float> original) {
return (yaw != null) ? yaw : original.call(instance);
}

@WrapOperation(method = "attack", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;getYaw()F"))
private float wrapAttackYaw(PlayerEntity instance, Operation<Float> original) {
if ((Object) this != Lambda.getMc().player) {
return original.call(instance);
}

Float yaw = RotationManager.getMovementYaw();
return (yaw != null) ? yaw : original.call(instance);
}
// @WrapOperation(method = "attack", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;getYaw()F"))
// private float wrapAttackYaw(PlayerEntity instance, Operation<Float> original) {
// if ((Object) this != Lambda.getMc().player) {
// return original.call(instance);
// }
//
// Float yaw = RotationManager.getMovementYaw();
// return (yaw != null) ? yaw : original.call(instance);
// }
}
2 changes: 1 addition & 1 deletion src/main/java/com/lambda/mixin/input/KeyBindingMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class KeyBindingMixin {
@ModifyReturnValue(method = "isPressed", at = @At("RETURN"))
boolean modifyIsPressed(boolean original) {
KeyBinding instance = (KeyBinding) (Object) this;
if (!Objects.equals(instance.getTranslationKey(), "key.sprint")) return original;
if (!Objects.equals(instance.getId(), "key.sprint")) return original;

if (Sprint.INSTANCE.isEnabled()) return true;
if (Speed.INSTANCE.isEnabled() && Speed.getMode() == Speed.Mode.GrimStrafe) return true;
Expand Down
26 changes: 18 additions & 8 deletions src/main/java/com/lambda/mixin/input/KeyboardMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,45 @@
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import net.minecraft.client.Keyboard;
import net.minecraft.client.input.CharInput;
import net.minecraft.client.input.KeyInput;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
* Mixin to intercept keyboard input events.
*
* Note: In 1.21.11, onKey/onChar methods were refactored to use KeyInput/CharInput records.
* - onKey(long window, int action, KeyInput input) where KeyInput has key, scancode, modifiers
* - onChar(long window, CharInput input) where CharInput has codepoint, modifiers
*/
@Mixin(Keyboard.class)
public class KeyboardMixin {
@WrapMethod(method = "onKey")
private void onKey(long window, int key, int scancode, int action, int modifiers, Operation<Void> original) {
EventFlow.post(new KeyboardEvent.Press(key, scancode, action, modifiers));
original.call(window, key, scancode, action, modifiers);
private void onKey(long window, int action, KeyInput input, Operation<Void> original) {
EventFlow.post(new KeyboardEvent.Press(input.key(), input.scancode(), action, input.modifiers()));
original.call(window, action, input);
}

@Inject(method = "onKey", at = @At("RETURN"))
private void onKeyTail(long window, int key, int scancode, int action, int modifiers, CallbackInfo ci) {
private void onKeyTail(long window, int action, KeyInput input, CallbackInfo ci) {
int key = input.key();
if (!InventoryMove.getShouldMove() || !InventoryMove.isKeyMovementRelated(key)) return;
InputUtil.Key fromCode = InputUtil.fromKeyCode(key, scancode);
InputUtil.Key fromCode = InputUtil.fromKeyCode(input);
KeyBinding.setKeyPressed(fromCode, action != 0);
}

@WrapMethod(method = "onChar")
private void onChar(long window, int codePoint, int modifiers, Operation<Void> original) {
char[] chars = Character.toChars(codePoint);
private void onChar(long window, CharInput input, Operation<Void> original) {
char[] chars = Character.toChars(input.codepoint());

for (char c : chars)
EventFlow.post(new KeyboardEvent.Char(c));

original.call(window, codePoint, modifiers);
original.call(window, input);
}
}
9 changes: 5 additions & 4 deletions src/main/java/com/lambda/mixin/input/MouseMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import net.minecraft.client.Mouse;
import net.minecraft.client.input.MouseInput;
import net.minecraft.client.option.SimpleOption;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -36,10 +37,10 @@ public class MouseMixin {

@Shadow private double y;

@WrapMethod(method = "onMouseButton(JIII)V")
private void onMouseButton(long window, int button, int action, int mods, Operation<Void> original) {
if (!EventFlow.post(new MouseEvent.Click(button, action, mods)).isCanceled())
original.call(window, button, action, mods);
@WrapMethod(method = "onMouseButton")
private void onMouseButton(long window, MouseInput input, int action, Operation<Void> original) {
if (!EventFlow.post(new MouseEvent.Click(input.button(), action, input.modifiers())).isCanceled())
original.call(window, input, action);
}

@WrapMethod(method = "onMouseScroll(JDD)V")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ void injectJoinPacket(GameJoinS2CPacket packet, CallbackInfo ci) {
void injectPlayerList(PlayerListS2CPacket.Action action, PlayerListS2CPacket.Entry receivedEntry, PlayerListEntry currentEntry, CallbackInfo ci) {
if (action != PlayerListS2CPacket.Action.UPDATE_LISTED) return;

var name = currentEntry.getProfile().getName();
var uuid = currentEntry.getProfile().getId();
var name = currentEntry.getProfile().name();
var uuid = currentEntry.getProfile().id();

if (receivedEntry.listed()) {
EventFlow.post(new WorldEvent.Player.Join(name, uuid, currentEntry));
} else EventFlow.post(new WorldEvent.Player.Leave(name, uuid, currentEntry));
}

@Inject(method = "onUpdateSelectedSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkThreadUtils;forceMainThread(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/util/thread/ThreadExecutor;)V", shift = At.Shift.AFTER), cancellable = true)
@Inject(method = "onUpdateSelectedSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkThreadUtils;forceMainThread(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/network/PacketApplyBatcher;)V", shift = At.Shift.AFTER), cancellable = true)
private void onUpdateSelectedSlot(UpdateSelectedSlotS2CPacket packet, CallbackInfo ci) {
if (EventFlow.post(new InventoryEvent.HotbarSlot.Sync(packet.slot())).isCanceled()) ci.cancel();
}
Expand All @@ -64,17 +64,19 @@ private void onScreenHandlerSlotUpdate(ScreenHandlerSlotUpdateS2CPacket packet,
}

/**
* Sets displayedUnsecureChatWarning to {@link NoRender#getNoChatVerificationToast()}
* Sets seenInsecureChatWarning to {@link NoRender#getNoChatVerificationToast()}
* <pre>{@code
* this.secureChatEnforced = packet.enforcesSecureChat();
* if (this.serverInfo != null && !this.displayedUnsecureChatWarning && !this.isSecureChatEnforced()) {
* if (this.serverInfo != null && !this.seenInsecureChatWarning && !this.isSecureChatEnforced()) {
* SystemToast systemToast = SystemToast.create(this.client, SystemToast.Type.UNSECURE_SERVER_WARNING, UNSECURE_SERVER_TOAST_TITLE, UNSECURE_SERVER_TOAST_TEXT);
* this.client.getToastManager().add(systemToast);
* this.displayedUnsecureChatWarning = true;
* this.seenInsecureChatWarning = true;
* }
* }</pre>
*
* Note: In 1.21.11, displayedUnsecureChatWarning was renamed to seenInsecureChatWarning.
*/
@ModifyExpressionValue(method = "onGameJoin(Lnet/minecraft/network/packet/s2c/play/GameJoinS2CPacket;)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;displayedUnsecureChatWarning:Z", ordinal = 0))
@ModifyExpressionValue(method = "onGameJoin(Lnet/minecraft/network/packet/s2c/play/GameJoinS2CPacket;)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;seenInsecureChatWarning:Z", ordinal = 0))
public boolean onServerMetadata(boolean original) {
return (NoRender.getNoChatVerificationToast() && NoRender.INSTANCE.isEnabled()) || original;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@SuppressWarnings("UnstableApiUsage")
@Mixin(AbstractTerrainRenderContext.class)
public class AbstractTerrainRenderContextMixin {
@Final
Expand Down
Loading