From 7285273852b4a1791e0fc0df32ee50ad36fec909 Mon Sep 17 00:00:00 2001 From: "Paul P." <37075355+Ghosty920@users.noreply.github.com> Date: Tue, 14 Apr 2026 00:15:31 +0200 Subject: [PATCH] feat: Displace better player check & options --- settings.gradle.kts | 2 +- .../axle/suim/feature/combat/Displace.java | 92 ++++++++++++++----- 2 files changed, 71 insertions(+), 23 deletions(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 9702322..3b6c5be 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -23,4 +23,4 @@ plugins { } -rootProject.name = "myau-injection-template" +rootProject.name = "SUIM" diff --git a/src/main/java/coffee/axle/suim/feature/combat/Displace.java b/src/main/java/coffee/axle/suim/feature/combat/Displace.java index 2d1e22e..5346ecb 100644 --- a/src/main/java/coffee/axle/suim/feature/combat/Displace.java +++ b/src/main/java/coffee/axle/suim/feature/combat/Displace.java @@ -7,14 +7,20 @@ import coffee.axle.suim.util.MyauLogger; import coffee.axle.suim.util.Utils; import net.minecraft.client.Minecraft; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ChatComponentText; import net.minecraft.util.Vec3; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.player.AttackEntityEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.client.settings.KeyBinding; -import org.lwjgl.input.Mouse; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemSword; import java.util.HashMap; import java.util.Iterator; @@ -22,15 +28,17 @@ @SuppressWarnings({ "unused" }) public class Displace extends Feature { + private static final Minecraft mc = Minecraft.getMinecraft(); private static final int DISPLACE_WINDOW_TICKS = 10; - private static final String[] DIRECTIONS = {"Left", "Right"}; + private static final String[] DIRECTIONS = { "Left", "Right" }; private Object moduleInstance; private Object yawOffsetProperty; private Object delayProperty; private Object directionProperty; private Object findVoidProperty; + private Object weaponOnly, knockbackOnly; private boolean displaceThisTick = false; private boolean active = false; @@ -38,6 +46,7 @@ public class Displace extends Feature { private boolean displaceLeft = false; private boolean wasDisplacingLastTick = false; private boolean hasKB = false; + private Entity attackedLivingEntity = null; private int tickCounter = 0; private final Map targetWindowStartTicks = new HashMap<>(); @@ -61,9 +70,11 @@ public boolean initialize() { delayProperty = creator.createIntegerProperty("delay-ms", 0, 0, 500); directionProperty = creator.createEnumProperty("direction", 0, DIRECTIONS); findVoidProperty = creator.createBooleanProperty("find-void", false); + weaponOnly = creator.createBooleanProperty("weapon-only", true); + knockbackOnly = creator.createBooleanProperty("knockback-only", false); creator.registerProperties(moduleInstance, yawOffsetProperty, delayProperty, - directionProperty, findVoidProperty); + directionProperty, findVoidProperty, weaponOnly, knockbackOnly); manager.reloadModuleCommand(); MinecraftForge.EVENT_BUS.register(this); @@ -83,6 +94,7 @@ private void onEnable() { hasKB = false; compensateNextTick = false; wasDisplacingLastTick = false; + attackedLivingEntity = null; tickCounter = 0; targetWindowStartTicks.clear(); } @@ -92,11 +104,13 @@ private void onDisable() { hasKB = false; compensateNextTick = false; wasDisplacingLastTick = false; + attackedLivingEntity = null; targetWindowStartTicks.clear(); } private int msToTicks(double ms) { - if (ms <= 0.0) return 0; + if (ms <= 0.0) + return 0; return (int) Math.ceil(ms / 50.0); } @@ -107,11 +121,19 @@ private boolean anyMovementKey() { || mc.gameSettings.keyBindRight.isKeyDown(); } - private boolean tryFindVoidDirection(EntityPlayer target) { + private boolean isHoldingAllowedWeapon() { + ItemStack heldItem = mc.thePlayer.getHeldItem(); + if (heldItem == null) + return false; + return heldItem.getItem() instanceof ItemSword || heldItem.getItem() == Items.stick; + } + + private boolean tryFindVoidDirection(Entity target) { double dx = target.posX - mc.thePlayer.posX; double dz = target.posZ - mc.thePlayer.posZ; double dist = Math.sqrt(dx * dx + dz * dz); - if (dist < 0.001) return false; + if (dist < 0.001) + return false; dx /= dist; dz /= dist; double rightX = -dz; @@ -130,8 +152,10 @@ private boolean tryFindVoidDirection(EntityPlayer target) { if (mc.theWorld.rayTraceBlocks(new Vec3(lx, eyeY, lz), new Vec3(lx, eyeY - 10, lz)) == null) leftVoidCount++; } - if (leftVoidCount == 0 && rightVoidCount == 0) return false; - if (leftVoidCount != rightVoidCount) displaceLeft = leftVoidCount > rightVoidCount; + if (leftVoidCount == 0 && rightVoidCount == 0) + return false; + if (leftVoidCount != rightVoidCount) + displaceLeft = leftVoidCount > rightVoidCount; return true; } @@ -149,8 +173,9 @@ private void pruneTargetDelayStates() { } } - private boolean shouldDisplaceInCurrentWindow(EntityPlayer target, int currentTick) { - if (target == null) return true; + private boolean shouldDisplaceInCurrentWindow(Entity target, int currentTick) { + if (target == null) + return true; int targetId = target.getEntityId(); Integer windowStartTick = targetWindowStartTicks.get(targetId); if (windowStartTick == null || currentTick - windowStartTick >= DISPLACE_WINDOW_TICKS) { @@ -158,7 +183,8 @@ private boolean shouldDisplaceInCurrentWindow(EntityPlayer target, int currentTi return true; } int delayTicks = msToTicks(properties.getInt(delayProperty, 0)); - if (delayTicks <= 0) return true; + if (delayTicks <= 0) + return true; return currentTick - windowStartTick >= delayTicks; } @@ -166,7 +192,8 @@ private EntityPlayer findClosestTarget(double rangeSq) { EntityPlayer closest = null; double closestDist = rangeSq; for (EntityPlayer player : mc.theWorld.playerEntities) { - if (player == mc.thePlayer || player.isDead || player.deathTime != 0) continue; + if (player == mc.thePlayer || player.isDead || player.deathTime != 0) + continue; double dist = mc.thePlayer.getDistanceSqToEntity(player); if (dist < closestDist) { closestDist = dist; @@ -178,7 +205,8 @@ private EntityPlayer findClosestTarget(double rangeSq) { @SubscribeEvent(priority = EventPriority.HIGH) public void onPrePlayerInput(PrePlayerInputEvent e) { - if (!manager.isModuleEnabled(moduleInstance)) return; + if (!manager.isModuleEnabled(moduleInstance)) + return; if (!active) { compensateNextTick = false; return; @@ -190,16 +218,28 @@ public void onPrePlayerInput(PrePlayerInputEvent e) { return; } - if (!displaceThisTick || hasKB) return; - if (!anyMovementKey()) return; + if (!displaceThisTick || hasKB) + return; + if (!anyMovementKey()) + return; e.setForward(1); compensateNextTick = true; } + @SubscribeEvent(priority = EventPriority.HIGHEST) + public void onAttack(AttackEntityEvent e) { + if (e.entityPlayer != mc.thePlayer) + return; + if (!(e.target instanceof EntityLivingBase)) return; +// if (!(e.target instanceof EntityPlayer)) return; + attackedLivingEntity = e.target; + } + @SubscribeEvent(priority = EventPriority.LOW) public void onPreMotion(PreMotionEvent e) { - if (!manager.isModuleEnabled(moduleInstance)) return; + if (!manager.isModuleEnabled(moduleInstance)) + return; if (!Utils.nullCheck()) { active = false; compensateNextTick = false; @@ -210,13 +250,17 @@ public void onPreMotion(PreMotionEvent e) { tickCounter++; int currentTick = tickCounter; pruneTargetDelayStates(); + boolean knockbackOnlyEnabled = properties.getBoolean(knockbackOnly, false); boolean hasKBEnchant = EnchantmentHelper.getKnockbackModifier(mc.thePlayer) > 0; + boolean weaponOnlyEnabled = properties.getBoolean(weaponOnly, true); - boolean attacking = Mouse.isButtonDown(0); - EntityPlayer target = attacking ? findClosestTarget(9.0) : null; + Entity target = attackedLivingEntity; + attackedLivingEntity = null; - active = target != null && (hasKBEnchant || anyMovementKey()); hasKB = hasKBEnchant; + boolean weaponAllowed = !weaponOnlyEnabled || isHoldingAllowedWeapon(); + boolean knockbackFlag = !knockbackOnlyEnabled || hasKB; + active = target != null && weaponAllowed && (hasKB || anyMovementKey()); if (!active) { displaceThisTick = false; compensateNextTick = false; @@ -246,12 +290,16 @@ public void onPreMotion(PreMotionEvent e) { } wasDisplacingLastTick = displaceThisTick; - if (!displaceThisTick) return; + if (!displaceThisTick) + return; float baseYaw = mc.thePlayer.rotationYaw; float offset = properties.getInt(yawOffsetProperty, 90); - if (displaceLeft) baseYaw -= offset; - else baseYaw += offset; + if (displaceLeft) + baseYaw -= offset; + else + baseYaw += offset; e.setYaw(baseYaw); } + }