more rendering options to New Chunks (#142)

This commit is contained in:
cqb13
2022-07-24 04:08:24 -04:00
committed by GitHub
parent 99474abecb
commit 36bc339e74

View File

@@ -1,7 +1,6 @@
package anticope.rejects.modules; package anticope.rejects.modules;
import anticope.rejects.MeteorRejectsAddon; import anticope.rejects.MeteorRejectsAddon;
import meteordevelopment.orbit.EventHandler;
import meteordevelopment.meteorclient.events.packets.PacketEvent; import meteordevelopment.meteorclient.events.packets.PacketEvent;
import meteordevelopment.meteorclient.events.render.Render3DEvent; import meteordevelopment.meteorclient.events.render.Render3DEvent;
import meteordevelopment.meteorclient.renderer.ShapeMode; import meteordevelopment.meteorclient.renderer.ShapeMode;
@@ -9,10 +8,16 @@ import meteordevelopment.meteorclient.settings.*;
import meteordevelopment.meteorclient.systems.modules.Module; import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.utils.render.color.Color; import meteordevelopment.meteorclient.utils.render.color.Color;
import meteordevelopment.meteorclient.utils.render.color.SettingColor; import meteordevelopment.meteorclient.utils.render.color.SettingColor;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.fluid.FluidState; import net.minecraft.fluid.FluidState;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.packet.s2c.play.*; import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket;
import net.minecraft.util.math.*; import net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket;
import net.minecraft.network.packet.s2c.play.ChunkDeltaUpdateS2CPacket;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.chunk.WorldChunk; import net.minecraft.world.chunk.WorldChunk;
import java.util.*; import java.util.*;
@@ -23,136 +28,172 @@ import java.util.*;
public class NewChunks extends Module { public class NewChunks extends Module {
private final SettingGroup sgGeneral = settings.getDefaultGroup(); private final SettingGroup sgGeneral = settings.getDefaultGroup();
private final SettingGroup sgRender = settings.createGroup("Render");
private final Setting<Boolean> remove = sgGeneral.add(new BoolSetting.Builder() // general
.name("remove")
.description("Removes the cached chunks when disabling the module.") private final Setting<Boolean> remove = sgGeneral.add(new BoolSetting.Builder()
.defaultValue(true) .name("remove")
.build() .description("Removes the cached chunks when disabling the module.")
.defaultValue(true)
.build()
); );
private final Setting<SettingColor> newChunksColor = sgGeneral.add(new ColorSetting.Builder() // render
.name("new-chunks-color") public final Setting<Integer> renderHeight = sgRender.add(new IntSetting.Builder()
.description("Color of the chunks that are (most likely) completely new.") .name("render-height")
.defaultValue(new SettingColor(204, 153, 217)) .description("The height at which new chunks will be rendered")
.build() .defaultValue(0)
); .min(-64)
.sliderRange(-64,319)
.build()
);
private final Setting<SettingColor> oldChunksColor = sgGeneral.add(new ColorSetting.Builder() private final Setting<ShapeMode> shapeMode = sgRender.add(new EnumSetting.Builder<ShapeMode>()
.name("old-chunks-color") .name("shape-mode")
.description("Color of the chunks that have (most likely) been loaded before.") .description("How the shapes are rendered.")
.defaultValue(new SettingColor(230, 51, 51)) .defaultValue(ShapeMode.Both)
.build() .build()
); );
private Set<ChunkPos> newChunks = Collections.synchronizedSet(new HashSet<>()); private final Setting<SettingColor> newChunksSideColor = sgRender.add(new ColorSetting.Builder()
private Set<ChunkPos> oldChunks = Collections.synchronizedSet(new HashSet<>()); .name("new-chunks-side-color")
.description("Color of the chunks that are (most likely) completely new.")
.defaultValue(new SettingColor(255, 0, 0, 75))
.visible(() -> shapeMode.get() == ShapeMode.Sides || shapeMode.get() == ShapeMode.Both)
.build()
);
private final Setting<SettingColor> oldChunksSideColor = sgRender.add(new ColorSetting.Builder()
.name("old-chunks-side-color")
.description("Color of the chunks that have (most likely) been loaded before.")
.defaultValue(new SettingColor(0, 255, 0, 75))
.visible(() -> shapeMode.get() == ShapeMode.Sides || shapeMode.get() == ShapeMode.Both)
.build()
);
private final Setting<SettingColor> newChunksLineColor = sgRender.add(new ColorSetting.Builder()
.name("new-chunks-line-color")
.description("Color of the chunks that are (most likely) completely new.")
.defaultValue(new SettingColor(255, 0, 0, 255))
.visible(() -> shapeMode.get() == ShapeMode.Lines || shapeMode.get() == ShapeMode.Both)
.build()
);
private final Setting<SettingColor> oldChunksLineColor = sgRender.add(new ColorSetting.Builder()
.name("old-chunks-line-color")
.description("Color of the chunks that have (most likely) been loaded before.")
.defaultValue(new SettingColor(0, 255, 0, 255))
.visible(() -> shapeMode.get() == ShapeMode.Lines || shapeMode.get() == ShapeMode.Both)
.build()
);
private final Set<ChunkPos> newChunks = Collections.synchronizedSet(new HashSet<>());
private final Set<ChunkPos> oldChunks = Collections.synchronizedSet(new HashSet<>());
private static final Direction[] searchDirs = new Direction[] { Direction.EAST, Direction.NORTH, Direction.WEST, Direction.SOUTH, Direction.UP }; private static final Direction[] searchDirs = new Direction[] { Direction.EAST, Direction.NORTH, Direction.WEST, Direction.SOUTH, Direction.UP };
public NewChunks() { public NewChunks() {
super(MeteorRejectsAddon.CATEGORY,"new-chunks", "Detects completely new chunks using certain traits of them"); super(MeteorRejectsAddon.CATEGORY,"new-chunks", "Detects completely new chunks using certain traits of them");
} }
@Override @Override
public void onDeactivate() { public void onDeactivate() {
if (remove.get()) { if (remove.get()) {
newChunks.clear(); newChunks.clear();
oldChunks.clear(); oldChunks.clear();
} }
super.onDeactivate(); super.onDeactivate();
} }
@EventHandler @EventHandler
private void onRender(Render3DEvent event) { private void onRender(Render3DEvent event) {
if (newChunksColor.get().a > 5) { if (newChunksLineColor.get().a > 5 || newChunksSideColor.get().a > 5) {
synchronized (newChunks) { synchronized (newChunks) {
for (ChunkPos c : newChunks) { for (ChunkPos c : newChunks) {
if (mc.getCameraEntity().getBlockPos().isWithinDistance(c.getStartPos(), 1024)) { if (mc.getCameraEntity().getBlockPos().isWithinDistance(c.getStartPos(), 1024)) {
drawBoxOutline(new Box(c.getStartPos(), c.getStartPos().add(16, 0, 16)), newChunksColor.get(), event); render(new Box(c.getStartPos(), c.getStartPos().add(16, renderHeight.get(), 16)), newChunksSideColor.get(), newChunksLineColor.get(), shapeMode.get(), event);
} }
} }
} }
} }
if (oldChunksColor.get().a > 5){ if (oldChunksLineColor.get().a > 5 || oldChunksSideColor.get().a > 5){
synchronized (oldChunks) { synchronized (oldChunks) {
for (ChunkPos c : oldChunks) { for (ChunkPos c : oldChunks) {
if (mc.getCameraEntity().getBlockPos().isWithinDistance(c.getStartPos(), 1024)) { if (mc.getCameraEntity().getBlockPos().isWithinDistance(c.getStartPos(), 1024)) {
drawBoxOutline(new Box(c.getStartPos(), c.getStartPos().add(16, 0, 16)), oldChunksColor.get(), event); render(new Box(c.getStartPos(), c.getStartPos().add(16, renderHeight.get(), 16)), oldChunksSideColor.get(), oldChunksLineColor.get(), shapeMode.get(), event);
} }
} }
} }
} }
} }
private void drawBoxOutline(Box box, Color color, Render3DEvent event) { private void render(Box box, Color sides, Color lines, ShapeMode shapeMode, Render3DEvent event) {
event.renderer.box( event.renderer.box(
box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ, box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ, sides, lines, shapeMode, 0);
new Color(0,0,0,0), color, ShapeMode.Lines, 0 }
);
}
@EventHandler @EventHandler
private void onReadPacket(PacketEvent.Receive event) { private void onReadPacket(PacketEvent.Receive event) {
if (event.packet instanceof ChunkDeltaUpdateS2CPacket) { if (event.packet instanceof ChunkDeltaUpdateS2CPacket) {
ChunkDeltaUpdateS2CPacket packet = (ChunkDeltaUpdateS2CPacket) event.packet; ChunkDeltaUpdateS2CPacket packet = (ChunkDeltaUpdateS2CPacket) event.packet;
packet.visitUpdates((pos, state) -> { packet.visitUpdates((pos, state) -> {
if (!state.getFluidState().isEmpty() && !state.getFluidState().isStill()) { if (!state.getFluidState().isEmpty() && !state.getFluidState().isStill()) {
ChunkPos chunkPos = new ChunkPos(pos); ChunkPos chunkPos = new ChunkPos(pos);
for (Direction dir: searchDirs) { for (Direction dir: searchDirs) {
if (mc.world.getBlockState(pos.offset(dir)).getFluidState().isStill() && !oldChunks.contains(chunkPos)) { if (mc.world.getBlockState(pos.offset(dir)).getFluidState().isStill() && !oldChunks.contains(chunkPos)) {
newChunks.add(chunkPos); newChunks.add(chunkPos);
return; return;
} }
} }
} }
}); });
} }
else if (event.packet instanceof BlockUpdateS2CPacket) { else if (event.packet instanceof BlockUpdateS2CPacket) {
BlockUpdateS2CPacket packet = (BlockUpdateS2CPacket) event.packet; BlockUpdateS2CPacket packet = (BlockUpdateS2CPacket) event.packet;
if (!packet.getState().getFluidState().isEmpty() && !packet.getState().getFluidState().isStill()) { if (!packet.getState().getFluidState().isEmpty() && !packet.getState().getFluidState().isStill()) {
ChunkPos chunkPos = new ChunkPos(packet.getPos()); ChunkPos chunkPos = new ChunkPos(packet.getPos());
for (Direction dir: searchDirs) { for (Direction dir: searchDirs) {
if (mc.world.getBlockState(packet.getPos().offset(dir)).getFluidState().isStill() && !oldChunks.contains(chunkPos)) { if (mc.world.getBlockState(packet.getPos().offset(dir)).getFluidState().isStill() && !oldChunks.contains(chunkPos)) {
newChunks.add(chunkPos); newChunks.add(chunkPos);
return; return;
} }
} }
} }
} }
else if (event.packet instanceof ChunkDataS2CPacket && mc.world != null) { else if (event.packet instanceof ChunkDataS2CPacket && mc.world != null) {
ChunkDataS2CPacket packet = (ChunkDataS2CPacket) event.packet; ChunkDataS2CPacket packet = (ChunkDataS2CPacket) event.packet;
ChunkPos pos = new ChunkPos(packet.getX(), packet.getZ()); ChunkPos pos = new ChunkPos(packet.getX(), packet.getZ());
if (!newChunks.contains(pos) && mc.world.getChunkManager().getChunk(packet.getX(), packet.getZ()) == null) { if (!newChunks.contains(pos) && mc.world.getChunkManager().getChunk(packet.getX(), packet.getZ()) == null) {
WorldChunk chunk = new WorldChunk(mc.world, pos); WorldChunk chunk = new WorldChunk(mc.world, pos);
try { try {
chunk.loadFromPacket(packet.getChunkData().getSectionsDataBuf(), new NbtCompound(), packet.getChunkData().getBlockEntities(packet.getX(), packet.getZ())); chunk.loadFromPacket(packet.getChunkData().getSectionsDataBuf(), new NbtCompound(), packet.getChunkData().getBlockEntities(packet.getX(), packet.getZ()));
} catch (ArrayIndexOutOfBoundsException e) { } catch (ArrayIndexOutOfBoundsException e) {
return; return;
} }
for (int x = 0; x < 16; x++) { for (int x = 0; x < 16; x++) {
for (int y = mc.world.getBottomY(); y < mc.world.getTopY(); y++) { for (int y = mc.world.getBottomY(); y < mc.world.getTopY(); y++) {
for (int z = 0; z < 16; z++) { for (int z = 0; z < 16; z++) {
FluidState fluid = chunk.getFluidState(x, y, z); FluidState fluid = chunk.getFluidState(x, y, z);
if (!fluid.isEmpty() && !fluid.isStill()) { if (!fluid.isEmpty() && !fluid.isStill()) {
oldChunks.add(pos); oldChunks.add(pos);
return; return;
} }
} }
} }
} }
} }
} }
} }
} }