|
| 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.Comparator; |
| 13 | +import java.util.List; |
| 14 | +import java.util.function.BiPredicate; |
| 15 | +import java.util.stream.Collectors; |
| 16 | + |
| 17 | +import net.minecraft.block.Block; |
| 18 | +import net.minecraft.block.BlockState; |
| 19 | +import net.minecraft.block.Blocks; |
| 20 | +import net.minecraft.client.util.math.MatrixStack; |
| 21 | +import net.minecraft.util.math.BlockPos; |
| 22 | +import net.minecraft.util.math.Box; |
| 23 | +import net.minecraft.util.math.ChunkPos; |
| 24 | +import net.minecraft.util.math.Vec3d; |
| 25 | +import net.wurstclient.Category; |
| 26 | +import net.wurstclient.SearchTags; |
| 27 | +import net.wurstclient.events.CameraTransformViewBobbingListener; |
| 28 | +import net.wurstclient.events.RenderListener; |
| 29 | +import net.wurstclient.events.UpdateListener; |
| 30 | +import net.wurstclient.hack.Hack; |
| 31 | +import net.wurstclient.hacks.portalesp.LiquidEspBlockGroup; |
| 32 | +import net.wurstclient.settings.CheckboxSetting; |
| 33 | +import net.wurstclient.settings.ChunkAreaSetting; |
| 34 | +import net.wurstclient.settings.ColorSetting; |
| 35 | +import net.wurstclient.settings.EspStyleSetting; |
| 36 | +import net.wurstclient.settings.SliderSetting; |
| 37 | +import net.wurstclient.settings.SliderSetting.ValueDisplay; |
| 38 | +import net.wurstclient.util.RotationUtils; |
| 39 | +import net.wurstclient.util.RenderUtils; |
| 40 | +import net.wurstclient.util.chunk.ChunkSearcher.Result; |
| 41 | +import net.wurstclient.util.chunk.ChunkSearcherCoordinator; |
| 42 | + |
| 43 | +@SearchTags({"lavaesp", "wateresp", "lava water", "LavaWaterESP"}) |
| 44 | +public final class LavaWaterEspHack extends Hack implements UpdateListener, |
| 45 | + CameraTransformViewBobbingListener, RenderListener |
| 46 | +{ |
| 47 | + private final EspStyleSetting style = new EspStyleSetting(); |
| 48 | + private final CheckboxSetting stickyArea = |
| 49 | + new CheckboxSetting("Sticky area", |
| 50 | + "Off: Re-centers every chunk to match ESP drop-off.\n" |
| 51 | + + "On: Keeps results anchored so you can path back to them.", |
| 52 | + false); |
| 53 | + private final ChunkAreaSetting area = new ChunkAreaSetting("Area", |
| 54 | + "The area around the player to search in.\n" |
| 55 | + + "Higher values require a faster computer.", |
| 56 | + ChunkAreaSetting.ChunkArea.A3); |
| 57 | + |
| 58 | + // Default colors: lava orange, water blue |
| 59 | + private final LiquidEspBlockGroup lavaGroup = |
| 60 | + new LiquidEspBlockGroup(Blocks.LAVA, |
| 61 | + new ColorSetting("Lava color", |
| 62 | + "Lava will be highlighted in this color.", new Color(0xFF8C00)), |
| 63 | + new CheckboxSetting("Include lava", true)); |
| 64 | + private final LiquidEspBlockGroup waterGroup = new LiquidEspBlockGroup( |
| 65 | + Blocks.WATER, |
| 66 | + new ColorSetting("Water color", |
| 67 | + "Water will be highlighted in this color.", new Color(0x3F76E4)), |
| 68 | + new CheckboxSetting("Include water", true)); |
| 69 | + private final List<LiquidEspBlockGroup> groups = |
| 70 | + Arrays.asList(lavaGroup, waterGroup); |
| 71 | + |
| 72 | + // Transparency sliders per type (0-255) |
| 73 | + private final SliderSetting lavaAlpha = |
| 74 | + new SliderSetting("Lava transparency", |
| 75 | + "Transparency for lava (0 = fully transparent, 255 = opaque).", 64, |
| 76 | + 0, 255, 1, ValueDisplay.INTEGER); |
| 77 | + private final SliderSetting waterAlpha = |
| 78 | + new SliderSetting("Water transparency", |
| 79 | + "Transparency for water (0 = fully transparent, 255 = opaque).", 64, |
| 80 | + 0, 255, 1, ValueDisplay.INTEGER); |
| 81 | + |
| 82 | + // How many blocks to render (100 - 1000) |
| 83 | + private final SliderSetting renderAmount = new SliderSetting( |
| 84 | + "Render amount", "Maximum number of blocks to render at once.", 100, |
| 85 | + 100, 1000, 10, ValueDisplay.INTEGER); |
| 86 | + |
| 87 | + private final BiPredicate<BlockPos, BlockState> query = |
| 88 | + (pos, state) -> isTargetBlock(state.getBlock()); |
| 89 | + private final ChunkSearcherCoordinator coordinator = |
| 90 | + new ChunkSearcherCoordinator(query, area); |
| 91 | + private boolean groupsUpToDate; |
| 92 | + private ChunkAreaSetting.ChunkArea lastAreaSelection; |
| 93 | + private ChunkPos lastPlayerChunk; |
| 94 | + |
| 95 | + public LavaWaterEspHack() |
| 96 | + { |
| 97 | + super("LavaWaterESP"); |
| 98 | + setCategory(Category.RENDER); |
| 99 | + addSetting(style); |
| 100 | + groups.stream().flatMap(LiquidEspBlockGroup::getSettings) |
| 101 | + .forEach(this::addSetting); |
| 102 | + addSetting(area); |
| 103 | + addSetting(stickyArea); |
| 104 | + // add transparency and render amount settings |
| 105 | + addSetting(lavaAlpha); |
| 106 | + addSetting(waterAlpha); |
| 107 | + addSetting(renderAmount); |
| 108 | + } |
| 109 | + |
| 110 | + private boolean isTargetBlock(Block b) |
| 111 | + { |
| 112 | + for(LiquidEspBlockGroup g : groups) |
| 113 | + if(g.getBlock() == b) |
| 114 | + return true; |
| 115 | + return false; |
| 116 | + } |
| 117 | + |
| 118 | + @Override |
| 119 | + protected void onEnable() |
| 120 | + { |
| 121 | + groupsUpToDate = false; |
| 122 | + lastAreaSelection = area.getSelected(); |
| 123 | + lastPlayerChunk = new ChunkPos(MC.player.getBlockPos()); |
| 124 | + EVENTS.add(UpdateListener.class, this); |
| 125 | + EVENTS.add(CameraTransformViewBobbingListener.class, this); |
| 126 | + EVENTS.add(RenderListener.class, this); |
| 127 | + EVENTS.add(net.wurstclient.events.PacketInputListener.class, |
| 128 | + coordinator); |
| 129 | + } |
| 130 | + |
| 131 | + @Override |
| 132 | + protected void onDisable() |
| 133 | + { |
| 134 | + EVENTS.remove(UpdateListener.class, this); |
| 135 | + EVENTS.remove(CameraTransformViewBobbingListener.class, this); |
| 136 | + EVENTS.remove(RenderListener.class, this); |
| 137 | + EVENTS.remove(net.wurstclient.events.PacketInputListener.class, |
| 138 | + coordinator); |
| 139 | + coordinator.reset(); |
| 140 | + groups.forEach(LiquidEspBlockGroup::clear); |
| 141 | + } |
| 142 | + |
| 143 | + @Override |
| 144 | + public void onUpdate() |
| 145 | + { |
| 146 | + ChunkAreaSetting.ChunkArea currentArea = area.getSelected(); |
| 147 | + if(currentArea != lastAreaSelection) |
| 148 | + { |
| 149 | + lastAreaSelection = currentArea; |
| 150 | + coordinator.reset(); |
| 151 | + groupsUpToDate = false; |
| 152 | + } |
| 153 | + // Recenter per chunk when sticky is off |
| 154 | + ChunkPos currentChunk = new ChunkPos(MC.player.getBlockPos()); |
| 155 | + if(!stickyArea.isChecked() && !currentChunk.equals(lastPlayerChunk)) |
| 156 | + { |
| 157 | + lastPlayerChunk = currentChunk; |
| 158 | + coordinator.reset(); |
| 159 | + groupsUpToDate = false; |
| 160 | + } |
| 161 | + boolean searchersChanged = coordinator.update(); |
| 162 | + if(searchersChanged) |
| 163 | + groupsUpToDate = false; |
| 164 | + if(!groupsUpToDate && coordinator.isDone()) |
| 165 | + updateGroupBoxes(); |
| 166 | + } |
| 167 | + |
| 168 | + @Override |
| 169 | + public void onCameraTransformViewBobbing( |
| 170 | + CameraTransformViewBobbingEvent event) |
| 171 | + { |
| 172 | + if(style.getSelected().hasLines()) |
| 173 | + event.cancel(); |
| 174 | + } |
| 175 | + |
| 176 | + @Override |
| 177 | + public void onRender(MatrixStack matrixStack, float partialTicks) |
| 178 | + { |
| 179 | + if(style.getSelected().hasBoxes()) |
| 180 | + renderBoxes(matrixStack); |
| 181 | + if(style.getSelected().hasLines()) |
| 182 | + renderTracers(matrixStack, partialTicks); |
| 183 | + } |
| 184 | + |
| 185 | + private void renderBoxes(MatrixStack matrixStack) |
| 186 | + { |
| 187 | + for(LiquidEspBlockGroup group : groups) |
| 188 | + { |
| 189 | + if(!group.isEnabled()) |
| 190 | + continue; |
| 191 | + List<Box> boxes = group.getBoxes(); |
| 192 | + int alpha = group == lavaGroup ? lavaAlpha.getValueI() |
| 193 | + : waterAlpha.getValueI(); |
| 194 | + int quadsColor = group.getColorI(alpha); |
| 195 | + int linesColor = group.getColorI(alpha); |
| 196 | + RenderUtils.drawSolidBoxes(matrixStack, boxes, quadsColor, false); |
| 197 | + RenderUtils.drawOutlinedBoxes(matrixStack, boxes, linesColor, |
| 198 | + false); |
| 199 | + } |
| 200 | + } |
| 201 | + |
| 202 | + private void renderTracers(MatrixStack matrixStack, float partialTicks) |
| 203 | + { |
| 204 | + for(LiquidEspBlockGroup group : groups) |
| 205 | + { |
| 206 | + if(!group.isEnabled()) |
| 207 | + continue; |
| 208 | + List<Box> boxes = group.getBoxes(); |
| 209 | + List<Vec3d> ends = boxes.stream().map(Box::getCenter).toList(); |
| 210 | + int alpha = group == lavaGroup ? lavaAlpha.getValueI() |
| 211 | + : waterAlpha.getValueI(); |
| 212 | + int color = group.getColorI(alpha); |
| 213 | + RenderUtils.drawTracers(matrixStack, partialTicks, ends, color, |
| 214 | + false); |
| 215 | + } |
| 216 | + } |
| 217 | + |
| 218 | + private void updateGroupBoxes() |
| 219 | + { |
| 220 | + groups.forEach(LiquidEspBlockGroup::clear); |
| 221 | + int limit = renderAmount.getValueI(); |
| 222 | + java.util.List<Result> matches = coordinator.getMatches() |
| 223 | + .sorted(Comparator.comparingDouble( |
| 224 | + r -> r.pos().getSquaredDistance(RotationUtils.getEyesPos()))) |
| 225 | + .limit(limit).collect(Collectors.toList()); |
| 226 | + matches.forEach(this::addToGroupBoxes); |
| 227 | + groupsUpToDate = true; |
| 228 | + } |
| 229 | + |
| 230 | + private void addToGroupBoxes(Result result) |
| 231 | + { |
| 232 | + for(LiquidEspBlockGroup group : groups) |
| 233 | + if(result.state().getBlock() == group.getBlock()) |
| 234 | + { |
| 235 | + group.add(result.pos()); |
| 236 | + break; |
| 237 | + } |
| 238 | + } |
| 239 | +} |
0 commit comments