Updated RenderUtil, NewChunks has options for colors and sizing now as well with new modes

This commit is contained in:
noil 2020-12-15 19:32:22 -05:00
parent a9865f6580
commit 4610347483
4 changed files with 177 additions and 157 deletions

View File

@ -202,15 +202,7 @@ public final class RenderUtil {
float blue = (hex & 0xFF) / 255.0F;
float alpha = (hex >> 24 & 0xFF) / 255.0F;
GlStateManager.disableTexture2D();
GlStateManager.enableBlend();
GlStateManager.disableAlpha();
GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 1, 0);
GlStateManager.shadeModel(GL_SMOOTH);
glLineWidth(thickness);
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
GlStateManager.disableDepth();
glEnable(GL32.GL_DEPTH_CLAMP);
final Tessellator tessellator = Tessellator.getInstance();
final BufferBuilder bufferbuilder = tessellator.getBuffer();
@ -218,23 +210,10 @@ public final class RenderUtil {
bufferbuilder.pos((double) x, (double) y, (double) z).color(red, green, blue, alpha).endVertex();
bufferbuilder.pos((double) x1, (double) y1, (double) z1).color(red, green, blue, alpha).endVertex();
tessellator.draw();
GlStateManager.shadeModel(GL_FLAT);
glDisable(GL_LINE_SMOOTH);
GlStateManager.enableDepth();
glDisable(GL32.GL_DEPTH_CLAMP);
GlStateManager.disableBlend();
GlStateManager.enableAlpha();
GlStateManager.enableTexture2D();
}
public static void drawBoundingBox(AxisAlignedBB bb, float width, float red, float green, float blue, float alpha) {
GlStateManager.enableBlend();
GlStateManager.disableDepth();
GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 0, 1);
GlStateManager.disableTexture2D();
GlStateManager.depthMask(false);
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glLineWidth(width);
final Tessellator tessellator = Tessellator.getInstance();
@ -260,11 +239,6 @@ public final class RenderUtil {
bufferbuilder.pos(bb.maxX, bb.minY, bb.minZ).color(red, green, blue, alpha).endVertex();
bufferbuilder.pos(bb.maxX, bb.minY, bb.minZ).color(red, green, blue, 0.0F).endVertex();
tessellator.draw();
glDisable(GL_LINE_SMOOTH);
GlStateManager.depthMask(true);
GlStateManager.enableDepth();
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}
public static void drawBoundingBox(AxisAlignedBB bb, float width, int color) {
@ -275,6 +249,27 @@ public final class RenderUtil {
drawBoundingBox(bb, width, red, green, blue, alpha);
}
public static void drawFilledBox(double x, double y, double z, AxisAlignedBB bb, int color) {
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
drawFilledBox(bb, color);
GL11.glPopMatrix();
}
public static void drawBoundingBox(double x, double y, double z, AxisAlignedBB bb, float width, int color) {
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
drawBoundingBox(bb, width, color);
GL11.glPopMatrix();
}
public static void drawCrosses(double x, double y, double z, AxisAlignedBB bb, float width, int color) {
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
drawCrosses(bb, width, color);
GL11.glPopMatrix();
}
public static void drawPlane(double x, double y, double z, AxisAlignedBB bb, float width, int color) {
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
@ -284,19 +279,7 @@ public final class RenderUtil {
public static void drawPlane(AxisAlignedBB axisalignedbb, float width, int color) {
GlStateManager.glLineWidth(width);
GlStateManager.enableBlend();
GlStateManager.disableDepth();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE);
GlStateManager.disableTexture2D();
GlStateManager.depthMask(false);
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
drawPlane(axisalignedbb, color);
glDisable(GL_LINE_SMOOTH);
GlStateManager.depthMask(true);
GlStateManager.enableDepth();
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}
public static void drawPlane(AxisAlignedBB boundingBox, int color) {
@ -326,12 +309,6 @@ public final class RenderUtil {
}
public static void drawFilledBox(AxisAlignedBB bb, int color) {
GlStateManager.enableBlend();
GlStateManager.disableDepth();
GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 0, 1);
GlStateManager.disableTexture2D();
GlStateManager.depthMask(false);
final float alpha = (color >> 24 & 0xFF) / 255.0F;
final float red = (color >> 16 & 0xFF) / 255.0F;
final float green = (color >> 8 & 0xFF) / 255.0F;
@ -371,18 +348,10 @@ public final class RenderUtil {
bufferbuilder.pos(bb.minX, bb.maxY, bb.maxZ).color(red, green, blue, alpha).endVertex();
bufferbuilder.pos(bb.minX, bb.maxY, bb.minZ).color(red, green, blue, alpha).endVertex();
tessellator.draw();
GlStateManager.depthMask(true);
GlStateManager.enableDepth();
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}
public static void drawCrosses(AxisAlignedBB bb, int color) {
GlStateManager.enableBlend();
GlStateManager.disableDepth();
GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 0, 1);
GlStateManager.disableTexture2D();
GlStateManager.depthMask(false);
public static void drawCrosses(AxisAlignedBB bb, float width, int color) {
GlStateManager.glLineWidth(width);
glColor(color);
GL11.glBegin(GL_LINES);
GL11.glVertex3d(bb.maxX, bb.maxY, bb.maxZ);
@ -398,10 +367,6 @@ public final class RenderUtil {
GL11.glVertex3d(bb.minX, bb.minY, bb.minZ);
GL11.glVertex3d(bb.maxX, bb.minY, bb.maxZ);
GL11.glEnd();
GlStateManager.depthMask(true);
GlStateManager.enableDepth();
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}
public static void glScissor(float x, float y, float x1, float y1, final ScaledResolution sr) {
@ -488,6 +453,7 @@ public final class RenderUtil {
GlStateManager.disableTexture2D();
GlStateManager.disableDepth();
GL11.glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
}
public static void end3D() {

View File

@ -22,8 +22,8 @@ import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
import java.awt.*;
/**
* Author Seth
* 8/14/2019 @ 1:13 AM.
* @author Seth
* @author noil
*/
public final class BlockHighlightModule extends Module {
@ -42,7 +42,7 @@ public final class BlockHighlightModule extends Module {
private Color currentColor = new Color(255, 255, 255, 255);
public BlockHighlightModule() {
super("BlockHighlight", new String[]{"BHighlight", "BlockHigh"}, "Highlights the block at your crosshair", "NONE", -1, ModuleType.RENDER);
super("BlockHighlight", new String[]{"BHighlight", "BlockHigh"}, "Highlights the block at your cross-hair", "NONE", -1, ModuleType.RENDER);
}
@Listener
@ -74,7 +74,7 @@ public final class BlockHighlightModule extends Module {
break;
case CROSS:
RenderUtil.drawFilledBox(bb, ColorUtil.changeAlpha(color, this.alpha.getValue() / 2));
RenderUtil.drawCrosses(bb, color);
RenderUtil.drawCrosses(bb, this.width.getValue(), color);
RenderUtil.drawBoundingBox(bb, this.width.getValue(), color);
break;
}

View File

@ -0,0 +1,149 @@
package me.rigamortis.seppuku.impl.module.render;
import me.rigamortis.seppuku.api.event.EventStageable;
import me.rigamortis.seppuku.api.event.client.EventSaveConfig;
import me.rigamortis.seppuku.api.event.network.EventReceivePacket;
import me.rigamortis.seppuku.api.event.render.EventRender3D;
import me.rigamortis.seppuku.api.module.Module;
import me.rigamortis.seppuku.api.util.ColorUtil;
import me.rigamortis.seppuku.api.util.RenderUtil;
import me.rigamortis.seppuku.api.value.Value;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.client.renderer.culling.ICamera;
import net.minecraft.network.play.server.SPacketChunkData;
import net.minecraft.util.math.AxisAlignedBB;
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
/**
* @author Seth
* @author noil
*/
public final class NewChunksModule extends Module {
public final Value<Mode> mode = new Value<Mode>("Mode", new String[]{"M", "type", "t"}, "Select which mode to draw the new chunk visual.", Mode.BOX);
public final Value<Integer> red = new Value<Integer>("Red", new String[]{"Re", "r"}, "Red value for the new chunk visual.", 255, 0, 255, 1);
public final Value<Integer> green = new Value<Integer>("Green", new String[]{"Gre", "g"}, "Green value for the new chunk visual.", 255, 0, 255, 1);
public final Value<Integer> blue = new Value<Integer>("Blue", new String[]{"Blu", "b"}, "Blue value for the new chunk visual.", 255, 0, 255, 1);
public final Value<Integer> alpha = new Value<Integer>("Alpha", new String[]{"Alp", "Opacity", "a", "o"}, "Alpha value for the new chunk visual.", 127, 0, 255, 1);
public final Value<Float> width = new Value<Float>("Width", new String[]{"W", "size", "s"}, "Width value of the new chunk visual.", 1.5f, 0.0f, 5.0f, 0.1f);
public enum Mode {
BOX, OUTLINE, PLANE
}
private Color currentColor;
private final ICamera frustum = new Frustum();
private final List<ChunkData> chunkDataList = new ArrayList<>();
public NewChunksModule() {
super("NewChunks", new String[]{"ChunkGen"}, "Highlights newly generated chunks", "NONE", -1, ModuleType.RENDER);
this.currentColor = new Color(this.red.getValue(), this.blue.getValue(), this.green.getValue(), this.alpha.getValue());
}
@Listener
public void onToggle() {
super.onToggle();
this.chunkDataList.clear();
}
@Listener
public void receivePacket(EventReceivePacket event) {
if (event.getStage() == EventStageable.EventStage.PRE) {
if (event.getPacket() instanceof SPacketChunkData) {
final SPacketChunkData packet = (SPacketChunkData) event.getPacket();
if (!packet.isFullChunk()) {
final ChunkData chunk = new ChunkData(packet.getChunkX() * 16, packet.getChunkZ() * 16);
if (!this.contains(chunk)) {
this.chunkDataList.add(chunk);
}
}
}
}
}
@Listener
public void render3D(EventRender3D event) {
if (Minecraft.getMinecraft().getRenderViewEntity() == null)
return;
RenderUtil.begin3D();
for (int i = this.chunkDataList.size() - 1; i >= 0; i--) {
final ChunkData chunkData = this.chunkDataList.get(i);
if (chunkData != null) {
this.frustum.setPosition(Minecraft.getMinecraft().getRenderViewEntity().posX, Minecraft.getMinecraft().getRenderViewEntity().posY, Minecraft.getMinecraft().getRenderViewEntity().posZ);
final AxisAlignedBB bb = new AxisAlignedBB(chunkData.x, 0, chunkData.z, chunkData.x + 16, 1, chunkData.z + 16);
if (frustum.isBoundingBoxInFrustum(bb)) {
final int color = ColorUtil.changeAlpha(currentColor.getRGB(), this.alpha.getValue());
double x = chunkData.x - Minecraft.getMinecraft().getRenderManager().viewerPosX;
double y = -Minecraft.getMinecraft().getRenderManager().viewerPosY;
double z = chunkData.z - Minecraft.getMinecraft().getRenderManager().viewerPosZ;
final AxisAlignedBB chunkBB = new AxisAlignedBB(0, 0, 0, 16, 2, 16);
switch (this.mode.getValue()) {
case BOX:
RenderUtil.drawFilledBox(x, y, z, chunkBB, ColorUtil.changeAlpha(color, this.alpha.getValue()));
break;
case OUTLINE:
RenderUtil.drawBoundingBox(x, y, z, chunkBB, this.width.getValue(), color);
break;
case PLANE:
RenderUtil.drawPlane(x, y, z, new AxisAlignedBB(0, 0, 0, 16, 1, 16), this.width.getValue(), color);
break;
}
}
}
}
RenderUtil.end3D();
}
@Listener
public void onConfigSave(EventSaveConfig event) {
this.currentColor = new Color(this.red.getValue(), this.green.getValue(), this.blue.getValue());
}
private boolean contains(final ChunkData chunkData) {
boolean temp = false;
for (ChunkData data : this.chunkDataList) {
if (data.x == chunkData.x && data.z == chunkData.z)
temp = true;
}
return temp;
}
public static class ChunkData {
private int x;
private int z;
public ChunkData(int x, int z) {
this.x = x;
this.z = z;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getZ() {
return z;
}
public void setZ(int z) {
this.z = z;
}
}
}

View File

@ -1,95 +0,0 @@
package me.rigamortis.seppuku.impl.module.world;
import me.rigamortis.seppuku.api.event.EventStageable;
import me.rigamortis.seppuku.api.event.network.EventReceivePacket;
import me.rigamortis.seppuku.api.event.render.EventRender3D;
import me.rigamortis.seppuku.api.module.Module;
import me.rigamortis.seppuku.api.util.RenderUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.client.renderer.culling.ICamera;
import net.minecraft.network.play.server.SPacketChunkData;
import net.minecraft.util.math.AxisAlignedBB;
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
import java.util.ArrayList;
import java.util.List;
/**
* Author Seth
* 5/11/2019 @ 7:46 AM.
*/
public final class NewChunksModule extends Module {
private ICamera frustum = new Frustum();
private List<ChunkData> chunkDataList = new ArrayList<>();
public NewChunksModule() {
super("NewChunks", new String[]{"ChunkGen"}, "Highlights newly generated chunks", "NONE", -1, ModuleType.WORLD);
}
@Listener
public void onToggle() {
super.onToggle();
this.chunkDataList.clear();
}
@Listener
public void receivePacket(EventReceivePacket event) {
if (event.getStage() == EventStageable.EventStage.PRE) {
if (event.getPacket() instanceof SPacketChunkData) {
final SPacketChunkData packet = (SPacketChunkData) event.getPacket();
if (!packet.isFullChunk()) {
final ChunkData chunk = new ChunkData(packet.getChunkX() * 16, packet.getChunkZ() * 16);
if (!this.chunkDataList.contains(chunk)) {
this.chunkDataList.add(chunk);
}
}
}
}
}
@Listener
public void render3D(EventRender3D event) {
for (ChunkData chunkData : this.chunkDataList) {
if (chunkData != null) {
this.frustum.setPosition(Minecraft.getMinecraft().getRenderViewEntity().posX, Minecraft.getMinecraft().getRenderViewEntity().posY, Minecraft.getMinecraft().getRenderViewEntity().posZ);
final AxisAlignedBB bb = new AxisAlignedBB(chunkData.x, 0, chunkData.z, chunkData.x + 16, 1, chunkData.z + 16);
if (frustum.isBoundingBoxInFrustum(bb)) {
RenderUtil.drawPlane(chunkData.x - Minecraft.getMinecraft().getRenderManager().viewerPosX, -Minecraft.getMinecraft().getRenderManager().viewerPosY, chunkData.z - Minecraft.getMinecraft().getRenderManager().viewerPosZ, new AxisAlignedBB(0, 0, 0, 16, 1, 16), 1, 0xFF9900EE);
}
}
}
}
public static class ChunkData {
private int x;
private int z;
public ChunkData(int x, int z) {
this.x = x;
this.z = z;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getZ() {
return z;
}
public void setZ(int z) {
this.z = z;
}
}
}