From c34c0f8d34099fed645d91b130784604225969ba Mon Sep 17 00:00:00 2001 From: tanishisherewithhh <120117618+tanishisherewithhh@users.noreply.github.com> Date: Sun, 1 Sep 2024 23:01:02 +0530 Subject: [PATCH] Added rotation preview --- .../mixin/LivingEntityRendererMixin.java | 25 +++++++++++++++++++ .../module/modules/movement/Scaffold.java | 2 ++ .../java/dev/heliosclient/util/TickTimer.java | 5 ++++ .../util/player/RotationSimulator.java | 2 ++ .../util/player/RotationUtils.java | 16 +++++++++++- 5 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/main/java/dev/heliosclient/mixin/LivingEntityRendererMixin.java b/src/main/java/dev/heliosclient/mixin/LivingEntityRendererMixin.java index 450ad9d2..7174a0c1 100644 --- a/src/main/java/dev/heliosclient/mixin/LivingEntityRendererMixin.java +++ b/src/main/java/dev/heliosclient/mixin/LivingEntityRendererMixin.java @@ -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; @@ -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) @@ -50,5 +53,27 @@ private void onHasLabel(T entity, CallbackInfoReturnable 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; + } + } diff --git a/src/main/java/dev/heliosclient/module/modules/movement/Scaffold.java b/src/main/java/dev/heliosclient/module/modules/movement/Scaffold.java index 029088a7..cab59394 100644 --- a/src/main/java/dev/heliosclient/module/modules/movement/Scaffold.java +++ b/src/main/java/dev/heliosclient/module/modules/movement/Scaffold.java @@ -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? diff --git a/src/main/java/dev/heliosclient/util/TickTimer.java b/src/main/java/dev/heliosclient/util/TickTimer.java index 77318c17..68f13b99 100644 --- a/src/main/java/dev/heliosclient/util/TickTimer.java +++ b/src/main/java/dev/heliosclient/util/TickTimer.java @@ -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; diff --git a/src/main/java/dev/heliosclient/util/player/RotationSimulator.java b/src/main/java/dev/heliosclient/util/player/RotationSimulator.java index 4da7774c..b64874bc 100644 --- a/src/main/java/dev/heliosclient/util/player/RotationSimulator.java +++ b/src/main/java/dev/heliosclient/util/player/RotationSimulator.java @@ -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(); diff --git a/src/main/java/dev/heliosclient/util/player/RotationUtils.java b/src/main/java/dev/heliosclient/util/player/RotationUtils.java index 685d5ae4..d7c1a64a 100644 --- a/src/main/java/dev/heliosclient/util/player/RotationUtils.java +++ b/src/main/java/dev/heliosclient/util/player/RotationUtils.java @@ -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; @@ -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)); @@ -103,6 +106,9 @@ 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()); @@ -110,14 +116,22 @@ public static void rotate(double yaw, double pitch, boolean clientSide, @Nullabl 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()),