From 45c213ba940eb6b6be7169e3e78fe946497dc6d8 Mon Sep 17 00:00:00 2001 From: xiaozhou233 Date: Sat, 22 Aug 2026 23:40:42 +0800 Subject: [PATCH] Refactor: Move ESP rendering into RenderUtils --- .../cn/xiaozhou233/orangex/module/Module.java | 8 ++ .../orangex/module/ModuleManager.java | 1 + .../orangex/module/impl/render/ESP.java | 61 ++++++++++ .../orangex/utils/RenderUtils.java | 112 ++++++++++++++++++ 4 files changed, 182 insertions(+) create mode 100644 OrangeX/src/main/java/cn/xiaozhou233/orangex/module/impl/render/ESP.java create mode 100644 OrangeX/src/main/java/cn/xiaozhou233/orangex/utils/RenderUtils.java diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/module/Module.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/module/Module.java index a8ca543..2dd1429 100644 --- a/OrangeX/src/main/java/cn/xiaozhou233/orangex/module/Module.java +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/module/Module.java @@ -71,4 +71,12 @@ public class Module { setEnabled(!this.enabled); } + public > T getOption(String name, Class clazz) { + for (Option option : options) { + if (option.getName().equalsIgnoreCase(name) && clazz.isInstance(option)) { + return clazz.cast(option); + } + } + return null; + } } diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/module/ModuleManager.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/module/ModuleManager.java index 356d636..f3ce985 100644 --- a/OrangeX/src/main/java/cn/xiaozhou233/orangex/module/ModuleManager.java +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/module/ModuleManager.java @@ -35,6 +35,7 @@ public class ModuleManager { // Render addModule(new HUD()); addModule(new ClickGUI()); + addModule(new ESP()); } public List getModulesByCategory(ModuleCategory category) { diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/module/impl/render/ESP.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/module/impl/render/ESP.java new file mode 100644 index 0000000..70a28f1 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/module/impl/render/ESP.java @@ -0,0 +1,61 @@ +package cn.xiaozhou233.orangex.module.impl.render; + +import cn.xiaozhou233.orangex.event.impl.EventRender3D; +import cn.xiaozhou233.orangex.module.Module; +import cn.xiaozhou233.orangex.module.ModuleCategory; +import cn.xiaozhou233.orangex.module.option.impl.BooleanOption; +import cn.xiaozhou233.orangex.utils.RenderUtils; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.monster.EntityMob; +import net.minecraft.entity.passive.EntityAnimal; +import net.minecraft.entity.passive.EntityVillager; +import net.minecraft.entity.player.EntityPlayer; +import org.greenrobot.eventbus.Subscribe; + +public class ESP extends Module { + + public ESP() { + super("ESP", "See entities through walls", ModuleCategory.RENDER); + + addOption(new BooleanOption("Render Self", "Render self", this, false)); + addOption(new BooleanOption("Render Players", "Render players", this, true)); + addOption(new BooleanOption("Render Villagers", "Render villagers", this, false)); + addOption(new BooleanOption("Render Mobs", "Render mobs", this, false)); + addOption(new BooleanOption("Render Animals", "Render animals", this, false)); + addOption(new BooleanOption("Render Items", "Render items", this, false)); + } + + @Subscribe + public void onRender3D(EventRender3D event) { + if (mc.theWorld == null || mc.thePlayer == null) return; + + BooleanOption renderSelf = getOption("Render Self", BooleanOption.class); + BooleanOption renderPlayers = getOption("Render Players", BooleanOption.class); + BooleanOption renderVillagers = getOption("Render Villagers", BooleanOption.class); + BooleanOption renderMobs = getOption("Render Mobs", BooleanOption.class); + BooleanOption renderAnimals = getOption("Render Animals", BooleanOption.class); + BooleanOption renderItems = getOption("Render Items", BooleanOption.class); + + for (Entity entity : mc.theWorld.loadedEntityList) { + if (entity == mc.thePlayer && !renderSelf.getValue()) + continue; + + if (entity instanceof EntityPlayer) { + if (!renderPlayers.getValue()) continue; + } else if (entity instanceof EntityVillager) { + if (!renderVillagers.getValue()) continue; + } else if (entity instanceof EntityAnimal) { + if (!renderAnimals.getValue()) continue; + } else if (entity instanceof EntityMob) { + if (!renderMobs.getValue()) continue; + } else if (entity instanceof EntityItem) { + if (!renderItems.getValue()) continue; + } else { + continue; + } + + RenderUtils.drawEntityBox(entity, event.getPartialTicks()); + } + } +} \ No newline at end of file diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/utils/RenderUtils.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/utils/RenderUtils.java new file mode 100644 index 0000000..8198a51 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/utils/RenderUtils.java @@ -0,0 +1,112 @@ +package cn.xiaozhou233.orangex.utils; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.entity.Entity; +import net.minecraft.util.AxisAlignedBB; +import org.lwjgl.opengl.GL11; + +public class RenderUtils { + + private static final Minecraft mc = Minecraft.getMinecraft(); + + public static void drawEntityBox(Entity entity, float partialTicks) { + Entity view = mc.getRenderViewEntity(); + double renderPosX = view.lastTickPosX + (view.posX - view.lastTickPosX) * partialTicks; + double renderPosY = view.lastTickPosY + (view.posY - view.lastTickPosY) * partialTicks; + double renderPosZ = view.lastTickPosZ + (view.posZ - view.lastTickPosZ) * partialTicks; + + double x = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * partialTicks - renderPosX; + double y = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * partialTicks - renderPosY; + double z = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * partialTicks - renderPosZ; + + AxisAlignedBB bb = entity.getEntityBoundingBox(); + double expand = 0.15; + bb = bb.expand(expand, expand, expand); + bb = bb.offset(-entity.posX, -entity.posY, -entity.posZ); + bb = bb.offset(x, y, z); + + GlStateManager.pushMatrix(); + GlStateManager.enableBlend(); + GlStateManager.disableTexture2D(); + GlStateManager.disableDepth(); + GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); + GL11.glLineWidth(2.0f); + + GL11.glColor4f(1.0f, 1.0f, 1.0f, 0.5f); + drawBox(bb); + + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + drawOutline(bb); + + GlStateManager.enableDepth(); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + GlStateManager.popMatrix(); + } + + public static void drawBox(AxisAlignedBB bb) { + GL11.glBegin(GL11.GL_QUADS); + GL11.glVertex3d(bb.minX, bb.minY, bb.minZ); + GL11.glVertex3d(bb.maxX, bb.minY, bb.minZ); + GL11.glVertex3d(bb.maxX, bb.minY, bb.maxZ); + GL11.glVertex3d(bb.minX, bb.minY, bb.maxZ); + + GL11.glVertex3d(bb.minX, bb.maxY, bb.minZ); + GL11.glVertex3d(bb.minX, bb.maxY, bb.maxZ); + GL11.glVertex3d(bb.maxX, bb.maxY, bb.maxZ); + GL11.glVertex3d(bb.maxX, bb.maxY, bb.minZ); + + GL11.glVertex3d(bb.minX, bb.minY, bb.minZ); + GL11.glVertex3d(bb.minX, bb.maxY, bb.minZ); + GL11.glVertex3d(bb.maxX, bb.maxY, bb.minZ); + GL11.glVertex3d(bb.maxX, bb.minY, bb.minZ); + + GL11.glVertex3d(bb.maxX, bb.minY, bb.minZ); + GL11.glVertex3d(bb.maxX, bb.maxY, bb.minZ); + GL11.glVertex3d(bb.maxX, bb.maxY, bb.maxZ); + GL11.glVertex3d(bb.maxX, bb.minY, bb.maxZ); + + GL11.glVertex3d(bb.minX, bb.minY, bb.maxZ); + GL11.glVertex3d(bb.maxX, bb.minY, bb.maxZ); + GL11.glVertex3d(bb.maxX, bb.maxY, bb.maxZ); + GL11.glVertex3d(bb.minX, bb.maxY, bb.maxZ); + + GL11.glVertex3d(bb.minX, bb.minY, bb.minZ); + GL11.glVertex3d(bb.minX, bb.minY, bb.maxZ); + GL11.glVertex3d(bb.minX, bb.maxY, bb.maxZ); + GL11.glVertex3d(bb.minX, bb.maxY, bb.minZ); + GL11.glEnd(); + } + + public static void drawOutline(AxisAlignedBB bb) { + GL11.glBegin(GL11.GL_LINES); + GL11.glVertex3d(bb.minX, bb.minY, bb.minZ); + GL11.glVertex3d(bb.maxX, bb.minY, bb.minZ); + GL11.glVertex3d(bb.maxX, bb.minY, bb.minZ); + GL11.glVertex3d(bb.maxX, bb.minY, bb.maxZ); + GL11.glVertex3d(bb.maxX, bb.minY, bb.maxZ); + GL11.glVertex3d(bb.minX, bb.minY, bb.maxZ); + GL11.glVertex3d(bb.minX, bb.minY, bb.maxZ); + GL11.glVertex3d(bb.minX, bb.minY, bb.minZ); + + GL11.glVertex3d(bb.minX, bb.maxY, bb.minZ); + GL11.glVertex3d(bb.maxX, bb.maxY, bb.minZ); + GL11.glVertex3d(bb.maxX, bb.maxY, bb.minZ); + GL11.glVertex3d(bb.maxX, bb.maxY, bb.maxZ); + GL11.glVertex3d(bb.maxX, bb.maxY, bb.maxZ); + GL11.glVertex3d(bb.minX, bb.maxY, bb.maxZ); + GL11.glVertex3d(bb.minX, bb.maxY, bb.maxZ); + GL11.glVertex3d(bb.minX, bb.maxY, bb.minZ); + + GL11.glVertex3d(bb.minX, bb.minY, bb.minZ); + GL11.glVertex3d(bb.minX, bb.maxY, bb.minZ); + GL11.glVertex3d(bb.maxX, bb.minY, bb.minZ); + GL11.glVertex3d(bb.maxX, bb.maxY, bb.minZ); + GL11.glVertex3d(bb.maxX, bb.minY, bb.maxZ); + GL11.glVertex3d(bb.maxX, bb.maxY, bb.maxZ); + GL11.glVertex3d(bb.minX, bb.minY, bb.maxZ); + GL11.glVertex3d(bb.minX, bb.maxY, bb.maxZ); + GL11.glEnd(); + } +} \ No newline at end of file