mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 21:15:53 +08:00
Refactor: Move ESP rendering into RenderUtils
This commit is contained in:
1 parent
62e32ee807
commit
45c213ba94
4 files changed
+182
No files matched your search
@@ -71,4 +71,12 @@ public class Module {
|
||||
setEnabled(!this.enabled);
|
||||
}
|
||||
|
||||
public <T extends Option<?>> T getOption(String name, Class<T> clazz) {
|
||||
for (Option<?> option : options) {
|
||||
if (option.getName().equalsIgnoreCase(name) && clazz.isInstance(option)) {
|
||||
return clazz.cast(option);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ public class ModuleManager {
|
||||
// Render
|
||||
addModule(new HUD());
|
||||
addModule(new ClickGUI());
|
||||
addModule(new ESP());
|
||||
}
|
||||
|
||||
public List<Module> getModulesByCategory(ModuleCategory category) {
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user