make select show the selection, make ESP settings less cluttered, fix a bug with sections, add SimpleRender
All checks were successful
/ Build BaseBand DSM & Broadway (push) Successful in 2m22s

This commit is contained in:
Daniella / Tove 2024-06-20 20:23:25 +02:00
parent 4dd5a5fd54
commit 8dead855f2
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
6 changed files with 350 additions and 56 deletions

View file

@ -128,10 +128,12 @@ public abstract class Feature extends ToggleButton implements SetCommand {
Description descriptionAnnotation = f.getDeclaredAnnotation(Description.class); Description descriptionAnnotation = f.getDeclaredAnnotation(Description.class);
Section section = f.getDeclaredAnnotation(Section.class); Section section = f.getDeclaredAnnotation(Section.class);
String path = ""; String path = "";
if(section != null && !sections.containsKey(section.value())) { if (section != null) {
ArrayList<Component> comps = new ArrayList<>(); if (!sections.containsKey(section.value())) {
sections.put(section.value(), comps); ArrayList<Component> comps = new ArrayList<>();
subComponents.add(new Component(section.value(), comps, true)); sections.put(section.value(), comps);
subComponents.add(new Component(section.value(), comps, true));
}
path = section.value() + "/"; path = section.value() + "/";
} }
String description = descriptionAnnotation == null ? null : descriptionAnnotation.value(); String description = descriptionAnnotation == null ? null : descriptionAnnotation.value();

View file

@ -4,15 +4,43 @@ import de.com.baseband.client.BaseBand;
import de.com.baseband.client.event.Priority; import de.com.baseband.client.event.Priority;
import de.com.baseband.client.event.events.SelectEvent; import de.com.baseband.client.event.events.SelectEvent;
import de.com.baseband.client.feature.Feature; import de.com.baseband.client.feature.Feature;
import de.com.baseband.client.feature.Features;
import de.com.baseband.client.feature.category.Ingame; import de.com.baseband.client.feature.category.Ingame;
import de.com.baseband.client.registry.annotation.KeyBound; import de.com.baseband.client.feature.modules.client.Client;
import de.com.baseband.client.registry.annotation.Trigger; import de.com.baseband.client.registry.annotation.*;
import de.com.baseband.client.util.adapt.Marker;
import de.com.baseband.client.util.render.Pixels;
import de.com.baseband.client.util.render.SimpleRender;
import de.com.baseband.client.util.type.Selection; import de.com.baseband.client.util.type.Selection;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@Ingame @Ingame
public class Select extends Feature { public class Select extends Feature {
@Config("Render selection")
@Marker(1)
public boolean renderSelection = true;
@Config("Render incomplete selection")
@Gate(1)
public boolean renderIncomplete = true;
@Config("Wireframe")
@Gate(1)
public boolean wireframe = true;
@Config("Fill")
@Gate(1)
@Marker(2)
public boolean fill = true;
@Config("Fill opacity")
@Range("0.05..0.5@0.05")
@Gate(2)
public float opacity = 0.1f;
public static BlockPos begin, end; public static BlockPos begin, end;
public static Selection selection; public static Selection selection;
@ -49,6 +77,27 @@ public class Select extends Feature {
BaseBand.notify("Selection reset."); BaseBand.notify("Selection reset.");
} }
@SubscribeEvent
public void render(RenderWorldLastEvent event) {
if(!renderSelection)
return;
Selection selection = Select.selection;
if(selection == null) {
BlockPos pos = mc.objectMouseOver.getBlockPos();
//noinspection ConstantValue - pos can indeed be null.
if(renderIncomplete && begin != null && pos != null)
selection = new Selection(begin, pos);
else
return;
}
int c = Features.getFeature(Client.class).theme.getGreenColor() | 0xff000000;
SimpleRender simpleRender = new SimpleRender(event.getPartialTicks());
if(wireframe)
simpleRender.color(c).lines().aabb(selection.toAABB()).back();
if(fill)
simpleRender.color(Pixels.mulTransparency(c, opacity)).quadsFill().aabb(selection.toAABB()).back();
simpleRender.finish();
}
@Override @Override
public String toString() { public String toString() {

View file

@ -5,9 +5,7 @@ import de.com.baseband.client.feature.Feature;
import de.com.baseband.client.feature.Features; import de.com.baseband.client.feature.Features;
import de.com.baseband.client.feature.category.Render; import de.com.baseband.client.feature.category.Render;
import de.com.baseband.client.feature.modules.client.Client; import de.com.baseband.client.feature.modules.client.Client;
import de.com.baseband.client.registry.annotation.Config; import de.com.baseband.client.registry.annotation.*;
import de.com.baseband.client.registry.annotation.Gate;
import de.com.baseband.client.registry.annotation.Range;
import de.com.baseband.client.util.adapt.Marker; import de.com.baseband.client.util.adapt.Marker;
import de.com.baseband.client.util.render.Pixels; import de.com.baseband.client.util.render.Pixels;
import de.com.baseband.client.util.render.RenderAdapter; import de.com.baseband.client.util.render.RenderAdapter;
@ -26,7 +24,6 @@ import java.util.function.Consumer;
import static de.com.baseband.client.util.render.RenderAdapter.*; import static de.com.baseband.client.util.render.RenderAdapter.*;
//Feature complete.
@Render @Render
public class ESP extends Feature { public class ESP extends Feature {
@Override @Override
@ -34,29 +31,55 @@ public class ESP extends Feature {
return "ESP"; return "ESP";
} }
private static final int M_CURSOR = 1, M_ENTITIES = 2, M_TILE_ENTITIES = 3, M_CFILL = 4, M_OFILL = 5;
private static final String S_CURSOR = "Cursor", S_OBJECTS = "Objects";
@Section(S_CURSOR)
@Config("Highlight") @Config("Highlight")
@Marker(0) @Marker(M_CURSOR)
public boolean highlight; public boolean highlight;
@Config("Highlight Nothing") @Section(S_CURSOR)
@Gate(0) @Config("Highlight Air")
public boolean hightlightNothing; @Gate(M_CURSOR)
public boolean highlightAir;
@Section(S_CURSOR)
@Config("Wireframe")
@Gate(M_CURSOR)
public boolean cursorWireframe = true;
@Section(S_CURSOR)
@Config("Fill")
@Marker(M_CFILL)
@Gate(M_CURSOR)
public boolean cursorFill = true;
@Section(S_OBJECTS)
@Config("Entities") @Config("Entities")
@Marker(M_ENTITIES)
public boolean entities; public boolean entities;
@Section(S_OBJECTS)
@Config("Tile Entities") @Config("Tile Entities")
@Marker(M_TILE_ENTITIES)
public boolean tileEntities; public boolean tileEntities;
@Section(S_OBJECTS)
@Config("Wireframe") @Config("Wireframe")
@MultiGate(or = {M_ENTITIES, M_TILE_ENTITIES})
public boolean wireframe; public boolean wireframe;
@Section(S_OBJECTS)
@Config("Fill") @Config("Fill")
@Marker(1) @MultiGate(or = {M_ENTITIES, M_TILE_ENTITIES})
@Marker(M_OFILL)
public boolean fill; public boolean fill;
@Config("Fill opacity") @Config("Fill opacity")
@Range("0.1..1") @Range("0.1..0.5@0.05")
@Gate(1) @MultiGate(or = {M_CFILL, M_OFILL})
public float opacity = 0.2f; public float opacity = 0.2f;
@ -68,60 +91,52 @@ public class ESP extends Feature {
Vec3d eyePos = Objects.requireNonNull(mc.getRenderViewEntity()).getPositionEyes(event.getPartialTicks()).add(0, -mc.getRenderViewEntity().getEyeHeight(), 0); Vec3d eyePos = Objects.requireNonNull(mc.getRenderViewEntity()).getPositionEyes(event.getPartialTicks()).add(0, -mc.getRenderViewEntity().getEyeHeight(), 0);
if (fill) { ready();
ready(); translate(-eyePos.x, -eyePos.y, -eyePos.z);
translate(-eyePos.x, -eyePos.y, -eyePos.z); color(Pixels.mulTransparency(Features.getFeature(Client.class).theme.getGreenColor() | 0xff000000, opacity));
color(Pixels.mulTransparency(Features.getFeature(Client.class).theme.getGreenColor() | 0xff000000, opacity)); depth(false);
depth(false); begin(GL11.GL_QUADS);
begin(GL11.GL_QUADS);
draw(event, RenderAdapter::drawAABBNow); draw(event, RenderAdapter::drawAABBNow, false, true);
end(); changeColor(Features.getFeature(Client.class).theme.getGreenColor());
} switchMode(GL11.GL_LINES);
draw(event, RenderAdapter::drawAABBLinesNow, true, false);
if (wireframe) { end();
ready();
translate(-eyePos.x, -eyePos.y, -eyePos.z);
color(Features.getFeature(Client.class).theme.getGreenColor());
depth(false);
begin(GL11.GL_LINES);
draw(event, RenderAdapter::drawAABBLinesNow);
end();
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
BaseBand.LOGGER.error("Please send the above stacktrace to a developer!"); BaseBand.LOGGER.error("Please send the above stacktrace to a developer!");
} }
} }
private void draw(RenderWorldLastEvent event, Consumer<AxisAlignedBB> renderer) { private void draw(RenderWorldLastEvent event, Consumer<AxisAlignedBB> renderer, boolean wfPass, boolean fPass) {
if (entities) { if(wfPass && wireframe || fPass && fill) {
for (Entity entity : mc.world.loadedEntityList) { if (entities) {
AxisAlignedBB interpolated = RenderAdapter.getLiveEntityBB(entity, event.getPartialTicks()); for (Entity entity : mc.world.loadedEntityList) {
if (entity == mc.getRenderViewEntity() && mc.gameSettings.thirdPersonView == 0) { AxisAlignedBB interpolated = RenderAdapter.getLiveEntityBB(entity, event.getPartialTicks());
continue; if (entity == mc.getRenderViewEntity() && mc.gameSettings.thirdPersonView == 0) {
continue;
}
renderer.accept(interpolated);
}
}
if (tileEntities) {
for (TileEntity entity : mc.world.loadedTileEntityList) {
// this is a fuck
// getRenderBoundingBox often falls back to bullshit like INFINITE BOUNDING BOXES.
BlockPos pos = entity.getPos();
renderer.accept(mc.world.getBlockState(pos).getBoundingBox(mc.world, pos).offset(pos));
} }
renderer.accept(interpolated);
} }
} }
if (tileEntities) { if(highlight && (wfPass && cursorWireframe || fPass && cursorFill)) {
for (TileEntity entity : mc.world.loadedTileEntityList) {
// this is a fuck
// getRenderBoundingBox often falls back to bullshit like INFINITE BOUNDING BOXES.
BlockPos pos = entity.getPos();
renderer.accept(mc.world.getBlockState(pos).getBoundingBox(mc.world, pos).offset(pos));
}
}
if(highlight) {
if(mc.objectMouseOver != null) { if(mc.objectMouseOver != null) {
BlockPos pos = mc.objectMouseOver.getBlockPos(); BlockPos pos = mc.objectMouseOver.getBlockPos();
if ((mc.objectMouseOver.typeOfHit != RayTraceResult.Type.MISS || hightlightNothing) && mc.objectMouseOver.typeOfHit != RayTraceResult.Type.ENTITY) { if ((mc.objectMouseOver.typeOfHit != RayTraceResult.Type.MISS || highlightAir) && mc.objectMouseOver.typeOfHit != RayTraceResult.Type.ENTITY) {
renderer.accept(mc.world.getBlockState(pos).getBoundingBox(mc.world, pos).offset(pos)); renderer.accept(mc.world.getBlockState(pos).getBoundingBox(mc.world, pos).offset(pos));
} }
} }

View file

@ -17,7 +17,7 @@ public class RenderAdapter {
static Vec3d translated; static Vec3d translated;
static boolean depth; static boolean depth;
private static byte[] splitIntBE(int i) { static byte[] splitIntBE(int i) {
return new byte[]{(byte)(i >> 24 & 0xff), (byte)(i >> 16 & 0xff), (byte)(i >> 8 & 0xff), (byte)(i >> 0 & 0xff)}; return new byte[]{(byte)(i >> 24 & 0xff), (byte)(i >> 16 & 0xff), (byte)(i >> 8 & 0xff), (byte)(i >> 0 & 0xff)};
} }
@ -84,6 +84,10 @@ public class RenderAdapter {
depth(depth); depth(depth);
glBegin(mode); glBegin(mode);
} }
public static void switchMode(int modeIn) {
glEnd();
glBegin(mode = modeIn);
}
/** /**
* Draws an outline around a block. * Draws an outline around a block.

View file

@ -0,0 +1,219 @@
package de.com.baseband.client.util.render;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import static de.com.baseband.client.BaseBand.mc;
import static de.com.baseband.client.util.render.RenderAdapter.splitIntBE;
import static org.lwjgl.opengl.GL11.*;
public class SimpleRender {
private final Vec3d translate;
public SimpleRender(float pt) {
Vec3d eyePos = mc.getRenderViewEntity().getPositionEyes(pt).add(0, -mc.getRenderViewEntity().getEyeHeight(), 0);
glPushMatrix();
translate = new Vec3d(-eyePos.x, -eyePos.y, -eyePos.z);
glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glClear(GL_DEPTH_BUFFER_BIT);
}
public SimpleRender color(int color) {
byte[] bytes = splitIntBE(color);
glColor4ub(bytes[1], bytes[2], bytes[3], bytes[0]);
return this;
}
public SimpleLineBackend lines() {
glBegin(GL_LINES);
return new SimpleLineBackend();
}
public SimpleQuadBackend quadsFill() {
glBegin(GL_QUADS);
return new SimpleQuadBackend();
}
private void put(double x, double y, double z) {
glVertex3d(x + translate.x, y + translate.y, z + translate.z);
}
public interface SimpleRenderBackend {
default SimpleRenderBackend qaabb(AxisAlignedBB box) {
return mesh()
.point(box.minX, box.minY, box.minZ)
.point(box.minX, box.minY, box.maxZ)
.point(box.maxX, box.minY, box.maxZ)
.point(box.maxX, box.minY, box.minZ)
.next()
.point(box.minX, box.maxY, box.minZ)
.point(box.minX, box.maxY, box.maxZ)
.point(box.maxX, box.maxY, box.maxZ)
.point(box.maxX, box.maxY, box.minZ)
.next()
.point(box.minX, box.minY, box.minZ)
.point(box.minX, box.maxY, box.minZ)
.point(box.maxX, box.maxY, box.minZ)
.point(box.maxX, box.minY, box.minZ)
.next()
.point(box.minX, box.minY, box.minZ)
.point(box.minX, box.minY, box.maxZ)
.point(box.minX, box.maxY, box.maxZ)
.point(box.minX, box.maxY, box.minZ)
.next()
.point(box.minX, box.minY, box.maxZ)
.point(box.minX, box.maxY, box.maxZ)
.point(box.maxX, box.maxY, box.maxZ)
.point(box.maxX, box.minY, box.maxZ)
.next()
.point(box.maxX, box.minY, box.minZ)
.point(box.maxX, box.minY, box.maxZ)
.point(box.maxX, box.maxY, box.maxZ)
.point(box.maxX, box.maxY, box.minZ)
.end();
}
SimpleRenderBackend aabb(AxisAlignedBB box);
SimplePolyMesh<?> mesh();
SimpleRender back();
}
public class SimplePolyMesh<T extends SimpleRenderBackend> {
private final T parent;
private SimplePolyMesh(T parent) {
this.parent = parent;
}
public SimplePolyMesh<T> point(double x, double y, double z) {
put(x, y, z);
return this;
}
public T end() {
return parent;
}
public SimplePolyMesh<T> next() {
return this;
}
}
public class SimpleLinePolyMesh<T extends SimpleRenderBackend> extends SimplePolyMesh<T> {
private SimpleLinePolyMesh(T parent) {
super(parent);
}
double fx, fy, fz;
double lx, ly, lz;
boolean b;
@Override
public SimpleLinePolyMesh<T> point(double x, double y, double z) {
if(b) {
put(lx, ly, lz);
put(lx = x, ly = y, lz = z);
} else {
fx = lx = x;
fy = ly = y;
fz = lz = z;
b = true;
}
return this;
}
@Override
public T end() {
if(b) {
put(lx, ly, lz);
put(fx, fy, fz);
}
return super.end();
}
@Override
public SimpleLinePolyMesh<T> next() {
if(b) {
put(lx, ly, lz);
put(fx, fy, fz);
}
b = false;
return this;
}
}
public class SimpleQuadBackend implements SimpleRenderBackend {
@Override
public SimpleQuadBackend aabb(AxisAlignedBB box) {
return (SimpleQuadBackend) qaabb(box);
}
@Override
public SimplePolyMesh<SimpleQuadBackend> mesh() {
return new SimplePolyMesh<>(this);
}
@Override
public SimpleRender back() {
glEnd();
return SimpleRender.this;
}
}
public class SimpleLineBackend implements SimpleRenderBackend {
@Override
public SimpleLineBackend aabb(AxisAlignedBB box) {
return mesh()
.point(box.minX, box.minY, box.minZ)
.point(box.minX, box.minY, box.maxZ)
.point(box.maxX, box.minY, box.maxZ)
.point(box.maxX, box.minY, box.minZ)
.next()
.point(box.minX, box.maxY, box.minZ)
.point(box.minX, box.maxY, box.maxZ)
.point(box.maxX, box.maxY, box.maxZ)
.point(box.maxX, box.maxY, box.minZ)
.end()
.vline(box.minX, box.minY, box.minZ, box.maxY)
.vline(box.minX, box.minY, box.maxZ, box.maxY)
.vline(box.maxX, box.minY, box.maxZ, box.maxY)
.vline(box.maxX, box.minY, box.minZ, box.maxY);
}
public SimpleLineBackend vline(double x, double y0, double z, double y1) {
put(x, y0, z);
put(x, y1, z);
return this;
}
public SimpleLineBackend line(double x0, double y0, double z0, double x1, double y1, double z1) {
put(x0, y0, z0);
put(x1, y1, z1);
return this;
}
@Override
public SimpleLinePolyMesh<SimpleLineBackend> mesh() {
return new SimpleLinePolyMesh<>(this);
}
@Override
public SimpleRender back() {
glEnd();
return SimpleRender.this;
}
}
public void finish() {
glEnable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glPopMatrix();
}
}

View file

@ -1,5 +1,6 @@
package de.com.baseband.client.util.type; package de.com.baseband.client.util.type;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i; import net.minecraft.util.math.Vec3i;
@ -35,4 +36,8 @@ public class Selection {
public String toString() { public String toString() {
return "Selection[" + area() + "B from " + pos1 + " to " + pos2 + "]"; return "Selection[" + area() + "B from " + pos1 + " to " + pos2 + "]";
} }
public AxisAlignedBB toAABB() {
return new AxisAlignedBB(pos1, pos2.add(1,1,1));
}
} }