AutoAnchor module

AutoAnchor: Minecraft 26.3 cheat module, full source for every implementation (2 clients: MelaHack (ThunderHack fork), Combatant).

2 implementationsCOMBAT

Full module source: 2 implementations

Every implementation below is the complete module file, verbatim. Expand a client to read its code.

MelaHack (ThunderHack fork)COMBATsrc/main/java/thunder/hack/features/modules/combat/AutoAnchor.javaJava · 913 lines · 42.3 KB

Automatically places and explodes respawn anchors.

SettingsPageAK47TimingRotateYawStepYawAngleTargetLogicTargetRangeSelfPredictTicksUseOptimizedCalcInteractPlaceDelayLowPlaceDelayPlaceRangePlaceWallRangePredictTicksExplodeDelayLowExplodeDelayMiningEatingAuraPistonAuraSurroundMiddleClickHPSwitchPauseSwitchDelaySortMinDamageMaxSelfDamageSafetySafetyBalanceProtectFriendsOverrideSelfDamageLethalMultiplierArmorBreakerArmor %FacePlaceHpFacePlaceBtnSwitch
AutoAnchor.javaJava · Minecraft 26.2 · 913 lines · 42.3 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.combat;
2
3
import com.google.common.collect.Lists;
4
import com.mojang.blaze3d.platform.InputConstants;
5
import com.mojang.blaze3d.vertex.PoseStack;
6
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
7
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
8
import meteordevelopment.orbit.EventHandler;
9
import meteordevelopment.orbit.EventPriority;
10
import net.minecraft.network.protocol.game.*;
11
import net.minecraft.util.Mth;
12
import net.minecraft.core.*;
13
import net.minecraft.world.InteractionHand;
14
import net.minecraft.world.entity.player.Player;
15
import net.minecraft.world.inventory.ContainerInput;
16
import net.minecraft.world.item.BlockItem;
17
import net.minecraft.world.item.ItemStack;
18
import net.minecraft.world.item.Items;
19
import net.minecraft.world.level.ClipContext;
20
import net.minecraft.world.level.block.Blocks;
21
import net.minecraft.world.level.block.RespawnAnchorBlock;
22
import net.minecraft.world.level.block.state.BlockState;
23
import net.minecraft.world.phys.*;
24
import org.jetbrains.annotations.NotNull;
25
import org.jetbrains.annotations.Nullable;
26
import org.lwjgl.glfw.GLFW;
27
import thunder.hack.core.Managers;
28
import thunder.hack.core.manager.client.ModuleManager;
29
import thunder.hack.core.manager.player.CombatManager;
30
import thunder.hack.events.impl.*;
31
import thunder.hack.features.modules.Module;
32
import thunder.hack.features.modules.client.HudEditor;
33
import thunder.hack.setting.Setting;
34
import thunder.hack.setting.impl.Bind;
35
import thunder.hack.setting.impl.BooleanSettingGroup;
36
import thunder.hack.setting.impl.ColorSetting;
37
import thunder.hack.utility.Timer;
38
import thunder.hack.utility.world.ExplosionUtility;
39
import thunder.hack.utility.math.MathUtility;
40
import thunder.hack.utility.player.InteractionUtility;
41
import thunder.hack.utility.player.InventoryUtility;
42
import thunder.hack.utility.player.PlayerUtility;
43
import thunder.hack.utility.player.SearchInvResult;
44
import thunder.hack.utility.render.Render2DEngine;
45
import thunder.hack.utility.render.Render3DEngine;
46
47
import java.awt.*;
48
import java.util.ArrayList;
49
import java.util.HashMap;
50
import java.util.List;
51
import java.util.Map;
52
import java.util.concurrent.ConcurrentHashMap;
53
54
import static net.minecraft.util.Mth.wrapDegrees;
55
56
public final class AutoAnchor extends Module {
57
    /*   MAIN   */
58
    private static final Setting<Pages> page = new Setting<>("Page", Pages.Main);
59
    private final Setting<AK47> ak47 = new Setting<>("AK47", AK47.ON, v -> page.getValue() == Pages.Main);
60
    private final Setting<Timing> timing = new Setting<>("Timing", Timing.NORMAL, v -> page.getValue() == Pages.Main);
61
    private final Setting<Boolean> rotate = new Setting<>("Rotate", true, v -> page.getValue() == Pages.Main);
62
    private final Setting<BooleanSettingGroup> yawStep = new Setting<>("YawStep", new BooleanSettingGroup(false), v -> rotate.getValue() && page.getValue() == Pages.Main);
63
    private final Setting<Float> yawAngle = new Setting<>("YawAngle", 180.0f, 1.0f, 180.0f, v -> rotate.getValue() && page.getValue() == Pages.Main).addToGroup(yawStep);
64
    private final Setting<CombatManager.TargetBy> targetLogic = new Setting<>("TargetLogic", CombatManager.TargetBy.Distance, v -> page.getValue() == Pages.Main);
65
    private final Setting<Float> targetRange = new Setting<>("TargetRange", 10.0f, 1.0f, 15f, v -> page.getValue() == Pages.Main);
66
    public static final Setting<Integer> selfPredictTicks = new Setting<>("SelfPredictTicks", 3, 0, 20, v -> page.getValue() == Pages.Main);
67
    public final Setting<Boolean> useOptimizedCalc = new Setting<>("UseOptimizedCalc", true, v -> page.getValue() == Pages.Main);
68
69
    /*   PLACE   */
70
    private final Setting<InteractionUtility.Interact> interact = new Setting<>("Interact", InteractionUtility.Interact.Vanilla, v -> page.getValue() == Pages.Place);
71
    private final Setting<Integer> placeDelay = new Setting<>("PlaceDelay", 0, 0, 1000, v -> page.getValue() == Pages.Place);
72
    private final Setting<Integer> lowPlaceDelay = new Setting<>("LowPlaceDelay", 550, 0, 1000, v -> page.getValue() == Pages.Place);
73
    private final Setting<Float> placeRange = new Setting<>("PlaceRange", 5f, 1.0f, 6f, v -> page.getValue() == Pages.Place);
74
    private final Setting<Float> placeWallRange = new Setting<>("PlaceWallRange", 3.5f, 1.0f, 6f, v -> page.getValue() == Pages.Place);
75
    public static final Setting<Integer> predictTicks = new Setting<>("PredictTicks", 3, 0, 20, v -> page.getValue() == Pages.Place);
76
77
    /*   EXPLODE   */
78
    private final Setting<Integer> explodeDelay = new Setting<>("ExplodeDelay", 0, 0, 1000, v -> page.getValue() == Pages.Break);
79
    private final Setting<Integer> lowExplodeDelay = new Setting<>("LowExplodeDelay", 550, 0, 1000, v -> page.getValue() == Pages.Break);
80
81
    /*   PAUSE   */
82
    private final Setting<Boolean> mining = new Setting<>("Mining", true, v -> page.getValue() == Pages.Pause);
83
    private final Setting<Boolean> eating = new Setting<>("Eating", true, v -> page.getValue() == Pages.Pause);
84
    private final Setting<Boolean> aura = new Setting<>("Aura", false, v -> page.getValue() == Pages.Pause);
85
    private final Setting<Boolean> pistonAura = new Setting<>("PistonAura", true, v -> page.getValue() == Pages.Pause);
86
    private final Setting<Boolean> surround = new Setting<>("Surround", true, v -> page.getValue() == Pages.Pause);
87
    private final Setting<Boolean> middleClick = new Setting<>("MiddleClick", true, v -> page.getValue() == Pages.Pause);
88
    private final Setting<Float> pauseHP = new Setting<>("HP", 8.0f, 2.0f, 10f, v -> page.getValue() == Pages.Pause);
89
    private final Setting<BooleanSettingGroup> switchPause = new Setting<>("SwitchPause", new BooleanSettingGroup(true), v -> page.getValue() == Pages.Pause);
90
    private final Setting<Integer> switchDelay = new Setting<>("SwitchDelay", 100, 0, 1000, v -> page.getValue() == Pages.Pause).addToGroup(switchPause);
91
92
    /*   DAMAGES   */
93
    public final Setting<Sort> sort = new Setting<>("Sort", Sort.DAMAGE, v -> page.getValue() == Pages.Damages);
94
    public final Setting<Float> minDamage = new Setting<>("MinDamage", 6.0f, 2.0f, 20f, v -> page.getValue() == Pages.Damages);
95
    public final Setting<Float> maxSelfDamage = new Setting<>("MaxSelfDamage", 10.0f, 2.0f, 20f, v -> page.getValue() == Pages.Damages);
96
    private final Setting<Safety> safety = new Setting<>("Safety", Safety.NONE, v -> page.getValue() == Pages.Damages);
97
    private final Setting<Float> safetyBalance = new Setting<>("SafetyBalance", 1.1f, 0.1f, 3f, v -> page.getValue() == Pages.Damages && safety.getValue() == Safety.BALANCE);
98
    public final Setting<Boolean> protectFriends = new Setting<>("ProtectFriends", true, v -> page.getValue() == Pages.Damages);
99
    private final Setting<Boolean> overrideSelfDamage = new Setting<>("OverrideSelfDamage", true, v -> page.getValue() == Pages.Damages);
100
    private final Setting<Float> lethalMultiplier = new Setting<>("LethalMultiplier", 1.0f, 0.0f, 5f, v -> page.getValue() == Pages.Damages);
101
    private final Setting<BooleanSettingGroup> armorBreaker = new Setting<>("ArmorBreaker", new BooleanSettingGroup(true), v -> page.getValue() == Pages.Damages);
102
    private final Setting<Float> armorScale = new Setting<>("Armor %", 5.0f, 0.0f, 40f, v -> page.getValue() == Pages.Damages).addToGroup(armorBreaker);
103
    private final Setting<Float> facePlaceHp = new Setting<>("FacePlaceHp", 5.0f, 0.0f, 20f, v -> page.getValue() == Pages.Damages);
104
    private final Setting<Bind> facePlaceButton = new Setting<>("FacePlaceBtn", new Bind(GLFW.GLFW_KEY_LEFT_SHIFT, false, false), v -> page.getValue() == Pages.Damages);
105
106
    /*   SWITCH   */
107
    private final Setting<Switch> autoSwitch = new Setting<>("Switch", Switch.NORMAL, v -> page.getValue() == Pages.Switch);
108
    private final Setting<Switch> antiWeakness = new Setting<>("AntiWeakness", Switch.SILENT, v -> page.getValue() == Pages.Switch);
109
110
    /*   RENDER   */
111
    private final Setting<Boolean> render = new Setting<>("Render", true, v -> page.getValue() == Pages.Render);
112
    private final Setting<Render> renderMode = new Setting<>("RenderMode", Render.Fade, v -> page.getValue() == Pages.Render);
113
    private final Setting<Boolean> rselfDamage = new Setting<>("SelfDamage", true, v -> page.getValue() == Pages.Render);
114
    private final Setting<Boolean> drawDamage = new Setting<>("RenderDamage", true, v -> page.getValue() == Pages.Render);
115
    private final Setting<ColorSetting> fillColor = new Setting<>("Block Fill Color", new ColorSetting(HudEditor.getColor(0)), v -> page.getValue() == Pages.Render);
116
    private final Setting<ColorSetting> lineColor = new Setting<>("Block Line Color", new ColorSetting(HudEditor.getColor(0)), v -> page.getValue() == Pages.Render);
117
    private final Setting<Integer> lineWidth = new Setting<>("Block Line Width", 2, 1, 10, v -> page.getValue() == Pages.Render);
118
    private final Setting<Integer> slideDelay = new Setting<>("Slide Delay", 200, 1, 1000, v -> page.getValue() == Pages.Render);
119
    private final Setting<ColorSetting> textColor = new Setting<>("Text Color", new ColorSetting(Color.WHITE), v -> page.getValue() == Pages.Render);
120
121
    /*   INFO   */
122
    private final Setting<Boolean> targetName = new Setting<>("TargetName", false, v -> page.getValue() == Pages.Info);
123
    private final Setting<Boolean> currentSide = new Setting<>("CurrentSide", true, v -> page.getValue() == Pages.Info);
124
    private final Setting<Boolean> speed = new Setting<>("Speed", true, v -> page.getValue() == Pages.Info);
125
    private final Setting<Boolean> confirmInfo = new Setting<>("ConfirmTime", true, v -> page.getValue() == Pages.Info);
126
    private final Setting<Boolean> calcInfo = new Setting<>("CalcInfo", false, v -> page.getValue() == Pages.Info);
127
128
    public static Player target;
129
    private PlaceData bestPosition;
130
    private BlockHitResult bestAnchor;
131
132
    private final Timer placeTimer = new Timer();
133
    private final Timer breakTimer = new Timer();
134
    private final Timer pauseTimer = new Timer();
135
136
    private final Map<BlockPos, Long> placedAnchors = new HashMap<>();
137
138
    public float renderDamage, renderSelfDamage, rotationYaw, rotationPitch;
139
140
    private int prevAnchorAmmount, anchorSpeed, invTimer;
141
142
    private boolean rotated, facePlacing;
143
144
    private long confirmTime, calcTime;
145
146
    private BlockPos renderPos, prevRenderPos;
147
    private long renderMultiplier;
148
    private final Map<BlockPos, Long> renderPositions = new ConcurrentHashMap<>();
149
150
    public AutoAnchor() {
151
        super("AutoAnchor", Category.COMBAT);
152
    }
153
154
    @Override
155
    public void onEnable() {
156
        resetVars();
157
    }
158
159
    @Override
160
    public void onDisable() {
161
        resetVars();
162
    }
163
164
    private void resetVars() {
165
        facePlacing = false;
166
        rotated = false;
167
        renderDamage = 0;
168
        renderSelfDamage = 0;
169
        renderMultiplier = 0;
170
        confirmTime = 0;
171
        renderPositions.clear();
172
        placedAnchors.clear();
173
        breakTimer.reset();
174
        placeTimer.reset();
175
        bestAnchor = null;
176
        bestPosition = null;
177
        renderPos = null;
178
        prevRenderPos = null;
179
        target = null;
180
    }
181
182
    @EventHandler(priority = EventPriority.HIGHEST)
183
    public void onTick(EventTick e) {
184
        if (mc.player == null || mc.level == null) return;
185
186
        long currentTime = System.currentTimeMillis();
187
        final List<PlaceData> blocks = getPossibleBlocks(target, mc.player.position(), placeRange.getValue());
188
        calcPosition(blocks);
189
        getAnchorToExplode(blocks);
190
        calcTime = System.currentTimeMillis() - currentTime;
191
192
        if (timing.is(Timing.NORMAL)) {
193
            if (bestPosition != null && placeTimer.passedMs(facePlacing ? lowPlaceDelay.getValue() : (placeDelay.getValue())))
194
                placeAnchor(bestPosition, false);
195
196
            if (bestAnchor != null && breakTimer.passedMs(facePlacing ? lowExplodeDelay.getValue() : explodeDelay.getValue()))
197
                explodeAnchor(bestAnchor);
198
        }
199
    }
200
201
    @EventHandler
202
    public void onPlayerUpdate(PlayerUpdateEvent event) {
203
        if (rotate.getValue())
204
            calcRotations();
205
    }
206
207
    @EventHandler
208
    public void onSync(EventSync e) {
209
        if (mc.player == null || mc.level == null) return;
210
211
        target = Managers.COMBAT.getTarget(targetRange.getValue(), targetLogic.getValue());
212
213
        if (target != null && (target.isDeadOrDying() || target.getHealth() < 0)) {
214
            target = null;
215
            return;
216
        }
217
218
        if (invTimer++ >= 20) {
219
            anchorSpeed = MathUtility.clamp(prevAnchorAmmount - InventoryUtility.getItemCount(Items.RESPAWN_ANCHOR), 0, 255);
220
            prevAnchorAmmount = InventoryUtility.getItemCount(Items.RESPAWN_ANCHOR);
221
            invTimer = 0;
222
        }
223
224
        // Rotate
225
        if (rotate.getValue() && mc.player != null && rotationYaw != mc.player.getYRot() && rotationPitch != mc.player.getXRot()) {
226
            mc.player.setYRot(rotationYaw);
227
            mc.player.setXRot(rotationPitch);
228
        }
229
    }
230
231
    @EventHandler
232
    public void onPostSync(EventPostSync e) {
233
        if (timing.is(Timing.SEQUENTIAL)) {
234
            if (bestPosition != null && placeTimer.passedMs(facePlacing ? lowPlaceDelay.getValue() : (placeDelay.getValue())))
235
                placeAnchor(bestPosition, false);
236
237
            if (bestAnchor != null && breakTimer.passedMs(facePlacing ? lowExplodeDelay.getValue() : explodeDelay.getValue()))
238
                explodeAnchor(bestAnchor);
239
        }
240
    }
241
242
    @Override
243
    public String getDisplayInfo() {
244
        StringBuilder info = new StringBuilder();
245
246
        Direction side = bestPosition == null ? null : bestPosition.bhr().getDirection();
247
        if (side != null) {
248
            if (targetName.getValue() && target != null) info.append(target.getName().getString()).append(" | ");
249
            if (speed.getValue()) info.append(anchorSpeed).append(" c/s").append(" | ");
250
            if (currentSide.getValue()) info.append(side.toString().toUpperCase()).append(" | ");
251
            if (confirmInfo.getValue()) info.append("c: ").append(confirmTime).append(" | ");
252
            if (calcInfo.getValue()) info.append("calc: ").append(calcTime).append(" | ");
253
        }
254
        return info.length() < 4 ? info.toString() : info.substring(0, info.length() - 3);
255
    }
256
257
    @EventHandler
258
    public void onBlockDestruct(EventSetBlockState e) {
259
        if (mc.player == null || mc.level == null) return;
260
261
        if (e.getPrevState() == null || e.getState() == null)
262
            return;
263
264
        if (target != null && target.distanceToSqr(net.minecraft.world.phys.Vec3.atBottomCenterOf(e.getPos())) <= 4 && e.getState().getBlock() instanceof RespawnAnchorBlock && e.getPrevState().canBeReplaced()) {
265
            debug("Detected change of state " + e.getPos() + ", exploding...");
266
            //explodeAnchor(getInteractResult(e.getPos()));
267
        }
268
    }
269
270
    public void calcRotations() {
271
        if (rotate.getValue() && !shouldPause() && (bestPosition != null || bestAnchor != null) && mc.player != null) {
272
            Vec3 vec = bestPosition == null ? bestAnchor.getLocation() : bestPosition.bhr().getLocation();
273
274
            float yawDelta = wrapDegrees((float) wrapDegrees(Math.toDegrees(Math.atan2(vec.z - mc.player.getZ(), (vec.x - mc.player.getX()))) - 90) - rotationYaw);
275
            float pitchDelta = ((float) (-Math.toDegrees(Math.atan2(vec.y - (mc.player.position().y + mc.player.getEyeHeight(mc.player.getPose())), Math.sqrt(Math.pow((vec.x - mc.player.getX()), 2) + Math.pow(vec.z - mc.player.getZ(), 2))))) - rotationPitch);
276
277
            yawDelta = (float) (yawDelta + Render2DEngine.interpolate(-1.2f, 1.2f, Math.sin(mc.player.tickCount % 80)) + MathUtility.random(-1.2f, 1.2f));
278
            pitchDelta = pitchDelta + MathUtility.random(-0.8f, 0.8f);
279
280
            if (yawDelta > 180)
281
                yawDelta = yawDelta - 180;
282
283
            float yawStepVal = 180f;
284
285
            if (yawStep.getValue().isEnabled())
286
                yawStepVal = yawAngle.getValue();
287
288
            float clampedYawDelta = Mth.clamp(Mth.abs(yawDelta), -yawStepVal, yawStepVal);
289
            float clampedPitchDelta = Mth.clamp(pitchDelta, -45, 45);
290
291
            rotated = Mth.abs(yawDelta) <= yawStepVal || !yawStep.getValue().isEnabled();
292
293
            float newYaw = rotationYaw + (yawDelta > 0 ? clampedYawDelta : -clampedYawDelta);
294
            float newPitch = Mth.clamp(rotationPitch + clampedPitchDelta, -90.0F, 90.0F);
295
296
            double gcdFix = (Math.pow(mc.options.sensitivity().get() * 0.6 + 0.2, 3.0)) * 1.2;
297
298
            rotationYaw = (float) (newYaw - (newYaw - rotationYaw) % gcdFix);
299
            rotationPitch = (float) (newPitch - (newPitch - rotationPitch) % gcdFix);
300
301
            ModuleManager.rotations.fixRotation = rotationYaw;
302
        } else {
303
            rotationYaw = mc.player.getYRot();
304
            rotationPitch = mc.player.getXRot();
305
        }
306
    }
307
308
    @Override
309
    public void onRender3D(PoseStack stack) {
310
        if (render.getValue()) {
311
            final Object2ObjectMap<BlockPos, Long> cache = new Object2ObjectOpenHashMap<>(renderPositions);
312
313
            cache.forEach((pos, time) -> {
314
                if (System.currentTimeMillis() - time > 500)
315
                    renderPositions.remove(pos);
316
            });
317
318
            String dmg = MathUtility.round2(renderDamage) + (rselfDamage.getValue() ? " / " + MathUtility.round2(renderSelfDamage) : "");
319
320
            if (renderMode.getValue() == Render.Fade) {
321
                cache.forEach((pos, time) -> {
322
                    if (System.currentTimeMillis() - time < 500) {
323
                        int alpha = (int) (100f * (1f - ((System.currentTimeMillis() - time) / 500f)));
324
325
                        Render3DEngine.FILLED_QUEUE.add(new Render3DEngine.FillAction(new AABB(pos), Render2DEngine.injectAlpha(fillColor.getValue().getColorObject(), alpha)));
326
                        Render3DEngine.OUTLINE_QUEUE.add(new Render3DEngine.OutlineAction(new AABB(pos), Render2DEngine.injectAlpha(lineColor.getValue().getColorObject(), alpha), lineWidth.getValue()));
327
328
                        if (drawDamage.getValue())
329
                            Render3DEngine.drawTextIn3D(dmg, net.minecraft.world.phys.Vec3.atBottomCenterOf(pos), 0, 0.1, 0, Render2DEngine.applyOpacity(textColor.getValue().getColorObject(), alpha / 100f));
330
                    }
331
                });
332
            } else if (renderMode.getValue() == Render.Slide && renderPos != null) {
333
                if (prevRenderPos == null) prevRenderPos = renderPos;
334
                if (renderPositions.isEmpty()) return;
335
                float mult = MathUtility.clamp((System.currentTimeMillis() - renderMultiplier) / (float) slideDelay.getValue(), 0f, 1f);
336
                AABB interpolatedBox = Render3DEngine.interpolateBox(new AABB(prevRenderPos), new AABB(renderPos), mult);
337
338
                renderBox(dmg, interpolatedBox);
339
            } else if (renderPos != null) {
340
                AABB box = new AABB(renderPos);
341
                if (renderPositions.isEmpty())
342
                    return;
343
344
                renderBox(dmg, box);
345
            }
346
        }
347
    }
348
349
    private void renderBox(String dmg, AABB box) {
350
        Render3DEngine.FILLED_QUEUE.add(new Render3DEngine.FillAction(box, fillColor.getValue().getColorObject()));
351
        Render3DEngine.OUTLINE_QUEUE.add(new Render3DEngine.OutlineAction(box, lineColor.getValue().getColorObject(), lineWidth.getValue()));
352
353
        if (drawDamage.getValue())
354
            Render3DEngine.drawTextIn3D(dmg, box.getCenter(), 0, 0.1, 0, textColor.getValue().getColorObject());
355
    }
356
357
    public boolean shouldPause() {
358
        if (mc.player == null || mc.level == null || mc.gameMode == null) return true;
359
360
        boolean offhand = mc.player.getOffhandItem().getItem() == Items.RESPAWN_ANCHOR;
361
        boolean mainHand = mc.player.getMainHandItem().getItem() == Items.RESPAWN_ANCHOR;
362
363
        boolean offhandGlow = mc.player.getOffhandItem().getItem() == Items.GLOWSTONE;
364
        boolean mainHandGlow = mc.player.getMainHandItem().getItem() == Items.GLOWSTONE;
365
366
        if (!pauseTimer.passedMs(1000))
367
            return true;
368
369
        if (mc.gameMode.isDestroying() && !offhand && mining.getValue())
370
            return true;
371
372
        if (autoSwitch.is(Switch.NONE) && !offhand && !mainHand)
373
            return true;
374
375
        if ((autoSwitch.is(Switch.SILENT) || autoSwitch.is(Switch.NORMAL)) && !InventoryUtility.findItemInHotBar(Items.RESPAWN_ANCHOR).found() && !offhand)
376
            return true;
377
378
        if (autoSwitch.is(Switch.INVENTORY) && !InventoryUtility.findItemInInventory(Items.RESPAWN_ANCHOR).found() && !offhand)
379
            return true;
380
381
        if (autoSwitch.is(Switch.NONE) && !offhandGlow && !mainHandGlow)
382
            return true;
383
384
        if ((autoSwitch.is(Switch.SILENT) || autoSwitch.is(Switch.NORMAL)) && !InventoryUtility.findItemInHotBar(Items.GLOWSTONE).found() && !offhandGlow)
385
            return true;
386
387
        if (autoSwitch.is(Switch.INVENTORY) && !InventoryUtility.findItemInInventory(Items.GLOWSTONE).found() && !offhandGlow)
388
            return true;
389
390
        if (mc.player.isUsingItem() && eating.getValue())
391
            return true;
392
393
        if (rotationMarkedDirty())
394
            return true;
395
396
        if (mc.player.getHealth() + mc.player.getAbsorptionAmount() < pauseHP.getValue())
397
            return true;
398
399
        boolean silentWeakness = antiWeakness.getValue() == Switch.SILENT || antiWeakness.getValue() == Switch.INVENTORY;
400
401
        boolean silent = autoSwitch.getValue() == Switch.SILENT || autoSwitch.getValue() == Switch.INVENTORY;
402
403
        return switchPause.getValue().isEnabled() && !Managers.PLAYER.switchTimer.passedMs(switchDelay.getValue()) && !silent && !silentWeakness;
404
    }
405
406
    public boolean rotationMarkedDirty() {
407
        if (ModuleManager.surround.isEnabled() && !ModuleManager.surround.inactivityTimer.passedMs(500) && surround.getValue())
408
            return true;
409
410
        if (ModuleManager.middleClick.isEnabled() && mc.options.keyPickItem.isDown() && middleClick.getValue())
411
            return true;
412
413
        if (ModuleManager.autoTrap.isEnabled() && !ModuleManager.surround.inactivityTimer.passedMs(500))
414
            return true;
415
416
        if (ModuleManager.blocker.isEnabled() && !ModuleManager.surround.inactivityTimer.passedMs(500))
417
            return true;
418
419
        if (ModuleManager.holeFill.isEnabled() && !HoleFill.inactivityTimer.passedMs(500))
420
            return true;
421
422
        if (ModuleManager.aura.isEnabled() && aura.getValue())
423
            return true;
424
425
        return ModuleManager.pistonAura.isEnabled() && pistonAura.getValue();
426
    }
427
428
    public void explodeAnchor(BlockHitResult bhr) {
429
        if (shouldPause() || mc.player == null) return;
430
        int prevSlot = -1;
431
432
        SearchInvResult glowResult = InventoryUtility.findItemInHotBar(Items.GLOWSTONE);
433
        SearchInvResult anchorResult = InventoryUtility.findInHotBar(stack -> !(stack.getItem() instanceof BlockItem));
434
        SearchInvResult glowInvResult = InventoryUtility.findItemInInventory(Items.GLOWSTONE);
435
436
        boolean offhand = mc.player.getOffhandItem().getItem() == Items.GLOWSTONE;
437
        boolean holdingAnchor = mc.player.getMainHandItem().getItem() == Items.GLOWSTONE || offhand;
438
439
        if (rotate.getValue() && !rotated)
440
            return;
441
442
        if (autoSwitch.getValue() != Switch.NONE && !holdingAnchor)
443
            prevSlot = switchTo(glowResult, glowInvResult, autoSwitch);
444
445
        if (!(mc.player.getMainHandItem().getItem() == Items.GLOWSTONE || offhand || autoSwitch.getValue() == Switch.SILENT))
446
            return;
447
448
        if (ak47.is(AK47.OFF)) {
449
            if (mc.player.isShiftKeyDown())
450
                sendPacket(new net.minecraft.network.protocol.game.ServerboundPlayerInputPacket(new net.minecraft.world.entity.player.Input(false, false, false, false, false, false, false)));
451
452
            if (mc.level.getBlockState(bhr.getBlockPos()).getValue(RespawnAnchorBlock.CHARGE) == 0) {
453
                sendSequencedPacket(id -> new ServerboundUseItemOnPacket(offhand ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND, bhr, id));
454
                mc.player.swing(offhand ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND);
455
            } else {
456
                anchorResult.switchTo();
457
                sendSequencedPacket(id -> new ServerboundUseItemOnPacket(InteractionHand.MAIN_HAND, bhr, id));
458
                mc.player.swing(InteractionHand.MAIN_HAND);
459
            }
460
        } else {
461
            if (mc.player.isShiftKeyDown())
462
                sendPacket(new net.minecraft.network.protocol.game.ServerboundPlayerInputPacket(new net.minecraft.world.entity.player.Input(false, false, false, false, false, false, false)));
463
            sendSequencedPacket(id -> new ServerboundUseItemOnPacket(offhand ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND, bhr, id));
464
            mc.player.swing(offhand ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND);
465
466
            anchorResult.switchTo();
467
            sendSequencedPacket(id -> new ServerboundUseItemOnPacket(InteractionHand.MAIN_HAND, bhr, id));
468
            mc.player.swing(InteractionHand.MAIN_HAND);
469
        }
470
471
        breakTimer.reset();
472
473
        postPlaceSwitch(prevSlot);
474
    }
475
476
    private int switchTo(SearchInvResult result, SearchInvResult resultInv, @NotNull Setting<Switch> switchMode) {
477
        if (mc.player == null || mc.level == null || mc.gameMode == null) return -1;
478
479
        int prevSlot = mc.player.getInventory().getSelectedSlot();
480
481
        switch (switchMode.getValue()) {
482
            case INVENTORY -> {
483
                if (resultInv.found()) {
484
                    prevSlot = resultInv.slot();
485
                    mc.gameMode.handleContainerInput(mc.player.containerMenu.containerId, prevSlot, mc.player.getInventory().getSelectedSlot(), ContainerInput.SWAP, mc.player);
486
                    sendPacket(new ServerboundContainerClosePacket(mc.player.containerMenu.containerId));
487
                }
488
            }
489
            case NORMAL -> result.switchTo();
490
            case SILENT -> result.switchToSilent();
491
            case NONE -> {
492
            }
493
        }
494
        return prevSlot;
495
    }
496
497
    public void placeAnchor(PlaceData data, boolean instant) {
498
        if (shouldPause() || mc.player == null || data.anchor()) return;
499
        int prevSlot = -1;
500
501
        SearchInvResult anchorResult = InventoryUtility.findItemInHotBar(Items.RESPAWN_ANCHOR);
502
        SearchInvResult anchorInvResult = InventoryUtility.findItemInInventory(Items.RESPAWN_ANCHOR);
503
504
        boolean offhand = mc.player.getOffhandItem().getItem() == Items.RESPAWN_ANCHOR;
505
        boolean holdingAnchor = mc.player.getMainHandItem().getItem() == Items.RESPAWN_ANCHOR || offhand;
506
507
        if (rotate.getValue()) {
508
            if (instant) {
509
                float[] angle = InteractionUtility.calculateAngle(data.bhr().getLocation());
510
                sendPacket(new ServerboundMovePlayerPacket.PosRot(mc.player.getX(), mc.player.getY(), mc.player.getZ(), angle[0], angle[1], mc.player.onGround(), mc.player.horizontalCollision));
511
            } else if (!rotated)
512
                return;
513
        }
514
515
        if (autoSwitch.getValue() != Switch.NONE && !holdingAnchor)
516
            prevSlot = switchTo(anchorResult, anchorInvResult, autoSwitch);
517
518
        if (!(mc.player.getMainHandItem().getItem() == Items.RESPAWN_ANCHOR || offhand || autoSwitch.getValue() == Switch.SILENT))
519
            return;
520
521
        sendSequencedPacket(id -> new ServerboundUseItemOnPacket(offhand ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND, data.bhr(), id));
522
523
        mc.player.swing(offhand ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND);
524
        placeTimer.reset();
525
526
        if (!data.bp().equals(renderPos)) {
527
            renderMultiplier = System.currentTimeMillis();
528
            prevRenderPos = renderPos;
529
            renderPos = data.bp();
530
        }
531
532
        //if (!placedAnchors.containsKey(data.bp()))
533
        //placedAnchors.put(data.bp(), System.currentTimeMillis());
534
535
        renderPositions.put(data.bp(), System.currentTimeMillis());
536
537
        if (ak47.is(AK47.ON)) {
538
            BlockHitResult placeResult = getInteractResult(data.bp);
539
            if (placeResult != null)
540
                explodeAnchor(placeResult);
541
        }
542
543
        postPlaceSwitch(prevSlot);
544
    }
545
546
    private void postPlaceSwitch(int slot) {
547
        if (mc.player == null || mc.level == null || mc.gameMode == null) return;
548
549
        if (autoSwitch.getValue() == Switch.SILENT )
550
            InventoryUtility.switchTo(slot);
551
552
        if (autoSwitch.getValue() == Switch.INVENTORY && slot != -1) {
553
            mc.gameMode.handleContainerInput(mc.player.containerMenu.containerId, slot, mc.player.getInventory().getSelectedSlot(), ContainerInput.SWAP, mc.player);
554
            sendPacket(new ServerboundContainerClosePacket(mc.player.containerMenu.containerId));
555
        }
556
    }
557
558
    public void calcPosition(List<PlaceData> blocks) {
559
        if (mc.player == null || mc.level == null) return;
560
        if (target == null) {
561
            renderPos = null;
562
            prevRenderPos = null;
563
            bestPosition = null;
564
            return;
565
        }
566
        List<PlaceData> list = blocks.stream().filter(data -> isSafe(data.damage, data.selfDamage, data.overrideDamage)).toList();
567
        bestPosition = list.isEmpty() ? null : filterPositions(list);
568
    }
569
570
    private @NotNull List<PlaceData> getPossibleBlocks(Player target, Vec3 center, float range) {
571
        List<PlaceData> blocks = new ArrayList<>();
572
        BlockPos playerPos = BlockPos.containing(center);
573
574
        for (int x = (int) Math.floor(playerPos.getX() - range); x <= Math.ceil(playerPos.getX() + range); x++) {
575
            for (int y = (int) Math.floor(playerPos.getY() - range); y <= Math.ceil(playerPos.getY() + range); y++) {
576
                for (int z = (int) Math.floor(playerPos.getZ() - range); z <= Math.ceil(playerPos.getZ() + range); z++) {
577
                    PlaceData data = getPlaceData(new BlockPos(x, y, z), target);
578
                    if (data != null)
579
                        blocks.add(data);
580
                }
581
            }
582
        }
583
584
        return blocks;
585
    }
586
587
    public void getAnchorToExplode(List<PlaceData> blocks) {
588
        if (target == null) {
589
            bestAnchor = null;
590
            return;
591
        }
592
593
        List<PlaceData> list = blocks.stream().filter(data -> isSafe(data.damage, data.selfDamage, data.overrideDamage) && data.anchor()).toList();
594
        bestAnchor = list.isEmpty() ? null : filterAnchors(list);
595
    }
596
597
    public boolean isSafe(float damage, float selfDamage, boolean overrideDamage) {
598
        if (mc.player == null || mc.level == null) return false;
599
600
        if (overrideDamage)
601
            return true;
602
603
        if (selfDamage + 0.5 > mc.player.getHealth() + mc.player.getAbsorptionAmount()) return false;
604
        else if (safety.getValue() == Safety.STABLE) return damage - selfDamage > 0;
605
        else if (safety.getValue() == Safety.BALANCE) return (damage * safetyBalance.getValue()) - selfDamage > 0;
606
        return true;
607
    }
608
609
    private @Nullable PlaceData filterPositions(@NotNull List<PlaceData> clearedList) {
610
        PlaceData bestData = null;
611
612
        float bestVal = 0f;
613
        for (PlaceData data : clearedList) {
614
            if ((shouldOverride(data.damage) || data.damage > minDamage.getValue())) {
615
                if (sort.getValue() == Sort.DAMAGE) {
616
                    if (bestVal < data.damage) {
617
                        bestData = data;
618
                        bestVal = data.damage;
619
                    }
620
                } else {
621
                    if (bestVal < data.damage / data.selfDamage) {
622
                        bestData = data;
623
                        bestVal = data.damage / data.selfDamage;
624
                    }
625
                }
626
            }
627
        }
628
629
        if (bestData == null) return null;
630
        facePlacing = bestData.damage < minDamage.getValue();
631
        renderDamage = bestData.damage;
632
        renderSelfDamage = bestData.selfDamage;
633
        return bestData;
634
    }
635
636
    public boolean shouldOverride(float damage) {
637
        if (target == null) return false;
638
639
        boolean override = target.getHealth() + target.getAbsorptionAmount() <= facePlaceHp.getValue();
640
641
        if (armorBreaker.getValue().isEnabled())
642
            for (ItemStack armor : thunder.hack.utility.player.ArmorUtility.getArmorItems(target))
643
                if (armor != null && !armor.getItem().equals(Items.AIR) && ((armor.getMaxDamage() - armor.getDamageValue()) / (float) armor.getMaxDamage()) * 100 < armorScale.getValue()) {
644
                    override = true;
645
                    break;
646
                }
647
648
        if (facePlaceButton.getValue().getKey() != -1 && InputConstants.isKeyDown(mc.getWindow(), facePlaceButton.getValue().getKey()))
649
            override = true;
650
651
        if ((target.getHealth() + target.getAbsorptionAmount()) - (damage * lethalMultiplier.getValue()) < 0.5)
652
            override = true;
653
654
        return override;
655
    }
656
657
    private @Nullable BlockHitResult filterAnchors(@NotNull List<PlaceData> clearedList) {
658
        PlaceData bestData = null;
659
        float bestVal = 0f;
660
        for (PlaceData data : clearedList) {
661
            if ((shouldOverride(data.damage) || data.damage > minDamage.getValue())) {
662
                if (sort.getValue() == Sort.DAMAGE) {
663
                    if (bestVal < data.damage) {
664
                        bestData = data;
665
                        bestVal = data.damage;
666
                    }
667
                } else {
668
                    if (bestVal < data.damage / data.selfDamage) {
669
                        bestData = data;
670
                        bestVal = data.damage / data.selfDamage;
671
                    }
672
                }
673
            }
674
        }
675
676
        if (bestData == null) return null;
677
        renderDamage = bestData.damage;
678
        renderSelfDamage = bestData.selfDamage;
679
        return bestData.bhr;
680
    }
681
682
    public @Nullable PlaceData getPlaceData(BlockPos bp, Player target) {
683
        if (mc.player == null || mc.level == null)
684
            return null;
685
686
        if (target != null && target.position().distanceToSqr(net.minecraft.world.phys.Vec3.atBottomCenterOf(bp)) > 144)
687
            return null;
688
689
        BlockState state = mc.level.getBlockState(bp);
690
        boolean isAnchor = state.getBlock() instanceof RespawnAnchorBlock;
691
692
        if (!state.canBeReplaced() && !isAnchor)
693
            return null;
694
695
        if (isAnchor)
696
            mc.level.setBlockAndUpdate(bp, Blocks.AIR.defaultBlockState());
697
698
        BlockHitResult placeResult = InteractionUtility.getPlaceResult(bp, interact.getValue(), false);
699
700
        if (placeResult == null) {
701
            if (isAnchor)
702
                mc.level.setBlockAndUpdate(bp, state);
703
            return null;
704
        }
705
706
        float damage = target == null ? 10f : ExplosionUtility.getAutoCrystalDamage(net.minecraft.world.phys.Vec3.atBottomCenterOf(bp), target, predictTicks.getValue(), useOptimizedCalc.getValue());
707
        if (damage < 1.5f) {
708
            if (isAnchor)
709
                mc.level.setBlockAndUpdate(bp, state);
710
            return null;
711
        }
712
713
        float selfDamage = ExplosionUtility.getAutoCrystalDamage(net.minecraft.world.phys.Vec3.atBottomCenterOf(bp), mc.player, selfPredictTicks.getValue(), useOptimizedCalc.getValue());
714
        boolean overrideDamage = shouldOverrideDamage(damage, selfDamage);
715
716
        if (protectFriends.getValue()) {
717
            List<Player> players = Lists.newArrayList(mc.level.players());
718
            for (Player pl : players) {
719
                if (!Managers.FRIEND.isFriend(pl)) continue;
720
                float fdamage = ExplosionUtility.getAutoCrystalDamage(net.minecraft.world.phys.Vec3.atBottomCenterOf(bp), pl, selfPredictTicks.getValue(), useOptimizedCalc.getValue());
721
                if (fdamage > selfDamage) {
722
                    selfDamage = fdamage;
723
                }
724
            }
725
        }
726
727
        if (isAnchor) {
728
            mc.level.setBlockAndUpdate(bp, state);
729
            placeResult = getInteractResult(bp);
730
        }
731
732
        if (placeResult == null)
733
            return null;
734
735
        if (selfDamage > maxSelfDamage.getValue() && !overrideDamage) return null;
736
737
        return new PlaceData(placeResult, bp, damage, selfDamage, overrideDamage, isAnchor);
738
    }
739
740
    public boolean shouldOverrideDamage(float damage, float selfDamage) {
741
        if (overrideSelfDamage.getValue() && target != null) {
742
            if (mc.player == null || mc.level == null) return false;
743
744
            boolean targetSafe = (target.getOffhandItem().getItem() == Items.TOTEM_OF_UNDYING
745
                    || target.getMainHandItem().getItem() == Items.TOTEM_OF_UNDYING);
746
747
            boolean playerSafe = (mc.player.getOffhandItem().getItem() == Items.TOTEM_OF_UNDYING
748
                    || mc.player.getMainHandItem().getItem() == Items.TOTEM_OF_UNDYING);
749
750
            float targetHp = target.getHealth() + target.getAbsorptionAmount() - 1f;
751
752
            float playerHp = mc.player.getHealth() + mc.player.getAbsorptionAmount() - 1f;
753
754
            boolean canPop = damage > targetHp && targetSafe;
755
756
            boolean canKill = damage > targetHp && !targetSafe;
757
758
            boolean canPopSelf = selfDamage > playerHp && playerSafe;
759
760
            boolean canKillSelf = selfDamage > playerHp && !playerSafe;
761
762
            if (canPopSelf && canKill)
763
                return true;
764
765
            return selfDamage > maxSelfDamage.getValue() && (canPop || canKill) && !canKillSelf && !canPopSelf;
766
        }
767
        return false;
768
    }
769
770
    public BlockHitResult getInteractResult(BlockPos bp) {
771
        BlockHitResult interactResult = null;
772
        switch (interact.getValue()) {
773
            case Vanilla, AirPlace -> interactResult = getDefaultInteract(bp);
774
            case Strict -> interactResult = getStrictInteract(bp);
775
            case Legit -> interactResult = getLegitInteract(bp);
776
        }
777
        return interactResult;
778
    }
779
780
    private @Nullable BlockHitResult getDefaultInteract(BlockPos bp) {
781
        if (mc.player == null || mc.level == null) return null;
782
783
        Vec3 vec = net.minecraft.world.phys.Vec3.atBottomCenterOf(bp).add(0, -0.5, 0);
784
785
        if (PlayerUtility.squaredDistanceFromEyes(vec) > placeRange.getPow2Value())
786
            return null;
787
788
        BlockHitResult wallCheck = mc.level.clip(new ClipContext(InteractionUtility.getEyesPos(mc.player), vec, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player));
789
790
        if (wallCheck != null && wallCheck.getType() == HitResult.Type.BLOCK && wallCheck.getBlockPos() != bp)
791
            if (PlayerUtility.squaredDistanceFromEyes(vec) > placeWallRange.getPow2Value())
792
                return null;
793
794
        return new BlockHitResult(vec, mc.level.isInWorldBounds(bp.above()) ? Direction.UP : Direction.DOWN, bp, false);
795
    }
796
797
    public BlockHitResult getStrictInteract(@NotNull BlockPos bp) {
798
        if (mc.player == null || mc.level == null) return null;
799
800
        float bestDistance = Float.MAX_VALUE;
801
        Direction bestDirection = null;
802
        Vec3 bestVector = null;
803
804
        float upPoint = bp.above().getY();
805
806
        if (mc.player.getEyePosition().y() > upPoint) {
807
            bestDirection = Direction.UP;
808
            bestVector = new Vec3(bp.getX() + 0.5, bp.getY() + 1, bp.getZ() + 0.5);
809
        } else if (mc.player.getEyePosition().y() < bp.getY() && mc.level.isEmptyBlock(bp.below())) {
810
            bestDirection = Direction.DOWN;
811
            bestVector = new Vec3(bp.getX() + 0.5, bp.getY(), bp.getZ() + 0.5);
812
        } else {
813
            for (Direction dir : InteractionUtility.getStrictBlockDirections(bp)) {
814
                if (dir == Direction.UP || dir == Direction.DOWN)
815
                    continue;
816
817
                Vec3 directionVec = new Vec3(bp.getX() + 0.5 + dir.getUnitVec3i().getX() * 0.5, bp.getY() + 0.9, bp.getZ() + 0.5 + dir.getUnitVec3i().getZ() * 0.5);
818
819
                if (!mc.level.isEmptyBlock(bp.relative(dir)))
820
                    continue;
821
822
                float distance = PlayerUtility.squaredDistanceFromEyes(directionVec);
823
                if (bestDistance > distance) {
824
                    bestDirection = dir;
825
                    bestVector = directionVec;
826
                    bestDistance = distance;
827
                }
828
            }
829
        }
830
831
        if (bestVector == null) return null;
832
833
        if (PlayerUtility.squaredDistanceFromEyes(bestVector) > placeRange.getPow2Value())
834
            return null;
835
836
        BlockHitResult wallCheck = mc.level.clip(new ClipContext(InteractionUtility.getEyesPos(mc.player), bestVector, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player));
837
838
        if (wallCheck != null && wallCheck.getType() == HitResult.Type.BLOCK && wallCheck.getBlockPos() != bp)
839
            if (PlayerUtility.squaredDistanceFromEyes(bestVector) > placeWallRange.getPow2Value())
840
                return null;
841
842
        return new BlockHitResult(bestVector, bestDirection, bp, false);
843
    }
844
845
    public BlockHitResult getLegitInteract(BlockPos bp) {
846
        if (mc.player == null || mc.level == null) return null;
847
848
        float bestDistance = Float.MAX_VALUE;
849
        BlockHitResult bestResult = null;
850
        for (float x = 0f; x <= 1f; x += 0.2f) {
851
            for (float y = 0f; y <= 1f; y += 0.2f) {
852
                for (float z = 0f; z <= 1f; z += 0.2f) {
853
                    Vec3 point = new Vec3(bp.getX() + x, bp.getY() + y, bp.getZ() + z);
854
                    float distance = PlayerUtility.squaredDistanceFromEyes(point);
855
856
                    BlockHitResult wallCheck = mc.level.clip(new ClipContext(InteractionUtility.getEyesPos(mc.player), point, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player));
857
                    if (wallCheck != null && wallCheck.getType() == HitResult.Type.BLOCK && wallCheck.getBlockPos() != bp)
858
                        if (distance > placeWallRange.getPow2Value())
859
                            continue;
860
861
862
                    BlockHitResult result = ExplosionUtility.rayCastBlock(new ClipContext(InteractionUtility.getEyesPos(mc.player), point, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player), bp);
863
                    if (distance > placeRange.getPow2Value())
864
                        continue;
865
866
                    if (distance < bestDistance) {
867
                        if (result != null && result.getType() == HitResult.Type.BLOCK) {
868
                            bestResult = result;
869
                            bestDistance = distance;
870
                        }
871
                    }
872
                }
873
            }
874
        }
875
        return bestResult;
876
    }
877
878
    public void pause() {
879
        pauseTimer.reset();
880
    }
881
882
    public record PlaceData(BlockHitResult bhr, BlockPos bp, float damage, float selfDamage, boolean overrideDamage,
883
                            boolean anchor) {
884
    }
885
886
    private enum Pages {
887
        Place, Break, Pause, Render, Damages, Main, Switch, Info
888
    }
889
890
    private enum Switch {
891
        NONE, NORMAL, SILENT, INVENTORY
892
    }
893
894
    private enum Timing {
895
        NORMAL, SEQUENTIAL
896
    }
897
898
    public enum Safety {
899
        BALANCE, STABLE, NONE
900
    }
901
902
    public enum Sort {
903
        SAFE, DAMAGE
904
    }
905
906
    public enum Render {
907
        Fade, Slide, Default
908
    }
909
910
    public enum AK47 {
911
        OFF, ON, SEMI
912
    }
913
}
CombatantCOMBATsrc/main/java/combatant/client/features/module/modules/combat/AutoAnchor.javaJava · 1,174 lines · 45.3 KB
SettingsautoanchorPlaceautoanchorExplodeautoanchorTimingautoanchorCalcDelayautoanchorPlaceDelayautoanchorLowPlaceDelayautoanchorExplodeDelayautoanchorLowExplodeDelayautoanchorPlaceRangeautoanchorWallRangeautoanchorPlacementModeautoanchorAirPlaceautoanchorTargetRangeautoanchorTargetsautoanchorPriorityautoanchorMinDamageautoanchorFaceplaceHealthautoanchorMaxSelfDamageautoanchorPredictTicksautoanchorSelfPredictTicksautoanchorUnsafeDimensionOnlyautoanchorPauseMiningautoanchorPauseEatingautoanchorPauseHealthautoanchorSwapScopeautoanchorSwapVisibilityautoanchorRestoreItemautoanchorAttackModeautoanchorMovementCorrectionautoanchorRotationResetTicksautoanchorRotationResetThresholdautoanchorRenderautoanchorRenderModeautoanchorRenderSelfDamageautoanchorRenderDamageautoanchorFillColorautoanchorLineColorautoanchorLineWidthautoanchorTextColorautoanchorBillboardSize
AutoAnchor.javaJava · Minecraft 26.2 · 1,174 lines · 45.3 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Combatant Client distribution.
3
 * Copyright (c) 2026 pivosos2007.
4
 *
5
 * Licensed under the GNU General Public License v3.0.
6
 */
7
8
package combatant.client.features.module.modules.combat;
9
10
import combatant.client.render.engine.text.BuiltinFontCatalog;
11
import combatant.client.config.common.CommonSettingSchemas;
12
import combatant.client.config.common.impl.TargetFilters;
13
import combatant.client.config.values.*;
14
import combatant.client.events.EventHandler;
15
import combatant.client.events.impl.RotationUpdateEvent;
16
import combatant.client.features.module.Module;
17
import combatant.client.features.module.ModuleCategory;
18
import combatant.client.features.module.ModuleInfo;
19
import combatant.client.features.module.WorldPhase;
20
import combatant.client.features.module.modules.combat.autoanchor.*;
21
import combatant.client.render.engine.RenderState;
22
import combatant.client.render.engine.color.RenderColor;
23
import combatant.client.render.engine.renderer.Renderer3D;
24
import combatant.client.render.engine.text.TextRenderer;
25
import combatant.client.render.engine.text.WorldTextRenderer;
26
import combatant.client.render.engine.world.WorldUiPresentationService;
27
import combatant.client.util.aiming.RestrictedSingleUseAction;
28
import combatant.client.util.aiming.RotationManager;
29
import combatant.client.util.aiming.RotationTarget;
30
import combatant.client.util.aiming.data.Rotation;
31
import combatant.client.util.aiming.features.MovementCorrection;
32
import combatant.client.util.combat.CombatRotationModeUtil;
33
import combatant.client.util.combat.CombatEntityQuery;
34
import combatant.client.util.combat.ExplosionDamageRules;
35
import combatant.client.util.combat.ExplosionRenderUtil;
36
import combatant.client.util.combat.RubberHandUseUtil;
37
import combatant.client.util.item.FoodUtil;
38
import combatant.client.util.entity.simulation.PositionExtrapolation;
39
import combatant.client.util.player.inventory.InventorySearchScope;
40
import combatant.client.util.player.inventory.InventorySwap;
41
import combatant.client.util.player.inventory.InventorySwapVisibility;
42
import combatant.client.util.player.simulation.PlayerSimulationCache;
43
import combatant.client.util.target.TargetManager;
44
import combatant.client.util.target.TargetingUtil;
45
import net.minecraft.client.Minecraft;
46
import net.minecraft.client.multiplayer.ClientLevel;
47
import net.minecraft.client.player.LocalPlayer;
48
import net.minecraft.core.BlockPos;
49
import net.minecraft.util.Mth;
50
import net.minecraft.world.entity.LivingEntity;
51
import net.minecraft.world.entity.player.Player;
52
import net.minecraft.world.level.Level;
53
import net.minecraft.world.level.block.Blocks;
54
import net.minecraft.world.level.block.RespawnAnchorBlock;
55
import net.minecraft.world.level.block.state.BlockState;
56
import net.minecraft.world.phys.AABB;
57
import net.minecraft.world.phys.BlockHitResult;
58
import net.minecraft.world.phys.Vec3;
59
60
import java.util.ArrayList;
61
import java.util.List;
62
import java.util.Map;
63
import java.util.concurrent.ConcurrentHashMap;
64
@ModuleInfo(
65
        id = "autoanchor",
66
        displayName = "AutoAnchor",
67
        aliases = {"AnchorAura", "Anchor"},
68
        category = ModuleCategory.COMBAT,
69
        description = "module.autoanchor.description"
70
)
71
public class AutoAnchor extends Module {
72
    private static final int ROTATION_PRIORITY = 34;
73
    private static final long DAMAGE_RESET_MS = 1000L;
74
    private static final long PENDING_ANCHOR_PLACE_CONFIRM_TIMEOUT_MS = 2500L;
75
    private static final long PENDING_ANCHOR_ACTION_CONFIRM_TIMEOUT_MS = 750L;
76
    private static final double TEXT_Y_OFFSET = 0.10;
77
    private static final double TEXT_WORLD_SCALE = 0.025;
78
    private static final double TEXT_SCALE = 1.0;
79
    private static final double TEXT_GAP_SCALE = 1.0;
80
    private final Minecraft mc = Minecraft.getInstance();
81
82
    private final BooleanValue placeEnabled = boolCommon("autoanchorPlace", CommonSettingSchemas.PLACE, true);
83
    private final BooleanValue explodeEnabled = boolCommon("autoanchorExplode", CommonSettingSchemas.EXPLODE, true);
84
    private final EnumValue<Timing> timing = enumCommon("autoanchorTiming", "timing", CommonSettingSchemas.TIMING, Timing.NORMAL);
85
    private final NumberValue<Integer> calcDelay = numCommon("autoanchorCalcDelay", "calc_delay", CommonSettingSchemas.CALC_DELAY, 100, 0, 500);
86
    private final NumberValue<Integer> placeDelay = numCommon(
87
            "autoanchorPlaceDelay",
88
            "place_delay",
89
            CommonSettingSchemas.PLACEMENT_DELAY,
90
            0,
91
            0,
92
            1000
93
    );
94
    private final NumberValue<Integer> lowPlaceDelay = numCommon("autoanchorLowPlaceDelay", "low_place_delay", CommonSettingSchemas.LOW_PLACE_DELAY, 550, 0, 1000);
95
    private final NumberValue<Integer> explodeDelay = numCommon(
96
            "autoanchorExplodeDelay",
97
            "explode_delay",
98
            CommonSettingSchemas.PLACEMENT_BREAK_DELAY,
99
            0,
100
            0,
101
            1000
102
    );
103
    private final NumberValue<Integer> lowExplodeDelay = numCommon("autoanchorLowExplodeDelay", "low_explode_delay", CommonSettingSchemas.LOW_EXPLODE_DELAY, 550, 0, 1000);
104
    private final NumberValue<Float> placeRange = numCommon(
105
            "autoanchorPlaceRange",
106
            "place_range",
107
            CommonSettingSchemas.PLACEMENT_RANGE,
108
            5.0f,
109
            1.0f,
110
            6.0f
111
    );
112
    private final NumberValue<Float> wallRange = numCommon(
113
            "autoanchorWallRange",
114
            "wall_range",
115
            CommonSettingSchemas.PLACEMENT_WALL_RANGE,
116
            3.5f,
117
            0.0f,
118
            6.0f
119
    );
120
    private final EnumValue<AutoAnchorPlacementMode> placementMode = enumCommon(
121
            "autoanchorPlacementMode",
122
            "placement_mode",
123
            CommonSettingSchemas.PLACEMENT_MODE,
124
            AutoAnchorPlacementMode.DEFAULT,
125
            AutoAnchorPlacementMode.values()
126
    );
127
    private final BooleanValue airPlace = boolCommon("autoanchorAirPlace", "air_place", CommonSettingSchemas.AIR_PLACE, false);
128
    private final NumberValue<Float> targetRange = numCommon(
129
            "autoanchorTargetRange",
130
            "target_range",
131
            CommonSettingSchemas.COMBAT_RANGE,
132
            10.0f,
133
            1.0f,
134
            15.0f
135
    );
136
    private final BooleanMapValue targetToggles = groupCommon(
137
            "autoanchorTargets",
138
            "targets",
139
            CommonSettingSchemas.TARGET_FILTERS
140
    );
141
    private final EnumValue<TargetingUtil.TargetPriority> priority = enumCommon(
142
            "autoanchorPriority",
143
            "priority",
144
            CommonSettingSchemas.COMBAT_PRIORITY,
145
            TargetingUtil.TargetPriority.DISTANCE,
146
            TargetingUtil.TargetPriority.values()
147
    );
148
    private final NumberValue<Float> minDamage = numCommon("autoanchorMinDamage", "min_damage", CommonSettingSchemas.MIN_DAMAGE, 6.0f, 0.0f, 36.0f);
149
    private final NumberValue<Float> faceplaceHealth = numCommon("autoanchorFaceplaceHealth", "faceplace_health", CommonSettingSchemas.FACEPLACE_HEALTH, 5.0f, 0.0f, 36.0f);
150
    private final NumberValue<Float> maxSelfDamage = numCommon("autoanchorMaxSelfDamage", "max_self_damage", CommonSettingSchemas.MAX_SELF_DAMAGE, 10.0f, 0.0f, 36.0f);
151
    private final NumberValue<Integer> predictTicks = numCommon(
152
            "autoanchorPredictTicks",
153
            "predict_ticks",
154
            CommonSettingSchemas.PLACEMENT_PREDICTION,
155
            3,
156
            0,
157
            20
158
    );
159
    private final NumberValue<Integer> selfPredictTicks = numCommon("autoanchorSelfPredictTicks", "self_predict_ticks", CommonSettingSchemas.SELF_PREDICT_TICKS, 3, 0, 20);
160
    private final BooleanValue unsafeDimensionOnly = boolCommon("autoanchorUnsafeDimensionOnly", "unsafe_dimension_only", CommonSettingSchemas.UNSAFE_DIMENSION_ONLY, true);
161
    private final BooleanValue pauseMining = boolCommon("autoanchorPauseMining", "pause_mining", CommonSettingSchemas.PAUSE_MINING, true);
162
    private final BooleanValue pauseEating = boolCommon("autoanchorPauseEating", "pause_eating", CommonSettingSchemas.PAUSE_EATING, true);
163
    private final NumberValue<Float> pauseHealth = numCommon(
164
            "autoanchorPauseHealth",
165
            "pause_health",
166
            CommonSettingSchemas.PLAYER_HEALTH_THRESHOLD,
167
            8.0f,
168
            0.0f,
169
            20.0f
170
    );
171
    private final EnumValue<InventorySearchScope> swapScope = enumCommon(
172
            "autoanchorSwapScope",
173
            "swap_scope",
174
            CommonSettingSchemas.INVENTORY_SEARCH_SCOPE,
175
            InventorySearchScope.FULL,
176
            InventorySearchScope.values()
177
    );
178
    private final EnumValue<InventorySwapVisibility> swapVisibility = enumCommon(
179
            "autoanchorSwapVisibility",
180
            "swap_visibility",
181
            CommonSettingSchemas.INVENTORY_SWAP_VISIBILITY,
182
            InventorySwapVisibility.SILENT,
183
            InventorySwapVisibility.values()
184
    );
185
    private final BooleanValue restoreItem = boolCommon(
186
            "autoanchorRestoreItem",
187
            "restore_item",
188
            CommonSettingSchemas.INVENTORY_RESTORE_ITEM,
189
            true
190
    );
191
    private final ModeValue attackMode = modeCommon(
192
            "autoanchorAttackMode",
193
            "attack_mode",
194
            CommonSettingSchemas.COMBAT_ATTACK_MODE,
195
            CombatRotationModeUtil.MODE_ROTATIONS,
196
            CombatRotationModeUtil.MODE_ROTATIONS,
197
            CombatRotationModeUtil.MODE_NO_ROTATIONS
198
    );
199
    private final EnumValue<MovementCorrection> movementCorrection = visibleWhen(enumCommon(
200
            "autoanchorMovementCorrection",
201
            "movement_correction",
202
            CommonSettingSchemas.PLACEMENT_MOVEMENT_CORRECTION,
203
            MovementCorrection.SILENT,
204
            MovementCorrection.values()
205
    ), this::usesRotationSettings);
206
    private final NumberValue<Integer> rotationResetTicks = visibleWhen(numCommon(
207
            "autoanchorRotationResetTicks",
208
            "rotation_reset_ticks",
209
            CommonSettingSchemas.ROTATION_RESET_TICKS,
210
            1,
211
            1,
212
            20
213
    ), this::usesRotationSettings);
214
    private final NumberValue<Float> rotationResetThreshold = visibleWhen(numCommon(
215
            "autoanchorRotationResetThreshold",
216
            "rotation_reset_threshold",
217
            CommonSettingSchemas.ROTATION_RESET_THRESHOLD,
218
            2.0f,
219
            0.1f,
220
            15.0f
221
    ), this::usesRotationSettings);
222
    private final BooleanValue renderEnabled = boolCommon(
223
            "autoanchorRender",
224
            "render",
225
            CommonSettingSchemas.PLACEMENT_RENDER,
226
            true
227
    );
228
    private final EnumValue<RenderMode> renderMode = enumCommon(
229
            "autoanchorRenderMode",
230
            "render_mode",
231
            CommonSettingSchemas.PLACEMENT_RENDER_MODE,
232
            RenderMode.FADE,
233
            RenderMode.values()
234
    );
235
    private final BooleanValue renderSelfDamage = boolCommon("autoanchorRenderSelfDamage", CommonSettingSchemas.RENDER_SELF_DAMAGE, true);
236
    private final BooleanValue drawDamage = boolCommon("autoanchorRenderDamage", CommonSettingSchemas.RENDER_DAMAGE, true);
237
    private final RGBAColorValue fillColor = common(color("autoanchorFillColor", "#5A285AFF"), CommonSettingSchemas.FILL_COLOR);
238
    private final RGBAColorValue lineColor = common(color("autoanchorLineColor", "#FFAA55FF"), CommonSettingSchemas.LINE_COLOR);
239
    private final NumberValue<Float> lineWidth = numCommon("autoanchorLineWidth", CommonSettingSchemas.LINE_WIDTH, 2.0f, 1.0f, 6.0f);
240
    private final RGBAColorValue textColor = common(color("autoanchorTextColor", "#FFFFFFFF"), CommonSettingSchemas.TEXT_COLOR);
241
    private final NumberValue<Float> billboardSize = visibleWhen(numCommon(
242
            "autoanchorBillboardSize", "billboard_size", CommonSettingSchemas.BILLBOARD_SIZE, 0.72f, 0.35f, 1.50f),
243
            drawDamage::get);
244
    private final BooleanValue billboardDynamicScale = visibleWhen(boolCommon(
245
            "autoanchorBillboardDynamicScale", "billboard_dynamic_scale", CommonSettingSchemas.BILLBOARD_DYNAMIC_SCALE, true),
246
            drawDamage::get);
247
    private final NumberValue<Float> billboardDynamicScaleCoefficient = visibleWhen(numCommon(
248
            "autoanchorBillboardDynamicScaleCoefficient", "billboard_dynamic_scale_coefficient",
249
            CommonSettingSchemas.BILLBOARD_DYNAMIC_SCALE_COEFFICIENT, 0.25f, 0.0f, 1.0f),
250
            () -> drawDamage.get() && billboardDynamicScale.get());
251
    private final NumberValue<Integer> slideDelay = visibleWhen(numCommon("autoanchorSlideDelay", CommonSettingSchemas.SLIDE_DELAY, 200, 1, 1000),
252
            () -> renderMode.get() == RenderMode.SLIDE);
253
    private final NumberValue<Integer> fadeTime = visibleWhen(numCommon("autoanchorFadeTime", CommonSettingSchemas.FADE_TIME, 500, 100, 2000),
254
            () -> renderMode.get() == RenderMode.FADE);
255
256
    private final AutoAnchorPlanner planner = new AutoAnchorPlanner();
257
    private final AutoAnchorPlanner.Context plannerContext = new PlannerContext();
258
    private final Map<BlockPos, Long> renderPositions = new ConcurrentHashMap<>();
259
260
    private LivingEntity target;
261
    private AutoAnchorData bestPlace;
262
    private AutoAnchorData bestExplode;
263
    private BlockPos renderPos;
264
    private BlockPos prevRenderPos;
265
    private BlockPos bestPosition;
266
    private int renderTick;
267
    private int renderStartTick;
268
    private long lastPlaceMs;
269
    private long lastExplodeMs;
270
    private long lastDamageUpdateMs;
271
    private long lastCalcMs;
272
    private BlockPos pendingAnchorPos;
273
    private AutoAnchorData pendingAnchorData;
274
    private PendingAnchorPhase pendingAnchorPhase;
275
    private long pendingAnchorActionMs;
276
    private float renderDamage;
277
    private float renderSelfDamageValue;
278
    private boolean lowDamageMode;
279
    private int lastScanned;
280
    private int lastCandidates;
281
    private int lastSafeCandidates;
282
    private int lastSelfDamageRejects;
283
284
    @Override
285
    public WorldPhase getWorldPhase() {
286
        return WorldPhase.AFTER_POST_PROCESS;
287
    }
288
289
    @Override
290
    public void onEnable() {
291
        resetState();
292
    }
293
294
    @Override
295
    public void onDisable() {
296
        resetState();
297
        RotationManager.INSTANCE.clear(this);
298
        TargetManager.setAutoAnchorTarget(null);
299
    }
300
301
    @Override
302
    public void onTick() {
303
        if (!isEnabled()) return;
304
        renderTick++;
305
        InventorySwap.INSTANCE.tick();
306
        purgeExpiredRenderPositions();
307
        if (System.currentTimeMillis() - lastDamageUpdateMs > DAMAGE_RESET_MS && renderPositions.isEmpty()) {
308
            renderDamage = 0.0f;
309
            renderSelfDamageValue = 0.0f;
310
        }
311
    }
312
313
    @EventHandler(priority = 24)
314
    private void onRotationUpdate(RotationUpdateEvent event) {
315
        if (event.getType() != RotationUpdateEvent.Type.PRE) {
316
            return;
317
        }
318
        if (!isEnabled()) return;
319
320
        if (mc.player == null || mc.level == null || mc.gameMode == null) {
321
            clearCombatState();
322
            TargetManager.setAutoAnchorTarget(null);
323
            return;
324
        }
325
326
        target = findCombatTarget();
327
        TargetManager.setAutoAnchorTarget(target);
328
        updateCandidates();
329
330
        if (timing.get() == Timing.NORMAL) {
331
            runCombatCycle();
332
        }
333
    }
334
335
    @EventHandler(priority = -24)
336
    private void onRotationUpdatePost(RotationUpdateEvent event) {
337
        if (event.getType() != RotationUpdateEvent.Type.POST) {
338
            return;
339
        }
340
        if (!isEnabled() || timing.get() != Timing.SEQUENTIAL) return;
341
        runCombatCycle();
342
    }
343
344
    @Override
345
    public void onRenderWorldEngine(Renderer3D renderer, Renderer3D depthRenderer, float tickDelta) {
346
        if (!isEnabled() || mc.player == null || mc.level == null) return;
347
        if (renderEnabled.get()) {
348
            renderPlacement(renderer, tickDelta);
349
        }
350
    }
351
352
    private void updateCandidates() {
353
        if (target == null || shouldPause()) {
354
            bestPlace = null;
355
            bestExplode = null;
356
            lastCalcMs = 0L;
357
            return;
358
        }
359
360
        long now = System.currentTimeMillis();
361
        long delay = Math.max(0, calcDelay.get());
362
        if (delay > 0L && now - lastCalcMs < delay) {
363
            return;
364
        }
365
        lastCalcMs = now;
366
367
        AutoAnchorPlanner.ScanResult result = planner.scan(
368
                plannerContext,
369
                target,
370
                resolvePredictedPosition(target, predictTicks.get()),
371
                Mth.ceil(placeRange.get())
372
        );
373
        bestPlace = result.bestPlace();
374
        bestExplode = result.bestExplode();
375
        lastScanned = result.scanned();
376
        lastCandidates = result.candidates();
377
        lastSafeCandidates = result.safeCandidates();
378
        lastSelfDamageRejects = result.selfDamageRejects();
379
380
        AutoAnchorData renderData = bestExplode != null ? bestExplode : bestPlace;
381
        if (renderData != null) {
382
            setRenderCandidate(renderData);
383
            lowDamageMode = !ExplosionDamageRules.shouldOverrideMinDamage(target, renderData.damage(), faceplaceHealth.get())
384
                    && renderData.damage() < minDamage.get();
385
        } else if (renderPositions.isEmpty()) {
386
            bestPosition = null;
387
        }
388
    }
389
390
    private void runCombatCycle() {
391
        if (mc.player == null || mc.level == null || shouldPause()) {
392
            RotationManager.INSTANCE.clear(this);
393
            return;
394
        }
395
396
        if (continuePendingAnchorCycle()) {
397
            return;
398
        }
399
400
        if (target == null) {
401
            RotationManager.INSTANCE.clear(this);
402
            return;
403
        }
404
405
        if (explodeEnabled.get() && bestExplode != null && hasExplodeDelayElapsed()) {
406
            beginPendingAnchor(bestExplode, bestExplode.charges() > 0
407
                    ? PendingAnchorPhase.DETONATING
408
                    : PendingAnchorPhase.CHARGING);
409
            continuePendingAnchorCycle();
410
            return;
411
        }
412
413
        if (placeEnabled.get() && bestPlace != null && hasPlaceDelayElapsed()) {
414
            beginPendingAnchor(bestPlace, PendingAnchorPhase.PLACING);
415
            continuePendingAnchorCycle();
416
            return;
417
        }
418
419
        RotationManager.INSTANCE.clear(this);
420
    }
421
422
    private void executeWithRotation(AutoAnchorData data, Runnable action) {
423
        if (data == null || action == null || mc.player == null) return;
424
        if (!usesRotationSettings()) {
425
            RotationManager.INSTANCE.clear(this);
426
            action.run();
427
            return;
428
        }
429
430
        RotationTarget rotationTarget = new RotationTarget(
431
                Rotation.lookingAt(data.hitResult().getLocation(), mc.player.getEyePosition()).normalize(),
432
                target,
433
                List.of(),
434
                rotationResetTicks.get(),
435
                rotationResetThreshold.get(),
436
                true,
437
                movementCorrection.get(),
438
                new RestrictedSingleUseAction(action)
439
        );
440
        RotationManager.INSTANCE.setRotationTarget(rotationTarget, ROTATION_PRIORITY, this);
441
    }
442
443
    private void placeReservedAnchor(AutoAnchorData data) {
444
        if (data == null || data.pos() == null || data.existingAnchor() || !hasPlaceDelayElapsed() || shouldPause()) {
445
            return;
446
        }
447
        if (!data.pos().equals(pendingAnchorPos) || pendingAnchorPhase != PendingAnchorPhase.PLACING) {
448
            return;
449
        }
450
        if (target == null) {
451
            clearPendingAnchor();
452
            return;
453
        }
454
455
        AutoAnchorData refreshed = planner.evaluate(plannerContext, data.pos(), target);
456
        if (refreshed == null) {
457
            clearPendingAnchor();
458
            return;
459
        }
460
        if (refreshed.existingAnchor()) {
461
            pendingAnchorData = refreshed;
462
            pendingAnchorPhase = refreshed.charges() > 0 ? PendingAnchorPhase.DETONATING : PendingAnchorPhase.CHARGING;
463
            pendingAnchorActionMs = 0L;
464
            return;
465
        }
466
467
        boolean placed = AutoAnchorActionUtil.placeAnchor(
468
                mc,
469
                this,
470
                refreshed.hitResult(),
471
                swapScope.get(),
472
                swapVisibility.get(),
473
                restoreItem.get()
474
        );
475
        if (!placed) return;
476
477
        long now = System.currentTimeMillis();
478
        lastPlaceMs = now;
479
        pendingAnchorActionMs = now;
480
        pendingAnchorData = refreshed;
481
        pendingAnchorPhase = PendingAnchorPhase.WAITING_FOR_ANCHOR;
482
        markPlaced(refreshed);
483
    }
484
485
    private boolean continuePendingAnchorCycle() {
486
        if (pendingAnchorPos == null || pendingAnchorPhase == null) {
487
            return false;
488
        }
489
        if (mc.player == null || mc.level == null) {
490
            clearPendingAnchor();
491
            return false;
492
        }
493
        if (shouldPause()) {
494
            RotationManager.INSTANCE.clear(this);
495
            return true;
496
        }
497
498
        long now = System.currentTimeMillis();
499
        BlockState state = mc.level.getBlockState(pendingAnchorPos);
500
        boolean anchorPresent = state.is(Blocks.RESPAWN_ANCHOR);
501
        int charges = anchorPresent ? getAnchorCharges(state) : 0;
502
503
        if (anchorPresent && (pendingAnchorPhase == PendingAnchorPhase.PLACING
504
                || pendingAnchorPhase == PendingAnchorPhase.WAITING_FOR_ANCHOR)) {
505
            pendingAnchorPhase = charges > 0 ? PendingAnchorPhase.DETONATING : PendingAnchorPhase.CHARGING;
506
            pendingAnchorActionMs = 0L;
507
        }
508
509
        if (!anchorPresent && (pendingAnchorPhase == PendingAnchorPhase.CHARGING
510
                || pendingAnchorPhase == PendingAnchorPhase.WAITING_FOR_CHARGE
511
                || pendingAnchorPhase == PendingAnchorPhase.DETONATING
512
                || pendingAnchorPhase == PendingAnchorPhase.WAITING_FOR_DETONATION)) {
513
            clearPendingAnchor();
514
            return false;
515
        }
516
517
        switch (pendingAnchorPhase) {
518
            case PLACING -> {
519
                AutoAnchorData data = resolvePendingPlaceData();
520
                if (data == null) {
521
                    clearPendingAnchor();
522
                    return false;
523
                }
524
                pendingAnchorData = data;
525
                if (hasPlaceDelayElapsed()) {
526
                    executeWithRotation(data, () -> placeReservedAnchor(data));
527
                } else {
528
                    RotationManager.INSTANCE.clear(this);
529
                }
530
                return true;
531
            }
532
            case WAITING_FOR_ANCHOR -> {
533
                if (anchorPresent) {
534
                    pendingAnchorPhase = charges > 0 ? PendingAnchorPhase.DETONATING : PendingAnchorPhase.CHARGING;
535
                    pendingAnchorActionMs = 0L;
536
                    return continuePendingAnchorCycle();
537
                }
538
                if (now - pendingAnchorActionMs >= PENDING_ANCHOR_PLACE_CONFIRM_TIMEOUT_MS) {
539
                    clearPendingAnchor();
540
                    return false;
541
                }
542
                RotationManager.INSTANCE.clear(this);
543
                return true;
544
            }
545
            case CHARGING -> {
546
                if (!anchorPresent) {
547
                    clearPendingAnchor();
548
                    return false;
549
                }
550
                AutoAnchorData data = resolvePendingAnchorData(pendingAnchorPos, state);
551
                if (data == null) {
552
                    RotationManager.INSTANCE.clear(this);
553
                    return true;
554
                }
555
                pendingAnchorData = data;
556
                if (data.charges() > 0) {
557
                    pendingAnchorPhase = PendingAnchorPhase.DETONATING;
558
                    pendingAnchorActionMs = 0L;
559
                    return continuePendingAnchorCycle();
560
                }
561
                if (hasExplodeDelayElapsed()) {
562
                    executeWithRotation(data, () -> chargeReservedAnchor(data));
563
                } else {
564
                    RotationManager.INSTANCE.clear(this);
565
                }
566
                return true;
567
            }
568
            case WAITING_FOR_CHARGE -> {
569
                if (!anchorPresent) {
570
                    clearPendingAnchor();
571
                    return false;
572
                }
573
                if (charges > 0) {
574
                    pendingAnchorPhase = PendingAnchorPhase.DETONATING;
575
                    pendingAnchorActionMs = 0L;
576
                    return continuePendingAnchorCycle();
577
                }
578
                if (now - pendingAnchorActionMs >= PENDING_ANCHOR_ACTION_CONFIRM_TIMEOUT_MS) {
579
                    pendingAnchorPhase = PendingAnchorPhase.CHARGING;
580
                    pendingAnchorActionMs = 0L;
581
                    return continuePendingAnchorCycle();
582
                }
583
                RotationManager.INSTANCE.clear(this);
584
                return true;
585
            }
586
            case DETONATING -> {
587
                if (!anchorPresent) {
588
                    clearPendingAnchor();
589
                    return false;
590
                }
591
                AutoAnchorData data = resolvePendingAnchorData(pendingAnchorPos, state);
592
                if (data == null) {
593
                    RotationManager.INSTANCE.clear(this);
594
                    return true;
595
                }
596
                pendingAnchorData = data;
597
                if (data.charges() <= 0) {
598
                    pendingAnchorPhase = PendingAnchorPhase.CHARGING;
599
                    pendingAnchorActionMs = 0L;
600
                    return continuePendingAnchorCycle();
601
                }
602
                if (explodeEnabled.get() && hasExplodeDelayElapsed()) {
603
                    executeWithRotation(data, () -> detonateReservedAnchor(data));
604
                } else {
605
                    RotationManager.INSTANCE.clear(this);
606
                }
607
                return true;
608
            }
609
            case WAITING_FOR_DETONATION -> {
610
                if (!anchorPresent) {
611
                    clearPendingAnchor();
612
                    return false;
613
                }
614
                if (now - pendingAnchorActionMs >= PENDING_ANCHOR_ACTION_CONFIRM_TIMEOUT_MS) {
615
                    pendingAnchorPhase = PendingAnchorPhase.DETONATING;
616
                    pendingAnchorActionMs = 0L;
617
                    return continuePendingAnchorCycle();
618
                }
619
                RotationManager.INSTANCE.clear(this);
620
                return true;
621
            }
622
        }
623
        return true;
624
    }
625
626
    private AutoAnchorData resolvePendingPlaceData() {
627
        if (pendingAnchorPos == null || target == null) {
628
            return null;
629
        }
630
        AutoAnchorData evaluated = planner.evaluate(plannerContext, pendingAnchorPos, target);
631
        if (evaluated != null) {
632
            return evaluated;
633
        }
634
        return pendingAnchorData != null && pendingAnchorPos.equals(pendingAnchorData.pos())
635
                ? pendingAnchorData
636
                : null;
637
    }
638
639
    private AutoAnchorData resolvePendingAnchorData(BlockPos pos, BlockState state) {
640
        if (pos == null || state == null || mc.player == null || mc.level == null) {
641
            return null;
642
        }
643
644
        AutoAnchorData evaluated = target != null ? planner.evaluate(plannerContext, pos, target) : null;
645
        if (evaluated != null && evaluated.existingAnchor()) {
646
            return evaluated;
647
        }
648
649
        BlockHitResult hit = AutoAnchorInteractionUtil.getAnchorInteractResult(
650
                mc.level,
651
                mc.player,
652
                pos,
653
                placementMode.get(),
654
                placeRange.get(),
655
                wallRange.get()
656
        );
657
        if (hit == null) {
658
            return null;
659
        }
660
661
        AutoAnchorData fallback = pendingAnchorData != null && pos.equals(pendingAnchorData.pos()) ? pendingAnchorData : null;
662
        return new AutoAnchorData(
663
                pos,
664
                hit,
665
                fallback != null ? fallback.damage() : renderDamage,
666
                fallback != null ? fallback.selfDamage() : renderSelfDamageValue,
667
                fallback != null && fallback.overrideDamage(),
668
                true,
669
                getAnchorCharges(state)
670
        );
671
    }
672
673
    private void chargeReservedAnchor(AutoAnchorData data) {
674
        if (data == null || data.pos() == null || !hasExplodeDelayElapsed() || shouldPause()) return;
675
        if (!data.pos().equals(pendingAnchorPos) || pendingAnchorPhase != PendingAnchorPhase.CHARGING) return;
676
677
        BlockHitResult anchorHit = AutoAnchorInteractionUtil.getAnchorInteractResult(
678
                mc.level,
679
                mc.player,
680
                data.pos(),
681
                placementMode.get(),
682
                placeRange.get(),
683
                wallRange.get()
684
        );
685
        if (anchorHit == null) return;
686
687
        boolean charged = AutoAnchorActionUtil.chargeAnchor(
688
                mc,
689
                anchorHit,
690
                swapScope.get(),
691
                swapVisibility.get(),
692
                restoreItem.get()
693
        );
694
        if (!charged) return;
695
696
        long now = System.currentTimeMillis();
697
        lastExplodeMs = now;
698
        pendingAnchorActionMs = now;
699
        pendingAnchorPhase = PendingAnchorPhase.WAITING_FOR_CHARGE;
700
        pendingAnchorData = new AutoAnchorData(
701
                data.pos(),
702
                anchorHit,
703
                data.damage(),
704
                data.selfDamage(),
705
                data.overrideDamage(),
706
                true,
707
                Math.max(1, data.charges() + 1)
708
        );
709
        markPlaced(pendingAnchorData);
710
    }
711
712
    private void detonateReservedAnchor(AutoAnchorData data) {
713
        if (data == null || !hasExplodeDelayElapsed() || shouldPause()) return;
714
        if (!data.pos().equals(pendingAnchorPos) || pendingAnchorPhase != PendingAnchorPhase.DETONATING) return;
715
716
        BlockHitResult anchorHit = AutoAnchorInteractionUtil.getAnchorInteractResult(
717
                mc.level,
718
                mc.player,
719
                data.pos(),
720
                placementMode.get(),
721
                placeRange.get(),
722
                wallRange.get()
723
        );
724
        if (anchorHit == null) return;
725
726
        boolean detonated = AutoAnchorActionUtil.detonateAnchor(
727
                mc,
728
                anchorHit,
729
                swapScope.get(),
730
                swapVisibility.get(),
731
                restoreItem.get()
732
        );
733
        if (!detonated) return;
734
735
        long now = System.currentTimeMillis();
736
        lastExplodeMs = now;
737
        pendingAnchorActionMs = now;
738
        pendingAnchorPhase = PendingAnchorPhase.WAITING_FOR_DETONATION;
739
        pendingAnchorData = data;
740
        markPlaced(data);
741
    }
742
743
    private void beginPendingAnchor(AutoAnchorData data, PendingAnchorPhase phase) {
744
        if (data == null || data.pos() == null || phase == null) return;
745
        if (pendingAnchorPos != null && !pendingAnchorPos.equals(data.pos())) {
746
            return;
747
        }
748
        if (pendingAnchorPos == null) {
749
            pendingAnchorActionMs = 0L;
750
        }
751
        pendingAnchorPos = data.pos();
752
        pendingAnchorData = data;
753
        pendingAnchorPhase = phase;
754
    }
755
756
757
    private int getAnchorCharges(BlockState state) {
758
        if (state == null || !state.hasProperty(RespawnAnchorBlock.CHARGE)) {
759
            return 0;
760
        }
761
        return state.getValue(RespawnAnchorBlock.CHARGE);
762
    }
763
764
    private void clearPendingAnchor() {
765
        pendingAnchorPos = null;
766
        pendingAnchorData = null;
767
        pendingAnchorPhase = null;
768
        pendingAnchorActionMs = 0L;
769
    }
770
771
    private boolean shouldPause() {
772
        if (mc.player == null || mc.level == null || mc.gameMode == null) return true;
773
        if (unsafeDimensionOnly.get() && mc.level.dimension() == Level.NETHER) return true;
774
        if (pauseMining.get() && mc.gameMode.isDestroying()) return true;
775
        if (pauseEating.get()
776
                && mc.player.isUsingItem()
777
                && FoodUtil.isFood(mc.player.getUseItem())
778
                && !RubberHandUseUtil.canBypassCurrentUse(mc)) return true;
779
        return mc.player.getHealth() + mc.player.getAbsorptionAmount() < pauseHealth.get();
780
    }
781
782
    private boolean hasPlaceDelayElapsed() {
783
        return System.currentTimeMillis() - lastPlaceMs >= Math.max(0, lowDamageMode ? lowPlaceDelay.get() : placeDelay.get());
784
    }
785
786
    private boolean hasExplodeDelayElapsed() {
787
        return System.currentTimeMillis() - lastExplodeMs >= Math.max(0, lowDamageMode ? lowExplodeDelay.get() : explodeDelay.get());
788
    }
789
790
    private long getPlaceDelayRemainingMs() {
791
        return Math.max(0L, Math.max(0, lowDamageMode ? lowPlaceDelay.get() : placeDelay.get()) - (System.currentTimeMillis() - lastPlaceMs));
792
    }
793
794
    private long getExplodeDelayRemainingMs() {
795
        return Math.max(0L, Math.max(0, lowDamageMode ? lowExplodeDelay.get() : explodeDelay.get()) - (System.currentTimeMillis() - lastExplodeMs));
796
    }
797
798
    private void setRenderCandidate(AutoAnchorData data) {
799
        bestPosition = data.pos();
800
        renderDamage = Math.max(0.0f, data.damage());
801
        renderSelfDamageValue = Math.max(0.0f, data.selfDamage());
802
        lastDamageUpdateMs = System.currentTimeMillis();
803
    }
804
805
    private void markPlaced(AutoAnchorData data) {
806
        if (data == null || data.pos() == null) return;
807
        BlockPos pos = data.pos();
808
        if (!pos.equals(renderPos)) {
809
            renderStartTick = renderTick;
810
            prevRenderPos = renderPos;
811
            renderPos = pos;
812
        }
813
        setRenderCandidate(data);
814
        renderPositions.put(pos, System.currentTimeMillis());
815
    }
816
817
    private void renderPlacement(Renderer3D renderer, float tickDelta) {
818
        String damageText = buildDamageText();
819
        if (damageText.isEmpty() && renderPositions.isEmpty() && renderPos == null) {
820
            return;
821
        }
822
823
        if (renderMode.get() == RenderMode.FADE) {
824
            renderFade(renderer);
825
            return;
826
        }
827
828
        BlockPos activePos = renderPositions.isEmpty() ? bestPosition : renderPos;
829
        if (activePos == null) return;
830
831
        if (renderMode.get() == RenderMode.SLIDE) {
832
            BlockPos slideTo = renderPositions.isEmpty() ? bestPosition : renderPos;
833
            BlockPos from = prevRenderPos != null ? prevRenderPos : slideTo;
834
            renderBox(renderer, ExplosionRenderUtil.lerpBox(new AABB(from), new AABB(slideTo), getSlideProgress(tickDelta)), 1.0f);
835
        } else {
836
            renderBox(renderer, new AABB(activePos), 1.0f);
837
        }
838
    }
839
840
    private float getSlideProgress(float tickDelta) {
841
        float clampedTickDelta = Mth.clamp(tickDelta, 0.0f, 1.0f);
842
        float durationTicks = Math.max(1.0f, slideDelay.get() / 50.0f);
843
        return Mth.clamp((renderTick - renderStartTick + clampedTickDelta) / durationTicks, 0.0f, 1.0f);
844
    }
845
846
    private void renderFade(Renderer3D renderer) {
847
        long now = System.currentTimeMillis();
848
        int lifetime = Math.max(1, fadeTime.get());
849
        List<Map.Entry<BlockPos, Long>> entries = new ArrayList<>(renderPositions.entrySet());
850
        for (Map.Entry<BlockPos, Long> entry : entries) {
851
            long age = now - entry.getValue();
852
            if (age > lifetime) {
853
                renderPositions.remove(entry.getKey());
854
                continue;
855
            }
856
            float alpha = 1.0f - (age / (float) lifetime);
857
            renderBox(renderer, new AABB(entry.getKey()), alpha);
858
        }
859
    }
860
861
    private void renderBox(Renderer3D renderer, AABB box, float alpha) {
862
        int fillArgb = ExplosionRenderUtil.applyOpacity(fillColor.getArgb(), alpha);
863
        int lineArgb = ExplosionRenderUtil.applyOpacity(lineColor.getArgb(), alpha);
864
        ExplosionRenderUtil.addFilledBox(renderer, box, fillArgb);
865
866
        float prevWidth = RenderState.lineWidth;
867
        RenderState.lineWidth = Math.max(0.5f, lineWidth.get());
868
        try {
869
            ExplosionRenderUtil.addOutlineBox(renderer, box, lineArgb);
870
        } finally {
871
            RenderState.lineWidth = prevWidth;
872
        }
873
874
        if (drawDamage.get()) {
875
            renderDamageText(renderer, box.getCenter(), alpha);
876
        }
877
    }
878
879
    private void renderDamageText(Renderer3D renderer, Vec3 anchor, float alpha) {
880
        double billboardWorldScale = resolveDamageBillboardScale(anchor);
881
        String mainText = ExplosionRenderUtil.formatDamage(renderDamage);
882
        if (mainText.isEmpty()) return;
883
884
        int mainArgb = ExplosionRenderUtil.applyOpacity(textColor.getArgb(), alpha);
885
        TextRenderer bold = BuiltinFontCatalog.IOSEVKA_BOLD.renderer(TextRenderer.get());
886
        WorldTextRenderer.Options baseOptions = WorldTextRenderer.Options.defaults()
887
                .withScale(TEXT_SCALE)
888
                .withWorldScale(billboardWorldScale)
889
                .withDepthMode(Renderer3D.DepthMode.NONE)
890
                .withShadow(true)
891
                .withOffset(0.0, TEXT_Y_OFFSET);
892
893
        if (!renderSelfDamage.get() || renderSelfDamageValue <= 0.0f) {
894
            WorldTextRenderer.drawBillboard(
895
                    renderer,
896
                    bold,
897
                    mainText,
898
                    anchor,
899
                    baseOptions.withCentered(true).withColor(new RenderColor(mainArgb))
900
            );
901
            return;
902
        }
903
904
        String tailText = " / " + ExplosionRenderUtil.formatDamage(renderSelfDamageValue);
905
        TextRenderer medium = BuiltinFontCatalog.IOSEVKA_REGULAR.renderer(TextRenderer.get());
906
        double mainWidth = ExplosionRenderUtil.measureWidth(bold, mainText, TEXT_SCALE);
907
        double tailWidth = ExplosionRenderUtil.measureWidth(medium, tailText, TEXT_GAP_SCALE);
908
        double startX = -(mainWidth + tailWidth) * 0.5;
909
910
        double drawnMain = WorldTextRenderer.drawBillboard(
911
                renderer,
912
                bold,
913
                mainText,
914
                anchor,
915
                baseOptions.withCentered(false)
916
                        .withOffset(startX, TEXT_Y_OFFSET)
917
                        .withColor(new RenderColor(mainArgb))
918
        );
919
920
        WorldTextRenderer.drawBillboard(
921
                renderer,
922
                medium,
923
                tailText,
924
                anchor,
925
                baseOptions.withCentered(false)
926
                        .withScale(TEXT_GAP_SCALE)
927
                        .withOffset(startX + drawnMain, TEXT_Y_OFFSET)
928
                        .withColor(new RenderColor(mainArgb))
929
        );
930
    }
931
932
    private double resolveDamageBillboardScale(Vec3 anchor) {
933
        double distance = RenderState.cameraPos != null ? RenderState.cameraPos.distanceTo(anchor) : 0.0;
934
        return WorldUiPresentationService.resolveWorldScale(
935
                TEXT_WORLD_SCALE,
936
                distance,
937
                12.0,
938
                4.0,
939
                billboardSize.get(),
940
                billboardDynamicScale.get(),
941
                billboardDynamicScaleCoefficient.get()
942
        );
943
    }
944
945
    private void purgeExpiredRenderPositions() {
946
        long now = System.currentTimeMillis();
947
        long lifetime = Math.max(1, fadeTime.get());
948
        renderPositions.entrySet().removeIf(entry -> now - entry.getValue() > lifetime);
949
    }
950
951
    public String getTargetHudStatus(LivingEntity hudTarget) {
952
        if (!isEnabled() || hudTarget == null || target == null || hudTarget != target) return null;
953
        if (mc.player == null || mc.level == null) return "Idle";
954
        if (shouldPause()) return "Paused";
955
        if (!AutoAnchorActionUtil.hasAnchor(mc, swapScope.get())) return "No anchors";
956
        if (!AutoAnchorActionUtil.hasGlowstone(mc, swapScope.get())) return "No glowstone";
957
958
        if (explodeEnabled.get() && bestExplode != null) {
959
            long wait = getExplodeDelayRemainingMs();
960
            if (wait > 0L) return "Explode in " + wait + "ms";
961
            return usesRotationSettings() ? "Rotate -> anchor" : "Exploding";
962
        }
963
        if (placeEnabled.get() && bestPlace != null) {
964
            long wait = getPlaceDelayRemainingMs();
965
            if (wait > 0L) return "Anchor in " + wait + "ms";
966
            return usesRotationSettings() ? "Rotate -> anchor" : "Placing anchor";
967
        }
968
        if (lastSelfDamageRejects > 0 || (lastCandidates > 0 && lastSafeCandidates <= 0)) return "Self dmg";
969
        if (lastScanned <= 0) return "No scan";
970
        return "No anchor";
971
    }
972
973
    private LivingEntity findCombatTarget() {
974
        if (mc.player == null || mc.level == null) return null;
975
        TargetingUtil.TargetingSettings settings = new TargetingUtil.TargetingSettings(
976
                targetRange.get(),
977
                180.0f,
978
                targetToggles.get(TargetFilters.PLAYERS_ONLY),
979
                targetToggles.get(TargetFilters.IGNORE_FRIENDS),
980
                targetToggles.get(TargetFilters.IGNORE_STAFF),
981
                targetToggles.get(TargetFilters.IGNORE_ENEMIES),
982
                targetToggles.get(TargetFilters.IGNORE_NAKED),
983
                targetToggles.get(TargetFilters.IGNORE_ENTITIES),
984
                targetToggles.get(TargetFilters.VISIBLE_ONLY),
985
                priority.get()
986
        );
987
        return TargetingUtil.findBestTarget(mc, settings);
988
    }
989
990
    private Vec3 resolvePredictedPosition(LivingEntity entity, int ticks) {
991
        if (entity == null || ticks <= 0) {
992
            return entity != null ? entity.position() : Vec3.ZERO;
993
        }
994
        if (entity instanceof Player player) {
995
            PlayerSimulationCache.SimulatedPlayerCache simulation =
996
                    player == mc.player
997
                            ? PlayerSimulationCache.getSimulationForLocalPlayer()
998
                            : PlayerSimulationCache.getSimulationForOtherPlayers(player);
999
            if (simulation != null) {
1000
                return simulation.getSnapshotAt(ticks).pos();
1001
            }
1002
        }
1003
        return PositionExtrapolation.getBestForEntity(entity).getPositionInTicks(ticks);
1004
    }
1005
1006
    private boolean shouldOverrideMaxSelfDamage(float damage, float selfDamage) {
1007
        return ExplosionDamageRules.shouldOverrideMaxSelfDamage(
1008
                mc.player,
1009
                target,
1010
                damage,
1011
                selfDamage,
1012
                maxSelfDamage.get()
1013
        );
1014
    }
1015
1016
    private boolean isSafe(float damage, float selfDamage, boolean overrideDamage) {
1017
        return ExplosionDamageRules.isSafe(mc.player, selfDamage, overrideDamage);
1018
    }
1019
1020
    private BlockHitResult getInteractResult(BlockPos pos, boolean existingAnchor) {
1021
        return AutoAnchorInteractionUtil.getInteractResult(
1022
                mc.level,
1023
                mc.player,
1024
                pos,
1025
                existingAnchor,
1026
                airPlace.get(),
1027
                placementMode.get(),
1028
                placeRange.get(),
1029
                wallRange.get()
1030
        );
1031
    }
1032
1033
1034
    private boolean usesRotationSettings() {
1035
        return CombatRotationModeUtil.usesRotations(attackMode);
1036
    }
1037
1038
    private String buildDamageText() {
1039
        String main = ExplosionRenderUtil.formatDamage(renderDamage);
1040
        if (main.isEmpty()) return "";
1041
        if (!renderSelfDamage.get() || renderSelfDamageValue <= 0.0f) return main;
1042
        return main + " / " + ExplosionRenderUtil.formatDamage(renderSelfDamageValue);
1043
    }
1044
1045
    private void clearCombatState() {
1046
        target = null;
1047
        bestPlace = null;
1048
        bestExplode = null;
1049
        bestPosition = null;
1050
        clearPendingAnchor();
1051
        RotationManager.INSTANCE.clear(this);
1052
        lastScanned = 0;
1053
        lastCandidates = 0;
1054
        lastSafeCandidates = 0;
1055
        lastSelfDamageRejects = 0;
1056
    }
1057
1058
    private void resetState() {
1059
        target = null;
1060
        bestPlace = null;
1061
        bestExplode = null;
1062
        renderPos = null;
1063
        prevRenderPos = null;
1064
        bestPosition = null;
1065
        renderTick = 0;
1066
        renderStartTick = 0;
1067
        lastPlaceMs = 0L;
1068
        lastExplodeMs = 0L;
1069
        lastDamageUpdateMs = 0L;
1070
        lastCalcMs = 0L;
1071
        clearPendingAnchor();
1072
        renderDamage = 0.0f;
1073
        renderSelfDamageValue = 0.0f;
1074
        lowDamageMode = false;
1075
        renderPositions.clear();
1076
        lastScanned = 0;
1077
        lastCandidates = 0;
1078
        lastSafeCandidates = 0;
1079
        lastSelfDamageRejects = 0;
1080
    }
1081
1082
    private final class PlannerContext implements AutoAnchorPlanner.Context {
1083
        @Override
1084
        public LocalPlayer player() {
1085
            return mc.player;
1086
        }
1087
1088
        @Override
1089
        public ClientLevel level() {
1090
            return mc.level;
1091
        }
1092
1093
        @Override
1094
        public Vec3 resolvePredictedPosition(LivingEntity entity, int ticks) {
1095
            return AutoAnchor.this.resolvePredictedPosition(entity, ticks);
1096
        }
1097
1098
        @Override
1099
        public BlockHitResult getInteractResult(BlockPos pos, boolean existingAnchor) {
1100
            return AutoAnchor.this.getInteractResult(pos, existingAnchor);
1101
        }
1102
1103
        @Override
1104
        public boolean isBlockedByEntity(BlockPos pos) {
1105
            return CombatEntityQuery.isBlocked(mc.level, new AABB(pos));
1106
        }
1107
1108
        @Override
1109
        public boolean shouldOverrideMaxSelfDamage(float damage, float selfDamage) {
1110
            return AutoAnchor.this.shouldOverrideMaxSelfDamage(damage, selfDamage);
1111
        }
1112
1113
        @Override
1114
        public boolean isSafe(float damage, float selfDamage, boolean overrideDamage) {
1115
            return AutoAnchor.this.isSafe(damage, selfDamage, overrideDamage);
1116
        }
1117
1118
        @Override
1119
        public float minDamage() {
1120
            return minDamage.get();
1121
        }
1122
1123
        @Override
1124
        public float faceplaceHealth() {
1125
            return faceplaceHealth.get();
1126
        }
1127
1128
        @Override
1129
        public float maxSelfDamage() {
1130
            return maxSelfDamage.get();
1131
        }
1132
1133
        @Override
1134
        public int predictTicks() {
1135
            return predictTicks.get();
1136
        }
1137
1138
        @Override
1139
        public int selfPredictTicks() {
1140
            return selfPredictTicks.get();
1141
        }
1142
1143
        @Override
1144
        public boolean allowAirPlace() {
1145
            return airPlace.get();
1146
        }
1147
1148
        @Override
1149
        public float placeRange() {
1150
            return placeRange.get();
1151
        }
1152
    }
1153
1154
    private enum Timing {
1155
        NORMAL,
1156
        SEQUENTIAL
1157
    }
1158
1159
    private enum PendingAnchorPhase {
1160
        PLACING,
1161
        WAITING_FOR_ANCHOR,
1162
        CHARGING,
1163
        WAITING_FOR_CHARGE,
1164
        DETONATING,
1165
        WAITING_FOR_DETONATION
1166
    }
1167
1168
    private enum RenderMode {
1169
        FADE,
1170
        SLIDE,
1171
        DEFAULT
1172
    }
1173
}
1174