Skip to content

Commit

Permalink
Merge branch 'master' into LongJump
Browse files Browse the repository at this point in the history
  • Loading branch information
Doogie13 committed Mar 17, 2023
2 parents 5b4fea5 + 879fbaf commit e3220f9
Show file tree
Hide file tree
Showing 22 changed files with 689 additions and 161 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Customize your experience, and improve your efficiency!
Find our plugins [here](https://github.com/lambda-plugins).

<p align="center">
<a href="https://github.com/lambda-client/lambda/releases/download/3.2.1/lambda-3.2.1.jar"><img alt="lambda-3.2.1.jar" src="https://raw.githubusercontent.com/lambda-client/assets/main/download_button_3.2.1.png" width="70%" height="70%"></a>
<a href="https://github.com/lambda-client/lambda/releases/download/3.3.0/lambda-3.3.0.jar"><img alt="lambda-3.3.0.jar" src="https://raw.githubusercontent.com/lambda-client/assets/main/download_button_3.3.0.png" width="70%" height="70%"></a>
</p>

<div align="center">
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ dependencies {
compileOnly 'org.jetbrains:annotations:23.0.0'

// This Baritone will NOT be included in the jar
implementation 'com.github.cabaletta:baritone:1.2.14'
implementation('cabaletta:baritone-deobf-unoptimized-mcp-dev:1.2').setChanging(true)

// This Baritone WILL be included in the jar
jarLibs 'cabaletta:baritone-api:1.2'
jarLibs('cabaletta:baritone-api:1.2').setChanging(true)

// Add everything in jarLibs to implementation (compile)
implementation configurations.jarLibs
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ org.gradle.caching=true
org.gradle.parallel=true

modGroup=com.lambda
modVersion=3.2.1
modVersion=3.3.0

minecraftVersion=1.12.2
forgeVersion=14.23.5.2860
mappingsChannel=stable
mappingsVersion=39-1.12

kotlinVersion=1.8.0
kotlinVersion=1.8.10
kotlinxCoroutinesVersion=1.6.4
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.lambda.mixin.network;

import com.lambda.client.event.LambdaEventBus;
import com.lambda.client.event.events.ChunkDataEvent;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.network.play.server.SPacketChunkData;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(value = NetHandlerPlayClient.class)
public class MixinNetHandlerPlayClient {

@Shadow private WorldClient world;

@Inject(method = "handleChunkData", at = @At("TAIL"))
public void handleChunkData(SPacketChunkData packetIn, CallbackInfo ci) {
LambdaEventBus.INSTANCE.post(new ChunkDataEvent(packetIn.isFullChunk(), this.world.getChunk(packetIn.getChunkX(), packetIn.getChunkZ())));
}
}
144 changes: 93 additions & 51 deletions src/main/java/com/lambda/mixin/player/MixinEntityPlayerSP.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import net.minecraft.inventory.IInventory;
import net.minecraft.network.play.client.CPacketEntityAction;
import net.minecraft.network.play.client.CPacketPlayer;
import net.minecraft.util.MovementInput;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IInteractionObject;
import net.minecraft.world.World;
Expand All @@ -37,9 +39,16 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Objects;

@Mixin(value = EntityPlayerSP.class, priority = Integer.MAX_VALUE)
public abstract class MixinEntityPlayerSP extends EntityPlayer {
@Shadow @Final public NetHandlerPlayClient connection;
@Shadow public MovementInput movementInput;
@Shadow public float renderArmYaw;
@Shadow public float renderArmPitch;
@Shadow public float prevRenderArmYaw;
@Shadow public float prevRenderArmPitch;
@Shadow protected Minecraft mc;
@Shadow private double lastReportedPosX;
@Shadow private double lastReportedPosY;
Expand All @@ -56,9 +65,6 @@ public MixinEntityPlayerSP(World worldIn, GameProfile gameProfileIn) {
super(worldIn, gameProfileIn);
}

@Shadow
protected abstract boolean isCurrentViewEntity();

@Shadow
protected abstract void updateAutoJump(float p_189810_1_, float p_189810_2_);

Expand Down Expand Up @@ -89,7 +95,7 @@ private void onPushOutOfBlocks(CallbackInfoReturnable<Boolean> callbackInfoRetur
public void onDisplayGUIChest(IInventory chestInventory, CallbackInfo ci) {
if (BeaconSelector.INSTANCE.isEnabled()) {
if (chestInventory instanceof IInteractionObject && "minecraft:beacon".equals(((IInteractionObject) chestInventory).getGuiID())) {
Minecraft.getMinecraft().displayGuiScreen(new LambdaGuiBeacon(this.inventory, chestInventory));
Minecraft.getMinecraft().displayGuiScreen(new LambdaGuiBeacon(inventory, chestInventory));
ci.cancel();
}
}
Expand All @@ -104,11 +110,11 @@ public void moveHead(MoverType type, double x, double y, double z, CallbackInfo
LambdaEventBus.INSTANCE.post(event);

if (event.isModified()) {
double prevX = this.posX;
double prevZ = this.posZ;
double prevX = posX;
double prevZ = posZ;

super.move(type, event.getX(), event.getY(), event.getZ());
this.updateAutoJump((float) (this.posX - prevX), (float) (this.posZ - prevZ));
updateAutoJump((float) (posX - prevX), (float) (posZ - prevZ));

ci.cancel();
}
Expand All @@ -123,11 +129,50 @@ public boolean modifySprinting(boolean sprinting) {
}
}

// We have to return true here so it would still update movement inputs from Baritone and send packets
@Inject(method = "isCurrentViewEntity", at = @At("RETURN"), cancellable = true)
protected void mixinIsCurrentViewEntity(CallbackInfoReturnable<Boolean> cir) {
if (Freecam.INSTANCE.isEnabled() && Freecam.INSTANCE.getCameraGuy() != null) {
cir.setReturnValue(mc.getRenderViewEntity() == Freecam.INSTANCE.getCameraGuy());
// Cannot use an inject in isCurrentViewEntity due to rusherhack redirecting it here
@Inject(method = "onUpdateWalkingPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/EntityPlayerSP;isCurrentViewEntity()Z"), cancellable = true)
protected void mixinUpdateWalkingPlayerCompat(CallbackInfo ci) {
if (Freecam.INSTANCE.isEnabled() && Freecam.INSTANCE.getCameraGuy() != null && Objects.equals(this, mc.player)) {
ci.cancel();
// we need to perform the same actions as what is in the mc method
++positionUpdateTicks;
final AxisAlignedBB boundingBox = getEntityBoundingBox();
final Vec3d pos = new Vec3d(posX, boundingBox.minY, posZ);
final Vec2f rot = new Vec2f(rotationYaw, rotationPitch);
final boolean isMoving = isMoving(pos);
final boolean isRotating = isRotating(rot);
sendPlayerPacket(isMoving, isRotating, pos, rot);
if (isMoving) {
lastReportedPosX = pos.x;
lastReportedPosY = pos.y;
lastReportedPosZ = pos.z;
positionUpdateTicks = 0;
}

if (isRotating) {
lastReportedYaw = rot.getX();
lastReportedPitch = rot.getY();
}

prevOnGround = onGround;
autoJumpEnabled = mc.gameSettings.autoJump;
}
}

// Cannot use an inject in isCurrentViewEntity due to rusherhack redirecting it here
@Inject(method = "updateEntityActionState", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/EntityPlayerSP;isCurrentViewEntity()Z"), cancellable = true)
protected void mixinEntityActionState(CallbackInfo ci) {
if (Freecam.INSTANCE.isEnabled() && Freecam.INSTANCE.getCameraGuy() != null && Objects.equals(this, mc.player)) {
ci.cancel();

// we need to perform the same actions as what is in the mc method
moveStrafing = movementInput.moveStrafe;
moveForward = movementInput.moveForward;
isJumping = movementInput.jump;
prevRenderArmYaw = renderArmYaw;
prevRenderArmPitch = renderArmPitch;
renderArmPitch = renderArmPitch + (rotationPitch - renderArmPitch) * 0.5f;
renderArmYaw = renderArmYaw + (rotationYaw - renderArmYaw) * 0.5f;
}
}

Expand All @@ -141,23 +186,25 @@ private void onUpdateInvokeOnUpdateWalkingPlayer(CallbackInfo ci) {
Vec3d serverSidePos = PlayerPacketManager.INSTANCE.getServerSidePosition();
Vec2f serverSideRotation = PlayerPacketManager.INSTANCE.getPrevServerSideRotation();

this.lastReportedPosX = serverSidePos.x;
this.lastReportedPosY = serverSidePos.y;
this.lastReportedPosZ = serverSidePos.z;
lastReportedPosX = serverSidePos.x;
lastReportedPosY = serverSidePos.y;
lastReportedPosZ = serverSidePos.z;

this.lastReportedYaw = serverSideRotation.getX();
this.lastReportedPitch = serverSideRotation.getY();
lastReportedYaw = serverSideRotation.getX();
lastReportedPitch = serverSideRotation.getY();
}

@Inject(method = "onUpdateWalkingPlayer", at = @At("HEAD"), cancellable = true)
private void onUpdateWalkingPlayerHead(CallbackInfo ci) {
if (Freecam.INSTANCE.isEnabled() && Freecam.INSTANCE.getCameraGuy() != null
&& Objects.equals(this, Freecam.INSTANCE.getCameraGuy())) return;

CriticalsUpdateWalkingEvent criticalsEditEvent = new CriticalsUpdateWalkingEvent();
LambdaEventBus.INSTANCE.post(criticalsEditEvent);

// Setup flags
Vec3d position = new Vec3d(this.posX, this.getEntityBoundingBox().minY, this.posZ);
Vec2f rotation = new Vec2f(this.rotationYaw, this.rotationPitch);
Vec3d position = new Vec3d(posX, getEntityBoundingBox().minY, posZ);
Vec2f rotation = new Vec2f(rotationYaw, rotationPitch);
boolean moving = isMoving(position);
boolean rotating = isRotating(rotation);

Expand All @@ -181,76 +228,71 @@ private void onUpdateWalkingPlayerHead(CallbackInfo ci) {
sendSneakPacket();
sendPlayerPacket(moving, rotating, position, rotation);

this.prevOnGround = onGround;
prevOnGround = onGround;
}

++this.positionUpdateTicks;
this.autoJumpEnabled = this.mc.gameSettings.autoJump;
++positionUpdateTicks;
autoJumpEnabled = mc.gameSettings.autoJump;
}

event = event.nextPhase();
LambdaEventBus.INSTANCE.post(event);
}

private void sendSprintPacket() {
boolean sprinting = this.isSprinting();
boolean sprinting = isSprinting();

if (sprinting != this.serverSprintState) {
if (sprinting != serverSprintState) {
if (sprinting) {
this.connection.sendPacket(new CPacketEntityAction(this, CPacketEntityAction.Action.START_SPRINTING));
connection.sendPacket(new CPacketEntityAction(this, CPacketEntityAction.Action.START_SPRINTING));
} else {
this.connection.sendPacket(new CPacketEntityAction(this, CPacketEntityAction.Action.STOP_SPRINTING));
connection.sendPacket(new CPacketEntityAction(this, CPacketEntityAction.Action.STOP_SPRINTING));
}
this.serverSprintState = sprinting;
serverSprintState = sprinting;
}
}

private void sendSneakPacket() {
boolean sneaking = this.isSneaking();
boolean sneaking = isSneaking();

if (sneaking != this.serverSneakState) {
if (sneaking != serverSneakState) {
if (sneaking) {
this.connection.sendPacket(new CPacketEntityAction(this, CPacketEntityAction.Action.START_SNEAKING));
connection.sendPacket(new CPacketEntityAction(this, CPacketEntityAction.Action.START_SNEAKING));
} else {
this.connection.sendPacket(new CPacketEntityAction(this, CPacketEntityAction.Action.STOP_SNEAKING));
connection.sendPacket(new CPacketEntityAction(this, CPacketEntityAction.Action.STOP_SNEAKING));
}
this.serverSneakState = sneaking;
serverSneakState = sneaking;
}
}

private void sendPlayerPacket(boolean moving, boolean rotating, Vec3d position, Vec2f rotation) {
if (!this.isCurrentViewEntity()) return;

if (this.isRiding()) {
this.connection.sendPacket(new CPacketPlayer.PositionRotation(this.motionX, -999.0D, this.motionZ, rotation.getX(), rotation.getY(), onGround));
if (isRiding()) {
connection.sendPacket(new CPacketPlayer.PositionRotation(motionX, -999.0D, motionZ, rotation.getX(), rotation.getY(), onGround));
moving = false;
} else if (moving && rotating) {
this.connection.sendPacket(new CPacketPlayer.PositionRotation(position.x, position.y, position.z, rotation.getX(), rotation.getY(), onGround));
connection.sendPacket(new CPacketPlayer.PositionRotation(position.x, position.y, position.z, rotation.getX(), rotation.getY(), onGround));
} else if (moving) {
this.connection.sendPacket(new CPacketPlayer.Position(position.x, position.y, position.z, onGround));
connection.sendPacket(new CPacketPlayer.Position(position.x, position.y, position.z, onGround));
} else if (rotating) {
this.connection.sendPacket(new CPacketPlayer.Rotation(rotation.getX(), rotation.getY(), onGround));
} else if (this.prevOnGround != onGround) {
this.connection.sendPacket(new CPacketPlayer(onGround));
connection.sendPacket(new CPacketPlayer.Rotation(rotation.getX(), rotation.getY(), onGround));
} else if (prevOnGround != onGround) {
connection.sendPacket(new CPacketPlayer(onGround));
}

if (moving) {
this.positionUpdateTicks = 0;
}
if (moving) positionUpdateTicks = 0;
}

private boolean isMoving(Vec3d position) {
double xDiff = position.x - this.lastReportedPosX;
double yDiff = position.y - this.lastReportedPosY;
double zDiff = position.z - this.lastReportedPosZ;
double xDiff = position.x - lastReportedPosX;
double yDiff = position.y - lastReportedPosY;
double zDiff = position.z - lastReportedPosZ;

return this.positionUpdateTicks >= 20 || xDiff * xDiff + yDiff * yDiff + zDiff * zDiff > 9.0E-4D;
return positionUpdateTicks >= 20 || xDiff * xDiff + yDiff * yDiff + zDiff * zDiff > 9.0E-4D;
}

private boolean isRotating(Vec2f rotation) {
double yawDiff = rotation.getX() - this.lastReportedYaw;
double pitchDiff = rotation.getY() - this.lastReportedPitch;

double yawDiff = rotation.getX() - lastReportedYaw;
double pitchDiff = rotation.getY() - lastReportedPitch;
return yawDiff != 0.0D || pitchDiff != 0.0D;
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/lambda/mixin/world/MixinWorld.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lambda.mixin.world;

import com.lambda.client.module.modules.misc.AntiWeather;
import com.lambda.client.module.modules.render.TimeWarp;
import com.lambda.client.module.modules.render.NoRender;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.EnumSkyBlock;
Expand Down Expand Up @@ -32,4 +33,10 @@ private void getRainStrengthHead(float delta, CallbackInfoReturnable<Float> cir)
cir.setReturnValue(0.0f);
}
}

@Inject(method = "getWorldTime", at = @At("HEAD"), cancellable = true)
public void onGetWorldTime(CallbackInfoReturnable<Long> cir) {
if (TimeWarp.INSTANCE.isEnabled())
cir.setReturnValue(TimeWarp.INSTANCE.getUpdatedTime());
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/com/lambda/client/LambdaMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class LambdaMod {
const val ID = "lambda"
const val DIRECTORY = "lambda"

const val VERSION = "3.2.1"
const val VERSION = "3.3.0"

const val APP_ID = 835368493150502923 // DiscordIPC
const val DEPENDENCIES = "required-after:forge@[14.23.5.2860,);"
Expand Down
16 changes: 16 additions & 0 deletions src/main/kotlin/com/lambda/client/command/Args.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.lambda.client.util.*
import com.lambda.client.util.threads.runSafeR
import kotlinx.coroutines.Dispatchers
import net.minecraft.block.Block
import net.minecraft.entity.EntityList
import net.minecraft.item.Item
import net.minecraft.util.math.BlockPos
import java.io.File
Expand Down Expand Up @@ -94,6 +95,21 @@ class BlockArg(
}
}

class EntityArg(
override val name: String
) : AbstractArg<String>(), AutoComplete by StaticPrefixMatch(allEntityNames) {
override suspend fun convertToType(string: String?): String? {
if (string == null) return null
// checks if a valid entity class is registered with this name
return if (EntityList.getClassFromName(string) != null) string else null
}

private companion object {
val allEntityNames = EntityList.getEntityNameList().map { it.path }
}
}


class BaritoneBlockArg(
override val name: String
) : AbstractArg<Block>(), AutoComplete by StaticPrefixMatch(baritoneBlockNames) {
Expand Down
9 changes: 8 additions & 1 deletion src/main/kotlin/com/lambda/client/command/ClientCommand.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.lambda.client.command

import com.lambda.client.capeapi.PlayerProfile
import com.lambda.client.command.CommandBuilder
import com.lambda.client.command.args.AbstractArg
import com.lambda.client.command.utils.BuilderBlock
import com.lambda.client.command.utils.ExecuteBlock
Expand Down Expand Up @@ -51,6 +50,14 @@ abstract class ClientCommand(
arg(BlockArg(name), block)
}

@CommandBuilder
protected inline fun AbstractArg<*>.entity(
name: String,
entity: BuilderBlock<String>
) {
arg(EntityArg(name), entity)
}

@CommandBuilder
protected inline fun AbstractArg<*>.item(
name: String,
Expand Down
Loading

0 comments on commit e3220f9

Please sign in to comment.