|
| 1 | +/* |
| 2 | + * Copyright (c) 2014-2025 Wurst-Imperium and contributors. |
| 3 | + * |
| 4 | + * This source code is subject to the terms of the GNU General Public |
| 5 | + * License, version 3. If a copy of the GPL was not distributed with this |
| 6 | + * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt |
| 7 | + */ |
| 8 | +package net.wurstclient.hacks; |
| 9 | + |
| 10 | +import java.awt.Color; |
| 11 | +import java.util.Arrays; |
| 12 | +import java.util.List; |
| 13 | +import java.util.function.BiPredicate; |
| 14 | + |
| 15 | +import net.minecraft.block.BlockState; |
| 16 | +import net.minecraft.block.BedBlock; |
| 17 | +import net.minecraft.client.util.math.MatrixStack; |
| 18 | +import net.minecraft.util.math.BlockPos; |
| 19 | +import net.minecraft.util.math.Box; |
| 20 | +import net.minecraft.util.math.ChunkPos; |
| 21 | +import net.minecraft.util.math.Vec3d; |
| 22 | +import net.wurstclient.Category; |
| 23 | +import net.wurstclient.SearchTags; |
| 24 | +import net.wurstclient.events.CameraTransformViewBobbingListener; |
| 25 | +import net.wurstclient.events.PacketInputListener; |
| 26 | +import net.wurstclient.events.RenderListener; |
| 27 | +import net.wurstclient.events.UpdateListener; |
| 28 | +import net.wurstclient.hack.Hack; |
| 29 | +import net.wurstclient.hacks.bedesp.BedEspBlockGroup; |
| 30 | +import net.wurstclient.settings.CheckboxSetting; |
| 31 | +import net.wurstclient.settings.ChunkAreaSetting; |
| 32 | +import net.wurstclient.settings.ColorSetting; |
| 33 | +import net.wurstclient.settings.EspStyleSetting; |
| 34 | +import net.wurstclient.util.RenderUtils; |
| 35 | +import net.wurstclient.util.chunk.ChunkSearcher.Result; |
| 36 | +import net.wurstclient.util.chunk.ChunkSearcherCoordinator; |
| 37 | + |
| 38 | +@SearchTags({"BedESP", "bed esp"}) |
| 39 | +public final class BedEspHack extends Hack implements UpdateListener, |
| 40 | + CameraTransformViewBobbingListener, RenderListener |
| 41 | +{ |
| 42 | + private final EspStyleSetting style = new EspStyleSetting(); |
| 43 | + private final net.wurstclient.settings.CheckboxSetting stickyArea = |
| 44 | + new net.wurstclient.settings.CheckboxSetting("Sticky area", |
| 45 | + "Off: Re-centers every chunk to match ESP drop-off.\n" |
| 46 | + + "On: Keeps results anchored so you can path back to them.", |
| 47 | + false); |
| 48 | + |
| 49 | + private final BedEspBlockGroup beds = |
| 50 | + new BedEspBlockGroup( |
| 51 | + new ColorSetting("Bed color", |
| 52 | + "Beds will be highlighted in this color.", new Color(0xFF69B4)), |
| 53 | + new CheckboxSetting("Include beds", true)); |
| 54 | + |
| 55 | + private final List<BedEspBlockGroup> groups = Arrays.asList(beds); |
| 56 | + |
| 57 | + private final ChunkAreaSetting area = new ChunkAreaSetting("Area", |
| 58 | + "The area around the player to search in.\n" |
| 59 | + + "Higher values require a faster computer."); |
| 60 | + |
| 61 | + private final BiPredicate<BlockPos, BlockState> query = |
| 62 | + (pos, state) -> state.getBlock() instanceof BedBlock; |
| 63 | + |
| 64 | + private final ChunkSearcherCoordinator coordinator = |
| 65 | + new ChunkSearcherCoordinator(query, area); |
| 66 | + |
| 67 | + private boolean groupsUpToDate; |
| 68 | + private ChunkPos lastPlayerChunk; |
| 69 | + |
| 70 | + public BedEspHack() |
| 71 | + { |
| 72 | + super("BedESP"); |
| 73 | + setCategory(Category.RENDER); |
| 74 | + addSetting(style); |
| 75 | + groups.stream().flatMap(BedEspBlockGroup::getSettings) |
| 76 | + .forEach(this::addSetting); |
| 77 | + addSetting(area); |
| 78 | + addSetting(stickyArea); |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + protected void onEnable() |
| 83 | + { |
| 84 | + groupsUpToDate = false; |
| 85 | + EVENTS.add(UpdateListener.class, this); |
| 86 | + EVENTS.add(PacketInputListener.class, coordinator); |
| 87 | + EVENTS.add(CameraTransformViewBobbingListener.class, this); |
| 88 | + EVENTS.add(RenderListener.class, this); |
| 89 | + lastPlayerChunk = new ChunkPos(MC.player.getBlockPos()); |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + protected void onDisable() |
| 94 | + { |
| 95 | + EVENTS.remove(UpdateListener.class, this); |
| 96 | + EVENTS.remove(PacketInputListener.class, coordinator); |
| 97 | + EVENTS.remove(CameraTransformViewBobbingListener.class, this); |
| 98 | + EVENTS.remove(RenderListener.class, this); |
| 99 | + |
| 100 | + coordinator.reset(); |
| 101 | + groups.forEach(BedEspBlockGroup::clear); |
| 102 | + } |
| 103 | + |
| 104 | + @Override |
| 105 | + public void onUpdate() |
| 106 | + { |
| 107 | + boolean searchersChanged = coordinator.update(); |
| 108 | + if(searchersChanged) |
| 109 | + groupsUpToDate = false; |
| 110 | + // Recenter per chunk when sticky is off |
| 111 | + ChunkPos currentChunk = new ChunkPos(MC.player.getBlockPos()); |
| 112 | + if(!stickyArea.isChecked() && !currentChunk.equals(lastPlayerChunk)) |
| 113 | + { |
| 114 | + lastPlayerChunk = currentChunk; |
| 115 | + coordinator.reset(); |
| 116 | + groupsUpToDate = false; |
| 117 | + } |
| 118 | + if(!groupsUpToDate && coordinator.isDone()) |
| 119 | + updateGroupBoxes(); |
| 120 | + } |
| 121 | + |
| 122 | + @Override |
| 123 | + public void onCameraTransformViewBobbing( |
| 124 | + CameraTransformViewBobbingEvent event) |
| 125 | + { |
| 126 | + if(style.hasLines()) |
| 127 | + event.cancel(); |
| 128 | + } |
| 129 | + |
| 130 | + @Override |
| 131 | + public void onRender(MatrixStack matrixStack, float partialTicks) |
| 132 | + { |
| 133 | + if(style.hasBoxes()) |
| 134 | + renderBoxes(matrixStack); |
| 135 | + |
| 136 | + if(style.hasLines()) |
| 137 | + renderTracers(matrixStack, partialTicks); |
| 138 | + } |
| 139 | + |
| 140 | + private void renderBoxes(MatrixStack matrixStack) |
| 141 | + { |
| 142 | + for(BedEspBlockGroup group : groups) |
| 143 | + { |
| 144 | + if(!group.isEnabled()) |
| 145 | + continue; |
| 146 | + |
| 147 | + List<Box> boxes = group.getBoxes(); |
| 148 | + int quadsColor = group.getColorI(0x40); |
| 149 | + int linesColor = group.getColorI(0x80); |
| 150 | + |
| 151 | + RenderUtils.drawSolidBoxes(matrixStack, boxes, quadsColor, false); |
| 152 | + RenderUtils.drawOutlinedBoxes(matrixStack, boxes, linesColor, |
| 153 | + false); |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + private void renderTracers(MatrixStack matrixStack, float partialTicks) |
| 158 | + { |
| 159 | + for(BedEspBlockGroup group : groups) |
| 160 | + { |
| 161 | + if(!group.isEnabled()) |
| 162 | + continue; |
| 163 | + |
| 164 | + List<Box> boxes = group.getBoxes(); |
| 165 | + List<Vec3d> ends = boxes.stream().map(Box::getCenter).toList(); |
| 166 | + int color = group.getColorI(0x80); |
| 167 | + |
| 168 | + RenderUtils.drawTracers(matrixStack, partialTicks, ends, color, |
| 169 | + false); |
| 170 | + } |
| 171 | + } |
| 172 | + |
| 173 | + private void updateGroupBoxes() |
| 174 | + { |
| 175 | + groups.forEach(BedEspBlockGroup::clear); |
| 176 | + coordinator.getMatches().forEach(this::addToGroupBoxes); |
| 177 | + groupsUpToDate = true; |
| 178 | + } |
| 179 | + |
| 180 | + private void addToGroupBoxes(Result result) |
| 181 | + { |
| 182 | + for(BedEspBlockGroup group : groups) |
| 183 | + { |
| 184 | + group.add(result); |
| 185 | + break; |
| 186 | + } |
| 187 | + } |
| 188 | +} |
0 commit comments