0
0
mirror of https://github.com/Wurst-Imperium/Wurst7.git synced 2024-09-20 09:16:20 +02:00

Split ChestESP into separate classes

This commit is contained in:
Alexander01998 2022-05-04 22:17:21 +02:00
parent 5196a26d5f
commit 6f8fb18d91
7 changed files with 465 additions and 302 deletions

View File

@ -9,94 +9,77 @@ package net.wurstclient.hacks;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Objects;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.lwjgl.opengl.GL11;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.block.BlockState;
import net.minecraft.block.ChestBlock;
import net.minecraft.block.entity.BarrelBlockEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.ChestBlockEntity;
import net.minecraft.block.entity.EnderChestBlockEntity;
import net.minecraft.block.entity.ShulkerBoxBlockEntity;
import net.minecraft.block.entity.TrappedChestBlockEntity;
import net.minecraft.block.enums.ChestType;
import net.minecraft.client.gl.VertexBuffer;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BufferRenderer;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.Shader;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.entity.vehicle.ChestMinecartEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.Matrix4f;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.chunk.WorldChunk;
import net.wurstclient.Category;
import net.wurstclient.events.CameraTransformViewBobbingListener;
import net.wurstclient.events.RenderListener;
import net.wurstclient.events.UpdateListener;
import net.wurstclient.hack.Hack;
import net.wurstclient.hacks.chestesp.ChestEspBlockGroup;
import net.wurstclient.hacks.chestesp.ChestEspEntityGroup;
import net.wurstclient.hacks.chestesp.ChestEspGroup;
import net.wurstclient.hacks.chestesp.ChestEspRenderer;
import net.wurstclient.hacks.chestesp.ChestEspStyle;
import net.wurstclient.settings.ColorSetting;
import net.wurstclient.settings.EnumSetting;
import net.wurstclient.util.BlockUtils;
import net.wurstclient.util.ChunkUtils;
import net.wurstclient.util.RenderUtils;
import net.wurstclient.util.RotationUtils;
public class ChestEspHack extends Hack implements UpdateListener,
CameraTransformViewBobbingListener, RenderListener
{
private final EnumSetting<Style> style =
new EnumSetting<>("Style", Style.values(), Style.BOXES);
private final EnumSetting<ChestEspStyle> style =
new EnumSetting<>("Style", ChestEspStyle.values(), ChestEspStyle.BOXES);
private final ColorSetting basicColor = new ColorSetting("Chest color",
"Normal chests will be\n" + "highlighted in this color.", Color.GREEN);
private final ChestEspBlockGroup basicChests =
new ChestEspBlockGroup(new ColorSetting("Chest color",
"Normal chests will be highlighted in this color.", Color.GREEN));
private final ColorSetting trapColor = new ColorSetting("Trap color",
"Trapped chests will be\n" + "highlighted in this color.",
new Color(0xFF8000));
private final ChestEspBlockGroup trapChests =
new ChestEspBlockGroup(new ColorSetting("Trap color",
"Trapped chests will be highlighted in this color.",
new Color(0xFF8000)));
private final ColorSetting enderColor = new ColorSetting("Ender color",
"Ender chests will be\n" + "highlighted in this color.", Color.CYAN);
private final ChestEspBlockGroup enderChests =
new ChestEspBlockGroup(new ColorSetting("Ender color",
"Ender chests will be highlighted in this color.", Color.CYAN));
private final ColorSetting shulkerColor = new ColorSetting("Shulker color",
"Shulker boxes will be\n" + "highlighted in this color.",
Color.MAGENTA);
private final ChestEspBlockGroup shulkerBoxes =
new ChestEspBlockGroup(new ColorSetting("Shulker color",
"Shulker boxes will be highlighted in this color.", Color.MAGENTA));
private final ColorSetting cartColor = new ColorSetting("Cart color",
"Minecarts will be\n" + "highlighted in this color.", Color.GREEN);
private final ChestEspEntityGroup minecarts =
new ChestEspEntityGroup(new ColorSetting("Cart color",
"Minecarts will be highlighted in this color.", Color.GREEN));
private final ArrayList<Box> basicChests = new ArrayList<>();
private final ArrayList<Box> trapChests = new ArrayList<>();
private final ArrayList<Box> enderChests = new ArrayList<>();
private final ArrayList<Box> shulkerBoxes = new ArrayList<>();
private final ArrayList<Entity> minecarts = new ArrayList<>();
private VertexBuffer solidBox;
private VertexBuffer outlinedBox;
private final List<ChestEspGroup> groups = Arrays.asList(basicChests,
trapChests, enderChests, shulkerBoxes, minecarts);
public ChestEspHack()
{
super("ChestESP");
setCategory(Category.RENDER);
addSetting(style);
addSetting(basicColor);
addSetting(trapColor);
addSetting(enderColor);
addSetting(shulkerColor);
addSetting(cartColor);
addSetting(style);
groups.stream().map(ChestEspGroup::getSetting)
.forEach(this::addSetting);
}
@Override
@ -106,15 +89,7 @@ public class ChestEspHack extends Hack implements UpdateListener,
EVENTS.add(CameraTransformViewBobbingListener.class, this);
EVENTS.add(RenderListener.class, this);
Stream.of(solidBox, outlinedBox).filter(Objects::nonNull)
.forEach(VertexBuffer::close);
solidBox = new VertexBuffer();
outlinedBox = new VertexBuffer();
Box box = new Box(BlockPos.ORIGIN);
RenderUtils.drawSolidBox(box, solidBox);
RenderUtils.drawOutlinedBox(box, outlinedBox);
ChestEspRenderer.prepareBuffers();
}
@Override
@ -124,143 +99,41 @@ public class ChestEspHack extends Hack implements UpdateListener,
EVENTS.remove(CameraTransformViewBobbingListener.class, this);
EVENTS.remove(RenderListener.class, this);
Stream.of(solidBox, outlinedBox).filter(Objects::nonNull)
.forEach(VertexBuffer::close);
groups.forEach(ChestEspGroup::clear);
ChestEspRenderer.closeBuffers();
}
@Override
public void onUpdate()
{
Stream.of(basicChests, trapChests, enderChests, shulkerBoxes)
.forEach(ArrayList::clear);
groups.forEach(ChestEspGroup::clear);
ArrayList<BlockEntity> blockEntities = getLoadedBlockEntities()
.collect(Collectors.toCollection(ArrayList::new));
ArrayList<BlockEntity> blockEntities =
ChunkUtils.getLoadedBlockEntities()
.collect(Collectors.toCollection(ArrayList::new));
for(BlockEntity blockEntity : blockEntities)
if(blockEntity instanceof ChestBlockEntity)
{
Box box = getBoxFromChest((ChestBlockEntity)blockEntity);
if(box == null)
continue;
if(blockEntity instanceof TrappedChestBlockEntity)
trapChests.add(box);
else
basicChests.add(box);
}else if(blockEntity instanceof EnderChestBlockEntity)
{
BlockPos pos = blockEntity.getPos();
if(!BlockUtils.canBeClicked(pos))
continue;
Box box = BlockUtils.getBoundingBox(pos);
enderChests.add(box);
}else if(blockEntity instanceof ShulkerBoxBlockEntity)
{
BlockPos pos = blockEntity.getPos();
if(!BlockUtils.canBeClicked(pos))
continue;
Box box = BlockUtils.getBoundingBox(pos);
shulkerBoxes.add(box);
}else if(blockEntity instanceof BarrelBlockEntity)
{
BlockPos pos = blockEntity.getPos();
if(!BlockUtils.canBeClicked(pos))
continue;
Box box = BlockUtils.getBoundingBox(pos);
basicChests.add(box);
}
minecarts.clear();
if(blockEntity instanceof TrappedChestBlockEntity)
trapChests.add(blockEntity);
else if(blockEntity instanceof ChestBlockEntity)
basicChests.add(blockEntity);
else if(blockEntity instanceof EnderChestBlockEntity)
enderChests.add(blockEntity);
else if(blockEntity instanceof ShulkerBoxBlockEntity)
shulkerBoxes.add(blockEntity);
else if(blockEntity instanceof BarrelBlockEntity)
basicChests.add(blockEntity);
for(Entity entity : MC.world.getEntities())
if(entity instanceof ChestMinecartEntity)
minecarts.add(entity);
}
private Stream<BlockEntity> getLoadedBlockEntities()
{
return getLoadedChunks()
.flatMap(chunk -> chunk.getBlockEntities().values().stream());
}
private Stream<WorldChunk> getLoadedChunks()
{
int radius = Math.max(2, MC.options.getViewDistance()) + 3;
int diameter = radius * 2 + 1;
ChunkPos center = MC.player.getChunkPos();
ChunkPos min = new ChunkPos(center.x - radius, center.z - radius);
ChunkPos max = new ChunkPos(center.x + radius, center.z + radius);
Stream<WorldChunk> stream = Stream.<ChunkPos> iterate(min, pos -> {
int x = pos.x;
int z = pos.z;
x++;
if(x > max.x)
{
x = min.x;
z++;
}
if(z > max.z)
throw new IllegalStateException("Stream limit didn't work.");
return new ChunkPos(x, z);
}).limit(diameter * diameter)
.filter(c -> MC.world.isChunkLoaded(c.x, c.z))
.map(c -> MC.world.getChunk(c.x, c.z)).filter(Objects::nonNull);
return stream;
}
private Box getBoxFromChest(ChestBlockEntity chestBE)
{
BlockState state = chestBE.getCachedState();
if(!state.contains(ChestBlock.CHEST_TYPE))
return null;
ChestType chestType = state.get(ChestBlock.CHEST_TYPE);
// ignore other block in double chest
if(chestType == ChestType.LEFT)
return null;
BlockPos pos = chestBE.getPos();
if(!BlockUtils.canBeClicked(pos))
return null;
Box box = BlockUtils.getBoundingBox(pos);
// larger box for double chest
if(chestType != ChestType.SINGLE)
{
BlockPos pos2 = pos.offset(ChestBlock.getFacing(state));
if(BlockUtils.canBeClicked(pos2))
{
Box box2 = BlockUtils.getBoundingBox(pos2);
box = box.union(box2);
}
}
return box;
}
@Override
public void onCameraTransformViewBobbing(
CameraTransformViewBobbingEvent event)
{
if(style.getSelected().lines)
if(style.getSelected().hasLines())
event.cancel();
}
@ -277,42 +150,19 @@ public class ChestEspHack extends Hack implements UpdateListener,
matrixStack.push();
RenderUtils.applyRegionalRenderOffset(matrixStack);
ArrayList<Box> minecartBoxes = calculateMinecartBoxes(partialTicks);
minecarts.updateBoxes(partialTicks);
ChestEspRenderer espRenderer = new ChestEspRenderer(matrixStack);
BlockPos camPos = RenderUtils.getCameraBlockPos();
int regionX = (camPos.getX() >> 9) * 512;
int regionZ = (camPos.getZ() >> 9) * 512;
if(style.getSelected().boxes)
if(style.getSelected().hasBoxes())
{
RenderSystem.setShader(GameRenderer::getPositionShader);
renderBoxes(matrixStack, basicChests, basicColor.getColorF(),
regionX, regionZ);
renderBoxes(matrixStack, trapChests, trapColor.getColorF(), regionX,
regionZ);
renderBoxes(matrixStack, enderChests, enderColor.getColorF(),
regionX, regionZ);
renderBoxes(matrixStack, shulkerBoxes, shulkerColor.getColorF(),
regionX, regionZ);
renderBoxes(matrixStack, minecartBoxes, cartColor.getColorF(),
regionX, regionZ);
groups.forEach(espRenderer::renderBoxes);
}
if(style.getSelected().lines)
if(style.getSelected().hasLines())
{
RenderSystem.setShader(GameRenderer::getPositionShader);
Vec3d start = RotationUtils.getClientLookVec()
.add(RenderUtils.getCameraPos()).subtract(regionX, 0, regionZ);
renderLines(matrixStack, start, basicChests, basicColor.getColorF(),
regionX, regionZ);
renderLines(matrixStack, start, trapChests, trapColor.getColorF(),
regionX, regionZ);
renderLines(matrixStack, start, enderChests, enderColor.getColorF(),
regionX, regionZ);
renderLines(matrixStack, start, shulkerBoxes,
shulkerColor.getColorF(), regionX, regionZ);
renderLines(matrixStack, start, minecartBoxes,
cartColor.getColorF(), regionX, regionZ);
groups.forEach(espRenderer::renderLines);
}
matrixStack.pop();
@ -323,100 +173,4 @@ public class ChestEspHack extends Hack implements UpdateListener,
GL11.glDisable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_LINE_SMOOTH);
}
private ArrayList<Box> calculateMinecartBoxes(float partialTicks)
{
ArrayList<Box> minecartBoxes = new ArrayList<>(minecarts.size());
minecarts.forEach(e -> {
double offsetX = -(e.getX() - e.lastRenderX)
+ (e.getX() - e.lastRenderX) * partialTicks;
double offsetY = -(e.getY() - e.lastRenderY)
+ (e.getY() - e.lastRenderY) * partialTicks;
double offsetZ = -(e.getZ() - e.lastRenderZ)
+ (e.getZ() - e.lastRenderZ) * partialTicks;
minecartBoxes
.add(e.getBoundingBox().offset(offsetX, offsetY, offsetZ));
});
return minecartBoxes;
}
private void renderBoxes(MatrixStack matrixStack, ArrayList<Box> boxes,
float[] colorF, int regionX, int regionZ)
{
for(Box box : boxes)
{
matrixStack.push();
matrixStack.translate(box.minX - regionX, box.minY,
box.minZ - regionZ);
matrixStack.scale((float)(box.maxX - box.minX),
(float)(box.maxY - box.minY), (float)(box.maxZ - box.minZ));
Matrix4f viewMatrix = matrixStack.peek().getPositionMatrix();
Matrix4f projMatrix = RenderSystem.getProjectionMatrix();
Shader shader = RenderSystem.getShader();
RenderSystem.setShaderColor(colorF[0], colorF[1], colorF[2], 0.25F);
solidBox.setShader(viewMatrix, projMatrix, shader);
RenderSystem.setShaderColor(colorF[0], colorF[1], colorF[2], 0.5F);
outlinedBox.setShader(viewMatrix, projMatrix, shader);
matrixStack.pop();
}
}
private void renderLines(MatrixStack matrixStack, Vec3d start,
ArrayList<Box> boxes, float[] colorF, int regionX, int regionZ)
{
Matrix4f matrix = matrixStack.peek().getPositionMatrix();
BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
RenderSystem.setShaderColor(colorF[0], colorF[1], colorF[2], 0.5F);
bufferBuilder.begin(VertexFormat.DrawMode.DEBUG_LINES,
VertexFormats.POSITION);
for(Box box : boxes)
{
Vec3d end = box.getCenter().subtract(regionX, 0, regionZ);
bufferBuilder
.vertex(matrix, (float)start.x, (float)start.y, (float)start.z)
.next();
bufferBuilder
.vertex(matrix, (float)end.x, (float)end.y, (float)end.z)
.next();
}
bufferBuilder.end();
BufferRenderer.draw(bufferBuilder);
}
private enum Style
{
BOXES("Boxes only", true, false),
LINES("Lines only", false, true),
LINES_AND_BOXES("Lines and boxes", true, true);
private final String name;
private final boolean boxes;
private final boolean lines;
private Style(String name, boolean boxes, boolean lines)
{
this.name = name;
this.boxes = boxes;
this.lines = lines;
}
@Override
public String toString()
{
return name;
}
}
}

View File

@ -0,0 +1,79 @@
/*
* Copyright (c) 2014-2022 Wurst-Imperium and contributors.
*
* This source code is subject to the terms of the GNU General Public
* License, version 3. If a copy of the GPL was not distributed with this
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
*/
package net.wurstclient.hacks.chestesp;
import net.minecraft.block.BlockState;
import net.minecraft.block.ChestBlock;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.ChestBlockEntity;
import net.minecraft.block.enums.ChestType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.wurstclient.settings.ColorSetting;
import net.wurstclient.util.BlockUtils;
public final class ChestEspBlockGroup extends ChestEspGroup
{
public ChestEspBlockGroup(ColorSetting color)
{
super(color);
}
public void add(BlockEntity be)
{
Box box = getBox(be);
if(box == null)
return;
boxes.add(box);
}
private Box getBox(BlockEntity be)
{
BlockPos pos = be.getPos();
if(!BlockUtils.canBeClicked(pos))
return null;
if(be instanceof ChestBlockEntity)
return getChestBox((ChestBlockEntity)be);
return BlockUtils.getBoundingBox(pos);
}
private Box getChestBox(ChestBlockEntity chestBE)
{
BlockState state = chestBE.getCachedState();
if(!state.contains(ChestBlock.CHEST_TYPE))
return null;
ChestType chestType = state.get(ChestBlock.CHEST_TYPE);
// ignore other block in double chest
if(chestType == ChestType.LEFT)
return null;
BlockPos pos = chestBE.getPos();
Box box = BlockUtils.getBoundingBox(pos);
// larger box for double chest
if(chestType != ChestType.SINGLE)
{
BlockPos pos2 = pos.offset(ChestBlock.getFacing(state));
if(BlockUtils.canBeClicked(pos2))
{
Box box2 = BlockUtils.getBoundingBox(pos2);
box = box.union(box2);
}
}
return box;
}
}

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2014-2022 Wurst-Imperium and contributors.
*
* This source code is subject to the terms of the GNU General Public
* License, version 3. If a copy of the GPL was not distributed with this
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
*/
package net.wurstclient.hacks.chestesp;
import java.util.ArrayList;
import net.minecraft.entity.Entity;
import net.wurstclient.settings.ColorSetting;
public final class ChestEspEntityGroup extends ChestEspGroup
{
private final ArrayList<Entity> entities = new ArrayList<>();
public ChestEspEntityGroup(ColorSetting color)
{
super(color);
}
public void add(Entity e)
{
entities.add(e);
}
@Override
public void clear()
{
entities.clear();
super.clear();
}
public void updateBoxes(float partialTicks)
{
boxes.clear();
for(Entity e : entities)
{
double offsetX = -(e.getX() - e.lastRenderX)
+ (e.getX() - e.lastRenderX) * partialTicks;
double offsetY = -(e.getY() - e.lastRenderY)
+ (e.getY() - e.lastRenderY) * partialTicks;
double offsetZ = -(e.getZ() - e.lastRenderZ)
+ (e.getZ() - e.lastRenderZ) * partialTicks;
boxes.add(e.getBoundingBox().offset(offsetX, offsetY, offsetZ));
}
}
}

View File

@ -0,0 +1,47 @@
/*
* Copyright (c) 2014-2022 Wurst-Imperium and contributors.
*
* This source code is subject to the terms of the GNU General Public
* License, version 3. If a copy of the GPL was not distributed with this
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
*/
package net.wurstclient.hacks.chestesp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import net.minecraft.util.math.Box;
import net.wurstclient.settings.ColorSetting;
public abstract class ChestEspGroup
{
protected final ArrayList<Box> boxes = new ArrayList<>();
private final ColorSetting color;
public ChestEspGroup(ColorSetting color)
{
this.color = Objects.requireNonNull(color);
}
public void clear()
{
boxes.clear();
}
public ColorSetting getSetting()
{
return color;
}
public float[] getColorF()
{
return color.getColorF();
}
public List<Box> getBoxes()
{
return Collections.unmodifiableList(boxes);
}
}

View File

@ -0,0 +1,124 @@
/*
* Copyright (c) 2014-2022 Wurst-Imperium and contributors.
*
* This source code is subject to the terms of the GNU General Public
* License, version 3. If a copy of the GPL was not distributed with this
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
*/
package net.wurstclient.hacks.chestesp;
import java.util.Objects;
import java.util.stream.Stream;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gl.VertexBuffer;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BufferRenderer;
import net.minecraft.client.render.Shader;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Matrix4f;
import net.minecraft.util.math.Vec3d;
import net.wurstclient.util.RenderUtils;
import net.wurstclient.util.RotationUtils;
public final class ChestEspRenderer
{
private static VertexBuffer solidBox;
private static VertexBuffer outlinedBox;
private final MatrixStack matrixStack;
private final int regionX;
private final int regionZ;
private final Vec3d start;
public ChestEspRenderer(MatrixStack matrixStack)
{
this.matrixStack = matrixStack;
BlockPos camPos = RenderUtils.getCameraBlockPos();
regionX = (camPos.getX() >> 9) * 512;
regionZ = (camPos.getZ() >> 9) * 512;
start = RotationUtils.getClientLookVec().add(RenderUtils.getCameraPos())
.subtract(regionX, 0, regionZ);
}
public void renderBoxes(ChestEspGroup group)
{
float[] colorF = group.getColorF();
for(Box box : group.getBoxes())
{
matrixStack.push();
matrixStack.translate(box.minX - regionX, box.minY,
box.minZ - regionZ);
matrixStack.scale((float)(box.maxX - box.minX),
(float)(box.maxY - box.minY), (float)(box.maxZ - box.minZ));
Matrix4f viewMatrix = matrixStack.peek().getPositionMatrix();
Matrix4f projMatrix = RenderSystem.getProjectionMatrix();
Shader shader = RenderSystem.getShader();
RenderSystem.setShaderColor(colorF[0], colorF[1], colorF[2], 0.25F);
solidBox.setShader(viewMatrix, projMatrix, shader);
RenderSystem.setShaderColor(colorF[0], colorF[1], colorF[2], 0.5F);
outlinedBox.setShader(viewMatrix, projMatrix, shader);
matrixStack.pop();
}
}
public void renderLines(ChestEspGroup group)
{
Matrix4f matrix = matrixStack.peek().getPositionMatrix();
BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
float[] colorF = group.getColorF();
RenderSystem.setShaderColor(colorF[0], colorF[1], colorF[2], 0.5F);
bufferBuilder.begin(VertexFormat.DrawMode.DEBUG_LINES,
VertexFormats.POSITION);
for(Box box : group.getBoxes())
{
Vec3d end = box.getCenter().subtract(regionX, 0, regionZ);
bufferBuilder
.vertex(matrix, (float)start.x, (float)start.y, (float)start.z)
.next();
bufferBuilder
.vertex(matrix, (float)end.x, (float)end.y, (float)end.z)
.next();
}
bufferBuilder.end();
BufferRenderer.draw(bufferBuilder);
}
public static void prepareBuffers()
{
closeBuffers();
solidBox = new VertexBuffer();
outlinedBox = new VertexBuffer();
Box box = new Box(BlockPos.ORIGIN);
RenderUtils.drawSolidBox(box, solidBox);
RenderUtils.drawOutlinedBox(box, outlinedBox);
}
public static void closeBuffers()
{
Stream.of(solidBox, outlinedBox).filter(Objects::nonNull)
.forEach(VertexBuffer::close);
}
}

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2014-2022 Wurst-Imperium and contributors.
*
* This source code is subject to the terms of the GNU General Public
* License, version 3. If a copy of the GPL was not distributed with this
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
*/
package net.wurstclient.hacks.chestesp;
public enum ChestEspStyle
{
BOXES("Boxes only", true, false),
LINES("Lines only", false, true),
LINES_AND_BOXES("Lines and boxes", true, true);
private final String name;
private final boolean boxes;
private final boolean lines;
private ChestEspStyle(String name, boolean boxes, boolean lines)
{
this.name = name;
this.boxes = boxes;
this.lines = lines;
}
public boolean hasBoxes()
{
return boxes;
}
public boolean hasLines()
{
return lines;
}
@Override
public String toString()
{
return name;
}
}

View File

@ -0,0 +1,65 @@
/*
* Copyright (c) 2014-2022 Wurst-Imperium and contributors.
*
* This source code is subject to the terms of the GNU General Public
* License, version 3. If a copy of the GPL was not distributed with this
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
*/
package net.wurstclient.util;
import java.util.Objects;
import java.util.stream.Stream;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.chunk.WorldChunk;
import net.wurstclient.WurstClient;
public enum ChunkUtils
{
;
private static final MinecraftClient MC = WurstClient.MC;
public static Stream<BlockEntity> getLoadedBlockEntities()
{
return getLoadedChunks()
.flatMap(chunk -> chunk.getBlockEntities().values().stream());
}
public static Stream<WorldChunk> getLoadedChunks()
{
int radius = Math.max(2, MC.options.getViewDistance()) + 3;
int diameter = radius * 2 + 1;
ChunkPos center = MC.player.getChunkPos();
ChunkPos min = new ChunkPos(center.x - radius, center.z - radius);
ChunkPos max = new ChunkPos(center.x + radius, center.z + radius);
Stream<WorldChunk> stream = Stream.<ChunkPos> iterate(min, pos -> {
int x = pos.x;
int z = pos.z;
x++;
if(x > max.x)
{
x = min.x;
z++;
}
if(z > max.z)
throw new IllegalStateException("Stream limit didn't work.");
return new ChunkPos(x, z);
}).limit(diameter * diameter)
.filter(c -> MC.world.isChunkLoaded(c.x, c.z))
.map(c -> MC.world.getChunk(c.x, c.z)).filter(Objects::nonNull);
return stream;
}
}