Skip to content

Commit

Permalink
fixes(legacy): FreeCam not detecting inputs and AutoTool not synchron…
Browse files Browse the repository at this point in the history
…izing break speed. (CCBlueX#4340)
  • Loading branch information
mems01 authored Nov 3, 2024
1 parent a6d5961 commit afd1a46
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object FreeCam : Module("FreeCam", Category.RENDER, gameDetecting = false, hideM
}

val velocity = Vec3_ZERO.apply {
strafe(speed = speed, moveCheck = !mc.thePlayer.isMoving)
strafe(speed = speed, moveCheck = !event.originalInput.isMoving)

this.yCoord = yAxisMovement * speed
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.util.BlockPos;
import net.minecraft.util.MovingObjectPosition;
Expand All @@ -45,9 +43,7 @@
import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.*;
Expand Down Expand Up @@ -80,9 +76,6 @@ public abstract class MixinMinecraft {
@Shadow
public EntityPlayerSP thePlayer;

@Shadow
public EffectRenderer effectRenderer;

@Shadow
public PlayerControllerMP playerController;

Expand Down Expand Up @@ -269,28 +262,16 @@ private void loadWorld(WorldClient p_loadWorld_1_, String p_loadWorld_2_, final
EventManager.INSTANCE.callEvent(new WorldEvent(p_loadWorld_1_));
}

/**
* @author CCBlueX
*/
@Overwrite
public void sendClickBlockToController(boolean leftClick) {
if (!leftClick) leftClickCounter = 0;

if (leftClickCounter <= 0 && (!thePlayer.isUsingItem() || MultiActions.INSTANCE.handleEvents())) {
if (leftClick && objectMouseOver != null && objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
BlockPos blockPos = objectMouseOver.getBlockPos();

if (leftClickCounter == 0)
EventManager.INSTANCE.callEvent(new ClickBlockEvent(blockPos, objectMouseOver.sideHit));

@Redirect(method = "sendClickBlockToController", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/EntityPlayerSP;isUsingItem()Z"))
private boolean injectMultiActions(EntityPlayerSP instance) {
return instance.isUsingItem() || MultiActions.INSTANCE.handleEvents();
}

if (theWorld.getBlockState(blockPos).getBlock().getMaterial() != Material.air && playerController.onPlayerDamageBlock(blockPos, objectMouseOver.sideHit)) {
effectRenderer.addBlockHitEffects(blockPos, objectMouseOver.sideHit);
thePlayer.swingItem();
}
} else if (!AbortBreaking.INSTANCE.handleEvents()) {
playerController.resetBlockRemoving();
}
@Redirect(method = "sendClickBlockToController", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/PlayerControllerMP;resetBlockRemoving()V"))
private void injectAbortBreaking(PlayerControllerMP instance) {
if (!AbortBreaking.INSTANCE.handleEvents()) {
instance.resetBlockRemoving();
}
}

Expand All @@ -299,11 +280,6 @@ private boolean injectTickBase(Queue instance) {
return TickBase.INSTANCE.getDuringTickModification() || instance.isEmpty();
}

@Redirect(method = "*", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/InventoryPlayer;currentItem:I", opcode = Opcodes.GETFIELD))
private int hookSilentHotbar(InventoryPlayer inventory) {
return inventory.currentItem;
}

/**
* @author CCBlueX
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
package net.ccbluex.liquidbounce.injection.forge.mixins.entity;

import net.ccbluex.liquidbounce.utils.SilentHotbar;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.player.InventoryPlayer;
import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import static net.ccbluex.liquidbounce.utils.MinecraftInstance.mc;

@Mixin(InventoryPlayer.class)
public class MixinInventoryPlayer {

@Redirect(method = {"getCurrentItem", "decrementAnimations", "getStrVsBlock"}, at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/InventoryPlayer;currentItem:I", opcode = Opcodes.GETFIELD))
@Redirect(method = {"getCurrentItem", "decrementAnimations", "getStrVsBlock", "canHeldItemHarvest"}, at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/InventoryPlayer;currentItem:I", opcode = Opcodes.GETFIELD))
private int hookSilentHotbar(InventoryPlayer instance) {
return instance.player instanceof EntityPlayerSP ? SilentHotbar.INSTANCE.getCurrentSlot() : instance.currentItem;
return instance.player.getGameProfile() == mc.thePlayer.getGameProfile() ? SilentHotbar.INSTANCE.getCurrentSlot() : instance.currentItem;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
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.Redirect;
Expand All @@ -32,9 +31,6 @@
@SideOnly(Side.CLIENT)
public class MixinPlayerControllerMP {

@Shadow
public int currentPlayerItem;

@Inject(method = "attackEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/PlayerControllerMP;syncCurrentPlayItem()V"))
private void attackEntity(EntityPlayer entityPlayer, Entity targetEntity, CallbackInfo callbackInfo) {
EventManager.INSTANCE.callEvent(new AttackEvent(targetEntity));
Expand All @@ -43,8 +39,7 @@ private void attackEntity(EntityPlayer entityPlayer, Entity targetEntity, Callba

@Inject(method = "getIsHittingBlock", at = @At("HEAD"), cancellable = true)
private void getIsHittingBlock(CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
if (AbortBreaking.INSTANCE.handleEvents())
callbackInfoReturnable.setReturnValue(false);
if (AbortBreaking.INSTANCE.handleEvents()) callbackInfoReturnable.setReturnValue(false);
}

@Inject(method = "windowClick", at = @At("HEAD"), cancellable = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ fun MovementInput.reset() {
}

val MovementInput.isSideways
get() = moveForward != 0f && moveStrafe != 0f
get() = moveForward != 0f && moveStrafe != 0f

val MovementInput.isMoving
get() = moveForward != 0f || moveStrafe != 0f
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import net.ccbluex.liquidbounce.utils.block.BlockUtils.getState
import net.ccbluex.liquidbounce.utils.render.ColorUtils.stripColor
import net.minecraft.client.entity.EntityPlayerSP
import net.minecraft.entity.Entity
import net.minecraft.entity.EntityLiving
import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.boss.EntityDragon
import net.minecraft.entity.monster.EntityGhast
Expand Down Expand Up @@ -128,8 +127,8 @@ val Entity.currPos: Vec3
val Entity.lastTickPos: Vec3
get() = Vec3(lastTickPosX, lastTickPosY, lastTickPosZ)

val EntityLivingBase.isMoving: Boolean
get() = this.run { moveForward != 0F || moveStrafing != 0F }
val EntityLivingBase?.isMoving: Boolean
get() = this?.run { moveForward != 0F || moveStrafing != 0F } == true

fun Entity.setPosAndPrevPos(currPos: Vec3, prevPos: Vec3 = currPos, lastTickPos: Vec3? = null) {
setPosition(currPos.xCoord, currPos.yCoord, currPos.zCoord)
Expand Down

0 comments on commit afd1a46

Please sign in to comment.