| 1 | /*
|
| 2 | * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
|
| 3 | * Copyright (c) Meteor Development.
|
| 4 | */
|
| 5 |
|
| 6 | package meteordevelopment.meteorclient.systems.modules.combat;
|
| 7 |
|
| 8 | import com.google.common.util.concurrent.AtomicDouble;
|
| 9 | import it.unimi.dsi.fastutil.ints.*;
|
| 10 | import meteordevelopment.meteorclient.events.entity.EntityAddedEvent;
|
| 11 | import meteordevelopment.meteorclient.events.entity.EntityRemovedEvent;
|
| 12 | import meteordevelopment.meteorclient.events.packets.PacketEvent;
|
| 13 | import meteordevelopment.meteorclient.events.render.Render2DEvent;
|
| 14 | import meteordevelopment.meteorclient.events.render.Render3DEvent;
|
| 15 | import meteordevelopment.meteorclient.events.world.TickEvent;
|
| 16 | import meteordevelopment.meteorclient.mixininterface.IAABB;
|
| 17 | import meteordevelopment.meteorclient.mixininterface.IClipContext;
|
| 18 | import meteordevelopment.meteorclient.mixininterface.IVec3;
|
| 19 | import meteordevelopment.meteorclient.renderer.ShapeMode;
|
| 20 | import meteordevelopment.meteorclient.renderer.text.TextRenderer;
|
| 21 | import meteordevelopment.meteorclient.settings.*;
|
| 22 | import meteordevelopment.meteorclient.systems.friends.Friends;
|
| 23 | import meteordevelopment.meteorclient.systems.modules.Categories;
|
| 24 | import meteordevelopment.meteorclient.systems.modules.Module;
|
| 25 | import meteordevelopment.meteorclient.utils.entity.DamageUtils;
|
| 26 | import meteordevelopment.meteorclient.utils.entity.EntityUtils;
|
| 27 | import meteordevelopment.meteorclient.utils.entity.Target;
|
| 28 | import meteordevelopment.meteorclient.utils.misc.Keybind;
|
| 29 | import meteordevelopment.meteorclient.utils.player.FindItemResult;
|
| 30 | import meteordevelopment.meteorclient.utils.player.InvUtils;
|
| 31 | import meteordevelopment.meteorclient.utils.player.PlayerUtils;
|
| 32 | import meteordevelopment.meteorclient.utils.player.Rotations;
|
| 33 | import meteordevelopment.meteorclient.utils.render.NametagUtils;
|
| 34 | import meteordevelopment.meteorclient.utils.render.RenderUtils;
|
| 35 | import meteordevelopment.meteorclient.utils.render.color.Color;
|
| 36 | import meteordevelopment.meteorclient.utils.render.color.SettingColor;
|
| 37 | import meteordevelopment.meteorclient.utils.world.BlockIterator;
|
| 38 | import meteordevelopment.meteorclient.utils.world.BlockUtils;
|
| 39 | import meteordevelopment.meteorclient.utils.world.TickRate;
|
| 40 | import meteordevelopment.orbit.EventHandler;
|
| 41 | import meteordevelopment.orbit.EventPriority;
|
| 42 | import net.minecraft.core.BlockPos;
|
| 43 | import net.minecraft.core.Direction;
|
| 44 | import net.minecraft.network.protocol.game.*;
|
| 45 | import net.minecraft.util.Mth;
|
| 46 | import net.minecraft.world.InteractionHand;
|
| 47 | import net.minecraft.world.effect.MobEffectInstance;
|
| 48 | import net.minecraft.world.effect.MobEffects;
|
| 49 | import net.minecraft.world.entity.*;
|
| 50 | import net.minecraft.world.entity.boss.enderdragon.EndCrystal;
|
| 51 | import net.minecraft.world.entity.player.Player;
|
| 52 | import net.minecraft.world.item.Item;
|
| 53 | import net.minecraft.world.item.ItemStack;
|
| 54 | import net.minecraft.world.item.Items;
|
| 55 | import net.minecraft.world.level.ClipContext;
|
| 56 | import net.minecraft.world.level.block.Blocks;
|
| 57 | import net.minecraft.world.phys.AABB;
|
| 58 | import net.minecraft.world.phys.BlockHitResult;
|
| 59 | import net.minecraft.world.phys.HitResult;
|
| 60 | import net.minecraft.world.phys.Vec3;
|
| 61 | import org.joml.Vector3d;
|
| 62 |
|
| 63 | import java.util.ArrayList;
|
| 64 | import java.util.List;
|
| 65 | import java.util.Set;
|
| 66 | import java.util.concurrent.atomic.AtomicBoolean;
|
| 67 | import java.util.concurrent.atomic.AtomicReference;
|
| 68 |
|
| 69 | public class CrystalAura extends Module {
|
| 70 | private final SettingGroup sgGeneral = settings.getDefaultGroup();
|
| 71 | private final SettingGroup sgSwitch = settings.createGroup("Switch");
|
| 72 | private final SettingGroup sgPlace = settings.createGroup("Place");
|
| 73 | private final SettingGroup sgFacePlace = settings.createGroup("Face Place");
|
| 74 | private final SettingGroup sgBreak = settings.createGroup("Break");
|
| 75 | private final SettingGroup sgPause = settings.createGroup("Pause");
|
| 76 | private final SettingGroup sgRender = settings.createGroup("Render");
|
| 77 |
|
| 78 | // General
|
| 79 |
|
| 80 | private final Setting<Double> targetRange = sgGeneral.add(new DoubleSetting.Builder()
|
| 81 | .name("target-range")
|
| 82 | .description("Range in which to target players.")
|
| 83 | .defaultValue(10)
|
| 84 | .min(0)
|
| 85 | .sliderMax(16)
|
| 86 | .build()
|
| 87 | );
|
| 88 |
|
| 89 | private final Setting<Boolean> predictMovement = sgGeneral.add(new BoolSetting.Builder()
|
| 90 | .name("predict-movement")
|
| 91 | .description("Predicts target movement.")
|
| 92 | .defaultValue(false)
|
| 93 | .build()
|
| 94 | );
|
| 95 |
|
| 96 | private final Setting<Double> minDamage = sgGeneral.add(new DoubleSetting.Builder()
|
| 97 | .name("min-damage")
|
| 98 | .description("Minimum damage the crystal needs to deal to your target.")
|
| 99 | .defaultValue(6)
|
| 100 | .min(0)
|
| 101 | .build()
|
| 102 | );
|
| 103 |
|
| 104 | private final Setting<Double> maxDamage = sgGeneral.add(new DoubleSetting.Builder()
|
| 105 | .name("max-damage")
|
| 106 | .description("Maximum damage crystals can deal to yourself.")
|
| 107 | .defaultValue(6)
|
| 108 | .range(0, 36)
|
| 109 | .sliderMax(36)
|
| 110 | .build()
|
| 111 | );
|
| 112 |
|
| 113 | private final Setting<Boolean> antiSuicide = sgGeneral.add(new BoolSetting.Builder()
|
| 114 | .name("anti-suicide")
|
| 115 | .description("Will not place and break crystals if they will kill you.")
|
| 116 | .defaultValue(true)
|
| 117 | .build()
|
| 118 | );
|
| 119 |
|
| 120 | private final Setting<Boolean> ignoreNakeds = sgGeneral.add(new BoolSetting.Builder()
|
| 121 | .name("ignore-nakeds")
|
| 122 | .description("Ignore players with no items.")
|
| 123 | .defaultValue(false)
|
| 124 | .build()
|
| 125 | );
|
| 126 |
|
| 127 | private final Setting<Boolean> rotate = sgGeneral.add(new BoolSetting.Builder()
|
| 128 | .name("rotate")
|
| 129 | .description("Rotates server-side towards the crystals being hit/placed.")
|
| 130 | .defaultValue(true)
|
| 131 | .build()
|
| 132 | );
|
| 133 |
|
| 134 | private final Setting<YawStepMode> yawStepMode = sgGeneral.add(new EnumSetting.Builder<YawStepMode>()
|
| 135 | .name("yaw-steps-mode")
|
| 136 | .description("When to run the yaw steps check.")
|
| 137 | .defaultValue(YawStepMode.Break)
|
| 138 | .visible(rotate::get)
|
| 139 | .build()
|
| 140 | );
|
| 141 |
|
| 142 | private final Setting<Double> yawSteps = sgGeneral.add(new DoubleSetting.Builder()
|
| 143 | .name("yaw-steps")
|
| 144 | .description("Maximum number of degrees its allowed to rotate in one tick.")
|
| 145 | .defaultValue(180)
|
| 146 | .range(1, 180)
|
| 147 | .visible(rotate::get)
|
| 148 | .build()
|
| 149 | );
|
| 150 |
|
| 151 | private final Setting<Set<EntityType<?>>> entities = sgGeneral.add(new EntityTypeListSetting.Builder()
|
| 152 | .name("entities")
|
| 153 | .description("Entities to attack.")
|
| 154 | .onlyAttackable()
|
| 155 | .defaultValue(EntityTypes.PLAYER, EntityTypes.WARDEN, EntityTypes.WITHER)
|
| 156 | .build()
|
| 157 | );
|
| 158 |
|
| 159 | // Switch
|
| 160 |
|
| 161 | private final Setting<AutoSwitchMode> autoSwitch = sgSwitch.add(new EnumSetting.Builder<AutoSwitchMode>()
|
| 162 | .name("auto-switch")
|
| 163 | .description("Switches to crystals in your hotbar once a target is found.")
|
| 164 | .defaultValue(AutoSwitchMode.Normal)
|
| 165 | .build()
|
| 166 | );
|
| 167 |
|
| 168 | private final Setting<Integer> switchDelay = sgSwitch.add(new IntSetting.Builder()
|
| 169 | .name("switch-delay")
|
| 170 | .description("The delay in ticks to wait to break a crystal after switching hotbar slot.")
|
| 171 | .defaultValue(0)
|
| 172 | .min(0)
|
| 173 | .build()
|
| 174 | );
|
| 175 |
|
| 176 | private final Setting<Boolean> noGapSwitch = sgSwitch.add(new BoolSetting.Builder()
|
| 177 | .name("no-gap-switch")
|
| 178 | .description("Won't auto switch if you're holding a gapple.")
|
| 179 | .defaultValue(true)
|
| 180 | .visible(() -> autoSwitch.get() == AutoSwitchMode.Normal)
|
| 181 | .build()
|
| 182 | );
|
| 183 |
|
| 184 | private final Setting<Boolean> noBowSwitch = sgSwitch.add(new BoolSetting.Builder()
|
| 185 | .name("no-bow-switch")
|
| 186 | .description("Won't auto switch if you're holding a bow.")
|
| 187 | .defaultValue(true)
|
| 188 | .build()
|
| 189 | );
|
| 190 |
|
| 191 | private final Setting<Boolean> antiWeakness = sgSwitch.add(new BoolSetting.Builder()
|
| 192 | .name("anti-weakness")
|
| 193 | .description("Switches to tools with so you can break crystals with the weakness effect.")
|
| 194 | .defaultValue(true)
|
| 195 | .build()
|
| 196 | );
|
| 197 |
|
| 198 | // Place
|
| 199 |
|
| 200 | private final Setting<Boolean> doPlace = sgPlace.add(new BoolSetting.Builder()
|
| 201 | .name("place")
|
| 202 | .description("If the CA should place crystals.")
|
| 203 | .defaultValue(true)
|
| 204 | .build()
|
| 205 | );
|
| 206 |
|
| 207 | public final Setting<Integer> placeDelay = sgPlace.add(new IntSetting.Builder()
|
| 208 | .name("place-delay")
|
| 209 | .description("The delay in ticks to wait to place a crystal after it's exploded.")
|
| 210 | .defaultValue(0)
|
| 211 | .min(0)
|
| 212 | .sliderMax(20)
|
| 213 | .build()
|
| 214 | );
|
| 215 |
|
| 216 | private final Setting<Double> placeRange = sgPlace.add(new DoubleSetting.Builder()
|
| 217 | .name("place-range")
|
| 218 | .description("Range in which to place crystals.")
|
| 219 | .defaultValue(4.5)
|
| 220 | .min(0)
|
| 221 | .sliderMax(6)
|
| 222 | .build()
|
| 223 | );
|
| 224 |
|
| 225 | private final Setting<Double> placeWallsRange = sgPlace.add(new DoubleSetting.Builder()
|
| 226 | .name("walls-range")
|
| 227 | .description("Range in which to place crystals when behind blocks.")
|
| 228 | .defaultValue(4.5)
|
| 229 | .min(0)
|
| 230 | .sliderMax(6)
|
| 231 | .build()
|
| 232 | );
|
| 233 |
|
| 234 | private final Setting<Boolean> placement112 = sgPlace.add(new BoolSetting.Builder()
|
| 235 | .name("1.12-placement")
|
| 236 | .description("Uses 1.12 crystal placement.")
|
| 237 | .defaultValue(false)
|
| 238 | .build()
|
| 239 | );
|
| 240 |
|
| 241 | private final Setting<SupportMode> support = sgPlace.add(new EnumSetting.Builder<SupportMode>()
|
| 242 | .name("support")
|
| 243 | .description("Places a support block in air if no other position have been found.")
|
| 244 | .defaultValue(SupportMode.Disabled)
|
| 245 | .build()
|
| 246 | );
|
| 247 |
|
| 248 | private final Setting<Integer> supportDelay = sgPlace.add(new IntSetting.Builder()
|
| 249 | .name("support-delay")
|
| 250 | .description("Delay in ticks after placing support block.")
|
| 251 | .defaultValue(1)
|
| 252 | .min(0)
|
| 253 | .visible(() -> support.get() != SupportMode.Disabled)
|
| 254 | .build()
|
| 255 | );
|
| 256 |
|
| 257 | // Face place
|
| 258 |
|
| 259 | private final Setting<Boolean> facePlace = sgFacePlace.add(new BoolSetting.Builder()
|
| 260 | .name("face-place")
|
| 261 | .description("Will face-place when target is below a certain health or armor durability threshold.")
|
| 262 | .defaultValue(true)
|
| 263 | .build()
|
| 264 | );
|
| 265 |
|
| 266 | private final Setting<Double> facePlaceHealth = sgFacePlace.add(new DoubleSetting.Builder()
|
| 267 | .name("face-place-health")
|
| 268 | .description("The health the target has to be at to start face placing.")
|
| 269 | .defaultValue(8)
|
| 270 | .min(1)
|
| 271 | .sliderMin(1)
|
| 272 | .sliderMax(36)
|
| 273 | .visible(facePlace::get)
|
| 274 | .build()
|
| 275 | );
|
| 276 |
|
| 277 | private final Setting<Double> facePlaceDurability = sgFacePlace.add(new DoubleSetting.Builder()
|
| 278 | .name("face-place-durability")
|
| 279 | .description("The durability threshold percentage to be able to face-place.")
|
| 280 | .defaultValue(2)
|
| 281 | .min(1)
|
| 282 | .sliderMin(1)
|
| 283 | .sliderMax(100)
|
| 284 | .visible(facePlace::get)
|
| 285 | .build()
|
| 286 | );
|
| 287 |
|
| 288 | private final Setting<Boolean> facePlaceArmor = sgFacePlace.add(new BoolSetting.Builder()
|
| 289 | .name("face-place-missing-armor")
|
| 290 | .description("Automatically starts face placing when a target misses a piece of armor.")
|
| 291 | .defaultValue(false)
|
| 292 | .visible(facePlace::get)
|
| 293 | .build()
|
| 294 | );
|
| 295 |
|
| 296 | private final Setting<Keybind> forceFacePlace = sgFacePlace.add(new KeybindSetting.Builder()
|
| 297 | .name("force-face-place")
|
| 298 | .description("Starts face place when this button is pressed.")
|
| 299 | .defaultValue(Keybind.none())
|
| 300 | .build()
|
| 301 | );
|
| 302 |
|
| 303 | // Break
|
| 304 |
|
| 305 | private final Setting<Boolean> doBreak = sgBreak.add(new BoolSetting.Builder()
|
| 306 | .name("break")
|
| 307 | .description("If the CA should break crystals.")
|
| 308 | .defaultValue(true)
|
| 309 | .build()
|
| 310 | );
|
| 311 |
|
| 312 | private final Setting<Integer> breakDelay = sgBreak.add(new IntSetting.Builder()
|
| 313 | .name("break-delay")
|
| 314 | .description("The delay in ticks to wait to break a crystal after it's placed.")
|
| 315 | .defaultValue(0)
|
| 316 | .min(0)
|
| 317 | .sliderMax(20)
|
| 318 | .build()
|
| 319 | );
|
| 320 |
|
| 321 | private final Setting<Boolean> smartDelay = sgBreak.add(new BoolSetting.Builder()
|
| 322 | .name("smart-delay")
|
| 323 | .description("Only breaks crystals when the target can receive damage.")
|
| 324 | .defaultValue(false)
|
| 325 | .build()
|
| 326 | );
|
| 327 |
|
| 328 | private final Setting<Double> breakRange = sgBreak.add(new DoubleSetting.Builder()
|
| 329 | .name("break-range")
|
| 330 | .description("Range in which to break crystals.")
|
| 331 | .defaultValue(4.5)
|
| 332 | .min(0)
|
| 333 | .sliderMax(6)
|
| 334 | .build()
|
| 335 | );
|
| 336 |
|
| 337 | private final Setting<Double> breakWallsRange = sgBreak.add(new DoubleSetting.Builder()
|
| 338 | .name("walls-range")
|
| 339 | .description("Range in which to break crystals when behind blocks.")
|
| 340 | .defaultValue(4.5)
|
| 341 | .min(0)
|
| 342 | .sliderMax(6)
|
| 343 | .build()
|
| 344 | );
|
| 345 |
|
| 346 | private final Setting<Boolean> onlyBreakOwn = sgBreak.add(new BoolSetting.Builder()
|
| 347 | .name("only-own")
|
| 348 | .description("Only breaks own crystals.")
|
| 349 | .defaultValue(false)
|
| 350 | .build()
|
| 351 | );
|
| 352 |
|
| 353 | private final Setting<Integer> breakAttempts = sgBreak.add(new IntSetting.Builder()
|
| 354 | .name("break-attempts")
|
| 355 | .description("How many times to hit a crystal before stopping to target it.")
|
| 356 | .defaultValue(2)
|
| 357 | .sliderMin(1)
|
| 358 | .sliderMax(5)
|
| 359 | .build()
|
| 360 | );
|
| 361 |
|
| 362 | private final Setting<Integer> ticksExisted = sgBreak.add(new IntSetting.Builder()
|
| 363 | .name("ticks-existed")
|
| 364 | .description("Amount of ticks a crystal needs to have lived for it to be attacked by CrystalAura.")
|
| 365 | .defaultValue(0)
|
| 366 | .min(0)
|
| 367 | .build()
|
| 368 | );
|
| 369 |
|
| 370 | private final Setting<Integer> attackFrequency = sgBreak.add(new IntSetting.Builder()
|
| 371 | .name("attack-frequency")
|
| 372 | .description("Maximum hits to do per second.")
|
| 373 | .defaultValue(25)
|
| 374 | .min(1)
|
| 375 | .sliderRange(1, 30)
|
| 376 | .build()
|
| 377 | );
|
| 378 |
|
| 379 | private final Setting<Boolean> fastBreak = sgBreak.add(new BoolSetting.Builder()
|
| 380 | .name("fast-break")
|
| 381 | .description("Ignores break delay and tries to break the crystal as soon as it's spawned in the world.")
|
| 382 | .defaultValue(true)
|
| 383 | .build()
|
| 384 | );
|
| 385 |
|
| 386 | // Pause
|
| 387 |
|
| 388 | public final Setting<PauseMode> pauseOnUse = sgPause.add(new EnumSetting.Builder<PauseMode>()
|
| 389 | .name("pause-on-use")
|
| 390 | .description("Which processes should be paused while using an item.")
|
| 391 | .defaultValue(PauseMode.Place)
|
| 392 | .build()
|
| 393 | );
|
| 394 |
|
| 395 | public final Setting<PauseMode> pauseOnMine = sgPause.add(new EnumSetting.Builder<PauseMode>()
|
| 396 | .name("pause-on-mine")
|
| 397 | .description("Which processes should be paused while mining a block.")
|
| 398 | .defaultValue(PauseMode.None)
|
| 399 | .build()
|
| 400 | );
|
| 401 |
|
| 402 | private final Setting<Boolean> pauseOnLag = sgPause.add(new BoolSetting.Builder()
|
| 403 | .name("pause-on-lag")
|
| 404 | .description("Whether to pause if the server is not responding.")
|
| 405 | .defaultValue(true)
|
| 406 | .build()
|
| 407 | );
|
| 408 |
|
| 409 | public final Setting<List<Module>> pauseModules = sgPause.add(new ModuleListSetting.Builder()
|
| 410 | .name("pause-modules")
|
| 411 | .description("Pauses while any of the selected modules are active.")
|
| 412 | .defaultValue(BedAura.class)
|
| 413 | .build()
|
| 414 | );
|
| 415 |
|
| 416 | public final Setting<Double> pauseHealth = sgPause.add(new DoubleSetting.Builder()
|
| 417 | .name("pause-health")
|
| 418 | .description("Pauses when you go below a certain health.")
|
| 419 | .defaultValue(5)
|
| 420 | .range(0, 36)
|
| 421 | .sliderRange(0, 36)
|
| 422 | .build()
|
| 423 | );
|
| 424 |
|
| 425 | // Render
|
| 426 |
|
| 427 | public final Setting<SwingMode> swingMode = sgRender.add(new EnumSetting.Builder<SwingMode>()
|
| 428 | .name("swing-mode")
|
| 429 | .description("How to swing when placing.")
|
| 430 | .defaultValue(SwingMode.Both)
|
| 431 | .build()
|
| 432 | );
|
| 433 |
|
| 434 | private final Setting<RenderMode> renderMode = sgRender.add(new EnumSetting.Builder<RenderMode>()
|
| 435 | .name("render-mode")
|
| 436 | .description("The mode to render in.")
|
| 437 | .defaultValue(RenderMode.Normal)
|
| 438 | .build()
|
| 439 | );
|
| 440 |
|
| 441 | private final Setting<Boolean> renderPlace = sgRender.add(new BoolSetting.Builder()
|
| 442 | .name("render-place")
|
| 443 | .description("Renders a block overlay over the block the crystals are being placed on.")
|
| 444 | .defaultValue(true)
|
| 445 | .visible(() -> renderMode.get() == RenderMode.Normal)
|
| 446 | .build()
|
| 447 | );
|
| 448 |
|
| 449 | private final Setting<Integer> placeRenderTime = sgRender.add(new IntSetting.Builder()
|
| 450 | .name("place-time")
|
| 451 | .description("How long to render placements.")
|
| 452 | .defaultValue(10)
|
| 453 | .min(0)
|
| 454 | .sliderMax(20)
|
| 455 | .visible(() -> renderMode.get() == RenderMode.Normal && renderPlace.get())
|
| 456 | .build()
|
| 457 | );
|
| 458 |
|
| 459 | private final Setting<Boolean> renderBreak = sgRender.add(new BoolSetting.Builder()
|
| 460 | .name("render-break")
|
| 461 | .description("Renders a block overlay over the block the crystals are broken on.")
|
| 462 | .defaultValue(false)
|
| 463 | .visible(() -> renderMode.get() == RenderMode.Normal)
|
| 464 | .build()
|
| 465 | );
|
| 466 |
|
| 467 | private final Setting<Integer> breakRenderTime = sgRender.add(new IntSetting.Builder()
|
| 468 | .name("break-time")
|
| 469 | .description("How long to render breaking for.")
|
| 470 | .defaultValue(13)
|
| 471 | .min(0)
|
| 472 | .sliderMax(20)
|
| 473 | .visible(() -> renderMode.get() == RenderMode.Normal && renderBreak.get())
|
| 474 | .build()
|
| 475 | );
|
| 476 |
|
| 477 | private final Setting<Integer> smoothness = sgRender.add(new IntSetting.Builder()
|
| 478 | .name("smoothness")
|
| 479 | .description("How smoothly the render should move around.")
|
| 480 | .defaultValue(10)
|
| 481 | .min(0)
|
| 482 | .sliderMax(20)
|
| 483 | .visible(() -> renderMode.get() == RenderMode.Smooth)
|
| 484 | .build()
|
| 485 | );
|
| 486 |
|
| 487 | private final Setting<Double> height = sgRender.add(new DoubleSetting.Builder()
|
| 488 | .name("height")
|
| 489 | .description("How tall the gradient should be.")
|
| 490 | .defaultValue(0.7)
|
| 491 | .min(0)
|
| 492 | .sliderMax(1)
|
| 493 | .visible(() -> renderMode.get() == RenderMode.Gradient)
|
| 494 | .build()
|
| 495 | );
|
| 496 |
|
| 497 | private final Setting<Integer> renderTime = sgRender.add(new IntSetting.Builder()
|
| 498 | .name("render-time")
|
| 499 | .description("How long to render placements.")
|
| 500 | .defaultValue(10)
|
| 501 | .min(0)
|
| 502 | .sliderMax(20)
|
| 503 | .visible(() -> renderMode.get() == RenderMode.Smooth || renderMode.get() == RenderMode.Fading)
|
| 504 | .build()
|
| 505 | );
|
| 506 |
|
| 507 | private final Setting<ShapeMode> shapeMode = sgRender.add(new EnumSetting.Builder<ShapeMode>()
|
| 508 | .name("shape-mode")
|
| 509 | .description("How the shapes are rendered.")
|
| 510 | .defaultValue(ShapeMode.Both)
|
| 511 | .visible(() -> renderMode.get() != RenderMode.None)
|
| 512 | .build()
|
| 513 | );
|
| 514 |
|
| 515 | private final Setting<SettingColor> sideColor = sgRender.add(new ColorSetting.Builder()
|
| 516 | .name("side-color")
|
| 517 | .description("The side color of the block overlay.")
|
| 518 | .defaultValue(new SettingColor(255, 255, 255, 45))
|
| 519 | .visible(() -> shapeMode.get().sides() && renderMode.get() != RenderMode.None)
|
| 520 | .build()
|
| 521 | );
|
| 522 |
|
| 523 | private final Setting<SettingColor> lineColor = sgRender.add(new ColorSetting.Builder()
|
| 524 | .name("line-color")
|
| 525 | .description("The line color of the block overlay.")
|
| 526 | .defaultValue(new SettingColor(255, 255, 255))
|
| 527 | .visible(() -> shapeMode.get().lines() && renderMode.get() != RenderMode.None)
|
| 528 | .build()
|
| 529 | );
|
| 530 |
|
| 531 | private final Setting<Boolean> renderDamageText = sgRender.add(new BoolSetting.Builder()
|
| 532 | .name("damage")
|
| 533 | .description("Renders crystal damage text in the block overlay.")
|
| 534 | .defaultValue(true)
|
| 535 | .visible(() -> renderMode.get() != RenderMode.None)
|
| 536 | .build()
|
| 537 | );
|
| 538 |
|
| 539 | private final Setting<SettingColor> damageColor = sgRender.add(new ColorSetting.Builder()
|
| 540 | .name("damage-color")
|
| 541 | .description("The color of the damage text.")
|
| 542 | .defaultValue(new SettingColor(255, 255, 255))
|
| 543 | .visible(() -> renderMode.get() != RenderMode.None && renderDamageText.get())
|
| 544 | .build()
|
| 545 | );
|
| 546 |
|
| 547 | private final Setting<Double> damageTextScale = sgRender.add(new DoubleSetting.Builder()
|
| 548 | .name("damage-scale")
|
| 549 | .description("How big the damage text should be.")
|
| 550 | .defaultValue(1.25)
|
| 551 | .min(1)
|
| 552 | .sliderMax(4)
|
| 553 | .visible(() -> renderMode.get() != RenderMode.None && renderDamageText.get())
|
| 554 | .build()
|
| 555 | );
|
| 556 |
|
| 557 | // Fields
|
| 558 |
|
| 559 | private Item mainItem, offItem;
|
| 560 |
|
| 561 | private int breakTimer, placeTimer, switchTimer, ticksPassed;
|
| 562 | private final List<LivingEntity> targets = new ArrayList<>();
|
| 563 |
|
| 564 | private final Vec3 vec3d = new Vec3(0, 0, 0);
|
| 565 | private final Vec3 playerEyePos = new Vec3(0, 0, 0);
|
| 566 | private final Vector3d vec3 = new Vector3d();
|
| 567 | private final BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos();
|
| 568 | private final AABB box = new AABB(0, 0, 0, 0, 0, 0);
|
| 569 |
|
| 570 | private final Vec3 vec3dRayTraceEnd = new Vec3(0, 0, 0);
|
| 571 | private ClipContext clipContext;
|
| 572 |
|
| 573 | private final IntSet placedCrystals = new IntOpenHashSet();
|
| 574 | private boolean placing;
|
| 575 | private int placingTimer;
|
| 576 | public int kaTimer;
|
| 577 | private final BlockPos.MutableBlockPos placingCrystalBlockPos = new BlockPos.MutableBlockPos();
|
| 578 |
|
| 579 | private final IntSet removed = new IntOpenHashSet();
|
| 580 | private final Int2IntMap attemptedBreaks = new Int2IntOpenHashMap();
|
| 581 | private final Int2IntMap waitingToExplode = new Int2IntOpenHashMap();
|
| 582 | private int attacks;
|
| 583 |
|
| 584 | private double serverYaw;
|
| 585 |
|
| 586 | private LivingEntity bestTarget;
|
| 587 | private double bestTargetDamage;
|
| 588 | private int bestTargetTimer;
|
| 589 |
|
| 590 | private boolean didRotateThisTick;
|
| 591 | private boolean isLastRotationPos;
|
| 592 | private final Vec3 lastRotationPos = new Vec3(0, 0, 0);
|
| 593 | private double lastYaw, lastPitch;
|
| 594 | private int lastRotationTimer;
|
| 595 |
|
| 596 | private int placeRenderTimer, breakRenderTimer;
|
| 597 | private final BlockPos.MutableBlockPos placeRenderPos = new BlockPos.MutableBlockPos();
|
| 598 | private final BlockPos.MutableBlockPos breakRenderPos = new BlockPos.MutableBlockPos();
|
| 599 | private AABB renderBoxOne, renderBoxTwo;
|
| 600 |
|
| 601 | private double renderDamage;
|
| 602 |
|
| 603 | public CrystalAura() {
|
| 604 | super(Categories.Combat, "crystal-aura", "Automatically places and attacks crystals.");
|
| 605 | }
|
| 606 |
|
| 607 | @Override
|
| 608 | public void onActivate() {
|
| 609 | breakTimer = 0;
|
| 610 | placeTimer = 0;
|
| 611 | ticksPassed = 0;
|
| 612 |
|
| 613 | clipContext = new ClipContext(new Vec3(0, 0, 0), new Vec3(0, 0, 0), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player);
|
| 614 |
|
| 615 | placing = false;
|
| 616 | placingTimer = 0;
|
| 617 | kaTimer = 0;
|
| 618 |
|
| 619 | attacks = 0;
|
| 620 |
|
| 621 | serverYaw = mc.player.getYRot();
|
| 622 |
|
| 623 | bestTargetDamage = 0;
|
| 624 | bestTargetTimer = 0;
|
| 625 |
|
| 626 | lastRotationTimer = getLastRotationStopDelay();
|
| 627 |
|
| 628 | placeRenderTimer = 0;
|
| 629 | breakRenderTimer = 0;
|
| 630 | }
|
| 631 |
|
| 632 | @Override
|
| 633 | public void onDeactivate() {
|
| 634 | targets.clear();
|
| 635 |
|
| 636 | placedCrystals.clear();
|
| 637 |
|
| 638 | attemptedBreaks.clear();
|
| 639 | waitingToExplode.clear();
|
| 640 |
|
| 641 | removed.clear();
|
| 642 |
|
| 643 | bestTarget = null;
|
| 644 | }
|
| 645 |
|
| 646 | private int getLastRotationStopDelay() {
|
| 647 | return Math.max(10, placeDelay.get() / 2 + breakDelay.get() / 2 + 10);
|
| 648 | }
|
| 649 |
|
| 650 | @EventHandler(priority = EventPriority.HIGH)
|
| 651 | private void onPreTick(TickEvent.Pre event) {
|
| 652 | // Update last rotation
|
| 653 | didRotateThisTick = false;
|
| 654 | lastRotationTimer++;
|
| 655 |
|
| 656 | // Decrement placing timer
|
| 657 | if (placing) {
|
| 658 | if (placingTimer > 0) placingTimer--;
|
| 659 | else placing = false;
|
| 660 | }
|
| 661 |
|
| 662 | if (kaTimer > 0) kaTimer--;
|
| 663 |
|
| 664 | if (ticksPassed < 20) ticksPassed++;
|
| 665 | else {
|
| 666 | ticksPassed = 0;
|
| 667 | attacks = 0;
|
| 668 | }
|
| 669 |
|
| 670 | // Decrement best target timer
|
| 671 | if (bestTargetTimer > 0) bestTargetTimer--;
|
| 672 | bestTargetDamage = 0;
|
| 673 |
|
| 674 | // Decrement break, place and switch timers
|
| 675 | if (breakTimer > 0) breakTimer--;
|
| 676 | if (placeTimer > 0) placeTimer--;
|
| 677 | if (switchTimer > 0) switchTimer--;
|
| 678 |
|
| 679 | // Decrement render timers
|
| 680 | if (placeRenderTimer > 0) placeRenderTimer--;
|
| 681 | if (breakRenderTimer > 0) breakRenderTimer--;
|
| 682 |
|
| 683 | mainItem = mc.player.getMainHandItem().getItem();
|
| 684 | offItem = mc.player.getOffhandItem().getItem();
|
| 685 |
|
| 686 | // Update waiting to explode crystals and mark them as existing if reached threshold
|
| 687 | for (IntIterator it = waitingToExplode.keySet().iterator(); it.hasNext(); ) {
|
| 688 | int id = it.nextInt();
|
| 689 | int ticks = waitingToExplode.get(id);
|
| 690 |
|
| 691 | if (ticks > 3) {
|
| 692 | it.remove();
|
| 693 | removed.remove(id);
|
| 694 | } else {
|
| 695 | waitingToExplode.put(id, ticks + 1);
|
| 696 | }
|
| 697 | }
|
| 698 |
|
| 699 | // Set player eye pos
|
| 700 | ((IVec3) playerEyePos).meteor$set(mc.player.position().x, mc.player.position().y + mc.player.getEyeHeight(mc.player.getPose()), mc.player.position().z);
|
| 701 |
|
| 702 | // Find targets, break and place
|
| 703 | findTargets();
|
| 704 |
|
| 705 | if (!targets.isEmpty()) {
|
| 706 | if (!didRotateThisTick) doBreak();
|
| 707 | if (!didRotateThisTick) doPlace();
|
| 708 | }
|
| 709 | }
|
| 710 |
|
| 711 | @EventHandler(priority = EventPriority.LOWEST - 666)
|
| 712 | private void onPreTickLast(TickEvent.Pre event) {
|
| 713 | // Rotate to last rotation
|
| 714 | if (rotate.get() && lastRotationTimer < getLastRotationStopDelay() && !didRotateThisTick) {
|
| 715 | Rotations.rotate(isLastRotationPos ? Rotations.getYaw(lastRotationPos) : lastYaw, isLastRotationPos ? Rotations.getPitch(lastRotationPos) : lastPitch, -100, null);
|
| 716 | }
|
| 717 | }
|
| 718 |
|
| 719 | @EventHandler
|
| 720 | private void onEntityAdded(EntityAddedEvent event) {
|
| 721 | if (!(event.entity instanceof EndCrystal)) return;
|
| 722 |
|
| 723 | if (placing && event.entity.blockPosition().equals(placingCrystalBlockPos)) {
|
| 724 | placing = false;
|
| 725 | placingTimer = 0;
|
| 726 | placedCrystals.add(event.entity.getId());
|
| 727 | }
|
| 728 |
|
| 729 | if (fastBreak.get() && !didRotateThisTick && attacks < attackFrequency.get()) {
|
| 730 | float damage = getBreakDamage(event.entity, true);
|
| 731 | if (damage > minDamage.get()) doBreak(event.entity);
|
| 732 | }
|
| 733 | }
|
| 734 |
|
| 735 | @EventHandler
|
| 736 | private void onEntityRemoved(EntityRemovedEvent event) {
|
| 737 | if (event.entity instanceof EndCrystal) {
|
| 738 | placedCrystals.remove(event.entity.getId());
|
| 739 | removed.remove(event.entity.getId());
|
| 740 | waitingToExplode.remove(event.entity.getId());
|
| 741 | }
|
| 742 | }
|
| 743 |
|
| 744 | private void setRotation(boolean isPos, Vec3 pos, double yaw, double pitch) {
|
| 745 | didRotateThisTick = true;
|
| 746 | isLastRotationPos = isPos;
|
| 747 |
|
| 748 | if (isPos) ((IVec3) lastRotationPos).meteor$set(pos.x, pos.y, pos.z);
|
| 749 | else {
|
| 750 | lastYaw = yaw;
|
| 751 | lastPitch = pitch;
|
| 752 | }
|
| 753 |
|
| 754 | lastRotationTimer = 0;
|
| 755 | }
|
| 756 |
|
| 757 | // Break
|
| 758 |
|
| 759 | private void doBreak() {
|
| 760 | if (!doBreak.get() || breakTimer > 0 || switchTimer > 0 || attacks >= attackFrequency.get()) return;
|
| 761 | if (shouldPause(PauseMode.Break)) return;
|
| 762 |
|
| 763 | float bestDamage = 0;
|
| 764 | Entity crystal = null;
|
| 765 |
|
| 766 | // Find best crystal to break
|
| 767 | for (Entity entity : mc.level.entitiesForRendering()) {
|
| 768 | float damage = getBreakDamage(entity, true);
|
| 769 |
|
| 770 | if (damage > bestDamage) {
|
| 771 | bestDamage = damage;
|
| 772 | crystal = entity;
|
| 773 | }
|
| 774 | }
|
| 775 |
|
| 776 | // Break the crystal
|
| 777 | if (crystal != null) doBreak(crystal);
|
| 778 | }
|
| 779 |
|
| 780 | private float getBreakDamage(Entity entity, boolean checkCrystalAge) {
|
| 781 | if (!(entity instanceof EndCrystal)) return 0;
|
| 782 |
|
| 783 | // Check only break own
|
| 784 | if (onlyBreakOwn.get() && !placedCrystals.contains(entity.getId())) return 0;
|
| 785 |
|
| 786 | // Check if it should already be removed
|
| 787 | if (removed.contains(entity.getId())) return 0;
|
| 788 |
|
| 789 | // Check attempted breaks
|
| 790 | if (attemptedBreaks.get(entity.getId()) > breakAttempts.get()) return 0;
|
| 791 |
|
| 792 | // Check crystal age
|
| 793 | if (checkCrystalAge && entity.tickCount < ticksExisted.get()) return 0;
|
| 794 |
|
| 795 | // Check range
|
| 796 | if (isOutOfRange(entity.position(), entity.blockPosition(), false)) return 0;
|
| 797 |
|
| 798 | // Check damage to self and anti suicide
|
| 799 | blockPos.set(entity.blockPosition()).move(0, -1, 0);
|
| 800 | float selfDamage = DamageUtils.crystalDamage(mc.player, entity.position(), predictMovement.get(), blockPos);
|
| 801 | if (selfDamage > maxDamage.get() || (antiSuicide.get() && selfDamage >= EntityUtils.getTotalHealth(mc.player)))
|
| 802 | return 0;
|
| 803 |
|
| 804 | // Check damage to targets and face place
|
| 805 | float damage = getDamageToTargets(entity.position(), blockPos, true, false);
|
| 806 | boolean shouldFacePlace = shouldFacePlace();
|
| 807 | double minimumDamage = shouldFacePlace ? Math.min(minDamage.get(), 1.5d) : minDamage.get();
|
| 808 |
|
| 809 | if (damage < minimumDamage) return 0f;
|
| 810 |
|
| 811 | return damage;
|
| 812 | }
|
| 813 |
|
| 814 | private void doBreak(Entity crystal) {
|
| 815 | // Anti weakness
|
| 816 | if (antiWeakness.get()) {
|
| 817 | MobEffectInstance weakness = mc.player.getEffect(MobEffects.WEAKNESS);
|
| 818 | MobEffectInstance strength = mc.player.getEffect(MobEffects.STRENGTH);
|
| 819 |
|
| 820 | // Check for strength
|
| 821 | if (weakness != null && (strength == null || strength.getAmplifier() <= weakness.getAmplifier())) {
|
| 822 | // Check if the item in your hand is already valid
|
| 823 | if (!isValidWeaknessItem(mc.player.getMainHandItem(), crystal)) {
|
| 824 | // Find valid item to break with
|
| 825 | if (!InvUtils.swap(InvUtils.findInHotbar(stack -> isValidWeaknessItem(stack, crystal)).slot(), false))
|
| 826 | return;
|
| 827 |
|
| 828 | switchTimer = 1;
|
| 829 | return;
|
| 830 | }
|
| 831 | }
|
| 832 | }
|
| 833 |
|
| 834 | // Rotate and attack
|
| 835 | boolean attacked = true;
|
| 836 |
|
| 837 | if (rotate.get()) {
|
| 838 | double yaw = Rotations.getYaw(crystal);
|
| 839 | double pitch = Rotations.getPitch(crystal, Target.Feet);
|
| 840 |
|
| 841 | if (doYawSteps(yaw, pitch)) {
|
| 842 | setRotation(true, crystal.position(), 0, 0);
|
| 843 | Rotations.rotate(yaw, pitch, 50, () -> attackCrystal(crystal));
|
| 844 |
|
| 845 | breakTimer = breakDelay.get();
|
| 846 | } else {
|
| 847 | attacked = false;
|
| 848 | }
|
| 849 | } else {
|
| 850 | attackCrystal(crystal);
|
| 851 | breakTimer = breakDelay.get();
|
| 852 | }
|
| 853 |
|
| 854 | if (attacked) {
|
| 855 | // Update state
|
| 856 | removed.add(crystal.getId());
|
| 857 | attemptedBreaks.put(crystal.getId(), attemptedBreaks.get(crystal.getId()) + 1);
|
| 858 | waitingToExplode.put(crystal.getId(), 0);
|
| 859 |
|
| 860 | // Break render
|
| 861 | breakRenderPos.set(crystal.blockPosition().below());
|
| 862 | breakRenderTimer = breakRenderTime.get();
|
| 863 | }
|
| 864 | }
|
| 865 |
|
| 866 | private boolean isValidWeaknessItem(ItemStack itemStack, Entity crystal) {
|
| 867 | return DamageUtils.getAttackDamage(mc.player, crystal, itemStack) > 0;
|
| 868 | }
|
| 869 |
|
| 870 | private void attackCrystal(Entity entity) {
|
| 871 | // Attack
|
| 872 | mc.player.connection.send(new ServerboundAttackPacket(entity.getId()));
|
| 873 |
|
| 874 | InteractionHand hand = InvUtils.findInHotbar(Items.END_CRYSTAL).getHand();
|
| 875 | if (hand == null) hand = InteractionHand.MAIN_HAND;
|
| 876 |
|
| 877 | if (swingMode.get().client()) mc.player.swing(hand);
|
| 878 | if (swingMode.get().packet()) mc.getConnection().send(new ServerboundSwingPacket(hand));
|
| 879 |
|
| 880 | attacks++;
|
| 881 | }
|
| 882 |
|
| 883 | @EventHandler
|
| 884 | private void onPacketSend(PacketEvent.Send event) {
|
| 885 | if (event.packet instanceof ServerboundSetCarriedItemPacket) {
|
| 886 | switchTimer = switchDelay.get();
|
| 887 | }
|
| 888 | }
|
| 889 |
|
| 890 | // Place
|
| 891 |
|
| 892 | private void doPlace() {
|
| 893 | if (!doPlace.get() || placeTimer > 0) return;
|
| 894 | if (shouldPause(PauseMode.Place)) return;
|
| 895 |
|
| 896 | // Return if there are no crystals in hotbar or offhand
|
| 897 | if (!InvUtils.testInHotbar(Items.END_CRYSTAL)) return;
|
| 898 |
|
| 899 | // Return if there are no crystals in either hand and auto switch mode is none
|
| 900 | if (autoSwitch.get() != AutoSwitchMode.None) {
|
| 901 | if (noGapSwitch.get() && autoSwitch.get() == AutoSwitchMode.Normal && offItem != Items.END_CRYSTAL) {
|
| 902 | if (mainItem == Items.ENCHANTED_GOLDEN_APPLE
|
| 903 | || offItem == Items.ENCHANTED_GOLDEN_APPLE
|
| 904 | || mainItem == Items.GOLDEN_APPLE
|
| 905 | || offItem == Items.GOLDEN_APPLE) return;
|
| 906 | }
|
| 907 | if (noBowSwitch.get() && (mainItem == Items.BOW || offItem == Items.BOW)) return;
|
| 908 | } else if (mainItem != Items.END_CRYSTAL && offItem != Items.END_CRYSTAL) return;
|
| 909 |
|
| 910 | // Check for multiplace
|
| 911 | for (Entity entity : mc.level.entitiesForRendering()) {
|
| 912 | if (getBreakDamage(entity, false) > 0) return;
|
| 913 | }
|
| 914 |
|
| 915 | // Setup variables
|
| 916 | AtomicDouble bestDamage = new AtomicDouble(0);
|
| 917 | AtomicReference<BlockPos.MutableBlockPos> bestBlockPos = new AtomicReference<>(new BlockPos.MutableBlockPos());
|
| 918 | AtomicBoolean isSupport = new AtomicBoolean(support.get() != SupportMode.Disabled);
|
| 919 |
|
| 920 | // Find best position to place the crystal on
|
| 921 | BlockIterator.register((int) Math.ceil(placeRange.get()), (int) Math.ceil(placeRange.get()), (bp, blockState) -> {
|
| 922 | // Check if its bedrock or obsidian and return if isSupport is false
|
| 923 | boolean hasBlock = blockState.is(Blocks.BEDROCK) || blockState.is(Blocks.OBSIDIAN);
|
| 924 | if (!hasBlock && (!isSupport.get() || !blockState.canBeReplaced())) return;
|
| 925 |
|
| 926 | // Check if there is air on top
|
| 927 | blockPos.set(bp.getX(), bp.getY() + 1, bp.getZ());
|
| 928 | if (!mc.level.getBlockState(blockPos).isAir()) return;
|
| 929 |
|
| 930 | if (placement112.get()) {
|
| 931 | blockPos.move(0, 1, 0);
|
| 932 | if (!mc.level.getBlockState(blockPos).isAir()) return;
|
| 933 | }
|
| 934 |
|
| 935 | // Check range
|
| 936 | ((IVec3) vec3d).meteor$set(bp.getX() + 0.5, bp.getY() + 1, bp.getZ() + 0.5);
|
| 937 | blockPos.set(bp).move(0, 1, 0);
|
| 938 | if (isOutOfRange(vec3d, blockPos, true)) return;
|
| 939 |
|
| 940 | // Check damage to self and anti suicide
|
| 941 | float selfDamage = DamageUtils.crystalDamage(mc.player, vec3d, predictMovement.get(), bp);
|
| 942 | if (selfDamage > maxDamage.get() || (antiSuicide.get() && selfDamage >= EntityUtils.getTotalHealth(mc.player)))
|
| 943 | return;
|
| 944 |
|
| 945 | // Check damage to targets and face place
|
| 946 | float damage = getDamageToTargets(vec3d, bp, false, !hasBlock && support.get() == SupportMode.Fast);
|
| 947 |
|
| 948 | boolean shouldFacePlace = shouldFacePlace();
|
| 949 | double minimumDamage = Math.min(minDamage.get(), shouldFacePlace ? 1.5 : minDamage.get());
|
| 950 |
|
| 951 | if (damage < minimumDamage) return;
|
| 952 |
|
| 953 | // Check if it can be placed
|
| 954 | double x = bp.getX();
|
| 955 | double y = bp.getY() + 1;
|
| 956 | double z = bp.getZ();
|
| 957 | ((IAABB) box).meteor$set(x, y, z, x + 1, y + (placement112.get() ? 1 : 2), z + 1);
|
| 958 |
|
| 959 | if (intersectsWithEntities(box)) return;
|
| 960 |
|
| 961 | // Compare damage
|
| 962 | if (damage > bestDamage.get() || (isSupport.get() && hasBlock)) {
|
| 963 | bestDamage.set(damage);
|
| 964 | bestBlockPos.get().set(bp);
|
| 965 | }
|
| 966 |
|
| 967 | if (hasBlock) isSupport.set(false);
|
| 968 | });
|
| 969 |
|
| 970 | // Place the crystal
|
| 971 | BlockIterator.after(() -> {
|
| 972 | if (bestDamage.get() == 0) return;
|
| 973 |
|
| 974 | BlockHitResult result = getPlaceInfo(bestBlockPos.get());
|
| 975 |
|
| 976 | ((IVec3) vec3d).meteor$set(
|
| 977 | result.getBlockPos().getX() + 0.5 + result.getDirection().getUnitVec3i().getX() * 1.0 / 2.0,
|
| 978 | result.getBlockPos().getY() + 0.5 + result.getDirection().getUnitVec3i().getY() * 1.0 / 2.0,
|
| 979 | result.getBlockPos().getZ() + 0.5 + result.getDirection().getUnitVec3i().getZ() * 1.0 / 2.0
|
| 980 | );
|
| 981 |
|
| 982 | if (rotate.get()) {
|
| 983 | double yaw = Rotations.getYaw(vec3d);
|
| 984 | double pitch = Rotations.getPitch(vec3d);
|
| 985 |
|
| 986 | if (yawStepMode.get() == YawStepMode.Break || doYawSteps(yaw, pitch)) {
|
| 987 | setRotation(true, vec3d, 0, 0);
|
| 988 | Rotations.rotate(yaw, pitch, 50, () -> placeCrystal(result, bestDamage.get(), isSupport.get() ? bestBlockPos.get() : null));
|
| 989 |
|
| 990 | placeTimer += placeDelay.get();
|
| 991 | }
|
| 992 | } else {
|
| 993 | placeCrystal(result, bestDamage.get(), isSupport.get() ? bestBlockPos.get() : null);
|
| 994 | placeTimer += placeDelay.get();
|
| 995 | }
|
| 996 | });
|
| 997 | }
|
| 998 |
|
| 999 | private BlockHitResult getPlaceInfo(BlockPos blockPos) {
|
| 1000 | ((IVec3) vec3d).meteor$set(mc.player.getX(), mc.player.getY() + mc.player.getEyeHeight(mc.player.getPose()), mc.player.getZ());
|
| 1001 |
|
| 1002 | for (Direction side : Direction.values()) {
|
| 1003 | ((IVec3) vec3dRayTraceEnd).meteor$set(
|
| 1004 | blockPos.getX() + 0.5 + side.getUnitVec3i().getX() * 0.5,
|
| 1005 | blockPos.getY() + 0.5 + side.getUnitVec3i().getY() * 0.5,
|
| 1006 | blockPos.getZ() + 0.5 + side.getUnitVec3i().getZ() * 0.5
|
| 1007 | );
|
| 1008 |
|
| 1009 | ((IClipContext) clipContext).meteor$set(vec3d, vec3dRayTraceEnd, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player);
|
| 1010 | BlockHitResult result = mc.level.clip(clipContext);
|
| 1011 |
|
| 1012 | if (result != null && result.getType() == HitResult.Type.BLOCK && result.getBlockPos().equals(blockPos)) {
|
| 1013 | return result;
|
| 1014 | }
|
| 1015 | }
|
| 1016 |
|
| 1017 | Direction side = blockPos.getY() > vec3d.y ? Direction.DOWN : Direction.UP;
|
| 1018 | return new BlockHitResult(vec3d, side, blockPos, false);
|
| 1019 | }
|
| 1020 |
|
| 1021 | private void placeCrystal(BlockHitResult result, double damage, BlockPos supportBlock) {
|
| 1022 | // Switch
|
| 1023 | Item targetItem = supportBlock == null ? Items.END_CRYSTAL : Items.OBSIDIAN;
|
| 1024 |
|
| 1025 | FindItemResult item = InvUtils.findInHotbar(targetItem);
|
| 1026 | if (!item.found()) return;
|
| 1027 |
|
| 1028 | int prevSlot = mc.player.getInventory().getSelectedSlot();
|
| 1029 |
|
| 1030 | if (autoSwitch.get() != AutoSwitchMode.None && !item.isOffhand()) InvUtils.swap(item.slot(), false);
|
| 1031 |
|
| 1032 | InteractionHand hand = item.getHand();
|
| 1033 | if (hand == null) return;
|
| 1034 |
|
| 1035 | // Place
|
| 1036 | if (supportBlock == null) {
|
| 1037 | // Place crystal
|
| 1038 | mc.gameMode.startPrediction(mc.level, sequence -> new ServerboundUseItemOnPacket(hand, result, sequence));
|
| 1039 |
|
| 1040 | if (swingMode.get().client()) mc.player.swing(hand);
|
| 1041 | if (swingMode.get().packet()) mc.getConnection().send(new ServerboundSwingPacket(hand));
|
| 1042 |
|
| 1043 | placing = true;
|
| 1044 | placingTimer = 4;
|
| 1045 | kaTimer = 8;
|
| 1046 | placingCrystalBlockPos.set(result.getBlockPos()).move(0, 1, 0);
|
| 1047 |
|
| 1048 | placeRenderPos.set(result.getBlockPos());
|
| 1049 | renderDamage = damage;
|
| 1050 |
|
| 1051 | if (renderMode.get() == RenderMode.Normal) {
|
| 1052 | placeRenderTimer = placeRenderTime.get();
|
| 1053 | } else {
|
| 1054 | placeRenderTimer = renderTime.get();
|
| 1055 | if (renderMode.get() == RenderMode.Fading) {
|
| 1056 | RenderUtils.renderTickingBlock(
|
| 1057 | placeRenderPos, sideColor.get(),
|
| 1058 | lineColor.get(), shapeMode.get(),
|
| 1059 | 0, renderTime.get(), true,
|
| 1060 | false
|
| 1061 | );
|
| 1062 | }
|
| 1063 | }
|
| 1064 | } else {
|
| 1065 | // Place support block
|
| 1066 | BlockUtils.place(supportBlock, item, false, 0, swingMode.get().client(), true, false);
|
| 1067 | placeTimer += supportDelay.get();
|
| 1068 |
|
| 1069 | if (supportDelay.get() == 0) placeCrystal(result, damage, null);
|
| 1070 | }
|
| 1071 |
|
| 1072 | // Switch back
|
| 1073 | if (autoSwitch.get() == AutoSwitchMode.Silent) InvUtils.swap(prevSlot, false);
|
| 1074 | }
|
| 1075 |
|
| 1076 | // Yaw steps
|
| 1077 |
|
| 1078 | @EventHandler
|
| 1079 | private void onPacketSent(PacketEvent.Sent event) {
|
| 1080 | if (event.packet instanceof ServerboundMovePlayerPacket packet) {
|
| 1081 | serverYaw = packet.getYRot((float) serverYaw);
|
| 1082 | }
|
| 1083 | }
|
| 1084 |
|
| 1085 | public boolean doYawSteps(double targetYaw, double targetPitch) {
|
| 1086 | targetYaw = Mth.wrapDegrees(targetYaw) + 180;
|
| 1087 | double serverYaw = Mth.wrapDegrees(this.serverYaw) + 180;
|
| 1088 |
|
| 1089 | if (distanceBetweenAngles(serverYaw, targetYaw) <= yawSteps.get()) return true;
|
| 1090 |
|
| 1091 | double delta = Math.abs(targetYaw - serverYaw);
|
| 1092 | double yaw = this.serverYaw;
|
| 1093 |
|
| 1094 | if (serverYaw < targetYaw) {
|
| 1095 | if (delta < 180) yaw += yawSteps.get();
|
| 1096 | else yaw -= yawSteps.get();
|
| 1097 | } else {
|
| 1098 | if (delta < 180) yaw -= yawSteps.get();
|
| 1099 | else yaw += yawSteps.get();
|
| 1100 | }
|
| 1101 |
|
| 1102 | setRotation(false, null, yaw, targetPitch);
|
| 1103 | Rotations.rotate(yaw, targetPitch, -100, null); // Priority -100 so it sends the packet as the last one, im pretty sure it doesn't matte but idc
|
| 1104 | return false;
|
| 1105 | }
|
| 1106 |
|
| 1107 | private static double distanceBetweenAngles(double alpha, double beta) {
|
| 1108 | double phi = Math.abs(beta - alpha) % 360;
|
| 1109 | return phi > 180 ? 360 - phi : phi;
|
| 1110 | }
|
| 1111 |
|
| 1112 | // Face place
|
| 1113 |
|
| 1114 | private boolean shouldFacePlace() {
|
| 1115 | if (!facePlace.get()) return false;
|
| 1116 |
|
| 1117 | if (forceFacePlace.get().isPressed()) return true;
|
| 1118 |
|
| 1119 | // Checks if the provided crystal position should face place to any target
|
| 1120 | for (LivingEntity target : targets) {
|
| 1121 | if (EntityUtils.getTotalHealth(target) <= facePlaceHealth.get()) return true;
|
| 1122 |
|
| 1123 | for (EquipmentSlot slot : EquipmentSlotGroup.ARMOR) {
|
| 1124 | ItemStack itemStack = target.getItemBySlot(slot);
|
| 1125 |
|
| 1126 | if (itemStack == null || itemStack.isEmpty()) {
|
| 1127 | if (facePlaceArmor.get()) return true;
|
| 1128 | } else {
|
| 1129 | if ((double) (itemStack.getMaxDamage() - itemStack.getDamageValue()) / itemStack.getMaxDamage() * 100 <= facePlaceDurability.get())
|
| 1130 | return true;
|
| 1131 | }
|
| 1132 | }
|
| 1133 | }
|
| 1134 |
|
| 1135 | return false;
|
| 1136 | }
|
| 1137 |
|
| 1138 | // Others
|
| 1139 |
|
| 1140 | private boolean shouldPause(PauseMode process) {
|
| 1141 | if (mc.player.isUsingItem() || mc.options.keyUse.isDown()) {
|
| 1142 | if (pauseOnUse.get().matches(process)) return true;
|
| 1143 | }
|
| 1144 |
|
| 1145 | if (pauseOnLag.get() && TickRate.INSTANCE.getTimeSinceLastTick() >= 1.0f) return true;
|
| 1146 | for (Module module : pauseModules.get()) if (module.isActive()) return true;
|
| 1147 | if (pauseOnMine.get().matches(process) && mc.gameMode.isDestroying()) return true;
|
| 1148 | return (EntityUtils.getTotalHealth(mc.player) <= pauseHealth.get());
|
| 1149 | }
|
| 1150 |
|
| 1151 | private boolean isOutOfRange(Vec3 vec3d, BlockPos blockPos, boolean place) {
|
| 1152 | ((IClipContext) clipContext).meteor$set(playerEyePos, vec3d, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player);
|
| 1153 |
|
| 1154 | BlockHitResult result = mc.level.clip(clipContext);
|
| 1155 |
|
| 1156 | if (result == null || !result.getBlockPos().equals(blockPos)) // Is behind wall
|
| 1157 | return !PlayerUtils.isWithin(vec3d, (place ? placeWallsRange : breakWallsRange).get());
|
| 1158 | return !PlayerUtils.isWithin(vec3d, (place ? placeRange : breakRange).get());
|
| 1159 | }
|
| 1160 |
|
| 1161 | private LivingEntity getNearestTarget() {
|
| 1162 | LivingEntity nearestTarget = null;
|
| 1163 | double nearestDistance = Double.MAX_VALUE;
|
| 1164 |
|
| 1165 | for (LivingEntity target : targets) {
|
| 1166 | double distance = PlayerUtils.squaredDistanceTo(target);
|
| 1167 |
|
| 1168 | if (distance < nearestDistance) {
|
| 1169 | nearestTarget = target;
|
| 1170 | nearestDistance = distance;
|
| 1171 | }
|
| 1172 | }
|
| 1173 |
|
| 1174 | return nearestTarget;
|
| 1175 | }
|
| 1176 |
|
| 1177 | private float getDamageToTargets(Vec3 vec3d, BlockPos obsidianPos, boolean breaking, boolean fast) {
|
| 1178 | float damage = 0;
|
| 1179 |
|
| 1180 | if (fast) {
|
| 1181 | LivingEntity target = getNearestTarget();
|
| 1182 | if (!(smartDelay.get() && breaking && target.hurtTime > 0))
|
| 1183 | damage = DamageUtils.crystalDamage(target, vec3d, predictMovement.get(), obsidianPos);
|
| 1184 | } else {
|
| 1185 | for (LivingEntity target : targets) {
|
| 1186 | if (smartDelay.get() && breaking && target.hurtTime > 0) continue;
|
| 1187 |
|
| 1188 | float dmg = DamageUtils.crystalDamage(target, vec3d, predictMovement.get(), obsidianPos);
|
| 1189 |
|
| 1190 | // Update best target
|
| 1191 | if (dmg > bestTargetDamage) {
|
| 1192 | bestTarget = target;
|
| 1193 | bestTargetDamage = dmg;
|
| 1194 | bestTargetTimer = 10;
|
| 1195 | }
|
| 1196 |
|
| 1197 | damage += dmg;
|
| 1198 | }
|
| 1199 | }
|
| 1200 |
|
| 1201 | return damage;
|
| 1202 | }
|
| 1203 |
|
| 1204 | @Override
|
| 1205 | public String getInfoString() {
|
| 1206 | return bestTarget != null && bestTargetTimer > 0 ? EntityUtils.getName(bestTarget) : null;
|
| 1207 | }
|
| 1208 |
|
| 1209 | private void findTargets() {
|
| 1210 | targets.clear();
|
| 1211 |
|
| 1212 | // Living Entities
|
| 1213 | for (Entity entity : mc.level.entitiesForRendering()) {
|
| 1214 | // Ignore non-living
|
| 1215 | if (!(entity instanceof LivingEntity livingEntity)) continue;
|
| 1216 |
|
| 1217 | // Player
|
| 1218 | if (livingEntity instanceof Player player) {
|
| 1219 | if (player.getAbilities().instabuild || livingEntity == mc.player) continue;
|
| 1220 | if (!player.isAlive() || !Friends.get().shouldAttack(player)) continue;
|
| 1221 |
|
| 1222 | if (ignoreNakeds.get()) {
|
| 1223 | if (player.getOffhandItem().isEmpty()
|
| 1224 | && player.getMainHandItem().isEmpty()
|
| 1225 | && player.getItemBySlot(EquipmentSlot.FEET).isEmpty()
|
| 1226 | && player.getItemBySlot(EquipmentSlot.LEGS).isEmpty()
|
| 1227 | && player.getItemBySlot(EquipmentSlot.CHEST).isEmpty()
|
| 1228 | && player.getItemBySlot(EquipmentSlot.HEAD).isEmpty()
|
| 1229 | ) continue;
|
| 1230 | }
|
| 1231 | }
|
| 1232 |
|
| 1233 | // Animals, water animals, monsters, bats, misc
|
| 1234 | if (!(entities.get().contains(livingEntity.getType()))) continue;
|
| 1235 |
|
| 1236 | // Close enough to damage
|
| 1237 | if (livingEntity.distanceToSqr(mc.player) > targetRange.get() * targetRange.get()) continue;
|
| 1238 |
|
| 1239 | targets.add(livingEntity);
|
| 1240 | }
|
| 1241 | }
|
| 1242 |
|
| 1243 | private boolean intersectsWithEntities(AABB box) {
|
| 1244 | return EntityUtils.intersectsWithEntity(box, entity -> !entity.isSpectator() && !removed.contains(entity.getId()));
|
| 1245 | }
|
| 1246 |
|
| 1247 | // Rendering
|
| 1248 |
|
| 1249 | @EventHandler
|
| 1250 | private void onRender(Render3DEvent event) {
|
| 1251 | if (renderMode.get() == RenderMode.None) return;
|
| 1252 |
|
| 1253 | switch (renderMode.get()) {
|
| 1254 | case Normal -> {
|
| 1255 | if (renderPlace.get() && placeRenderTimer > 0) {
|
| 1256 | event.renderer.box(placeRenderPos, sideColor.get(), lineColor.get(), shapeMode.get(), 0);
|
| 1257 | }
|
| 1258 | if (renderBreak.get() && breakRenderTimer > 0) {
|
| 1259 | event.renderer.box(breakRenderPos, sideColor.get(), lineColor.get(), shapeMode.get(), 0);
|
| 1260 | }
|
| 1261 | }
|
| 1262 |
|
| 1263 | case Smooth -> {
|
| 1264 | if (placeRenderTimer <= 0) return;
|
| 1265 |
|
| 1266 | if (renderBoxOne == null) renderBoxOne = new AABB(placeRenderPos);
|
| 1267 | if (renderBoxTwo == null) renderBoxTwo = new AABB(placeRenderPos);
|
| 1268 | else ((IAABB) renderBoxTwo).meteor$set(placeRenderPos);
|
| 1269 |
|
| 1270 | double offsetX = (renderBoxTwo.minX - renderBoxOne.minX) / smoothness.get();
|
| 1271 | double offsetY = (renderBoxTwo.minY - renderBoxOne.minY) / smoothness.get();
|
| 1272 | double offsetZ = (renderBoxTwo.minZ - renderBoxOne.minZ) / smoothness.get();
|
| 1273 |
|
| 1274 | ((IAABB) renderBoxOne).meteor$set(
|
| 1275 | renderBoxOne.minX + offsetX,
|
| 1276 | renderBoxOne.minY + offsetY,
|
| 1277 | renderBoxOne.minZ + offsetZ,
|
| 1278 | renderBoxOne.maxX + offsetX,
|
| 1279 | renderBoxOne.maxY + offsetY,
|
| 1280 | renderBoxOne.maxZ + offsetZ
|
| 1281 | );
|
| 1282 |
|
| 1283 | event.renderer.box(renderBoxOne, sideColor.get(), lineColor.get(), shapeMode.get(), 0);
|
| 1284 | }
|
| 1285 |
|
| 1286 | case Gradient -> {
|
| 1287 | if (placeRenderTimer <= 0) return;
|
| 1288 |
|
| 1289 | Color bottom = new Color(0, 0, 0, 0);
|
| 1290 |
|
| 1291 | int x = placeRenderPos.getX();
|
| 1292 | int y = placeRenderPos.getY() + 1;
|
| 1293 | int z = placeRenderPos.getZ();
|
| 1294 |
|
| 1295 | if (shapeMode.get().sides()) {
|
| 1296 | event.renderer.quadHorizontal(x, y, z, x + 1, z + 1, sideColor.get());
|
| 1297 | event.renderer.gradientQuadVertical(x, y, z, x + 1, y - height.get(), z, bottom, sideColor.get());
|
| 1298 | event.renderer.gradientQuadVertical(x, y, z, x, y - height.get(), z + 1, bottom, sideColor.get());
|
| 1299 | event.renderer.gradientQuadVertical(x + 1, y, z, x + 1, y - height.get(), z + 1, bottom, sideColor.get());
|
| 1300 | event.renderer.gradientQuadVertical(x, y, z + 1, x + 1, y - height.get(), z + 1, bottom, sideColor.get());
|
| 1301 | }
|
| 1302 |
|
| 1303 | if (shapeMode.get().lines()) {
|
| 1304 | event.renderer.line(x, y, z, x + 1, y, z, lineColor.get());
|
| 1305 | event.renderer.line(x, y, z, x, y, z + 1, lineColor.get());
|
| 1306 | event.renderer.line(x + 1, y, z, x + 1, y, z + 1, lineColor.get());
|
| 1307 | event.renderer.line(x, y, z + 1, x + 1, y, z + 1, lineColor.get());
|
| 1308 |
|
| 1309 | event.renderer.line(x, y, z, x, y - height.get(), z, lineColor.get(), bottom);
|
| 1310 | event.renderer.line(x + 1, y, z, x + 1, y - height.get(), z, lineColor.get(), bottom);
|
| 1311 | event.renderer.line(x, y, z + 1, x, y - height.get(), z + 1, lineColor.get(), bottom);
|
| 1312 | event.renderer.line(x + 1, y, z + 1, x + 1, y - height.get(), z + 1, lineColor.get(), bottom);
|
| 1313 | }
|
| 1314 | }
|
| 1315 | }
|
| 1316 | }
|
| 1317 |
|
| 1318 | @EventHandler
|
| 1319 | private void onRender2D(Render2DEvent event) {
|
| 1320 | if (renderMode.get() == RenderMode.None || !renderDamageText.get()) return;
|
| 1321 | if (placeRenderTimer <= 0 && breakRenderTimer <= 0) return;
|
| 1322 |
|
| 1323 | if (renderMode.get() == RenderMode.Smooth) {
|
| 1324 | if (renderBoxOne == null) return;
|
| 1325 | vec3.set(renderBoxOne.minX + 0.5, renderBoxOne.minY + 0.5, renderBoxOne.minZ + 0.5);
|
| 1326 | } else vec3.set(placeRenderPos.getX() + 0.5, placeRenderPos.getY() + 0.5, placeRenderPos.getZ() + 0.5);
|
| 1327 |
|
| 1328 | if (NametagUtils.to2D(vec3, damageTextScale.get())) {
|
| 1329 | NametagUtils.begin(vec3, event.graphics);
|
| 1330 | TextRenderer.get().begin(event.graphics, 1, false, true);
|
| 1331 |
|
| 1332 | String text = String.format("%.1f", renderDamage);
|
| 1333 | double w = TextRenderer.get().getWidth(text) / 2;
|
| 1334 | TextRenderer.get().render(text, -w, 0, damageColor.get(), true);
|
| 1335 |
|
| 1336 | TextRenderer.get().end();
|
| 1337 | NametagUtils.end(event.graphics);
|
| 1338 | }
|
| 1339 | }
|
| 1340 |
|
| 1341 | public enum YawStepMode {
|
| 1342 | Break,
|
| 1343 | All,
|
| 1344 | }
|
| 1345 |
|
| 1346 | public enum AutoSwitchMode {
|
| 1347 | Normal,
|
| 1348 | Silent,
|
| 1349 | None
|
| 1350 | }
|
| 1351 |
|
| 1352 | public enum SupportMode {
|
| 1353 | Disabled,
|
| 1354 | Accurate,
|
| 1355 | Fast
|
| 1356 | }
|
| 1357 |
|
| 1358 | public enum PauseMode {
|
| 1359 | Both,
|
| 1360 | Place,
|
| 1361 | Break,
|
| 1362 | None;
|
| 1363 |
|
| 1364 | public boolean matches(PauseMode process) {
|
| 1365 | return this == process || this == PauseMode.Both;
|
| 1366 | }
|
| 1367 | }
|
| 1368 |
|
| 1369 | public enum SwingMode {
|
| 1370 | Both,
|
| 1371 | Packet,
|
| 1372 | Client,
|
| 1373 | None;
|
| 1374 |
|
| 1375 | public boolean packet() {
|
| 1376 | return this == Packet || this == Both;
|
| 1377 | }
|
| 1378 |
|
| 1379 | public boolean client() {
|
| 1380 | return this == Client || this == Both;
|
| 1381 | }
|
| 1382 | }
|
| 1383 |
|
| 1384 | public enum RenderMode {
|
| 1385 | Normal,
|
| 1386 | Smooth,
|
| 1387 | Fading,
|
| 1388 | Gradient,
|
| 1389 | None
|
| 1390 | }
|
| 1391 | }
|
| 1392 |
|