AutoBed module

AutoBed: 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/AutoBed.javaJava · 399 lines · 19.9 KB

Automatically places and explodes beds.

SettingsInteractModeRangeWallRangePlaceDelayExplodeDelayMinDamageMaxSelfDamageDimensionCheckSwitchToHotbar1.12 PlaceAutoSwapAutoCraftMinBedsBedsPerCraftRenderSelfDamageRenderDamageFillLineText
AutoBed.javaJava · Minecraft 26.2 · 399 lines · 19.9 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.combat;
2
import net.minecraft.world.attribute.EnvironmentAttributes;
3
4
import meteordevelopment.orbit.EventHandler;
5
import net.minecraft.client.gui.screens.inventory.CraftingScreen;
6
import net.minecraft.client.gui.screens.recipebook.RecipeCollection;
7
import net.minecraft.core.BlockPos;
8
import net.minecraft.core.Direction;
9
import net.minecraft.network.protocol.game.ServerboundContainerClosePacket;
10
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
11
import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket;
12
import net.minecraft.util.context.ContextKeySet;
13
import net.minecraft.util.context.ContextMap;
14
import net.minecraft.world.InteractionHand;
15
import net.minecraft.world.entity.player.Player;
16
import net.minecraft.world.inventory.ContainerInput;
17
import net.minecraft.world.inventory.CraftingMenu;
18
import net.minecraft.world.item.BedItem;
19
import net.minecraft.world.item.ItemStack;
20
import net.minecraft.world.item.crafting.display.RecipeDisplayEntry;
21
import net.minecraft.world.item.crafting.display.RecipeDisplayId;
22
import net.minecraft.world.level.ClipContext;
23
import net.minecraft.world.level.block.BedBlock;
24
import net.minecraft.world.level.block.CraftingTableBlock;
25
import net.minecraft.world.level.block.state.BlockState;
26
import net.minecraft.world.phys.AABB;
27
import net.minecraft.world.phys.BlockHitResult;
28
import net.minecraft.world.phys.HitResult;
29
import net.minecraft.world.phys.Vec3;
30
import org.jetbrains.annotations.NotNull;
31
import thunder.hack.core.Managers;
32
import thunder.hack.core.manager.client.ModuleManager;
33
import thunder.hack.events.impl.EventPostSync;
34
import thunder.hack.events.impl.EventSync;
35
import thunder.hack.events.impl.PlayerUpdateEvent;
36
import thunder.hack.injection.accesors.IClientPlayerEntity;
37
import thunder.hack.injection.accesors.IEntity;
38
import thunder.hack.features.modules.Module;
39
import thunder.hack.features.modules.client.HudEditor;
40
import thunder.hack.setting.Setting;
41
import thunder.hack.setting.impl.ColorSetting;
42
import thunder.hack.setting.impl.SettingGroup;
43
import thunder.hack.utility.Timer;
44
import thunder.hack.utility.world.ExplosionUtility;
45
import thunder.hack.utility.math.MathUtility;
46
import thunder.hack.utility.player.InteractionUtility;
47
import thunder.hack.utility.player.InventoryUtility;
48
import thunder.hack.utility.player.PlayerUtility;
49
import thunder.hack.utility.player.SearchInvResult;
50
import thunder.hack.utility.render.Render2DEngine;
51
import thunder.hack.utility.render.Render3DEngine;
52
53
import java.awt.*;
54
import java.util.Objects;
55
56
import static thunder.hack.features.modules.client.ClientSettings.isRu;
57
58
import com.mojang.blaze3d.vertex.PoseStack;
59
60
public final class AutoBed extends Module {
61
    private final Setting<InteractionUtility.Interact> interactMode = new Setting<>("InteractMode", InteractionUtility.Interact.Vanilla);
62
    public static final Setting<Float> range = new Setting<>("Range", 4f, 2f, 6.0f);
63
    public static final Setting<Float> wallRange = new Setting<>("WallRange", 4f, 0f, 6.0f);
64
    public static final Setting<Integer> placeDelay = new Setting<>("PlaceDelay", 100, 0, 1000);
65
    public static final Setting<Integer> explodeDelay = new Setting<>("ExplodeDelay", 100, 0, 1000);
66
    public static final Setting<Float> minDamage = new Setting<>("MinDamage", 8f, 0f, 25.0f);
67
    public static final Setting<Float> maxSelfDamage = new Setting<>("MaxSelfDamage", 4f, 0f, 25.0f);
68
    private final Setting<Boolean> dimCheck = new Setting<>("DimensionCheck", false);
69
    public final Setting<Boolean> switchToHotbar = new Setting<>("SwitchToHotbar", true);
70
    public final Setting<Boolean> oldPlace = new Setting<>("1.12 Place",false);
71
    public final Setting<Boolean> autoSwap = new Setting<>("AutoSwap", true);
72
    public final Setting<Boolean> autoCraft = new Setting<>("AutoCraft", true);
73
    public static final Setting<Integer> minBeds = new Setting<>("MinBeds", 4, 0, 10);
74
    public static final Setting<Integer> bedsPerCraft = new Setting<>("BedsPerCraft", 8, 1, 27);
75
    private final Setting<SettingGroup> renderCategory = new Setting<>("Render", new SettingGroup(false, 0));
76
    private final Setting<Boolean> render = new Setting<>("Render", true).addToGroup(renderCategory);
77
    private final Setting<Boolean> rselfDamage = new Setting<>("SelfDamage", true).addToGroup(renderCategory);
78
    private final Setting<Boolean> drawDamage = new Setting<>("RenderDamage", true).addToGroup(renderCategory);
79
    private final Setting<ColorSetting> fillColor = new Setting<>("Fill", new ColorSetting(Render2DEngine.injectAlpha(HudEditor.getColor(0), 150))).addToGroup(renderCategory);
80
    private final Setting<ColorSetting> lineColor = new Setting<>("Line", new ColorSetting(HudEditor.getColor(0))).addToGroup(renderCategory);
81
    private final Setting<ColorSetting> textColor = new Setting<>("Text", new ColorSetting(Color.WHITE)).addToGroup(renderCategory);
82
83
    private Player target;
84
    private BedData bestBed, bestPos;
85
    private float rotationYaw, rotationPitch;
86
87
    private final Timer placeTimer = new Timer();
88
    private final Timer explodeTimer = new Timer();
89
90
    public AutoBed() {
91
        super("AutoBed", Category.COMBAT);
92
    }
93
94
    @EventHandler
95
    public void onSync(EventSync e) {
96
        if (bestBed != null || bestPos != null) {
97
            mc.player.setYRot(rotationYaw);
98
            mc.player.setXRot(rotationPitch);
99
        }
100
    }
101
102
    @EventHandler
103
    public void onPlayerUpdate(PlayerUpdateEvent e) {
104
        target = findTarget();
105
106
        if (!mc.level.environmentAttributes().getValue(EnvironmentAttributes.BED_RULE, mc.player.blockPosition()).explodes() && dimCheck.getValue()) {
107
            disable(isRu() ? "Кровати не взрываются в этом измерении!" : "Beds don't explode in this dimension!");
108
            return;
109
        }
110
111
        if (target != null && (target.isDeadOrDying() || target.getHealth() < 0)) {
112
            target = null;
113
            return;
114
        }
115
116
        bestBed = findBedToExplode();
117
        bestPos = findBlockToPlace();
118
119
        if (bestBed != null || bestPos != null) {
120
            float[] angle;
121
122
            angle = InteractionUtility.calculateAngle(Objects.requireNonNullElseGet(bestPos, () -> bestBed).hitResult().getLocation());
123
124
            rotationYaw = (angle[0]);
125
            rotationPitch = (angle[1]);
126
            ModuleManager.rotations.fixRotation = rotationYaw;
127
        }
128
129
        if (autoCraft.getValue()) {
130
            if (InventoryUtility.getBedsCount() <= minBeds.getValue()) {
131
                craftBed();
132
                return;
133
            }
134
            if (mc.player.containerMenu instanceof CraftingMenu) {
135
                sendPacket(new ServerboundContainerClosePacket(mc.player.containerMenu.containerId));
136
                mc.player.clientSideCloseContainer();
137
            }
138
        }
139
    }
140
141
    @EventHandler
142
    public void onPostSync(EventPostSync e) {
143
        if (!(mc.player.getMainHandItem().getItem() instanceof BedItem) && autoSwap.getValue() && bestPos != null) {
144
            SearchInvResult hotBarResult = InventoryUtility.findBedInHotBar();
145
            if (hotBarResult.found()) {
146
                hotBarResult.switchTo();
147
            } else if (switchToHotbar.getValue()) {
148
                SearchInvResult invResult = InventoryUtility.findBed();
149
                if (invResult.found() && !(mc.gui.screen() instanceof CraftingScreen)) {
150
                    mc.gameMode.handleContainerInput(mc.player.containerMenu.containerId, invResult.slot(), mc.player.getInventory().getSelectedSlot(), ContainerInput.SWAP, mc.player);
151
                    sendPacket(new ServerboundContainerClosePacket(mc.player.containerMenu.containerId));
152
                }
153
            }
154
        }
155
156
        if (bestBed != null && explodeTimer.passedMs(explodeDelay.getValue())) {
157
            sendSequencedPacket(id -> new ServerboundUseItemOnPacket(InteractionHand.MAIN_HAND, bestBed.hitResult(), id));
158
            mc.player.swing(InteractionHand.MAIN_HAND);
159
            explodeTimer.reset();
160
        }
161
162
        if (!(mc.player.getMainHandItem().getItem() instanceof BedItem))
163
            return;
164
165
        if (bestPos != null && placeTimer.passedMs(placeDelay.getValue()) && !(mc.level.getBlockState(bestPos.hitResult().getBlockPos().above()).getBlock() instanceof BedBlock)) {
166
            final float angle2 = InteractionUtility.calculateAngle(net.minecraft.world.phys.Vec3.atBottomCenterOf(bestPos.hitResult().getBlockPos()), net.minecraft.world.phys.Vec3.atBottomCenterOf(bestPos.hitResult().getBlockPos().relative(bestPos.dir())))[0];
167
            sendPacket(new ServerboundMovePlayerPacket.Rot(angle2, 0, mc.player.onGround(), mc.player.horizontalCollision));
168
            float prevYaw = mc.player.getYRot();
169
            mc.player.setYRot(angle2);
170
            ((thunder.hack.injection.accesors.IEntity) mc.player).setLastYaw(angle2);
171
            ((IEntity) mc.player).setLastYaw(angle2);
172
            sendSequencedPacket(id -> new ServerboundUseItemOnPacket(InteractionHand.MAIN_HAND, bestPos.hitResult(), id));
173
            mc.player.swing(InteractionHand.MAIN_HAND);
174
            placeTimer.reset();
175
            mc.player.setYRot(prevYaw);
176
        }
177
    }
178
179
    @Override
180
    public void onRender3D(PoseStack stack) {
181
        if (bestPos != null && render.getValue()) {
182
            AABB box = new AABB(bestPos.hitResult.getBlockPos().above());
183
            AABB box2 = new AABB(bestPos.hitResult.getBlockPos().above().relative(bestPos.dir));
184
185
            AABB finalBox = box.minmax(box2).setMaxY(box.maxY - 0.45f);
186
187
            String dmg = MathUtility.round2(bestPos.damage()) + (rselfDamage.getValue() ? " / " + MathUtility.round2(bestPos.selfDamage()) : "");
188
189
            Render3DEngine.OUTLINE_QUEUE.add(new Render3DEngine.OutlineAction(finalBox, lineColor.getValue().getColorObject(), 2f));
190
            Render3DEngine.FILLED_QUEUE.add(new Render3DEngine.FillAction(finalBox, fillColor.getValue().getColorObject()));
191
192
            if (drawDamage.getValue())
193
                Render3DEngine.drawTextIn3D(dmg, finalBox.getCenter(), 0, 0.1, 0, textColor.getValue().getColorObject());
194
        }
195
    }
196
197
    private Player findTarget() {
198
        return Managers.COMBAT.getNearestTarget(12f);
199
    }
200
201
    private BedData findBedToExplode() {
202
        int intRange = (int) (Math.floor(range.getValue()) + 1);
203
        Iterable<BlockPos> blocks_ = BlockPos.withinManhattan(new BlockPos(BlockPos.containing(mc.player.position()).above()), intRange, intRange, intRange);
204
205
        BedData bestData = null;
206
207
        for (BlockPos b : blocks_) {
208
            BlockState state = mc.level.getBlockState(b);
209
            if (PlayerUtility.squaredDistanceFromEyes(net.minecraft.world.phys.Vec3.atBottomCenterOf(b)) <= range.getPow2Value()) {
210
                if (state.getBlock() instanceof BedBlock) {
211
                    BlockHitResult bhr = getInteractResult(b);
212
213
                    mc.level.removeBlock(b, false);
214
                    float damage = ExplosionUtility.getExplosionDamage(net.minecraft.world.phys.Vec3.atBottomCenterOf(b).add(0, -0.5, 0), target, false);
215
                    float selfDamage = ExplosionUtility.getExplosionDamage(net.minecraft.world.phys.Vec3.atBottomCenterOf(b).add(0, -0.5, 0), mc.player, false);
216
                    mc.level.setBlockAndUpdate(b, state);
217
218
                    if (damage < minDamage.getValue())
219
                        continue;
220
221
                    if (selfDamage > maxSelfDamage.getValue())
222
                        continue;
223
224
                    if (selfDamage > mc.player.getHealth() + mc.player.getAbsorptionAmount() + 2f)
225
                        continue;
226
227
                    if (bestData != null && bestData.damage > damage)
228
                        continue;
229
230
                    if (bhr != null)
231
                        bestData = new BedData(bhr, damage, selfDamage, bhr.getDirection());
232
                }
233
            }
234
        }
235
        return bestData;
236
    }
237
238
    private BedData findBlockToPlace() {
239
        int intRange = (int) (Math.floor(range.getValue()) + 1);
240
        Iterable<BlockPos> blocks_ = BlockPos.withinManhattan(new BlockPos(BlockPos.containing(mc.player.position()).above()), intRange, intRange, intRange);
241
242
        BedData bestData = null;
243
244
        for (BlockPos b : blocks_) {
245
            BlockState state = mc.level.getBlockState(b);
246
            BlockState state2 = mc.level.getBlockState(b.above());
247
248
            if (PlayerUtility.squaredDistanceFromEyes(net.minecraft.world.phys.Vec3.atBottomCenterOf(b)) <= range.getPow2Value()) {
249
                if (state2.getBlock() instanceof BedBlock && !placeTimer.passedMs(1500) && bestPos != null)
250
                    return bestPos;
251
252
                if (!state.canBeReplaced()) {
253
                    BlockHitResult bhr = InteractionUtility.getPlaceResult(b.above(), interactMode.getValue(), false);
254
                    if (bhr != null) {
255
256
                        BlockHitResult wallCheck = mc.level.clip(new ClipContext(InteractionUtility.getEyesPos(mc.player), bhr.getLocation(), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player));
257
                        if (wallCheck != null && wallCheck.getType() == HitResult.Type.BLOCK && wallCheck.getBlockPos() != b)
258
                            continue;
259
260
                        float damage = ExplosionUtility.getExplosionDamage(net.minecraft.world.phys.Vec3.atBottomCenterOf(b.above()).add(0, -0.5, 0), target, false);
261
                        float selfDamage = ExplosionUtility.getExplosionDamage(net.minecraft.world.phys.Vec3.atBottomCenterOf(b.above()).add(0, -0.5, 0), mc.player, false);
262
263
                        if (damage < minDamage.getValue())
264
                            continue;
265
266
                        if (selfDamage > maxSelfDamage.getValue())
267
                            continue;
268
269
                        if (selfDamage > mc.player.getHealth() + mc.player.getAbsorptionAmount() + 2f)
270
                            continue;
271
272
                        if (bestData != null && bestData.damage > damage)
273
                            continue;
274
275
276
                        float bestDirdmg = 0;
277
                        Direction bestDir = null;
278
                        for (Direction dir : Direction.values()) {
279
                            if (dir == Direction.DOWN || dir == Direction.UP)
280
                                continue;
281
                            BlockPos offset = b.above().relative(dir);
282
283
                            if(!mc.level.getBlockState(offset).canBeReplaced())
284
                                continue;
285
286
                            if(oldPlace.getValue() && mc.level.getBlockState(b.relative(dir)).canBeReplaced()){
287
                                continue;
288
                            }
289
290
                            float dirdamage = ExplosionUtility.getExplosionDamage(net.minecraft.world.phys.Vec3.atBottomCenterOf(offset).add(0, -0.5, 0), target, false);
291
                            float dirSelfDamage = ExplosionUtility.getExplosionDamage(net.minecraft.world.phys.Vec3.atBottomCenterOf(offset).add(0, -0.5, 0), mc.player, false);
292
                            if (dirdamage > bestDirdmg && dirSelfDamage <= maxSelfDamage.getValue()) {
293
                                bestDir = dir;
294
                                bestDirdmg = dirdamage;
295
                            }
296
                        }
297
298
                        bestData = bestDir == null ? null : new BedData(bhr, damage, selfDamage, bestDir);
299
                    }
300
                }
301
            }
302
        }
303
        return bestData;
304
    }
305
306
307
    public void craftBed() {
308
        int intRange = (int) (Math.floor(range.getValue()) + 1);
309
        Iterable<BlockPos> blocks_ = BlockPos.withinManhattan(new BlockPos(BlockPos.containing(mc.player.position()).above()), intRange, intRange, intRange);
310
311
        for (BlockPos b : blocks_) {
312
            BlockState state = mc.level.getBlockState(b);
313
            if (state.getBlock() instanceof CraftingTableBlock) {
314
                BlockHitResult result = getInteractResult(b);
315
                if (result != null) {
316
                    if (mc.player.containerMenu instanceof CraftingMenu craft) {
317
                        mc.player.getRecipeBook().setOpen(craft.getRecipeBookType(), true);
318
                        ContextMap context = new ContextMap.Builder().create(new ContextKeySet.Builder().build());
319
                        for (RecipeCollection results : mc.player.getRecipeBook().getCollections()) {
320
                            for (RecipeDisplayEntry recipe : results.getRecipes()) {
321
                                ItemStack resultStack = recipe.display().result().resolveForFirstStack(context);
322
                                if (resultStack.getItem() instanceof BedItem) {
323
                                    RecipeDisplayId recipeId = recipe.id();
324
                                    for (int i = 0; i < bedsPerCraft.getValue(); i++)
325
                                        mc.gameMode.handlePlaceRecipe(mc.player.containerMenu.containerId, recipeId, false);
326
                                    mc.gameMode.handleContainerInput(mc.player.containerMenu.containerId, 0, 0, ContainerInput.QUICK_MOVE, mc.player);
327
                                    break;
328
                                }
329
                            }
330
                        }
331
                    } else {
332
                        float[] angle = InteractionUtility.calculateAngle(result.getLocation());
333
                        mc.player.setYRot(angle[0]);
334
                        mc.player.setXRot(angle[1]);
335
                        sendSequencedPacket(id -> new ServerboundUseItemOnPacket(InteractionHand.MAIN_HAND, result, id));
336
                    }
337
                }
338
            }
339
        }
340
    }
341
342
    public BlockHitResult getInteractResult(@NotNull BlockPos bp) {
343
        float bestDistance = 999f;
344
        BlockHitResult bestResult = null;
345
        for (float x = 0f; x < 1f; x += 0.25f) {
346
            for (float y = 0f; y < 0.5f; y += 0.125f) {
347
                for (float z = 0f; z < 1f; z += 0.25f) {
348
                    Vec3 point = new Vec3(bp.getX() + x, bp.getY() + y, bp.getZ() + z);
349
                    float distance = PlayerUtility.squaredDistanceFromEyes(point);
350
351
                    BlockHitResult wallCheck = mc.level.clip(new ClipContext(InteractionUtility.getEyesPos(mc.player), point, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player));
352
                    if (wallCheck != null && wallCheck.getType() == HitResult.Type.BLOCK && wallCheck.getBlockPos() != bp)
353
                        if (distance > wallRange.getPow2Value())
354
                            continue;
355
356
357
                    BlockHitResult result = ExplosionUtility.rayCastBlock(new ClipContext(InteractionUtility.getEyesPos(mc.player), point, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player), bp);
358
                    if (distance > range.getPow2Value())
359
                        continue;
360
361
                    if (distance < bestDistance) {
362
                        if (result != null && result.getType() == HitResult.Type.BLOCK) {
363
                            bestResult = result;
364
                            bestDistance = distance;
365
                        }
366
                    }
367
                }
368
            }
369
        }
370
371
        float bestDistance2 = 999f;
372
        Direction bestDirection = null;
373
374
        if (mc.player.getEyePosition().y() > bp.above().getY()) {
375
            bestDirection = Direction.UP;
376
        } else if (mc.player.getEyePosition().y() < bp.getY()) {
377
            bestDirection = Direction.DOWN;
378
        } else {
379
            for (Direction dir : Direction.values()) {
380
                Vec3 directionVec = new Vec3(bp.getX() + 0.5 + dir.getUnitVec3i().getX() * 0.5, bp.getY() + 0.5 + dir.getUnitVec3i().getY() * 0.5, bp.getZ() + 0.5 + dir.getUnitVec3i().getZ() * 0.5);
381
                float distance = PlayerUtility.squaredDistanceFromEyes(directionVec);
382
                if (bestDistance2 > distance) {
383
                    bestDirection = dir;
384
                    bestDistance2 = distance;
385
                }
386
            }
387
        }
388
389
        if(bestResult == null)
390
            return null;
391
392
        return new BlockHitResult(bestResult.getLocation(), bestDirection, bestResult.getBlockPos(), false);
393
    }
394
395
    private record BedData(BlockHitResult hitResult, float damage, float selfDamage, Direction dir) {
396
    }
397
398
}
399
CombatantCOMBATsrc/main/java/combatant/client/features/module/modules/combat/AutoBed.javaJava · 1,219 lines · 46.8 KB

Automatically places and detonates beds in explosive dimensions.

SettingsautobedPlaceautobedExplodeautobedInstantExplodeautobedTimingautobedCalcDelayautobedPlaceDelayautobedLowPlaceDelayautobedExplodeDelayautobedLowExplodeDelayautobedPlaceRangeautobedWallRangeautobedPlacementModeautobedTargetRangeautobedTargetsautobedPriorityautobedMinDamageautobedFaceplaceHealthautobedMaxSelfDamageautobedPredictTicksautobedSelfPredictTicksautobedPauseMiningautobedPauseEatingautobedPauseHealthautobedSwapScopeautobedSwapVisibilityautobedRestoreItemautobedAttackModeautobedMovementCorrectionautobedRotationResetTicksautobedRotationResetThresholdautobedRenderautobedRenderModeautobedRenderSelfDamageautobedRenderDamageautobedFillColorautobedLineColorautobedLineWidthautobedTextColorautobedBillboardSizeautobedBillboardDynamicScale
AutoBed.javaJava · Minecraft 26.2 · 1,219 lines · 46.8 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.autobed.*;
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.core.Direction;
50
import net.minecraft.util.Mth;
51
import net.minecraft.world.entity.LivingEntity;
52
import net.minecraft.world.entity.player.Player;
53
import net.minecraft.world.level.Level;
54
import net.minecraft.world.phys.AABB;
55
import net.minecraft.world.phys.BlockHitResult;
56
import net.minecraft.world.phys.Vec3;
57
58
import java.util.ArrayList;
59
import java.util.List;
60
import java.util.Map;
61
import java.util.concurrent.ConcurrentHashMap;
62
63
@ModuleInfo(
64
        id = "autobed",
65
        displayName = "AutoBed",
66
        aliases = {"BedAura", "Bed"},
67
        category = ModuleCategory.COMBAT,
68
        description = "module.autobed.description"
69
)
70
public class AutoBed extends Module {
71
    private static final int ROTATION_PRIORITY = 33;
72
    private static final long DAMAGE_RESET_MS = 1000L;
73
    private static final long PENDING_BED_PLACE_CONFIRM_TIMEOUT_MS = 180L;
74
    private static final long PENDING_BED_EXPLODE_CONFIRM_TIMEOUT_MS = 320L;
75
    private static final double TEXT_Y_OFFSET = 0.10;
76
    private static final double TEXT_WORLD_SCALE = 0.025;
77
    private static final double TEXT_SCALE = 1.0;
78
    private static final double TEXT_GAP_SCALE = 1.0;
79
80
    private final Minecraft mc = Minecraft.getInstance();
81
82
    private final BooleanValue placeEnabled = boolCommon("autobedPlace", "place", CommonSettingSchemas.PLACE, true);
83
    private final BooleanValue explodeEnabled = boolCommon("autobedExplode", "explode", CommonSettingSchemas.EXPLODE, true);
84
    private final BooleanValue instantExplode = bool("autobedInstantExplode", "instant_explode", true);
85
    private final EnumValue<Timing> timing = enumCommon("autobedTiming", "timing", CommonSettingSchemas.TIMING, Timing.NORMAL);
86
    private final NumberValue<Integer> calcDelay = numCommon("autobedCalcDelay", "calc_delay", CommonSettingSchemas.CALC_DELAY, 100, 0, 500);
87
    private final NumberValue<Integer> placeDelay = numCommon(
88
            "autobedPlaceDelay",
89
            "place_delay",
90
            CommonSettingSchemas.PLACEMENT_DELAY,
91
            0,
92
            0,
93
            1000
94
    );
95
    private final NumberValue<Integer> lowPlaceDelay = numCommon("autobedLowPlaceDelay", "low_place_delay", CommonSettingSchemas.LOW_PLACE_DELAY, 550, 0, 1000);
96
    private final NumberValue<Integer> explodeDelay = numCommon(
97
            "autobedExplodeDelay",
98
            "explode_delay",
99
            CommonSettingSchemas.PLACEMENT_BREAK_DELAY,
100
            0,
101
            0,
102
            1000
103
    );
104
    private final NumberValue<Integer> lowExplodeDelay = numCommon("autobedLowExplodeDelay", "low_explode_delay", CommonSettingSchemas.LOW_EXPLODE_DELAY, 550, 0, 1000);
105
    private final NumberValue<Float> placeRange = numCommon(
106
            "autobedPlaceRange",
107
            "place_range",
108
            CommonSettingSchemas.PLACEMENT_RANGE,
109
            5.0f,
110
            1.0f,
111
            6.0f
112
    );
113
    private final NumberValue<Float> wallRange = numCommon(
114
            "autobedWallRange",
115
            "wall_range",
116
            CommonSettingSchemas.PLACEMENT_WALL_RANGE,
117
            3.5f,
118
            0.0f,
119
            6.0f
120
    );
121
    private final EnumValue<AutoBedPlacementMode> placementMode = enumCommon(
122
            "autobedPlacementMode",
123
            "placement_mode",
124
            CommonSettingSchemas.PLACEMENT_MODE,
125
            AutoBedPlacementMode.DEFAULT,
126
            AutoBedPlacementMode.values()
127
    );
128
    private final NumberValue<Float> targetRange = numCommon(
129
            "autobedTargetRange",
130
            "target_range",
131
            CommonSettingSchemas.COMBAT_RANGE,
132
            10.0f,
133
            1.0f,
134
            15.0f
135
    );
136
    private final BooleanMapValue targetToggles = groupCommon(
137
            "autobedTargets",
138
            "targets",
139
            CommonSettingSchemas.TARGET_FILTERS
140
    );
141
    private final EnumValue<TargetingUtil.TargetPriority> priority = enumCommon(
142
            "autobedPriority",
143
            "priority",
144
            CommonSettingSchemas.COMBAT_PRIORITY,
145
            TargetingUtil.TargetPriority.DISTANCE,
146
            TargetingUtil.TargetPriority.values()
147
    );
148
    private final NumberValue<Float> minDamage = numCommon("autobedMinDamage", "min_damage", CommonSettingSchemas.MIN_DAMAGE, 6.0f, 0.0f, 36.0f);
149
    private final NumberValue<Float> faceplaceHealth = numCommon("autobedFaceplaceHealth", "faceplace_health", CommonSettingSchemas.FACEPLACE_HEALTH, 5.0f, 0.0f, 36.0f);
150
    private final NumberValue<Float> maxSelfDamage = numCommon("autobedMaxSelfDamage", "max_self_damage", CommonSettingSchemas.MAX_SELF_DAMAGE, 10.0f, 0.0f, 36.0f);
151
    private final NumberValue<Integer> predictTicks = numCommon(
152
            "autobedPredictTicks",
153
            "predict_ticks",
154
            CommonSettingSchemas.PLACEMENT_PREDICTION,
155
            3,
156
            0,
157
            20
158
    );
159
    private final NumberValue<Integer> selfPredictTicks = numCommon("autobedSelfPredictTicks", "self_predict_ticks", CommonSettingSchemas.SELF_PREDICT_TICKS, 3, 0, 20);
160
    private final BooleanValue pauseMining = boolCommon("autobedPauseMining", "pause_mining", CommonSettingSchemas.PAUSE_MINING, true);
161
    private final BooleanValue pauseEating = boolCommon("autobedPauseEating", "pause_eating", CommonSettingSchemas.PAUSE_EATING, true);
162
    private final NumberValue<Float> pauseHealth = numCommon(
163
            "autobedPauseHealth",
164
            "pause_health",
165
            CommonSettingSchemas.PLAYER_HEALTH_THRESHOLD,
166
            8.0f,
167
            0.0f,
168
            20.0f
169
    );
170
    private final EnumValue<InventorySearchScope> swapScope = enumCommon(
171
            "autobedSwapScope",
172
            "swap_scope",
173
            CommonSettingSchemas.INVENTORY_SEARCH_SCOPE,
174
            InventorySearchScope.FULL,
175
            InventorySearchScope.values()
176
    );
177
    private final EnumValue<InventorySwapVisibility> swapVisibility = enumCommon(
178
            "autobedSwapVisibility",
179
            "swap_visibility",
180
            CommonSettingSchemas.INVENTORY_SWAP_VISIBILITY,
181
            InventorySwapVisibility.SILENT,
182
            InventorySwapVisibility.values()
183
    );
184
    private final BooleanValue restoreItem = boolCommon(
185
            "autobedRestoreItem",
186
            "restore_item",
187
            CommonSettingSchemas.INVENTORY_RESTORE_ITEM,
188
            true
189
    );
190
    private final ModeValue attackMode = modeCommon(
191
            "autobedAttackMode",
192
            "attack_mode",
193
            CommonSettingSchemas.COMBAT_ATTACK_MODE,
194
            CombatRotationModeUtil.MODE_ROTATIONS,
195
            CombatRotationModeUtil.MODE_ROTATIONS,
196
            CombatRotationModeUtil.MODE_NO_ROTATIONS
197
    );
198
    private final EnumValue<MovementCorrection> movementCorrection = visibleWhen(enumCommon(
199
            "autobedMovementCorrection",
200
            "movement_correction",
201
            CommonSettingSchemas.PLACEMENT_MOVEMENT_CORRECTION,
202
            MovementCorrection.SILENT,
203
            MovementCorrection.values()
204
    ), this::usesRotationSettings);
205
    private final NumberValue<Integer> rotationResetTicks = visibleWhen(numCommon(
206
            "autobedRotationResetTicks",
207
            "rotation_reset_ticks",
208
            CommonSettingSchemas.ROTATION_RESET_TICKS,
209
            1,
210
            1,
211
            20
212
    ), this::usesRotationSettings);
213
    private final NumberValue<Float> rotationResetThreshold = visibleWhen(numCommon(
214
            "autobedRotationResetThreshold",
215
            "rotation_reset_threshold",
216
            CommonSettingSchemas.ROTATION_RESET_THRESHOLD,
217
            2.0f,
218
            0.1f,
219
            15.0f
220
    ), this::usesRotationSettings);
221
    private final BooleanValue renderEnabled = boolCommon(
222
            "autobedRender",
223
            "render",
224
            CommonSettingSchemas.PLACEMENT_RENDER,
225
            true
226
    );
227
    private final EnumValue<RenderMode> renderMode = enumCommon(
228
            "autobedRenderMode",
229
            "render_mode",
230
            CommonSettingSchemas.PLACEMENT_RENDER_MODE,
231
            RenderMode.FADE,
232
            RenderMode.values()
233
    );
234
    private final BooleanValue renderSelfDamage = boolCommon("autobedRenderSelfDamage", "render_self_damage", CommonSettingSchemas.RENDER_SELF_DAMAGE, true);
235
    private final BooleanValue drawDamage = boolCommon("autobedRenderDamage", "render_damage", CommonSettingSchemas.RENDER_DAMAGE, true);
236
    private final RGBAColorValue fillColor = common(color("autobedFillColor", "#5A285AFF"), CommonSettingSchemas.FILL_COLOR);
237
    private final RGBAColorValue lineColor = common(color("autobedLineColor", "#FFAA55FF"), CommonSettingSchemas.LINE_COLOR);
238
    private final NumberValue<Float> lineWidth = numCommon("autobedLineWidth", "line_width", CommonSettingSchemas.LINE_WIDTH, 2.0f, 1.0f, 6.0f);
239
    private final RGBAColorValue textColor = common(color("autobedTextColor", "#FFFFFFFF"), CommonSettingSchemas.TEXT_COLOR);
240
    private final NumberValue<Float> billboardSize = visibleWhen(numCommon(
241
            "autobedBillboardSize", "billboard_size", CommonSettingSchemas.BILLBOARD_SIZE, 0.72f, 0.35f, 1.50f),
242
            drawDamage::get);
243
    private final BooleanValue billboardDynamicScale = visibleWhen(boolCommon(
244
            "autobedBillboardDynamicScale", "billboard_dynamic_scale", CommonSettingSchemas.BILLBOARD_DYNAMIC_SCALE, true),
245
            drawDamage::get);
246
    private final NumberValue<Float> billboardDynamicScaleCoefficient = visibleWhen(numCommon(
247
            "autobedBillboardDynamicScaleCoefficient", "billboard_dynamic_scale_coefficient",
248
            CommonSettingSchemas.BILLBOARD_DYNAMIC_SCALE_COEFFICIENT, 0.25f, 0.0f, 1.0f),
249
            () -> drawDamage.get() && billboardDynamicScale.get());
250
    private final NumberValue<Integer> slideDelay = visibleWhen(numCommon("autobedSlideDelay", "slide_delay", CommonSettingSchemas.SLIDE_DELAY, 200, 1, 1000),
251
            () -> renderMode.get() == RenderMode.SLIDE);
252
    private final NumberValue<Integer> fadeTime = visibleWhen(numCommon("autobedFadeTime", "fade_time", CommonSettingSchemas.FADE_TIME, 500, 100, 2000),
253
            () -> renderMode.get() == RenderMode.FADE);
254
255
    private final AutoBedPlanner planner = new AutoBedPlanner();
256
    private final AutoBedPlanner.Context plannerContext = new PlannerContext();
257
    private final Map<BlockPos, Long> renderPositions = new ConcurrentHashMap<>();
258
259
    private LivingEntity target;
260
    private AutoBedData bestPlace;
261
    private AutoBedData bestExplode;
262
    private BlockPos renderFootPos;
263
    private BlockPos renderHeadPos;
264
    private BlockPos prevRenderFootPos;
265
    private BlockPos prevRenderHeadPos;
266
    private BlockPos bestFootPos;
267
    private BlockPos bestHeadPos;
268
    private int renderTick;
269
    private int renderStartTick;
270
    private long lastPlaceMs;
271
    private long lastExplodeMs;
272
    private long lastDamageUpdateMs;
273
    private long lastCalcMs;
274
    private AutoBedData pendingBedData;
275
    private long pendingBedSinceMs;
276
    private boolean pendingBedPlaceSent;
277
    private boolean pendingBedExplodeSent;
278
    private long pendingBedExplodeSentMs;
279
    private float renderDamage;
280
    private float renderSelfDamageValue;
281
    private boolean lowDamageMode;
282
    private int lastScanned;
283
    private int lastCandidates;
284
    private int lastSafeCandidates;
285
    private int lastSelfDamageRejects;
286
    private String disabledReason;
287
288
    @Override
289
    public WorldPhase getWorldPhase() {
290
        return WorldPhase.AFTER_POST_PROCESS;
291
    }
292
293
    @Override
294
    protected String getUnavailableReason() {
295
        if (mc != null && mc.level != null && !isExplosiveBedDimension(mc.level)) {
296
            return "Nether/End only";
297
        }
298
        return "";
299
    }
300
301
    @Override
302
    public void onEnable() {
303
        resetState();
304
    }
305
306
    @Override
307
    public void onDisable() {
308
        resetState();
309
        RotationManager.INSTANCE.clear(this);
310
        TargetManager.setAutoBedTarget(null);
311
    }
312
313
    @Override
314
    public void onTick() {
315
        if (!isEnabled()) return;
316
        renderTick++;
317
        InventorySwap.INSTANCE.tick();
318
        purgeExpiredRenderPositions();
319
        if (System.currentTimeMillis() - lastDamageUpdateMs > DAMAGE_RESET_MS && renderPositions.isEmpty()) {
320
            renderDamage = 0.0f;
321
            renderSelfDamageValue = 0.0f;
322
        }
323
    }
324
325
    @EventHandler(priority = 23)
326
    private void onRotationUpdate(RotationUpdateEvent event) {
327
        if (event.getType() != RotationUpdateEvent.Type.PRE) return;
328
        if (!isEnabled()) return;
329
330
        if (mc.player == null || mc.level == null || mc.gameMode == null) {
331
            clearCombatState();
332
            TargetManager.setAutoBedTarget(null);
333
            return;
334
        }
335
336
        if (!isExplosiveBedDimension(mc.level)) {
337
            disabledReason = "Wrong dimension";
338
            clearCombatState();
339
            TargetManager.setAutoBedTarget(null);
340
            RotationManager.INSTANCE.clear(this);
341
            return;
342
        }
343
        disabledReason = null;
344
345
        target = findCombatTarget();
346
        TargetManager.setAutoBedTarget(target);
347
        updateCandidates();
348
349
        if (timing.get() == Timing.NORMAL) {
350
            runCombatCycle();
351
        }
352
    }
353
354
    @EventHandler(priority = -23)
355
    private void onRotationUpdatePost(RotationUpdateEvent event) {
356
        if (event.getType() != RotationUpdateEvent.Type.POST) return;
357
        if (!isEnabled() || timing.get() != Timing.SEQUENTIAL) return;
358
        runCombatCycle();
359
    }
360
361
    @Override
362
    public void onRenderWorldEngine(Renderer3D renderer, Renderer3D depthRenderer, float tickDelta) {
363
        if (!isEnabled() || mc.player == null || mc.level == null) return;
364
        if (renderEnabled.get()) {
365
            renderPlacement(renderer, tickDelta);
366
        }
367
    }
368
369
    private void updateCandidates() {
370
        if (target == null || shouldPause()) {
371
            bestPlace = null;
372
            bestExplode = null;
373
            lastCalcMs = 0L;
374
            return;
375
        }
376
377
        long now = System.currentTimeMillis();
378
        long delay = Math.max(0, calcDelay.get());
379
        if (delay > 0L && now - lastCalcMs < delay) {
380
            return;
381
        }
382
        lastCalcMs = now;
383
384
        AutoBedPlanner.ScanResult result = planner.scan(
385
                plannerContext,
386
                target,
387
                resolvePredictedPosition(target, predictTicks.get()),
388
                Mth.ceil(placeRange.get())
389
        );
390
        bestPlace = result.bestPlace();
391
        bestExplode = result.bestExplode();
392
        lastScanned = result.scanned();
393
        lastCandidates = result.candidates();
394
        lastSafeCandidates = result.safeCandidates();
395
        lastSelfDamageRejects = result.selfDamageRejects();
396
397
        AutoBedData renderData = bestExplode != null ? bestExplode : bestPlace;
398
        if (renderData != null) {
399
            setRenderCandidate(renderData);
400
            lowDamageMode = !ExplosionDamageRules.shouldOverrideMinDamage(target, renderData.damage(), faceplaceHealth.get())
401
                    && renderData.damage() < minDamage.get();
402
        } else if (renderPositions.isEmpty()) {
403
            bestFootPos = null;
404
            bestHeadPos = null;
405
        }
406
    }
407
408
    private void runCombatCycle() {
409
        if (mc.player == null || mc.level == null) {
410
            clearPendingBed();
411
            RotationManager.INSTANCE.clear(this);
412
            return;
413
        }
414
        if (shouldPause()) {
415
            RotationManager.INSTANCE.clear(this);
416
            return;
417
        }
418
419
        if (continuePendingBedCycle()) {
420
            return;
421
        }
422
423
        if (target == null) {
424
            RotationManager.INSTANCE.clear(this);
425
            return;
426
        }
427
428
        if (explodeEnabled.get() && bestExplode != null && hasExplodeDelayElapsed()) {
429
            executeWithRotation(bestExplode, false, () -> explodeBed(bestExplode));
430
            return;
431
        }
432
433
        if (placeEnabled.get() && bestPlace != null && hasPlaceDelayElapsed()) {
434
            executeWithRotation(bestPlace, true, () -> placeBed(bestPlace));
435
            return;
436
        }
437
438
        RotationManager.INSTANCE.clear(this);
439
    }
440
441
    private void executeWithRotation(AutoBedData data, boolean placing, Runnable action) {
442
        if (data == null || action == null || mc.player == null) return;
443
        if (!usesRotationSettings()) {
444
            RotationManager.INSTANCE.clear(this);
445
            action.run();
446
            return;
447
        }
448
449
        Rotation rotation = rotationFor(data, placing);
450
        RotationTarget rotationTarget = new RotationTarget(
451
                rotation,
452
                target,
453
                List.of(),
454
                rotationResetTicks.get(),
455
                rotationResetThreshold.get(),
456
                true,
457
                movementCorrection.get(),
458
                new RestrictedSingleUseAction(action)
459
        );
460
        RotationManager.INSTANCE.setRotationTarget(rotationTarget, ROTATION_PRIORITY, this);
461
    }
462
463
    private Rotation rotationFor(AutoBedData data, boolean placing) {
464
        BlockHitResult hit = placing ? data.placeHitResult() : data.explodeHitResult();
465
        Vec3 point = hit != null ? hit.getLocation() : data.explosionVec();
466
        Rotation look = Rotation.lookingAt(point, mc.player.getEyePosition());
467
        if (placing) {
468
            return new Rotation(AutoBedInteractionUtil.yawForFacing(data.facing()), look.pitch()).normalize();
469
        }
470
        return look.normalize();
471
    }
472
473
    private void placeBed(AutoBedData data) {
474
        if (data == null || data.existingBed() || !hasPlaceDelayElapsed() || shouldPause()) return;
475
        AutoBedData refreshed = planner.evaluate(plannerContext, data, target);
476
        if (refreshed == null || refreshed.existingBed()) {
477
            clearPendingBedIfMatches(data);
478
            return;
479
        }
480
481
        setPendingBed(refreshed, true);
482
        boolean placed = AutoBedActionUtil.placeBed(
483
                mc,
484
                this,
485
                refreshed.placeHitResult(),
486
                swapScope.get(),
487
                swapVisibility.get(),
488
                restoreItem.get()
489
        );
490
        if (!placed) {
491
            clearPendingBedIfMatches(refreshed);
492
            return;
493
        }
494
495
        lastPlaceMs = System.currentTimeMillis();
496
        pendingBedSinceMs = lastPlaceMs;
497
        markPlaced(refreshed);
498
    }
499
500
    private void explodeBed(AutoBedData data) {
501
        if (data == null || !hasExplodeDelayElapsed() || shouldPause()) return;
502
        AutoBedData refreshed = planner.evaluate(plannerContext, data, target);
503
        if (refreshed == null || !refreshed.existingBed()) {
504
            clearPendingBedIfMatches(data);
505
            return;
506
        }
507
508
        setPendingBed(refreshed, false);
509
        detonatePendingBed(refreshed);
510
    }
511
512
    private boolean continuePendingBedCycle() {
513
        if (pendingBedData == null) {
514
            return false;
515
        }
516
        if (mc.player == null || mc.level == null) {
517
            clearPendingBed();
518
            return false;
519
        }
520
521
        long now = System.currentTimeMillis();
522
        BlockPos bedPos = findPendingBedInteractPos();
523
        if (bedPos == null) {
524
            if (pendingBedExplodeSent) {
525
                clearPendingBed();
526
                return false;
527
            }
528
            if (pendingBedPlaceSent && now - pendingBedSinceMs < PENDING_BED_PLACE_CONFIRM_TIMEOUT_MS) {
529
                RotationManager.INSTANCE.clear(this);
530
                return true;
531
            }
532
            clearPendingBed();
533
            return false;
534
        }
535
536
        AutoBedData pendingData = resolvePendingBedData(bedPos);
537
        if (pendingData == null) {
538
            if (now - pendingBedSinceMs < PENDING_BED_PLACE_CONFIRM_TIMEOUT_MS) {
539
                RotationManager.INSTANCE.clear(this);
540
                return true;
541
            }
542
            clearPendingBed();
543
            return false;
544
        }
545
546
        pendingBedData = pendingData;
547
        pendingBedSinceMs = now;
548
549
        if (pendingBedExplodeSent) {
550
            if (isPendingBedBlock(bedPos) && now - pendingBedExplodeSentMs < PENDING_BED_EXPLODE_CONFIRM_TIMEOUT_MS) {
551
                RotationManager.INSTANCE.clear(this);
552
                return true;
553
            }
554
            pendingBedExplodeSent = false;
555
            pendingBedExplodeSentMs = 0L;
556
            if (!isPendingBedBlock(bedPos)) {
557
                clearPendingBed();
558
                return false;
559
            }
560
        }
561
562
        if (!explodeEnabled.get()) {
563
            clearPendingBed();
564
            return false;
565
        }
566
567
        if (hasPendingExplodeDelayElapsed()) {
568
            executeWithRotation(pendingData, false, () -> detonatePendingBed(pendingData));
569
            return true;
570
        }
571
572
        RotationManager.INSTANCE.clear(this);
573
        return true;
574
    }
575
576
    private void detonatePendingBed(AutoBedData data) {
577
        if (data == null || data.explodeHitResult() == null || !hasPendingExplodeDelayElapsed() || shouldPause()) return;
578
579
        boolean exploded = AutoBedActionUtil.explodeBed(
580
                mc,
581
                this,
582
                data.explodeHitResult(),
583
                swapScope.get(),
584
                swapVisibility.get(),
585
                restoreItem.get()
586
        );
587
        if (!exploded) return;
588
589
        lastExplodeMs = System.currentTimeMillis();
590
        pendingBedExplodeSent = true;
591
        pendingBedExplodeSentMs = lastExplodeMs;
592
        markPlaced(data);
593
    }
594
595
    private AutoBedData resolvePendingBedData(BlockPos bedPos) {
596
        if (pendingBedData == null || bedPos == null || mc.player == null || mc.level == null) {
597
            return null;
598
        }
599
600
        BlockHitResult hit = findPendingBedInteractResult(bedPos);
601
        if (hit == null) {
602
            return null;
603
        }
604
605
        var state = mc.level.getBlockState(hit.getBlockPos());
606
        if (!AutoBedInteractionUtil.isBedBlock(state)) {
607
            return null;
608
        }
609
610
        BlockPos footPos = AutoBedInteractionUtil.resolveFootPos(state, hit.getBlockPos());
611
        BlockPos headPos = AutoBedInteractionUtil.resolveHeadPos(state, hit.getBlockPos());
612
        if (footPos == null || headPos == null) {
613
            return null;
614
        }
615
616
        AutoBedData template = new AutoBedData(
617
                footPos,
618
                headPos,
619
                AutoBedInteractionUtil.bedFacing(state),
620
                hit.getBlockPos(),
621
                pendingBedData.placeHitResult(),
622
                hit,
623
                AutoBedInteractionUtil.bedExplosionVec(hit.getBlockPos()),
624
                pendingBedData.damage(),
625
                pendingBedData.selfDamage(),
626
                pendingBedData.overrideDamage(),
627
                true
628
        );
629
        AutoBedData evaluated = target != null ? planner.evaluate(plannerContext, template, target) : null;
630
        if (evaluated != null && evaluated.existingBed()) {
631
            return evaluated;
632
        }
633
634
        return template;
635
    }
636
637
    private BlockPos findPendingBedInteractPos() {
638
        if (pendingBedData == null || mc.level == null) {
639
            return null;
640
        }
641
642
        BlockPos preferred = pendingBedData.interactPos();
643
        if (isPendingBedBlock(preferred)) return preferred;
644
        if (isPendingBedBlock(pendingBedData.footPos())) return pendingBedData.footPos();
645
        if (isPendingBedBlock(pendingBedData.headPos())) return pendingBedData.headPos();
646
647
        // If placement yaw was not applied exactly, vanilla can still place the bed at the same clicked foot
648
        // but with another horizontal head direction. Adopt that real client-side bed immediately instead of
649
        // sitting in Waiting bed until the confirm timeout expires.
650
        BlockPos adopted = findBedTouchingPendingPlacement();
651
        if (adopted != null) return adopted;
652
        return null;
653
    }
654
655
    private BlockHitResult findPendingBedInteractResult(BlockPos preferred) {
656
        if (preferred != null && isPendingBedBlock(preferred)) {
657
            BlockHitResult hit = getBedInteractResult(preferred);
658
            if (hit != null) return hit;
659
        }
660
661
        BlockPos foot = pendingBedData.footPos();
662
        if (foot != null && isPendingBedBlock(foot)) {
663
            BlockHitResult hit = getBedInteractResult(foot);
664
            if (hit != null) return hit;
665
        }
666
667
        BlockPos head = pendingBedData.headPos();
668
        if (head != null && isPendingBedBlock(head)) {
669
            BlockHitResult hit = getBedInteractResult(head);
670
            if (hit != null) return hit;
671
        }
672
673
        BlockPos adopted = findBedTouchingPendingPlacement();
674
        if (adopted != null) {
675
            BlockHitResult hit = getBedInteractResult(adopted);
676
            if (hit != null) return hit;
677
        }
678
        return null;
679
    }
680
681
    private BlockPos findBedTouchingPendingPlacement() {
682
        if (pendingBedData == null || mc.level == null) return null;
683
        BlockPos foot = pendingBedData.footPos();
684
        BlockPos head = pendingBedData.headPos();
685
686
        BlockPos direct = findBedAtOrAdjacent(foot);
687
        if (direct != null) return direct;
688
        return findBedAtOrAdjacent(head);
689
    }
690
691
    private BlockPos findBedAtOrAdjacent(BlockPos origin) {
692
        if (origin == null || mc.level == null) return null;
693
        if (isAdoptablePendingBedBlock(origin)) return origin;
694
        for (Direction direction : Direction.Plane.HORIZONTAL) {
695
            BlockPos pos = origin.relative(direction);
696
            if (isAdoptablePendingBedBlock(pos)) {
697
                return pos;
698
            }
699
        }
700
        return null;
701
    }
702
703
    private boolean isPendingBedBlock(BlockPos pos) {
704
        if (pos == null || mc.level == null || pendingBedData == null || !mc.level.isInWorldBounds(pos)) return false;
705
        var state = mc.level.getBlockState(pos);
706
        if (!AutoBedInteractionUtil.isBedBlock(state)) return false;
707
        BlockPos footPos = AutoBedInteractionUtil.resolveFootPos(state, pos);
708
        BlockPos headPos = AutoBedInteractionUtil.resolveHeadPos(state, pos);
709
        if (positionsEqual(footPos, pendingBedData.footPos()) && positionsEqual(headPos, pendingBedData.headPos())) {
710
            return true;
711
        }
712
        return pendingBedPlaceSent && overlapsPendingBed(footPos, headPos);
713
    }
714
715
    private boolean isAdoptablePendingBedBlock(BlockPos pos) {
716
        if (pos == null || mc.level == null || pendingBedData == null || !mc.level.isInWorldBounds(pos)) return false;
717
        var state = mc.level.getBlockState(pos);
718
        if (!AutoBedInteractionUtil.isBedBlock(state)) return false;
719
        BlockPos footPos = AutoBedInteractionUtil.resolveFootPos(state, pos);
720
        BlockPos headPos = AutoBedInteractionUtil.resolveHeadPos(state, pos);
721
        return overlapsPendingBed(footPos, headPos);
722
    }
723
724
    private boolean overlapsPendingBed(BlockPos footPos, BlockPos headPos) {
725
        if (pendingBedData == null) return false;
726
        return positionsEqual(footPos, pendingBedData.footPos())
727
                || positionsEqual(footPos, pendingBedData.headPos())
728
                || positionsEqual(headPos, pendingBedData.footPos())
729
                || positionsEqual(headPos, pendingBedData.headPos());
730
    }
731
732
    private boolean positionsEqual(BlockPos first, BlockPos second) {
733
        return first != null && first.equals(second);
734
    }
735
736
    private void setPendingBed(AutoBedData data, boolean placeSent) {
737
        if (data == null) {
738
            clearPendingBed();
739
            return;
740
        }
741
        if (pendingBedData == null
742
                || !positionsEqual(data.footPos(), pendingBedData.footPos())
743
                || !positionsEqual(data.headPos(), pendingBedData.headPos())) {
744
            pendingBedSinceMs = System.currentTimeMillis();
745
            pendingBedExplodeSent = false;
746
            pendingBedExplodeSentMs = 0L;
747
        }
748
        pendingBedData = data;
749
        pendingBedPlaceSent = placeSent || !data.existingBed();
750
    }
751
752
    private void clearPendingBedIfMatches(AutoBedData data) {
753
        if (data == null || pendingBedData == null) return;
754
        if (positionsEqual(data.footPos(), pendingBedData.footPos())
755
                && positionsEqual(data.headPos(), pendingBedData.headPos())) {
756
            clearPendingBed();
757
        }
758
    }
759
760
    private void clearPendingBed() {
761
        pendingBedData = null;
762
        pendingBedSinceMs = 0L;
763
        pendingBedPlaceSent = false;
764
        pendingBedExplodeSent = false;
765
        pendingBedExplodeSentMs = 0L;
766
    }
767
768
    private boolean shouldPause() {
769
        if (mc.player == null || mc.level == null || mc.gameMode == null) return true;
770
        if (!isExplosiveBedDimension(mc.level)) {
771
            disabledReason = "Wrong dimension";
772
            return true;
773
        }
774
        disabledReason = null;
775
        if (pauseMining.get() && mc.gameMode.isDestroying()) return true;
776
        if (pauseEating.get()
777
                && mc.player.isUsingItem()
778
                && FoodUtil.isFood(mc.player.getUseItem())
779
                && !RubberHandUseUtil.canBypassCurrentUse(mc)) return true;
780
        return mc.player.getHealth() + mc.player.getAbsorptionAmount() < pauseHealth.get();
781
    }
782
783
    private boolean isExplosiveBedDimension(ClientLevel level) {
784
        return level != null && (level.dimension() == Level.NETHER || level.dimension() == Level.END);
785
    }
786
787
    private boolean hasPlaceDelayElapsed() {
788
        return System.currentTimeMillis() - lastPlaceMs >= Math.max(0, lowDamageMode ? lowPlaceDelay.get() : placeDelay.get());
789
    }
790
791
    private boolean hasExplodeDelayElapsed() {
792
        return System.currentTimeMillis() - lastExplodeMs >= Math.max(0, lowDamageMode ? lowExplodeDelay.get() : explodeDelay.get());
793
    }
794
795
    private boolean hasPendingExplodeDelayElapsed() {
796
        return (pendingBedPlaceSent && instantExplode.get()) || hasExplodeDelayElapsed();
797
    }
798
799
    private long getPlaceDelayRemainingMs() {
800
        return Math.max(0L, Math.max(0, lowDamageMode ? lowPlaceDelay.get() : placeDelay.get()) - (System.currentTimeMillis() - lastPlaceMs));
801
    }
802
803
    private long getExplodeDelayRemainingMs() {
804
        return Math.max(0L, Math.max(0, lowDamageMode ? lowExplodeDelay.get() : explodeDelay.get()) - (System.currentTimeMillis() - lastExplodeMs));
805
    }
806
807
    private long getPendingExplodeDelayRemainingMs() {
808
        if (pendingBedPlaceSent && instantExplode.get()) return 0L;
809
        return getExplodeDelayRemainingMs();
810
    }
811
812
    private void setRenderCandidate(AutoBedData data) {
813
        bestFootPos = data.footPos();
814
        bestHeadPos = data.headPos();
815
        renderDamage = Math.max(0.0f, data.damage());
816
        renderSelfDamageValue = Math.max(0.0f, data.selfDamage());
817
        lastDamageUpdateMs = System.currentTimeMillis();
818
    }
819
820
    private void markPlaced(AutoBedData data) {
821
        if (data == null || data.footPos() == null || data.headPos() == null) return;
822
        if (!data.footPos().equals(renderFootPos) || !data.headPos().equals(renderHeadPos)) {
823
            renderStartTick = renderTick;
824
            prevRenderFootPos = renderFootPos;
825
            prevRenderHeadPos = renderHeadPos;
826
            renderFootPos = data.footPos();
827
            renderHeadPos = data.headPos();
828
        }
829
        setRenderCandidate(data);
830
        renderPositions.put(data.footPos(), System.currentTimeMillis());
831
        renderPositions.put(data.headPos(), System.currentTimeMillis());
832
    }
833
834
    private void renderPlacement(Renderer3D renderer, float tickDelta) {
835
        String damageText = buildDamageText();
836
        if (damageText.isEmpty() && renderPositions.isEmpty() && renderFootPos == null) {
837
            return;
838
        }
839
840
        if (renderMode.get() == RenderMode.FADE) {
841
            renderFade(renderer);
842
            return;
843
        }
844
845
        BlockPos activeFoot = renderPositions.isEmpty() ? bestFootPos : renderFootPos;
846
        BlockPos activeHead = renderPositions.isEmpty() ? bestHeadPos : renderHeadPos;
847
        if (activeFoot == null || activeHead == null) return;
848
849
        if (renderMode.get() == RenderMode.SLIDE) {
850
            BlockPos slideFoot = renderPositions.isEmpty() ? bestFootPos : renderFootPos;
851
            BlockPos slideHead = renderPositions.isEmpty() ? bestHeadPos : renderHeadPos;
852
            BlockPos fromFoot = prevRenderFootPos != null ? prevRenderFootPos : slideFoot;
853
            BlockPos fromHead = prevRenderHeadPos != null ? prevRenderHeadPos : slideHead;
854
            renderBox(renderer, ExplosionRenderUtil.lerpBox(bedBox(fromFoot, fromHead), bedBox(slideFoot, slideHead), getSlideProgress(tickDelta)), 1.0f);
855
        } else {
856
            renderBox(renderer, bedBox(activeFoot, activeHead), 1.0f);
857
        }
858
    }
859
860
    private AABB bedBox(BlockPos foot, BlockPos head) {
861
        return new AABB(foot).minmax(new AABB(head));
862
    }
863
864
    private float getSlideProgress(float tickDelta) {
865
        float clampedTickDelta = Mth.clamp(tickDelta, 0.0f, 1.0f);
866
        float durationTicks = Math.max(1.0f, slideDelay.get() / 50.0f);
867
        return Mth.clamp((renderTick - renderStartTick + clampedTickDelta) / durationTicks, 0.0f, 1.0f);
868
    }
869
870
    private void renderFade(Renderer3D renderer) {
871
        long now = System.currentTimeMillis();
872
        int lifetime = Math.max(1, fadeTime.get());
873
        List<Map.Entry<BlockPos, Long>> entries = new ArrayList<>(renderPositions.entrySet());
874
        for (Map.Entry<BlockPos, Long> entry : entries) {
875
            long age = now - entry.getValue();
876
            if (age > lifetime) {
877
                renderPositions.remove(entry.getKey());
878
                continue;
879
            }
880
            float alpha = 1.0f - (age / (float) lifetime);
881
            renderBox(renderer, new AABB(entry.getKey()), alpha);
882
        }
883
    }
884
885
    private void renderBox(Renderer3D renderer, AABB box, float alpha) {
886
        int fillArgb = ExplosionRenderUtil.applyOpacity(fillColor.getArgb(), alpha);
887
        int lineArgb = ExplosionRenderUtil.applyOpacity(lineColor.getArgb(), alpha);
888
        ExplosionRenderUtil.addFilledBox(renderer, box, fillArgb);
889
890
        float prevWidth = RenderState.lineWidth;
891
        RenderState.lineWidth = Math.max(0.5f, lineWidth.get());
892
        try {
893
            ExplosionRenderUtil.addOutlineBox(renderer, box, lineArgb);
894
        } finally {
895
            RenderState.lineWidth = prevWidth;
896
        }
897
898
        if (drawDamage.get()) {
899
            renderDamageText(renderer, box.getCenter(), alpha);
900
        }
901
    }
902
903
    private void renderDamageText(Renderer3D renderer, Vec3 anchor, float alpha) {
904
        double billboardWorldScale = resolveDamageBillboardScale(anchor);
905
        String mainText = ExplosionRenderUtil.formatDamage(renderDamage);
906
        if (mainText.isEmpty()) return;
907
908
        int mainArgb = ExplosionRenderUtil.applyOpacity(textColor.getArgb(), alpha);
909
        TextRenderer bold = BuiltinFontCatalog.IOSEVKA_BOLD.renderer(TextRenderer.get());
910
        WorldTextRenderer.Options baseOptions = WorldTextRenderer.Options.defaults()
911
                .withScale(TEXT_SCALE)
912
                .withWorldScale(billboardWorldScale)
913
                .withDepthMode(Renderer3D.DepthMode.NONE)
914
                .withShadow(true)
915
                .withOffset(0.0, TEXT_Y_OFFSET);
916
917
        if (!renderSelfDamage.get() || renderSelfDamageValue <= 0.0f) {
918
            WorldTextRenderer.drawBillboard(
919
                    renderer,
920
                    bold,
921
                    mainText,
922
                    anchor,
923
                    baseOptions.withCentered(true).withColor(new RenderColor(mainArgb))
924
            );
925
            return;
926
        }
927
928
        String tailText = " / " + ExplosionRenderUtil.formatDamage(renderSelfDamageValue);
929
        TextRenderer medium = BuiltinFontCatalog.IOSEVKA_REGULAR.renderer(TextRenderer.get());
930
        double mainWidth = ExplosionRenderUtil.measureWidth(bold, mainText, TEXT_SCALE);
931
        double tailWidth = ExplosionRenderUtil.measureWidth(medium, tailText, TEXT_GAP_SCALE);
932
        double startX = -(mainWidth + tailWidth) * 0.5;
933
934
        double drawnMain = WorldTextRenderer.drawBillboard(
935
                renderer,
936
                bold,
937
                mainText,
938
                anchor,
939
                baseOptions.withCentered(false)
940
                        .withOffset(startX, TEXT_Y_OFFSET)
941
                        .withColor(new RenderColor(mainArgb))
942
        );
943
944
        WorldTextRenderer.drawBillboard(
945
                renderer,
946
                medium,
947
                tailText,
948
                anchor,
949
                baseOptions.withCentered(false)
950
                        .withScale(TEXT_GAP_SCALE)
951
                        .withOffset(startX + drawnMain, TEXT_Y_OFFSET)
952
                        .withColor(new RenderColor(mainArgb))
953
        );
954
    }
955
956
    private double resolveDamageBillboardScale(Vec3 anchor) {
957
        double distance = RenderState.cameraPos != null ? RenderState.cameraPos.distanceTo(anchor) : 0.0;
958
        return WorldUiPresentationService.resolveWorldScale(
959
                TEXT_WORLD_SCALE,
960
                distance,
961
                12.0,
962
                4.0,
963
                billboardSize.get(),
964
                billboardDynamicScale.get(),
965
                billboardDynamicScaleCoefficient.get()
966
        );
967
    }
968
969
    private void purgeExpiredRenderPositions() {
970
        long now = System.currentTimeMillis();
971
        long lifetime = Math.max(1, fadeTime.get());
972
        renderPositions.entrySet().removeIf(entry -> now - entry.getValue() > lifetime);
973
    }
974
975
    public String getTargetHudStatus(LivingEntity hudTarget) {
976
        if (!isEnabled()) return null;
977
        if (disabledReason != null) return disabledReason;
978
        if (hudTarget == null || target == null || hudTarget != target) return null;
979
        if (mc.player == null || mc.level == null) return "Idle";
980
        if (!isExplosiveBedDimension(mc.level)) return "Wrong dimension";
981
        if (shouldPause()) return "Paused";
982
        if (!AutoBedActionUtil.hasBed(mc, swapScope.get())) return "No beds";
983
984
        if (pendingBedData != null) {
985
            if (pendingBedExplodeSent) return "Confirming bed";
986
            if (findPendingBedInteractPos() != null) {
987
                long wait = getPendingExplodeDelayRemainingMs();
988
                if (wait > 0L) return "Bed in " + wait + "ms";
989
                return usesRotationSettings() ? "Rotate -> bed" : "Exploding bed";
990
            }
991
            return "Waiting bed";
992
        }
993
        if (explodeEnabled.get() && bestExplode != null) {
994
            long wait = getExplodeDelayRemainingMs();
995
            if (wait > 0L) return "Bed in " + wait + "ms";
996
            return usesRotationSettings() ? "Rotate -> bed" : "Exploding bed";
997
        }
998
        if (placeEnabled.get() && bestPlace != null) {
999
            long wait = getPlaceDelayRemainingMs();
1000
            if (wait > 0L) return "Bed in " + wait + "ms";
1001
            return usesRotationSettings() ? "Rotate -> bed" : "Placing bed";
1002
        }
1003
        if (lastSelfDamageRejects > 0 || (lastCandidates > 0 && lastSafeCandidates <= 0)) return "Self dmg";
1004
        if (lastScanned <= 0) return "No scan";
1005
        return "No bed";
1006
    }
1007
1008
    private LivingEntity findCombatTarget() {
1009
        if (mc.player == null || mc.level == null) return null;
1010
        TargetingUtil.TargetingSettings settings = new TargetingUtil.TargetingSettings(
1011
                targetRange.get(),
1012
                180.0f,
1013
                targetToggles.get(TargetFilters.PLAYERS_ONLY),
1014
                targetToggles.get(TargetFilters.IGNORE_FRIENDS),
1015
                targetToggles.get(TargetFilters.IGNORE_STAFF),
1016
                targetToggles.get(TargetFilters.IGNORE_ENEMIES),
1017
                targetToggles.get(TargetFilters.IGNORE_NAKED),
1018
                targetToggles.get(TargetFilters.IGNORE_ENTITIES),
1019
                targetToggles.get(TargetFilters.VISIBLE_ONLY),
1020
                priority.get()
1021
        );
1022
        return TargetingUtil.findBestTarget(mc, settings);
1023
    }
1024
1025
    private Vec3 resolvePredictedPosition(LivingEntity entity, int ticks) {
1026
        if (entity == null || ticks <= 0) {
1027
            return entity != null ? entity.position() : Vec3.ZERO;
1028
        }
1029
        if (entity instanceof Player player) {
1030
            PlayerSimulationCache.SimulatedPlayerCache simulation =
1031
                    player == mc.player
1032
                            ? PlayerSimulationCache.getSimulationForLocalPlayer()
1033
                            : PlayerSimulationCache.getSimulationForOtherPlayers(player);
1034
            if (simulation != null) {
1035
                return simulation.getSnapshotAt(ticks).pos();
1036
            }
1037
        }
1038
        return PositionExtrapolation.getBestForEntity(entity).getPositionInTicks(ticks);
1039
    }
1040
1041
    private boolean shouldOverrideMaxSelfDamage(float damage, float selfDamage) {
1042
        return ExplosionDamageRules.shouldOverrideMaxSelfDamage(
1043
                mc.player,
1044
                target,
1045
                damage,
1046
                selfDamage,
1047
                maxSelfDamage.get()
1048
        );
1049
    }
1050
1051
    private boolean isSafe(float damage, float selfDamage, boolean overrideDamage) {
1052
        return ExplosionDamageRules.isSafe(mc.player, selfDamage, overrideDamage);
1053
    }
1054
1055
    private BlockHitResult getPlaceInteractResult(BlockPos footPos, BlockPos headPos) {
1056
        return AutoBedInteractionUtil.getPlaceSupportInteract(
1057
                mc.level,
1058
                mc.player,
1059
                footPos,
1060
                headPos,
1061
                placementMode.get(),
1062
                placeRange.get(),
1063
                wallRange.get()
1064
        );
1065
    }
1066
1067
    private BlockHitResult getBedInteractResult(BlockPos pos) {
1068
        return AutoBedInteractionUtil.getBedInteractResult(
1069
                mc.level,
1070
                mc.player,
1071
                pos,
1072
                placementMode.get(),
1073
                placeRange.get(),
1074
                wallRange.get()
1075
        );
1076
    }
1077
1078
    private boolean usesRotationSettings() {
1079
        return CombatRotationModeUtil.usesRotations(attackMode);
1080
    }
1081
1082
    private String buildDamageText() {
1083
        String main = ExplosionRenderUtil.formatDamage(renderDamage);
1084
        if (main.isEmpty()) return "";
1085
        if (!renderSelfDamage.get() || renderSelfDamageValue <= 0.0f) return main;
1086
        return main + " / " + ExplosionRenderUtil.formatDamage(renderSelfDamageValue);
1087
    }
1088
1089
    private void clearCombatState() {
1090
        target = null;
1091
        bestPlace = null;
1092
        bestExplode = null;
1093
        bestFootPos = null;
1094
        bestHeadPos = null;
1095
        clearPendingBed();
1096
        RotationManager.INSTANCE.clear(this);
1097
        lastScanned = 0;
1098
        lastCandidates = 0;
1099
        lastSafeCandidates = 0;
1100
        lastSelfDamageRejects = 0;
1101
    }
1102
1103
    private void resetState() {
1104
        target = null;
1105
        bestPlace = null;
1106
        bestExplode = null;
1107
        renderFootPos = null;
1108
        renderHeadPos = null;
1109
        prevRenderFootPos = null;
1110
        prevRenderHeadPos = null;
1111
        bestFootPos = null;
1112
        bestHeadPos = null;
1113
        renderTick = 0;
1114
        renderStartTick = 0;
1115
        lastPlaceMs = 0L;
1116
        lastExplodeMs = 0L;
1117
        lastDamageUpdateMs = 0L;
1118
        lastCalcMs = 0L;
1119
        clearPendingBed();
1120
        renderDamage = 0.0f;
1121
        renderSelfDamageValue = 0.0f;
1122
        lowDamageMode = false;
1123
        renderPositions.clear();
1124
        lastScanned = 0;
1125
        lastCandidates = 0;
1126
        lastSafeCandidates = 0;
1127
        lastSelfDamageRejects = 0;
1128
        disabledReason = null;
1129
    }
1130
1131
    private final class PlannerContext implements AutoBedPlanner.Context {
1132
        @Override
1133
        public LocalPlayer player() {
1134
            return mc.player;
1135
        }
1136
1137
        @Override
1138
        public ClientLevel level() {
1139
            return mc.level;
1140
        }
1141
1142
        @Override
1143
        public LivingEntity target() {
1144
            return AutoBed.this.target;
1145
        }
1146
1147
        @Override
1148
        public Vec3 resolvePredictedPosition(LivingEntity entity, int ticks) {
1149
            return AutoBed.this.resolvePredictedPosition(entity, ticks);
1150
        }
1151
1152
        @Override
1153
        public BlockHitResult getPlaceInteractResult(BlockPos footPos, BlockPos headPos) {
1154
            return AutoBed.this.getPlaceInteractResult(footPos, headPos);
1155
        }
1156
1157
        @Override
1158
        public BlockHitResult getBedInteractResult(BlockPos pos) {
1159
            return AutoBed.this.getBedInteractResult(pos);
1160
        }
1161
1162
        @Override
1163
        public boolean isBlockedByEntity(BlockPos footPos, BlockPos headPos) {
1164
            return CombatEntityQuery.isBlocked(mc.level, new AABB(footPos).minmax(new AABB(headPos)));
1165
        }
1166
1167
        @Override
1168
        public boolean shouldOverrideMaxSelfDamage(float damage, float selfDamage) {
1169
            return AutoBed.this.shouldOverrideMaxSelfDamage(damage, selfDamage);
1170
        }
1171
1172
        @Override
1173
        public boolean isSafe(float damage, float selfDamage, boolean overrideDamage) {
1174
            return AutoBed.this.isSafe(damage, selfDamage, overrideDamage);
1175
        }
1176
1177
        @Override
1178
        public float minDamage() {
1179
            return minDamage.get();
1180
        }
1181
1182
        @Override
1183
        public float faceplaceHealth() {
1184
            return faceplaceHealth.get();
1185
        }
1186
1187
        @Override
1188
        public float maxSelfDamage() {
1189
            return maxSelfDamage.get();
1190
        }
1191
1192
        @Override
1193
        public int predictTicks() {
1194
            return predictTicks.get();
1195
        }
1196
1197
        @Override
1198
        public int selfPredictTicks() {
1199
            return selfPredictTicks.get();
1200
        }
1201
1202
        @Override
1203
        public float placeRange() {
1204
            return placeRange.get();
1205
        }
1206
    }
1207
1208
    private enum Timing {
1209
        NORMAL,
1210
        SEQUENTIAL
1211
    }
1212
1213
    private enum RenderMode {
1214
        FADE,
1215
        SLIDE,
1216
        DEFAULT
1217
    }
1218
}
1219