Skip to content

Commit

Permalink
Add Rotation helper method for sending player look packets
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed Jan 4, 2024
1 parent d7f3dd2 commit 4eda3f9
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 71 deletions.
15 changes: 8 additions & 7 deletions src/main/java/net/wurstclient/hacks/AutoBuildHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import net.minecraft.block.BlockState;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
Expand All @@ -36,7 +35,13 @@
import net.wurstclient.settings.FileSetting;
import net.wurstclient.settings.SliderSetting;
import net.wurstclient.settings.SliderSetting.ValueDisplay;
import net.wurstclient.util.*;
import net.wurstclient.util.AutoBuildTemplate;
import net.wurstclient.util.BlockUtils;
import net.wurstclient.util.ChatUtils;
import net.wurstclient.util.DefaultAutoBuildTemplates;
import net.wurstclient.util.RegionPos;
import net.wurstclient.util.RenderUtils;
import net.wurstclient.util.RotationUtils;
import net.wurstclient.util.json.JsonException;

public final class AutoBuildHack extends Hack
Expand Down Expand Up @@ -250,11 +255,7 @@ private boolean tryToPlace(BlockPos pos, Vec3d eyesPos, double rangeSq)
continue;

// face block
Rotation rotation = RotationUtils.getNeededRotations(hitVec);
PlayerMoveC2SPacket.LookAndOnGround packet =
new PlayerMoveC2SPacket.LookAndOnGround(rotation.yaw(),
rotation.pitch(), MC.player.isOnGround());
MC.player.networkHandler.sendPacket(packet);
RotationUtils.getNeededRotations(hitVec).sendPlayerLookPacket();

// place block
IMC.getInteractionManager().rightClickBlock(neighbor,
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/net/wurstclient/hacks/AutoPotionHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.potion.PotionUtil;
import net.wurstclient.Category;
import net.wurstclient.SearchTags;
import net.wurstclient.events.UpdateListener;
import net.wurstclient.hack.Hack;
import net.wurstclient.settings.SliderSetting;
import net.wurstclient.settings.SliderSetting.ValueDisplay;
import net.wurstclient.util.Rotation;

@SearchTags({"AutoPotion", "auto potion", "AutoSplashPotion",
"auto splash potion"})
Expand Down Expand Up @@ -77,16 +77,13 @@ public void onUpdate()

// throw potion in hotbar
MC.player.getInventory().selectedSlot = potionInHotbar;
MC.player.networkHandler.sendPacket(
new PlayerMoveC2SPacket.LookAndOnGround(MC.player.getYaw(), 90,
MC.player.isOnGround()));
new Rotation(MC.player.getYaw(), 90).sendPlayerLookPacket();
IMC.getInteractionManager().rightClickItem();

// reset slot and rotation
MC.player.getInventory().selectedSlot = oldSlot;
MC.player.networkHandler.sendPacket(
new PlayerMoveC2SPacket.LookAndOnGround(MC.player.getYaw(),
MC.player.getPitch(), MC.player.isOnGround()));
new Rotation(MC.player.getYaw(), MC.player.getPitch())
.sendPlayerLookPacket();

// reset timer
timer = 10;
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/net/wurstclient/hacks/ClickAuraHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.util.Hand;
import net.wurstclient.Category;
import net.wurstclient.SearchTags;
Expand All @@ -27,7 +26,6 @@
import net.wurstclient.settings.SliderSetting.ValueDisplay;
import net.wurstclient.settings.filterlists.EntityFilterList;
import net.wurstclient.util.EntityUtils;
import net.wurstclient.util.Rotation;
import net.wurstclient.util.RotationUtils;

@SearchTags({"click aura", "ClickAimbot", "click aimbot"})
Expand Down Expand Up @@ -134,12 +132,8 @@ private void attack()
WURST.getHax().autoSwordHack.setSlot(target);

// face entity
Rotation rotation = RotationUtils
.getNeededRotations(target.getBoundingBox().getCenter());
PlayerMoveC2SPacket.LookAndOnGround packet =
new PlayerMoveC2SPacket.LookAndOnGround(rotation.yaw(),
rotation.pitch(), MC.player.isOnGround());
MC.player.networkHandler.sendPacket(packet);
RotationUtils.getNeededRotations(target.getBoundingBox().getCenter())
.sendPlayerLookPacket();

// attack entity
WURST.getHax().criticalsHack.doCritical();
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/net/wurstclient/hacks/DerpHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

import java.util.Random;

import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.wurstclient.Category;
import net.wurstclient.SearchTags;
import net.wurstclient.events.UpdateListener;
import net.wurstclient.hack.Hack;
import net.wurstclient.util.Rotation;

@SearchTags({"Retarded"})
public final class DerpHack extends Hack implements UpdateListener
Expand Down Expand Up @@ -48,8 +48,6 @@ public void onUpdate()
float yaw = MC.player.getYaw() + random.nextFloat() * 360F - 180F;
float pitch = random.nextFloat() * 180F - 90F;

MC.player.networkHandler
.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(yaw, pitch,
MC.player.isOnGround()));
new Rotation(yaw, pitch).sendPlayerLookPacket();
}
}
6 changes: 2 additions & 4 deletions src/main/java/net/wurstclient/hacks/HeadRollHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
*/
package net.wurstclient.hacks;

import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.util.math.MathHelper;
import net.wurstclient.Category;
import net.wurstclient.SearchTags;
import net.wurstclient.events.UpdateListener;
import net.wurstclient.hack.Hack;
import net.wurstclient.util.Rotation;

@SearchTags({"head roll", "nodding", "yes"})
public final class HeadRollHack extends Hack implements UpdateListener
Expand Down Expand Up @@ -45,8 +45,6 @@ public void onUpdate()
float timer = MC.player.age % 20 / 10F;
float pitch = MathHelper.sin(timer * (float)Math.PI) * 90F;

MC.player.networkHandler.sendPacket(
new PlayerMoveC2SPacket.LookAndOnGround(MC.player.getYaw(), pitch,
MC.player.isOnGround()));
new Rotation(MC.player.getYaw(), pitch).sendPlayerLookPacket();
}
}
11 changes: 3 additions & 8 deletions src/main/java/net/wurstclient/hacks/MultiAuraHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.Entity;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.util.Hand;
import net.wurstclient.Category;
import net.wurstclient.SearchTags;
Expand All @@ -25,7 +24,6 @@
import net.wurstclient.settings.SliderSetting.ValueDisplay;
import net.wurstclient.settings.filterlists.EntityFilterList;
import net.wurstclient.util.EntityUtils;
import net.wurstclient.util.Rotation;
import net.wurstclient.util.RotationUtils;

@SearchTags({"multi aura", "ForceField", "force field"})
Expand Down Expand Up @@ -116,12 +114,9 @@ public void onUpdate()
// attack entities
for(Entity entity : entities)
{
Rotation rotation = RotationUtils
.getNeededRotations(entity.getBoundingBox().getCenter());

player.networkHandler.sendPacket(
new PlayerMoveC2SPacket.LookAndOnGround(rotation.yaw(),
rotation.pitch(), MC.player.isOnGround()));
RotationUtils
.getNeededRotations(entity.getBoundingBox().getCenter())
.sendPlayerLookPacket();

WURST.getHax().criticalsHack.doCritical();
MC.interactionManager.attackEntity(player, entity);
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/net/wurstclient/hacks/ScaffoldWalkHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.minecraft.block.FallingBlock;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
Expand All @@ -25,7 +24,6 @@
import net.wurstclient.events.UpdateListener;
import net.wurstclient.hack.Hack;
import net.wurstclient.util.BlockUtils;
import net.wurstclient.util.Rotation;
import net.wurstclient.util.RotationUtils;

@SearchTags({"scaffold walk", "BridgeWalk", "bridge walk", "AutoBridge",
Expand Down Expand Up @@ -129,9 +127,7 @@ private void scaffoldTo(BlockPos belowPlayer)

private boolean placeBlock(BlockPos pos)
{
Vec3d eyesPos = new Vec3d(MC.player.getX(),
MC.player.getY() + MC.player.getEyeHeight(MC.player.getPose()),
MC.player.getZ());
Vec3d eyesPos = RotationUtils.getEyesPos();

for(Direction side : Direction.values())
{
Expand All @@ -155,11 +151,7 @@ private boolean placeBlock(BlockPos pos)
continue;

// place block
Rotation rotation = RotationUtils.getNeededRotations(hitVec);
PlayerMoveC2SPacket.LookAndOnGround packet =
new PlayerMoveC2SPacket.LookAndOnGround(rotation.yaw(),
rotation.pitch(), MC.player.isOnGround());
MC.player.networkHandler.sendPacket(packet);
RotationUtils.getNeededRotations(hitVec).sendPlayerLookPacket();
IMC.getInteractionManager().rightClickBlock(neighbor, side2,
hitVec);
MC.player.swingHand(Hand.MAIN_HAND);
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/net/wurstclient/hacks/TiredHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
*/
package net.wurstclient.hacks;

import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.wurstclient.Category;
import net.wurstclient.events.UpdateListener;
import net.wurstclient.hack.Hack;
import net.wurstclient.util.Rotation;

public final class TiredHack extends Hack implements UpdateListener
{
Expand Down Expand Up @@ -39,8 +39,7 @@ public void onDisable()
@Override
public void onUpdate()
{
MC.player.networkHandler.sendPacket(
new PlayerMoveC2SPacket.LookAndOnGround(MC.player.getYaw(),
MC.player.age % 100, MC.player.isOnGround()));
new Rotation(MC.player.getYaw(), MC.player.age % 100)
.sendPlayerLookPacket();
}
}
10 changes: 2 additions & 8 deletions src/main/java/net/wurstclient/hacks/TpAuraHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.util.Hand;
import net.wurstclient.Category;
import net.wurstclient.SearchTags;
import net.wurstclient.WurstClient;
import net.wurstclient.events.UpdateListener;
import net.wurstclient.hack.Hack;
import net.wurstclient.settings.AttackSpeedSliderSetting;
Expand All @@ -29,7 +27,6 @@
import net.wurstclient.settings.SliderSetting.ValueDisplay;
import net.wurstclient.settings.filterlists.EntityFilterList;
import net.wurstclient.util.EntityUtils;
import net.wurstclient.util.Rotation;
import net.wurstclient.util.RotationUtils;

@SearchTags({"TpAura", "tp aura", "EnderAura", "Ender-Aura", "ender aura"})
Expand Down Expand Up @@ -128,11 +125,8 @@ public void onUpdate()
return;

// attack entity
Rotation rotations = RotationUtils
.getNeededRotations(entity.getBoundingBox().getCenter());
WurstClient.MC.player.networkHandler
.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(rotations.yaw(),
rotations.pitch(), MC.player.isOnGround()));
RotationUtils.getNeededRotations(entity.getBoundingBox().getCenter())
.sendPlayerLookPacket();

WURST.getHax().criticalsHack.doCritical();
MC.interactionManager.attackEntity(player, entity);
Expand Down
13 changes: 2 additions & 11 deletions src/main/java/net/wurstclient/settings/FacingSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@

import java.util.function.Consumer;

import net.minecraft.client.MinecraftClient;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.util.math.Vec3d;
import net.wurstclient.WurstClient;
import net.wurstclient.util.Rotation;
import net.wurstclient.util.RotationUtils;

public final class FacingSetting extends EnumSetting<FacingSetting.Facing>
{
private static final WurstClient WURST = WurstClient.INSTANCE;
private static final MinecraftClient MC = WurstClient.MC;

private FacingSetting(String name, String description, Facing[] values,
Facing selected)
Expand Down Expand Up @@ -55,13 +51,8 @@ public enum Facing
CLIENT("Client-side",
v -> WURST.getRotationFaker().faceVectorClient(v)),

SPAM("Packet spam", v -> {
Rotation rotation = RotationUtils.getNeededRotations(v);
PlayerMoveC2SPacket.LookAndOnGround packet =
new PlayerMoveC2SPacket.LookAndOnGround(rotation.yaw(),
rotation.pitch(), MC.player.isOnGround());
MC.player.networkHandler.sendPacket(packet);
});
SPAM("Packet spam",
v -> RotationUtils.getNeededRotations(v).sendPlayerLookPacket());

private String name;
private Consumer<Vec3d> face;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/net/wurstclient/util/Rotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,29 @@
*/
package net.wurstclient.util;

import net.minecraft.client.MinecraftClient;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.util.math.MathHelper;
import net.wurstclient.WurstClient;

public record Rotation(float yaw, float pitch)
{
private static final MinecraftClient MC = WurstClient.MC;

public static Rotation wrapped(float yaw, float pitch)
{
return new Rotation(MathHelper.wrapDegrees(yaw),
MathHelper.wrapDegrees(pitch));
}

public void sendPlayerLookPacket()
{
sendPlayerLookPacket(MC.player.isOnGround());
}

public void sendPlayerLookPacket(boolean onGround)
{
MC.player.networkHandler.sendPacket(
new PlayerMoveC2SPacket.LookAndOnGround(yaw, pitch, onGround));
}
}

0 comments on commit 4eda3f9

Please sign in to comment.