|
6 | 6 | package meteordevelopment.meteorclient.systems.modules.movement; |
7 | 7 |
|
8 | 8 | import meteordevelopment.meteorclient.events.entity.player.ClipAtLedgeEvent; |
| 9 | +import meteordevelopment.meteorclient.events.render.Render3DEvent; |
| 10 | +import meteordevelopment.meteorclient.renderer.ShapeMode; |
| 11 | +import meteordevelopment.meteorclient.settings.*; |
9 | 12 | import meteordevelopment.meteorclient.systems.modules.Categories; |
10 | 13 | import meteordevelopment.meteorclient.systems.modules.Module; |
| 14 | +import meteordevelopment.meteorclient.utils.render.color.Color; |
11 | 15 | import meteordevelopment.orbit.EventHandler; |
| 16 | +import net.minecraft.util.PlayerInput; |
| 17 | +import net.minecraft.util.hit.BlockHitResult; |
| 18 | +import net.minecraft.util.hit.HitResult; |
| 19 | +import net.minecraft.util.math.Box; |
| 20 | +import net.minecraft.util.math.Vec3d; |
| 21 | +import net.minecraft.world.Heightmap; |
| 22 | +import net.minecraft.world.RaycastContext; |
12 | 23 |
|
13 | 24 | public class SafeWalk extends Module { |
| 25 | + private final SettingGroup sgGeneral = settings.getDefaultGroup(); |
| 26 | + private final SettingGroup sgRender = settings.createGroup("Render"); |
| 27 | + |
| 28 | + private final Setting<Integer> fallDistance = sgGeneral.add(new IntSetting.Builder() |
| 29 | + .name("minimum-fall-distance") |
| 30 | + .description("The minimum number of blocks you are expected to fall before the module activates.") |
| 31 | + .defaultValue(1) |
| 32 | + .min(1) |
| 33 | + .build() |
| 34 | + ); |
| 35 | + |
| 36 | + private final Setting<Boolean> sneak = sgGeneral.add(new BoolSetting.Builder() |
| 37 | + .name("sneak") |
| 38 | + .description("Sneak when approaching edge of block.") |
| 39 | + .defaultValue(false) |
| 40 | + .build() |
| 41 | + ); |
| 42 | + |
| 43 | + private final Setting<Boolean> safeSneak = sgGeneral.add(new BoolSetting.Builder() |
| 44 | + .name("safe-sneak") |
| 45 | + .description("Prevent you from falling if sneak doesn't trigger correctly.") |
| 46 | + .defaultValue(true) |
| 47 | + .visible(sneak::get) |
| 48 | + .build() |
| 49 | + ); |
| 50 | + |
| 51 | + private final Setting<Boolean> sneakSprint = sgGeneral.add(new BoolSetting.Builder() |
| 52 | + .name("sneak-on-sprint") |
| 53 | + .description("Sneak even when sprinting at the block edge.") |
| 54 | + .defaultValue(true) |
| 55 | + .visible(sneak::get) |
| 56 | + .build() |
| 57 | + ); |
| 58 | + |
| 59 | + private final Setting<Double> edgeDistance = sgGeneral.add(new DoubleSetting.Builder() |
| 60 | + .name("edge-distance") |
| 61 | + .description("Distance offset before reaching an edge.") |
| 62 | + .defaultValue(0.30) |
| 63 | + .sliderRange(0.00, 0.30) |
| 64 | + .decimalPlaces(2) |
| 65 | + .visible(sneak::get) |
| 66 | + .build() |
| 67 | + ); |
| 68 | + |
| 69 | + private final Setting<Boolean> renderEdgeDistance = sgRender.add(new BoolSetting.Builder() |
| 70 | + .name("render") |
| 71 | + .description("Render edge distance helper.") |
| 72 | + .defaultValue(false) |
| 73 | + .visible(sneak::get) |
| 74 | + .build() |
| 75 | + ); |
| 76 | + |
| 77 | + private final Setting<Boolean> renderPlayerBox = sgRender.add(new BoolSetting.Builder() |
| 78 | + .name("render-player-box") |
| 79 | + .description("Render player box helper.") |
| 80 | + .defaultValue(false) |
| 81 | + .visible(() -> sneak.get() && renderEdgeDistance.get()) |
| 82 | + .build() |
| 83 | + ); |
| 84 | + |
14 | 85 | public SafeWalk() { |
15 | 86 | super(Categories.Movement, "safe-walk", "Prevents you from walking off blocks."); |
16 | 87 | } |
17 | 88 |
|
18 | 89 | @EventHandler |
19 | 90 | private void onClipAtLedge(ClipAtLedgeEvent event) { |
20 | | - if (!mc.player.isSneaking()) event.setClip(true); |
| 91 | + if (fallDistance.get() > 1) { |
| 92 | + // meteordevelopment.meteorclient.utils.entity.DamageUtils.fallDamage |
| 93 | + int surface = mc.world.getWorldChunk(mc.player.getBlockPos()).getHeightmap(Heightmap.Type.MOTION_BLOCKING).get(mc.player.getBlockX() & 15, mc.player.getBlockZ() & 15); |
| 94 | + if (mc.player.getBlockY() >= surface) { |
| 95 | + if (mc.player.getBlockY() - surface < fallDistance.get()) return; |
| 96 | + } |
| 97 | + |
| 98 | + else { |
| 99 | + BlockHitResult raycastResult = mc.world.raycast(new RaycastContext(mc.player.getPos(), new Vec3d(mc.player.getX(), mc.world.getBottomY(), mc.player.getZ()), RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.WATER, mc.player)); |
| 100 | + if (raycastResult.getType() != HitResult.Type.MISS) { |
| 101 | + if ((int) (mc.player.getY() - raycastResult.getBlockPos().up().getY()) < fallDistance.get()) return; |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + if (sneak.get()) { |
| 107 | + boolean closeToEdge = false; |
| 108 | + boolean isSprinting = !sneakSprint.get() && mc.options.sprintKey.isPressed(); |
| 109 | + |
| 110 | + Box playerBox = mc.player.getBoundingBox(); |
| 111 | + Box adjustedBox = getAdjustedPlayerBox(playerBox); |
| 112 | + |
| 113 | + if (mc.world.isSpaceEmpty(mc.player, adjustedBox) && mc.player.isOnGround()) closeToEdge = true; |
| 114 | + |
| 115 | + if (!isSprinting) { |
| 116 | + if (closeToEdge) { |
| 117 | + mc.player.input.playerInput = new PlayerInput( |
| 118 | + mc.player.input.playerInput.forward(), |
| 119 | + mc.player.input.playerInput.backward(), |
| 120 | + mc.player.input.playerInput.left(), |
| 121 | + mc.player.input.playerInput.right(), |
| 122 | + mc.player.input.playerInput.jump(), |
| 123 | + true, |
| 124 | + mc.player.input.playerInput.sprint() |
| 125 | + ); |
| 126 | + } else if (safeSneak.get()) { |
| 127 | + event.setClip(true); |
| 128 | + } |
| 129 | + } |
| 130 | + } else { |
| 131 | + if (!mc.player.isSneaking()) event.setClip(true); |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + private Box getAdjustedPlayerBox(Box playerBox) { |
| 136 | + return playerBox.stretch(0, -mc.player.getStepHeight(), 0) |
| 137 | + .expand(-edgeDistance.get(), 0, -edgeDistance.get()); |
| 138 | + } |
| 139 | + |
| 140 | + @EventHandler |
| 141 | + private void onRender(Render3DEvent event) { |
| 142 | + if (sneak.get() && renderEdgeDistance.get()) { |
| 143 | + Box playerBox = mc.player.getBoundingBox(); |
| 144 | + Box adjustedBox = getAdjustedPlayerBox(playerBox); |
| 145 | + |
| 146 | + event.renderer.box(adjustedBox, Color.BLUE, Color.RED, ShapeMode.Lines, 0); |
| 147 | + |
| 148 | + if (renderPlayerBox.get()) { |
| 149 | + event.renderer.box(playerBox, Color.BLUE, Color.GREEN, ShapeMode.Lines, 0); |
| 150 | + } |
| 151 | + } |
21 | 152 | } |
22 | 153 | } |
0 commit comments