Skip to content

Commit

Permalink
add a broken clutch module
Browse files Browse the repository at this point in the history
  • Loading branch information
xia-mc committed Jul 10, 2024
1 parent 3c22630 commit f5bfe16
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 60 deletions.
4 changes: 2 additions & 2 deletions src/main/java/keystrokesmod/module/ModuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public class ModuleManager {
public static SlotHandler slotHandler;
public static StaffDetector staffDetector;
public static AutoRespawn autoRespawn;
public static Clutch clutch;

public void register() {
this.addModule(autoClicker = new AutoClicker());
Expand Down Expand Up @@ -212,8 +213,7 @@ public void register() {
this.addModule(slotHandler = new SlotHandler());
this.addModule(staffDetector = new StaffDetector());
this.addModule(new AutoWeapon());
this.addModule(autoRespawn = new AutoRespawn());

this.addModule(autoRespawn = new AutoRespawn());
antiBot.enable();
commandChat.enable();
modSpoofer.enable();
Expand Down
79 changes: 23 additions & 56 deletions src/main/java/keystrokesmod/module/impl/world/BlockIn.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package keystrokesmod.module.impl.world;

import keystrokesmod.event.PreMotionEvent;
import keystrokesmod.event.PreUpdateEvent;
import keystrokesmod.event.RotationEvent;
import keystrokesmod.module.Module;
import keystrokesmod.module.impl.other.SlotHandler;
import keystrokesmod.module.impl.other.anticheats.utils.phys.Vec2;
import keystrokesmod.module.impl.other.anticheats.utils.world.PlayerRotation;
import keystrokesmod.module.setting.impl.ButtonSetting;
import keystrokesmod.module.setting.impl.DescriptionSetting;
import keystrokesmod.module.setting.impl.ModeSetting;
import keystrokesmod.module.setting.impl.SliderSetting;
import keystrokesmod.module.setting.utils.ModeOnly;
import keystrokesmod.script.classes.Vec3;
import keystrokesmod.utility.*;
import net.minecraft.item.ItemBlock;
Expand Down Expand Up @@ -41,8 +43,8 @@ public BlockIn() {
super("Block-In", category.world);
this.registerSetting(new DescriptionSetting("make you block in."));
this.registerSetting(rotationMode = new ModeSetting("Rotation mode", rotationModes, 2));
this.registerSetting(aimSpeed = new SliderSetting("Aim speed", 5, 0, 5, 0.05));
this.registerSetting(lookView = new ButtonSetting("Look view", false));
this.registerSetting(aimSpeed = new SliderSetting("Aim speed", 5, 0, 10, 0.05, new ModeOnly(rotationMode, 1, 2)));
this.registerSetting(lookView = new ButtonSetting("Look view", false, new ModeOnly(rotationMode, 1, 2)));
this.registerSetting(placeDelay = new SliderSetting("Place delay", 50, 0, 500, 1, "ms"));
this.registerSetting(silentSwing = new ButtonSetting("Silent swing", false));
this.registerSetting(autoSwitch = new ButtonSetting("Auto switch", true));
Expand All @@ -53,7 +55,7 @@ public void onDisable() {
currentRot = null;
lastPlace = 0;
if (autoSwitch.isToggled() && lastSlot != -1) {
mc.thePlayer.inventory.currentItem = lastSlot;
SlotHandler.setCurrentSlot(lastSlot);
}
lastSlot = -1;
}
Expand All @@ -72,11 +74,11 @@ public void onPreMotion(RotationEvent event) {
}

@SubscribeEvent
public void onRender(TickEvent.RenderTickEvent event) {
public void onPreUpdate(PreUpdateEvent event) {
if (autoSwitch.isToggled() && lastSlot == -1) {
int slot = ContainerUtils.getSlot(ItemBlock.class);
lastSlot = mc.thePlayer.inventory.currentItem;
mc.thePlayer.inventory.currentItem = slot;
int slot = Scaffold.getSlot();
lastSlot = SlotHandler.getCurrentSlot();
SlotHandler.setCurrentSlot(slot);
}

try {
Expand All @@ -102,7 +104,7 @@ public void onRender(TickEvent.RenderTickEvent event) {

Triple<BlockPos, EnumFacing, Vec3> placeSideBlock;
try {
placeSideBlock = getPlaceSide(blockPos).orElseThrow(NoSuchElementException::new);
placeSideBlock = RotationUtils.getPlaceSide(blockPos).orElseThrow(NoSuchElementException::new);
} catch (NoSuchElementException e) {
continue;
}
Expand All @@ -119,7 +121,7 @@ public void onRender(TickEvent.RenderTickEvent event) {
currentRot = new Vec2(mc.thePlayer.rotationYaw, mc.thePlayer.rotationPitch);
}
if (rotationMode.getInput() != 0 && !currentRot.equals(rotation)) {
if (aimSpeed.getInput() == 5) {
if (aimSpeed.getInput() == 10) {
currentRot = rotation;
} else {
currentRot = new Vec2(
Expand All @@ -137,22 +139,22 @@ public void onRender(TickEvent.RenderTickEvent event) {
}

if (rotationMode.getInput() == 0 || currentRot.equals(rotation)) {
mc.playerController.onPlayerRightClick(
if (mc.playerController.onPlayerRightClick(
mc.thePlayer, mc.theWorld,
mc.thePlayer.getHeldItem(),
placeSideBlock.getLeft(), placeSideBlock.getMiddle(),
hitPos.toVec3()
);

if (silentSwing.isToggled()) {
mc.thePlayer.sendQueue.addToSendQueue(new C0APacketAnimation());
} else {
mc.thePlayer.swingItem();
mc.getItemRenderer().resetEquippedProgress();
)) {
if (silentSwing.isToggled()) {
mc.thePlayer.sendQueue.addToSendQueue(new C0APacketAnimation());
} else {
mc.thePlayer.swingItem();
mc.getItemRenderer().resetEquippedProgress();
}

lastPlace = currentTime;
placed++;
}

lastPlace = currentTime;
placed++;
}
}
if (placed == 0) disable();
Expand All @@ -162,39 +164,4 @@ public void onRender(TickEvent.RenderTickEvent event) {
return BlockUtils.getSurroundBlocks(mc.thePlayer);
}

public static @NotNull Optional<Triple<BlockPos, EnumFacing, Vec3>> getPlaceSide(@NotNull BlockPos blockPos) {
final List<BlockPos> possible = Arrays.asList(
blockPos.down(), blockPos.east(), blockPos.west(),
blockPos.north(), blockPos.south(), blockPos.up()
);

for (BlockPos pos : possible) {
if (BlockUtils.getBlockState(pos).getBlock().isFullBlock()) {
EnumFacing facing;
Vec3 hitPos;
if (pos.getY() < blockPos.getY()) {
facing = EnumFacing.UP;
hitPos = new Vec3(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5);
} else if (pos.getX() > blockPos.getX()) {
facing = EnumFacing.WEST;
hitPos = new Vec3(pos.getX(), pos.getY() + 0.5, pos.getZ() + 0.5);
} else if (pos.getX() < blockPos.getX()) {
facing = EnumFacing.EAST;
hitPos = new Vec3(pos.getX() + 1, pos.getY() + 0.5, pos.getZ() + 0.5);
} else if (pos.getZ() < blockPos.getZ()) {
facing = EnumFacing.SOUTH;
hitPos = new Vec3(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 1);
} else if (pos.getZ() > blockPos.getZ()) {
facing = EnumFacing.NORTH;
hitPos = new Vec3(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ());
} else {
facing = EnumFacing.DOWN;
hitPos = new Vec3(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5);
}

return Optional.of(Triple.of(pos, facing, hitPos));
}
}
return Optional.empty();
}
}
156 changes: 156 additions & 0 deletions src/main/java/keystrokesmod/module/impl/world/Clutch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
package keystrokesmod.module.impl.world;

import keystrokesmod.event.PreUpdateEvent;
import keystrokesmod.module.Module;
import keystrokesmod.module.impl.other.RotationHandler;
import keystrokesmod.module.impl.other.SlotHandler;
import keystrokesmod.module.impl.other.anticheats.utils.phys.Vec2;
import keystrokesmod.module.impl.other.anticheats.utils.world.PlayerRotation;
import keystrokesmod.module.setting.impl.ButtonSetting;
import keystrokesmod.module.setting.impl.ModeSetting;
import keystrokesmod.module.setting.impl.SliderSetting;
import keystrokesmod.module.setting.utils.ModeOnly;
import keystrokesmod.script.classes.Vec3;
import keystrokesmod.utility.*;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.client.C0APacketAnimation;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.MovingObjectPosition;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.apache.commons.lang3.tuple.Triple;

import java.util.List;
import java.util.Optional;

public class Clutch extends Module {
private final ModeSetting mode = new ModeSetting("Rotation mode", new String[]{"None", "Block", "Strict"}, 2);
private final SliderSetting aimSpeed = new SliderSetting("Aim speed", 20, 10, 30, 0.5, new ModeOnly(mode, 1, 2));
private final ButtonSetting lookView = new ButtonSetting("Look view", false, new ModeOnly(mode, 1, 2));
private final SliderSetting placeDelay = new SliderSetting("Place delay", 50, 0, 500, 1, "ms");
private final ButtonSetting overVoid = new ButtonSetting("Over void", true);
private final ButtonSetting fallDistance = new ButtonSetting("Fall distance", false);
private final SliderSetting minFallDistance = new SliderSetting("Min fall distance", 6, 0, 10, 1, fallDistance::isToggled);
private final ButtonSetting autoSwitch = new ButtonSetting("Auto switch", false);
private final ButtonSetting silentSwing = new ButtonSetting("Silent swing", false);
private Vec2 rot = null;
private long lastPlace = -1;

public Clutch() {
super("Clutch", category.world);
this.registerSetting(mode, aimSpeed, lookView, placeDelay, overVoid, fallDistance, minFallDistance, autoSwitch, silentSwing);
}

@SubscribeEvent(priority = EventPriority.HIGH)
public void onPreUpdate(PreUpdateEvent event) {
if (!shouldClutch()) {
rot = null;
return;
}
if (autoSwitch.isToggled()) {
ItemStack item = SlotHandler.getHeldItem();
if ((item == null || !(item.getItem() instanceof ItemBlock) || !ContainerUtils.canBePlaced((ItemBlock) item.getItem()))) {
int slot = Scaffold.getSlot();
SlotHandler.setCurrentSlot(slot);
}
}
if (SlotHandler.getHeldItem() == null || !(SlotHandler.getHeldItem().getItem() instanceof ItemBlock)) {
rot = null;
return;
}

if (rot == null) {
rot = new Vec2(RotationHandler.getRotationYaw(), RotationHandler.getRotationPitch());
}

final Vec3 eyePos = Utils.getEyePos();
final BlockPos position = mc.thePlayer.getPosition();
final Vec3 groundPos = new Vec3(position.getX() + 0.5, position.getY() - 1, position.getZ() + 0.5);
final List<BlockPos> blocks = BlockUtils.getAllInBox(position.add(-5, -5, -5), position.add(5, 0, 5));

double minDistance = Double.MAX_VALUE;
Triple<BlockPos, EnumFacing, Vec3> bestPlace = null;
for (BlockPos block : blocks) {
if (!BlockUtils.replaceable(block) || BlockUtils.isSamePos(block, position) || BlockUtils.isSamePos(block, position.up())) continue;

final Optional<Triple<BlockPos, EnumFacing, Vec3>> optional = RotationUtils.getPlaceSide(block);
if (!optional.isPresent()) continue;
final Triple<BlockPos, EnumFacing, Vec3> place = optional.get();

final double placeDistance = place.getRight().distanceTo(eyePos);
if (placeDistance > 4.5) continue;

final float yaw = PlayerRotation.getYaw(place.getRight());
final float pitch = PlayerRotation.getPitch(place.getRight());
if ((int) mode.getInput() == 2) {
MovingObjectPosition hitResult = RotationUtils.rayCast(4.5, yaw, pitch);
if (hitResult == null || !BlockUtils.isSamePos(hitResult.getBlockPos(), place.getLeft()))
return;
}

final double blockDistance = place.getRight().distanceTo(groundPos);

if (blockDistance < minDistance) {
minDistance = blockDistance;
bestPlace = place;
}
}

if (bestPlace != null) {
final BlockPos pos = bestPlace.getLeft();
final EnumFacing facing = bestPlace.getMiddle();
final Vec3 hitPos = bestPlace.getRight();

if (mode.getInput() != 0) { // need rotation
final float yaw = PlayerRotation.getYaw(hitPos);
final float pitch = PlayerRotation.getPitch(hitPos);

rot.x = AimSimulator.rotMove(yaw, rot.x, (float) aimSpeed.getInput());
rot.y = AimSimulator.rotMove(pitch, rot.y, (float) aimSpeed.getInput());
if (lookView.isToggled()) {
mc.thePlayer.rotationYaw = rot.x;
mc.thePlayer.rotationPitch = rot.y;
} else {
RotationHandler.setRotationYaw(rot.x);
RotationHandler.setRotationPitch(rot.y);
}

switch ((int) mode.getInput()) {
case 1:
if (rot.x != yaw || rot.y != pitch) return;
break;
case 2:
MovingObjectPosition hitResult = RotationUtils.rayCast(4.5, yaw, pitch);
if (hitResult == null || !BlockUtils.isSamePos(hitResult.getBlockPos(), pos))
return;
break;
}
}

long time = System.currentTimeMillis();
if (time - lastPlace < placeDelay.getInput()) return;

if (mc.playerController.onPlayerRightClick(
mc.thePlayer, mc.theWorld,
mc.thePlayer.getHeldItem(),
pos, facing,
hitPos.toVec3()
)) {
if (silentSwing.isToggled()) {
mc.thePlayer.sendQueue.addToSendQueue(new C0APacketAnimation());
} else {
mc.thePlayer.swingItem();
mc.getItemRenderer().resetEquippedProgress();
}
lastPlace = time;
}
}
}

private boolean shouldClutch() {
if (overVoid.isToggled() && Utils.overVoid()) return true;
return fallDistance.isToggled() && mc.thePlayer.fallDistance >= minFallDistance.getInput();
}
}
4 changes: 2 additions & 2 deletions src/main/java/keystrokesmod/module/impl/world/Scaffold.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public void onPreUpdate(PreUpdateEvent e) { // place here
for (BlockPos pos : possible) {
if (!BlockUtils.replaceable(pos)) continue;

Optional<Triple<BlockPos, EnumFacing, keystrokesmod.script.classes.Vec3>> placeSide = BlockIn.getPlaceSide(pos);
Optional<Triple<BlockPos, EnumFacing, keystrokesmod.script.classes.Vec3>> placeSide = RotationUtils.getPlaceSide(pos);
if (!placeSide.isPresent()) continue;

place(new MovingObjectPosition(MovingObjectPosition.MovingObjectType.BLOCK,
Expand Down Expand Up @@ -665,7 +665,7 @@ protected void place(MovingObjectPosition block, boolean extra) {
}
}

private int getSlot() {
public static int getSlot() {
int slot = -1;
int highestStack = -1;
for (int i = 0; i < 9; ++i) {
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/keystrokesmod/utility/RotationUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItemFrame;
import net.minecraft.util.*;
import org.apache.commons.lang3.tuple.Triple;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public class RotationUtils {
public static final Minecraft mc = Minecraft.getMinecraft();
Expand Down Expand Up @@ -313,4 +316,40 @@ public static boolean isMouseOver(final float yaw, final float pitch, final Enti

return false;
}

public static @NotNull Optional<Triple<BlockPos, EnumFacing, keystrokesmod.script.classes.Vec3>> getPlaceSide(@NotNull BlockPos blockPos) {
final List<BlockPos> possible = Arrays.asList(
blockPos.down(), blockPos.east(), blockPos.west(),
blockPos.north(), blockPos.south(), blockPos.up()
);

for (BlockPos pos : possible) {
if (BlockUtils.getBlockState(pos).getBlock().isFullBlock()) {
EnumFacing facing;
keystrokesmod.script.classes.Vec3 hitPos;
if (pos.getY() < blockPos.getY()) {
facing = EnumFacing.UP;
hitPos = new keystrokesmod.script.classes.Vec3(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5);
} else if (pos.getX() > blockPos.getX()) {
facing = EnumFacing.WEST;
hitPos = new keystrokesmod.script.classes.Vec3(pos.getX(), pos.getY() + 0.5, pos.getZ() + 0.5);
} else if (pos.getX() < blockPos.getX()) {
facing = EnumFacing.EAST;
hitPos = new keystrokesmod.script.classes.Vec3(pos.getX() + 1, pos.getY() + 0.5, pos.getZ() + 0.5);
} else if (pos.getZ() < blockPos.getZ()) {
facing = EnumFacing.SOUTH;
hitPos = new keystrokesmod.script.classes.Vec3(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 1);
} else if (pos.getZ() > blockPos.getZ()) {
facing = EnumFacing.NORTH;
hitPos = new keystrokesmod.script.classes.Vec3(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ());
} else {
facing = EnumFacing.DOWN;
hitPos = new keystrokesmod.script.classes.Vec3(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5);
}

return Optional.of(Triple.of(pos, facing, hitPos));
}
}
return Optional.empty();
}
}

0 comments on commit f5bfe16

Please sign in to comment.