Skip to content

Commit

Permalink
Added rotation preview
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishisherewithhh committed Sep 1, 2024
1 parent ee2c71b commit c34c0f8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.heliosclient.managers.ModuleManager;
import dev.heliosclient.module.modules.render.ESP;
import dev.heliosclient.module.modules.render.NameTags;
import dev.heliosclient.util.player.RotationUtils;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.LivingEntityRenderer;
import net.minecraft.client.render.entity.model.EntityModel;
Expand All @@ -12,9 +13,11 @@
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.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import static dev.heliosclient.util.render.Renderer3D.mc;
import static org.lwjgl.opengl.GL11C.*;

@Mixin(LivingEntityRenderer.class)
Expand Down Expand Up @@ -50,5 +53,27 @@ private void onHasLabel(T entity, CallbackInfoReturnable<Boolean> cir) {
cir.setReturnValue(true);
}
}

//ClientSide rotation preview in 3rd person
//From Meteor mixin

@ModifyVariable(method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", ordinal = 2, at = @At(value = "STORE", ordinal = 0))
public float changeYaw(float prevValue, LivingEntity entity) {
if (entity.equals(mc.player) && RotationUtils.timerSinceLastRotation.getElapsedTicks() < 10) return RotationUtils.serverYaw;
return prevValue;
}

@ModifyVariable(method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", ordinal = 3, at = @At(value = "STORE", ordinal = 0))
public float changeHeadYaw(float prevValue, LivingEntity entity) {
if (entity.equals(mc.player) && RotationUtils.timerSinceLastRotation.getElapsedTicks() < 10) return RotationUtils.serverYaw;
return prevValue;
}

@ModifyVariable(method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", ordinal = 5, at = @At(value = "STORE", ordinal = 3))
public float changePitch(float prevValue, LivingEntity entity) {
if (entity.equals(mc.player) && RotationUtils.timerSinceLastRotation.getElapsedTicks() < 10) return RotationUtils.serverPitch;
return prevValue;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ public void placeFromCenter(BlockPos center) {
break;
}
}
} else if(mc.player.getMainHandStack().isEmpty() || blocks.getSelectedEntries().stream().noneMatch(block -> block.asItem() == mc.player.getMainHandStack().getItem())){
return;
}
if (itemSlot == -1) {
//Toggle maybe?
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/dev/heliosclient/util/TickTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public TickTimer(int defaultTicks) {
public TickTimer() {
}

public TickTimer(boolean start) {
if(start)
startTicking();
}

public void startTicking() {
if (hasTimerStarted) return;
ticks = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public void simulateRotation(Entity entity, Runnable task, int tickTiming, int r

@SubscribeEvent
public void tick(TickEvent.PLAYER event) {
RotationUtils.timerSinceLastRotation.increment();

if (currentRotation != null) {
currentRotation.update();

Expand Down
16 changes: 15 additions & 1 deletion src/main/java/dev/heliosclient/util/player/RotationUtils.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.heliosclient.util.player;

import dev.heliosclient.util.TickTimer;
import dev.heliosclient.util.render.Renderer3D;
import net.fabricmc.loader.impl.lib.sat4j.core.Vec;
import net.minecraft.entity.Entity;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.util.hit.HitResult;
Expand All @@ -13,7 +13,10 @@
import static dev.heliosclient.util.render.Renderer3D.mc;

public class RotationUtils {
//Incremented in rotation simulator
public static final TickTimer timerSinceLastRotation = new TickTimer(true);
static float prevYaw, prevPitch;
public static float serverYaw, serverPitch;

public static void lookAt(Entity entity, LookAtPos lookAtPos) {
lookAt(lookAtPos.positionGetter.getPosition(entity));
Expand Down Expand Up @@ -103,21 +106,32 @@ public static double getPitch(Vec3d target) {


public static void rotate(double yaw, double pitch, boolean clientSide, @Nullable Runnable task) {
if(prevYaw != yaw && prevPitch != pitch && clientSide){
timerSinceLastRotation.restartTimer();
}
prevYaw = mc.player.getYaw(mc.getTickDelta());
prevPitch = mc.player.getPitch(mc.getTickDelta());

mc.player.setPitch((float) pitch);
mc.player.setYaw((float) yaw);

if (clientSide) {
mc.player.renderYaw = (float) yaw;
mc.player.renderPitch = (float) pitch;
mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround((float) yaw, (float) pitch, mc.player.isOnGround()));
if (task != null)
task.run();
setServerRotations((float) yaw, (float) pitch);
mc.player.setYaw(prevYaw);
mc.player.setPitch(prevPitch);
}
}

public static void setServerRotations(float yaw, float pitch){
serverYaw = yaw;
serverPitch = pitch;
}

public enum LookAtPos {
HEAD(Entity::getEyePos),
CENTER(entity -> entity.getBoundingBox().getCenter()),
Expand Down

0 comments on commit c34c0f8

Please sign in to comment.