mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
Remove Code
This commit is contained in:
1 parent
8965da4cd3
commit
9f779dec5e
85 files changed
+47
-8293
No files matched your search
@@ -3,7 +3,6 @@ package cn.xiaozhou233.orangex.loader;
|
||||
|
||||
import cn.xiaozhou233.juiceagent.api.JuiceAgent;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
|
||||
public class Loader {
|
||||
@@ -25,55 +24,55 @@ public class Loader {
|
||||
throw new IllegalStateException("Cannot find Minecraft client thread");
|
||||
}
|
||||
|
||||
// Check if LaunchWrapper exists
|
||||
if (Detector.isLaunchWrapper()){
|
||||
System.out.println("LaunchWrapper detected");
|
||||
}
|
||||
// // Check if LaunchWrapper exists
|
||||
// if (Detector.isLaunchWrapper()){
|
||||
// System.out.println("LaunchWrapper detected");
|
||||
// }
|
||||
|
||||
// Get Minecraft ClassLoader
|
||||
minecraftClassLoader = clientThread.getContextClassLoader();
|
||||
System.out.println("Minecraft ClassLoader: " + minecraftClassLoader);
|
||||
|
||||
switch (Detector.detect()) {
|
||||
case MCP:
|
||||
break;
|
||||
case VANILLA:
|
||||
// No more support
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
"Not support Vanilla Client! \n 不支持原版客户端!",
|
||||
"Vanilla Obfuscation",
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
throw new IllegalStateException("Not support Vanilla Client!");
|
||||
case LUNAR:
|
||||
break;
|
||||
case BADLION:
|
||||
// No more support
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
"Not support Badlion Client! \n 不支持Badlion客户端!",
|
||||
"Badlion Obfuscation",
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
throw new IllegalStateException("Not support Badlion Client!");
|
||||
case UNKNOWN:
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
"Inject Failed! Cause: Unknown Obfuscation \n 注入失败! 原因: 未知的混淆",
|
||||
"Unknown Obfuscation",
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
throw new IllegalStateException("Unknown Obfuscation");
|
||||
default:
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
"Inject Failed! Cause: Unknown Obfuscation",
|
||||
"Unknown Obfuscation",
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
throw new IllegalStateException("Unexpected value: " + Detector.detect());
|
||||
}
|
||||
// switch (Detector.detect()) {
|
||||
// case MCP:
|
||||
// break;
|
||||
// case VANILLA:
|
||||
// // No more support
|
||||
// JOptionPane.showMessageDialog(
|
||||
// null,
|
||||
// "Not support Vanilla Client! \n 不支持原版客户端!",
|
||||
// "Vanilla Obfuscation",
|
||||
// JOptionPane.ERROR_MESSAGE
|
||||
// );
|
||||
// throw new IllegalStateException("Not support Vanilla Client!");
|
||||
// case LUNAR:
|
||||
// break;
|
||||
// case BADLION:
|
||||
// // No more support
|
||||
// JOptionPane.showMessageDialog(
|
||||
// null,
|
||||
// "Not support Badlion Client! \n 不支持Badlion客户端!",
|
||||
// "Badlion Obfuscation",
|
||||
// JOptionPane.ERROR_MESSAGE
|
||||
// );
|
||||
// throw new IllegalStateException("Not support Badlion Client!");
|
||||
// case UNKNOWN:
|
||||
// JOptionPane.showMessageDialog(
|
||||
// null,
|
||||
// "Inject Failed! Cause: Unknown Obfuscation \n 注入失败! 原因: 未知的混淆",
|
||||
// "Unknown Obfuscation",
|
||||
// JOptionPane.ERROR_MESSAGE
|
||||
// );
|
||||
// throw new IllegalStateException("Unknown Obfuscation");
|
||||
// default:
|
||||
// JOptionPane.showMessageDialog(
|
||||
// null,
|
||||
// "Inject Failed! Cause: Unknown Obfuscation",
|
||||
// "Unknown Obfuscation",
|
||||
// JOptionPane.ERROR_MESSAGE
|
||||
// );
|
||||
// throw new IllegalStateException("Unexpected value: " + Detector.detect());
|
||||
// }
|
||||
|
||||
// Load OrangeX
|
||||
File injectionFile = new File(userDir + "/.orangex/OrangeX.jar");
|
||||
@@ -90,4 +89,5 @@ public class Loader {
|
||||
}
|
||||
System.out.println("======== Loader END ========");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +1,10 @@
|
||||
package cn.xiaozhou233.orangex;
|
||||
|
||||
import cn.xiaozhou233.orangex.font.FontManager;
|
||||
import cn.xiaozhou233.orangex.font.StbFontManager;
|
||||
import cn.xiaozhou233.orangex.manager.ThreadManager;
|
||||
import cn.xiaozhou233.orangex.mixin.MixinManager;
|
||||
import cn.xiaozhou233.orangex.module.ModuleManager;
|
||||
import lombok.Getter;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
@Getter
|
||||
public class OrangeX {
|
||||
public static final OrangeX INSTANCE = new OrangeX();
|
||||
public MixinManager mixinManager = new MixinManager();
|
||||
FontManager fontManager = new FontManager();
|
||||
StbFontManager stbFontManager = new StbFontManager();
|
||||
ModuleManager moduleManager = new ModuleManager();
|
||||
ThreadManager threadManager = new ThreadManager();
|
||||
private final EventBus eventBus = EventBus.builder()
|
||||
.logNoSubscriberMessages(false)
|
||||
.logSubscriberExceptions(false)
|
||||
@@ -27,18 +16,11 @@ public class OrangeX {
|
||||
public void start() {
|
||||
System.out.println("OrangeX starting...");
|
||||
|
||||
stbFontManager.loadFonts();
|
||||
mixinManager.start();
|
||||
threadManager.init();
|
||||
moduleManager.registerModules();
|
||||
moduleManager.loadConfig();
|
||||
|
||||
System.out.println("OrangeX started.");
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
System.out.println("OrangeX stopping...");
|
||||
moduleManager.saveConfig();
|
||||
System.out.println("OrangeX stopped.");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.config;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.option.OptionSerializer;
|
||||
import com.google.gson.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
|
||||
public class ModuleConfig {
|
||||
private final File configFile;
|
||||
private final Gson gson;
|
||||
|
||||
public ModuleConfig(String path) {
|
||||
this.configFile = new File(path);
|
||||
this.gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
}
|
||||
|
||||
public void save(List<Module> modules) {
|
||||
JsonObject config = new JsonObject();
|
||||
JsonArray modulesArray = new JsonArray();
|
||||
for (Module module : modules) {
|
||||
JsonObject moduleObj = new JsonObject();
|
||||
moduleObj.addProperty("name", module.getName());
|
||||
moduleObj.addProperty("enabled", module.isEnabled());
|
||||
moduleObj.addProperty("key", module.getKey());
|
||||
if (!module.getOptions().isEmpty()) {
|
||||
moduleObj.add("options", OptionSerializer.toJson(module.getOptions()));
|
||||
}
|
||||
modulesArray.add(moduleObj);
|
||||
}
|
||||
config.add("modules", modulesArray);
|
||||
writeConfig(config);
|
||||
}
|
||||
|
||||
public void saveClickGui(JsonObject clickGuiData) {
|
||||
JsonObject config = loadRaw();
|
||||
config.add("clickgui", clickGuiData);
|
||||
writeConfig(config);
|
||||
}
|
||||
|
||||
public JsonObject loadClickGui() {
|
||||
JsonObject config = loadRaw();
|
||||
if (config == null || !config.has("clickgui")) {
|
||||
return new JsonObject();
|
||||
}
|
||||
return config.getAsJsonObject("clickgui");
|
||||
}
|
||||
|
||||
private JsonObject loadRaw() {
|
||||
if (!configFile.exists()) return new JsonObject();
|
||||
try (Reader reader = new InputStreamReader(Files.newInputStream(configFile.toPath()), StandardCharsets.UTF_8)) {
|
||||
JsonObject config = gson.fromJson(reader, JsonObject.class);
|
||||
return config != null ? config : new JsonObject();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return new JsonObject();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeConfig(JsonObject config) {
|
||||
configFile.getParentFile().mkdirs();
|
||||
try (Writer writer = new OutputStreamWriter(Files.newOutputStream(configFile.toPath()), StandardCharsets.UTF_8)) {
|
||||
gson.toJson(config, writer);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void load(List<Module> modules) {
|
||||
if (!configFile.exists()) return;
|
||||
try (Reader reader = new InputStreamReader(Files.newInputStream(configFile.toPath()), StandardCharsets.UTF_8)) {
|
||||
JsonObject config = gson.fromJson(reader, JsonObject.class);
|
||||
if (config == null) return;
|
||||
JsonArray modulesArray = config.getAsJsonArray("modules");
|
||||
if (modulesArray == null) return;
|
||||
for (JsonElement element : modulesArray) {
|
||||
JsonObject moduleObj = element.getAsJsonObject();
|
||||
String name = moduleObj.get("name").getAsString();
|
||||
Module module = findModule(modules, name);
|
||||
if (module == null) continue;
|
||||
if (moduleObj.has("enabled") && moduleObj.get("enabled").getAsBoolean()) {
|
||||
module.setEnabled(true);
|
||||
}
|
||||
if (moduleObj.has("key")) {
|
||||
module.setKey(moduleObj.get("key").getAsInt());
|
||||
}
|
||||
if (moduleObj.has("options")) {
|
||||
OptionSerializer.fromJson(moduleObj.getAsJsonObject("options"), module.getOptions());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private Module findModule(List<Module> modules, String name) {
|
||||
for (Module module : modules) {
|
||||
if (module.getName().equalsIgnoreCase(name)) {
|
||||
return module;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package cn.xiaozhou233.orangex.loader;
|
||||
package cn.xiaozhou233.orangex.detector;
|
||||
|
||||
public class Detector {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package cn.xiaozhou233.orangex.loader;
|
||||
package cn.xiaozhou233.orangex.detector;
|
||||
|
||||
public enum DetectorType {
|
||||
BADLION,
|
||||
@@ -1,18 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.event;
|
||||
|
||||
public class Cancellable extends Event{
|
||||
|
||||
private boolean cancelled;
|
||||
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
this.cancelled = true;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.event;
|
||||
|
||||
public class Event {
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.event.impl;
|
||||
|
||||
import cn.xiaozhou233.orangex.event.Event;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class EventKey extends Event {
|
||||
private final int key;
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.event.impl;
|
||||
|
||||
public class EventLoop {
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.event.impl;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class EventMouseButton {
|
||||
private final int button;
|
||||
private final boolean pressed;
|
||||
private final int x;
|
||||
private final int y;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.event.impl;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class EventMouseMove {
|
||||
private final int x;
|
||||
private final int y;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.event.impl;
|
||||
|
||||
import cn.xiaozhou233.orangex.event.Cancellable;
|
||||
import cn.xiaozhou233.orangex.event.Event;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.network.Packet;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class EventPacketSend extends Cancellable {
|
||||
private Packet packet;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.event.impl;
|
||||
|
||||
import cn.xiaozhou233.orangex.event.Event;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class EventRender2D extends Event {
|
||||
private float partialTicks;
|
||||
|
||||
public EventRender2D(float partialTicks) {
|
||||
this.partialTicks = partialTicks;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.event.impl;
|
||||
|
||||
import cn.xiaozhou233.orangex.event.Event;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class EventRender3D extends Event {
|
||||
|
||||
private float partialTicks;
|
||||
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.event.impl;
|
||||
|
||||
public class EventTick {
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.event.impl;
|
||||
|
||||
import cn.xiaozhou233.orangex.event.Event;
|
||||
|
||||
public class EventTimerThread extends Event {
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.event.impl;
|
||||
|
||||
public class EventWorldLoad {
|
||||
}
|
||||
@@ -1,253 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font;
|
||||
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.texture.AbstractTexture;
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
|
||||
|
||||
public class CFont
|
||||
{
|
||||
private float imgSize = 1024;
|
||||
protected CharData[] charData = new CharData[256];
|
||||
protected Font font;
|
||||
protected boolean antiAlias;
|
||||
protected boolean fractionalMetrics;
|
||||
protected int fontHeight = -1;
|
||||
protected int charOffset = 0;
|
||||
private BufferedImage fontImage;
|
||||
protected AbstractTexture tex;
|
||||
|
||||
public CFont(Font font, boolean antiAlias, boolean fractionalMetrics)
|
||||
{
|
||||
this.font = font;
|
||||
this.antiAlias = antiAlias;
|
||||
this.fractionalMetrics = fractionalMetrics;
|
||||
this.fontImage = generateFontImage(font, antiAlias, fractionalMetrics, this.charData);
|
||||
}
|
||||
|
||||
protected AbstractTexture getTexture()
|
||||
{
|
||||
if (tex == null)
|
||||
{
|
||||
tex = setupTexture(fontImage);
|
||||
fontImage = null;
|
||||
}
|
||||
return tex;
|
||||
}
|
||||
|
||||
public AbstractTexture setupTexture(BufferedImage img)
|
||||
{
|
||||
try
|
||||
{
|
||||
AbstractTexture texture = new DynamicTexture(img);
|
||||
GlStateManager.bindTexture(texture.getGlTextureId());
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
|
||||
return texture;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected BufferedImage generateFontImage(Font font, boolean antiAlias, boolean fractionalMetrics, CharData[] chars)
|
||||
{
|
||||
int imgSize = (int) this.imgSize;
|
||||
this.fontHeight = -1;
|
||||
BufferedImage bufferedImage = null;
|
||||
|
||||
while (true)
|
||||
{
|
||||
bufferedImage = new BufferedImage(imgSize, imgSize, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g = (Graphics2D) bufferedImage.getGraphics();
|
||||
g.setFont(font.deriveFont(font.getSize2D() * 2.0F));
|
||||
g.setColor(new Color(255, 255, 255, 0));
|
||||
g.fillRect(0, 0, imgSize, imgSize);
|
||||
g.setColor(Color.WHITE);
|
||||
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, fractionalMetrics ? RenderingHints.VALUE_FRACTIONALMETRICS_ON : RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
|
||||
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, antiAlias ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antiAlias ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);
|
||||
FontMetrics fontMetrics = g.getFontMetrics();
|
||||
int charHeight = 0;
|
||||
int positionX = 0;
|
||||
int positionY = 1;
|
||||
boolean overflow = false;
|
||||
|
||||
for (int i = 0; i < chars.length; i++)
|
||||
{
|
||||
char ch = (char) i;
|
||||
CharData charData = new CharData();
|
||||
Rectangle2D dimensions = fontMetrics.getStringBounds(String.valueOf(ch), g);
|
||||
charData.width = (dimensions.getBounds().width + 8);
|
||||
charData.height = dimensions.getBounds().height;
|
||||
|
||||
if (positionX + charData.width >= imgSize)
|
||||
{
|
||||
positionX = 0;
|
||||
positionY += charHeight;
|
||||
charHeight = 0;
|
||||
}
|
||||
|
||||
if (positionY + charData.height >= imgSize)
|
||||
{
|
||||
overflow = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (charData.height > charHeight)
|
||||
{
|
||||
charHeight = charData.height;
|
||||
}
|
||||
|
||||
charData.storedX = positionX;
|
||||
charData.storedY = positionY;
|
||||
|
||||
if (charData.height > this.fontHeight)
|
||||
{
|
||||
this.fontHeight = charData.height;
|
||||
}
|
||||
|
||||
chars[i] = charData;
|
||||
g.drawString(String.valueOf(ch), positionX + 2, positionY + fontMetrics.getAscent());
|
||||
positionX += charData.width;
|
||||
}
|
||||
|
||||
g.dispose();
|
||||
|
||||
if (!overflow)
|
||||
{
|
||||
this.imgSize = imgSize;
|
||||
return bufferedImage;
|
||||
}
|
||||
|
||||
imgSize *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
public void drawChar(CharData[] chars, char c, float x, float y) throws ArrayIndexOutOfBoundsException
|
||||
{
|
||||
try
|
||||
{
|
||||
drawQuad(x, y, chars[c].width, chars[c].height, chars[c].storedX, chars[c].storedY, chars[c].width, chars[c].height);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawQuad(float x, float y, float width, float height, float srcX, float srcY, float srcWidth, float srcHeight)
|
||||
{
|
||||
float renderSRCX = srcX / imgSize;
|
||||
float renderSRCY = srcY / imgSize;
|
||||
float renderSRCWidth = srcWidth / imgSize;
|
||||
float renderSRCHeight = srcHeight / imgSize;
|
||||
GL11.glTexCoord2f(renderSRCX + renderSRCWidth, renderSRCY);
|
||||
GL11.glVertex2d(x + width, y);
|
||||
GL11.glTexCoord2f(renderSRCX, renderSRCY);
|
||||
GL11.glVertex2d(x, y);
|
||||
GL11.glTexCoord2f(renderSRCX, renderSRCY + renderSRCHeight);
|
||||
GL11.glVertex2d(x, y + height);
|
||||
GL11.glTexCoord2f(renderSRCX, renderSRCY + renderSRCHeight);
|
||||
GL11.glVertex2d(x, y + height);
|
||||
GL11.glTexCoord2f(renderSRCX + renderSRCWidth, renderSRCY + renderSRCHeight);
|
||||
GL11.glVertex2d(x + width, y + height);
|
||||
GL11.glTexCoord2f(renderSRCX + renderSRCWidth, renderSRCY);
|
||||
GL11.glVertex2d(x + width, y);
|
||||
}
|
||||
|
||||
public int getStringHeight(String text)
|
||||
{
|
||||
return getHeight();
|
||||
}
|
||||
|
||||
public int getHeight()
|
||||
{
|
||||
return (int) (((this.fontHeight - 8) / 2) * getFontScale());
|
||||
}
|
||||
|
||||
protected double getFontScale()
|
||||
{
|
||||
return (Minecraft.getMinecraft().displayWidth / 1920.0D) * 0.5D;
|
||||
}
|
||||
|
||||
public int getStringWidth(String text)
|
||||
{
|
||||
int width = 0;
|
||||
|
||||
for (char c : text.toCharArray())
|
||||
{
|
||||
if ((c < this.charData.length) && (c >= 0))
|
||||
{
|
||||
width += this.charData[c].width - 8 + this.charOffset;
|
||||
}
|
||||
}
|
||||
|
||||
return width / 2;
|
||||
}
|
||||
|
||||
public boolean isAntiAlias()
|
||||
{
|
||||
return this.antiAlias;
|
||||
}
|
||||
|
||||
public void setAntiAlias(boolean antiAlias)
|
||||
{
|
||||
if (this.antiAlias != antiAlias)
|
||||
{
|
||||
this.antiAlias = antiAlias;
|
||||
this.fontImage = generateFontImage(this.font, antiAlias, this.fractionalMetrics, this.charData);
|
||||
this.tex = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFractionalMetrics()
|
||||
{
|
||||
return this.fractionalMetrics;
|
||||
}
|
||||
|
||||
public void setFractionalMetrics(boolean fractionalMetrics)
|
||||
{
|
||||
if (this.fractionalMetrics != fractionalMetrics)
|
||||
{
|
||||
this.fractionalMetrics = fractionalMetrics;
|
||||
this.fontImage = generateFontImage(this.font, this.antiAlias, fractionalMetrics, this.charData);
|
||||
this.tex = null;
|
||||
}
|
||||
}
|
||||
|
||||
public Font getFont()
|
||||
{
|
||||
return this.font;
|
||||
}
|
||||
|
||||
public void setFont(Font font)
|
||||
{
|
||||
this.font = font;
|
||||
this.fontImage = generateFontImage(font, this.antiAlias, this.fractionalMetrics, this.charData);
|
||||
this.tex = null;
|
||||
}
|
||||
|
||||
protected class CharData
|
||||
{
|
||||
public int width;
|
||||
public int height;
|
||||
public int storedX;
|
||||
public int storedY;
|
||||
|
||||
protected CharData()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class FontManager {
|
||||
public FontRenderer MontserratLight18 = new FontRenderer("Montserrat-Light.ttf", 18, Font.PLAIN, true, true);
|
||||
|
||||
public FontRenderer MontserratRegular18 = new FontRenderer("Montserrat-Bold.ttf", 18, Font.PLAIN, true, true);
|
||||
public FontRenderer MontserratRegular32 = new FontRenderer("Montserrat-Bold.ttf", 32, Font.PLAIN, true, true);
|
||||
|
||||
public FontRenderer MontserratMedium18 = new FontRenderer("Montserrat-Medium.ttf", 18, Font.PLAIN, true, true);
|
||||
public FontRenderer MontserratMedium32 = new FontRenderer("Montserrat-Medium.ttf", 32, Font.PLAIN, true, true);
|
||||
|
||||
public FontRenderer MontserratBold18 = new FontRenderer("Montserrat-Bold.ttf", 18, Font.PLAIN, true, true);
|
||||
public FontRenderer MontserratBold32 = new FontRenderer("Montserrat-Bold.ttf", 32, Font.PLAIN, true, true);
|
||||
|
||||
public FontRenderer JelloMedium32 = new FontRenderer("JelloMedium.ttf", 32, Font.PLAIN, true, true);
|
||||
public FontRenderer JelloRegular16 = new FontRenderer("JelloRegular.ttf", 16, Font.PLAIN, true, true);
|
||||
}
|
||||
@@ -1,501 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font;
|
||||
|
||||
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.texture.AbstractTexture;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class FontRenderer extends CFont {
|
||||
protected CFont.CharData[] boldChars = new CFont.CharData[256];
|
||||
protected CFont.CharData[] italicChars = new CFont.CharData[256];
|
||||
protected CFont.CharData[] boldItalicChars = new CFont.CharData[256];
|
||||
|
||||
private final int[] colorCode = new int[32];
|
||||
|
||||
/*
|
||||
CREDIT G0dwhitelight.
|
||||
*/
|
||||
public FontRenderer(Font font, boolean antiAlias, boolean fractionalMetrics) {
|
||||
super(font, antiAlias, fractionalMetrics);
|
||||
setupMinecraftColorcodes();
|
||||
setupBoldItalicIDs();
|
||||
}
|
||||
|
||||
public FontRenderer(String filePath, int size, int fontType, boolean antiAlias, boolean fractionalMetrics) {
|
||||
super(FontUtil.getFontFromTTF(
|
||||
FontRenderer.class.getClassLoader().getResourceAsStream("fonts/" + filePath), size, fontType),
|
||||
antiAlias, fractionalMetrics);
|
||||
setupMinecraftColorcodes();
|
||||
setupBoldItalicIDs();
|
||||
}
|
||||
|
||||
public float drawString(String text, float x, float y, int color) {
|
||||
return drawString(text, x, y, color, false);
|
||||
}
|
||||
|
||||
public float drawString(String text, double x, double y, int color) {
|
||||
return drawString(text, x, y, color, false);
|
||||
}
|
||||
|
||||
public float drawStringWithShadow(String text, float x, float y, int color) {
|
||||
float shadowWidth = drawString(text, x + 1D, y + .5D, color, true);
|
||||
return Math.max(shadowWidth, drawString(text, x, y, color, false));
|
||||
}
|
||||
|
||||
public float drawStringWithShadow(String text, double x, double y, int color) {
|
||||
float shadowWidth = drawString(text, x + 1, y + .5, color, true);
|
||||
return Math.max(shadowWidth, drawString(text, x, y, color, false));
|
||||
}
|
||||
|
||||
public float drawCenteredString(String text, float x, float y, int color) {
|
||||
return drawString(text, x - getStringWidth(text) / 2, y, color);
|
||||
}
|
||||
|
||||
public float drawCenteredString(String text, double x, double y, int color) {
|
||||
return drawString(text, x - getStringWidth(text) / 2, y, color);
|
||||
}
|
||||
|
||||
public float drawCenteredStringWithShadow(String text, float x, float y, int color) {
|
||||
float shadowWidth = drawString(text, x - getStringWidth(text) / 2 + 0.45D, y + 0.5D, color, true);
|
||||
return drawString(text, x - getStringWidth(text) / 2, y, color);
|
||||
}
|
||||
|
||||
public void drawStringWithOutline(String text, double x, double y, int color) {
|
||||
drawString(text, x - .5, y, 0x000000);
|
||||
|
||||
drawString(text, x + .5, y, 0x000000);
|
||||
|
||||
drawString(text, x, y - .5, 0x000000);
|
||||
|
||||
drawString(text, x, y + .5, 0x000000);
|
||||
|
||||
drawString(text, x, y, color);
|
||||
}
|
||||
|
||||
public void drawCenteredStringWithOutline(String text, double x, double y, int color) {
|
||||
drawCenteredString(text, x - .5, y, 0x000000);
|
||||
|
||||
drawCenteredString(text, x + .5, y, 0x000000);
|
||||
|
||||
drawCenteredString(text, x, y - .5, 0x000000);
|
||||
|
||||
drawCenteredString(text, x, y + .5, 0x000000);
|
||||
|
||||
drawCenteredString(text, x, y, color);
|
||||
}
|
||||
|
||||
public float drawCenteredStringWithShadow(String text, double x, double y, int color) {
|
||||
float shadowWidth = drawString(text, x - getStringWidth(text) / 2 + 0.45D, y + 0.5D, color, true);
|
||||
return drawString(text, x - getStringWidth(text) / 2, y, color);
|
||||
}
|
||||
|
||||
public float drawString(String text, double x, double y, int color, boolean shadow) {
|
||||
x -= 1;
|
||||
|
||||
if (text == null) {
|
||||
return 0.0F;
|
||||
}
|
||||
|
||||
if (color == 553648127) {
|
||||
color = 16777215;
|
||||
}
|
||||
|
||||
if ((color & 0xFC000000) == 0) {
|
||||
color |= -16777216;
|
||||
}
|
||||
|
||||
if (shadow) {
|
||||
color = (color & 0xFCFCFC) >> 2 | color & new Color(20, 20, 20, 200).getRGB();
|
||||
}
|
||||
|
||||
CFont.CharData[] currentData = this.charData;
|
||||
float alpha = (color >> 24 & 0xFF) / 255.0F;
|
||||
boolean randomCase = false;
|
||||
boolean bold = false;
|
||||
boolean italic = false;
|
||||
boolean strikethrough = false;
|
||||
boolean underline = false;
|
||||
boolean render = true;
|
||||
double scaleFactor = 2.0D / getFontScale();
|
||||
x *= scaleFactor;
|
||||
y = (y - 3.0D) * scaleFactor;
|
||||
|
||||
if (render) {
|
||||
GL11.glPushMatrix();
|
||||
GlStateManager.scale(1.0D / scaleFactor, 1.0D / scaleFactor, 1.0D / scaleFactor);
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFunc(770, 771);
|
||||
GlStateManager.color((color >> 16 & 0xFF) / 255.0F, (color >> 8 & 0xFF) / 255.0F, (color & 0xFF) / 255.0F, alpha);
|
||||
int size = text.length();
|
||||
GlStateManager.enableTexture2D();
|
||||
GlStateManager.bindTexture(getTexture().getGlTextureId());
|
||||
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, getTexture().getGlTextureId());
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
char character = text.charAt(i);
|
||||
if ((String.valueOf(character).equals("\247")) && (i < size)) {
|
||||
int colorIndex = 21;
|
||||
|
||||
try {
|
||||
colorIndex = "0123456789abcdefklmnor".indexOf(text.charAt(i + 1));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (colorIndex < 16) {
|
||||
bold = false;
|
||||
italic = false;
|
||||
randomCase = false;
|
||||
underline = false;
|
||||
strikethrough = false;
|
||||
GlStateManager.bindTexture(getTexture().getGlTextureId());
|
||||
// GL11.glfunc_179144_i(GL11.GL_TEXTURE_2D,
|
||||
// tex.getGlTextureId());
|
||||
currentData = this.charData;
|
||||
|
||||
if ((colorIndex < 0) || (colorIndex > 15)) {
|
||||
colorIndex = 15;
|
||||
}
|
||||
|
||||
if (shadow) {
|
||||
colorIndex += 16;
|
||||
}
|
||||
|
||||
int colorcode = this.colorCode[colorIndex];
|
||||
GlStateManager.color((colorcode >> 16 & 0xFF) / 255.0F, (colorcode >> 8 & 0xFF) / 255.0F, (colorcode & 0xFF) / 255.0F, alpha);
|
||||
} else if (colorIndex == 16) {
|
||||
randomCase = true;
|
||||
} else if (colorIndex == 17) {
|
||||
bold = true;
|
||||
|
||||
if (italic) {
|
||||
GlStateManager.bindTexture(getTexItalicBold().getGlTextureId());
|
||||
// GL11.glfunc_179144_i(GL11.GL_TEXTURE_2D,
|
||||
// texItalicBold.getGlTextureId());
|
||||
currentData = this.boldItalicChars;
|
||||
} else {
|
||||
GlStateManager.bindTexture(getTexBold().getGlTextureId());
|
||||
// GL11.glfunc_179144_i(GL11.GL_TEXTURE_2D,
|
||||
// texBold.getGlTextureId());
|
||||
currentData = this.boldChars;
|
||||
}
|
||||
} else if (colorIndex == 18) {
|
||||
strikethrough = true;
|
||||
} else if (colorIndex == 19) {
|
||||
underline = true;
|
||||
} else if (colorIndex == 20) {
|
||||
italic = true;
|
||||
|
||||
if (bold) {
|
||||
GlStateManager.bindTexture(getTexItalicBold().getGlTextureId());
|
||||
// GL11.glfunc_179144_i(GL11.GL_TEXTURE_2D,
|
||||
// texItalicBold.getGlTextureId());
|
||||
currentData = this.boldItalicChars;
|
||||
} else {
|
||||
GlStateManager.bindTexture(getTexItalic().getGlTextureId());
|
||||
// GL11.glfunc_179144_i(GL11.GL_TEXTURE_2D,
|
||||
// texItalic.getGlTextureId());
|
||||
currentData = this.italicChars;
|
||||
}
|
||||
} else if (colorIndex == 21) {
|
||||
bold = false;
|
||||
italic = false;
|
||||
randomCase = false;
|
||||
underline = false;
|
||||
strikethrough = false;
|
||||
GlStateManager.color((color >> 16 & 0xFF) / 255.0F, (color >> 8 & 0xFF) / 255.0F, (color & 0xFF) / 255.0F, alpha);
|
||||
GlStateManager.bindTexture(getTexture().getGlTextureId());
|
||||
// GL11.glfunc_179144_i(GL11.GL_TEXTURE_2D,
|
||||
// tex.getGlTextureId());
|
||||
currentData = this.charData;
|
||||
}
|
||||
|
||||
i++;
|
||||
} else if ((character < currentData.length) && (character >= 0)) {
|
||||
GL11.glBegin(GL11.GL_TRIANGLES);
|
||||
drawChar(currentData, character, (float) x, (float) y);
|
||||
GL11.glEnd();
|
||||
|
||||
if (strikethrough) {
|
||||
drawLine(x, y + currentData[character].height / 2, x + currentData[character].width - 8.0D, y + currentData[character].height / 2, 1.0F);
|
||||
}
|
||||
|
||||
if (underline) {
|
||||
drawLine(x, y + currentData[character].height - 2.0D, x + currentData[character].width - 8.0D, y + currentData[character].height - 2.0D, 1.0F);
|
||||
}
|
||||
|
||||
x += currentData[character].width - 8 + this.charOffset;
|
||||
}
|
||||
}
|
||||
|
||||
GL11.glHint(GL11.GL_POLYGON_SMOOTH_HINT, GL11.GL_DONT_CARE);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
return (float) (x / scaleFactor);
|
||||
}
|
||||
|
||||
public int getStringWidth(String text) {
|
||||
if (text == null) {
|
||||
return 0;
|
||||
}
|
||||
int width = 0;
|
||||
CFont.CharData[] currentData = this.charData;
|
||||
boolean bold = false;
|
||||
boolean italic = false;
|
||||
int size = text.length();
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
char character = text.charAt(i);
|
||||
|
||||
if ((String.valueOf(character).equals("\247")) && (i < size)) {
|
||||
int colorIndex = "0123456789abcdefklmnor".indexOf(character);
|
||||
|
||||
if (colorIndex < 16) {
|
||||
bold = false;
|
||||
italic = false;
|
||||
} else if (colorIndex == 17) {
|
||||
bold = true;
|
||||
|
||||
if (italic) {
|
||||
currentData = this.boldItalicChars;
|
||||
} else {
|
||||
currentData = this.boldChars;
|
||||
}
|
||||
} else if (colorIndex == 20) {
|
||||
italic = true;
|
||||
|
||||
if (bold) {
|
||||
currentData = this.boldItalicChars;
|
||||
} else {
|
||||
currentData = this.italicChars;
|
||||
}
|
||||
} else if (colorIndex == 21) {
|
||||
bold = false;
|
||||
italic = false;
|
||||
currentData = this.charData;
|
||||
}
|
||||
|
||||
i++;
|
||||
} else if ((character < currentData.length) && (character >= 0)) {
|
||||
width += currentData[character].width - 8 + this.charOffset;
|
||||
}
|
||||
}
|
||||
|
||||
return (int) ((width / 2) * getFontScale());
|
||||
}
|
||||
|
||||
public int getStringWidthCust(String text) {
|
||||
if (text == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int width = 0;
|
||||
CFont.CharData[] currentData = this.charData;
|
||||
boolean bold = false;
|
||||
boolean italic = false;
|
||||
int size = text.length();
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
char character = text.charAt(i);
|
||||
|
||||
if ((String.valueOf(character).equals("§")) && (i < size)) {
|
||||
int colorIndex = "0123456789abcdefklmnor".indexOf(character);
|
||||
|
||||
if (colorIndex < 16) {
|
||||
bold = false;
|
||||
italic = false;
|
||||
} else if (colorIndex == 17) {
|
||||
bold = true;
|
||||
|
||||
if (italic) {
|
||||
currentData = this.boldItalicChars;
|
||||
} else {
|
||||
currentData = this.boldChars;
|
||||
}
|
||||
} else if (colorIndex == 20) {
|
||||
italic = true;
|
||||
|
||||
if (bold) {
|
||||
currentData = this.boldItalicChars;
|
||||
} else {
|
||||
currentData = this.italicChars;
|
||||
}
|
||||
} else if (colorIndex == 21) {
|
||||
bold = false;
|
||||
italic = false;
|
||||
currentData = this.charData;
|
||||
}
|
||||
|
||||
i++;
|
||||
} else if ((character < currentData.length) && (character >= 0)) {
|
||||
width += currentData[character].width - 8 + this.charOffset;
|
||||
}
|
||||
}
|
||||
|
||||
return (int) (((width - this.charOffset) / 2) * getFontScale());
|
||||
}
|
||||
|
||||
public void setFont(Font font) {
|
||||
super.setFont(font);
|
||||
setupBoldItalicIDs();
|
||||
}
|
||||
|
||||
public void setAntiAlias(boolean antiAlias) {
|
||||
super.setAntiAlias(antiAlias);
|
||||
setupBoldItalicIDs();
|
||||
}
|
||||
|
||||
public void setFractionalMetrics(boolean fractionalMetrics) {
|
||||
super.setFractionalMetrics(fractionalMetrics);
|
||||
setupBoldItalicIDs();
|
||||
}
|
||||
|
||||
protected AbstractTexture texBold;
|
||||
protected AbstractTexture texItalic;
|
||||
protected AbstractTexture texItalicBold;
|
||||
private BufferedImage boldImage;
|
||||
private BufferedImage italicImage;
|
||||
private BufferedImage boldItalicImage;
|
||||
|
||||
private void setupBoldItalicIDs() {
|
||||
boldImage = generateFontImage(this.font.deriveFont(1), this.antiAlias, this.fractionalMetrics, this.boldChars);
|
||||
italicImage = generateFontImage(this.font.deriveFont(2), this.antiAlias, this.fractionalMetrics, this.italicChars);
|
||||
boldItalicImage = generateFontImage(this.font.deriveFont(3), this.antiAlias, this.fractionalMetrics, this.boldItalicChars);
|
||||
texBold = null;
|
||||
texItalic = null;
|
||||
texItalicBold = null;
|
||||
}
|
||||
|
||||
private AbstractTexture getTexBold() {
|
||||
if (texBold == null) {
|
||||
texBold = setupTexture(boldImage);
|
||||
boldImage = null;
|
||||
}
|
||||
return texBold;
|
||||
}
|
||||
|
||||
private AbstractTexture getTexItalic() {
|
||||
if (texItalic == null) {
|
||||
texItalic = setupTexture(italicImage);
|
||||
italicImage = null;
|
||||
}
|
||||
return texItalic;
|
||||
}
|
||||
|
||||
private AbstractTexture getTexItalicBold() {
|
||||
if (texItalicBold == null) {
|
||||
texItalicBold = setupTexture(boldItalicImage);
|
||||
boldItalicImage = null;
|
||||
}
|
||||
return texItalicBold;
|
||||
}
|
||||
|
||||
private void drawLine(double x, double y, double x1, double y1, float width) {
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glLineWidth(width);
|
||||
GL11.glBegin(GL11.GL_LINES);
|
||||
GL11.glVertex2d(x, y);
|
||||
GL11.glVertex2d(x1, y1);
|
||||
GL11.glEnd();
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
public List<String> wrapWords(String text, double width) {
|
||||
List finalWords = new ArrayList();
|
||||
|
||||
if (getStringWidth(text) > width) {
|
||||
String[] words = text.split(" ");
|
||||
String currentWord = "";
|
||||
char lastColorCode = 65535;
|
||||
|
||||
for (String word : words) {
|
||||
for (int i = 0; i < word.toCharArray().length; i++) {
|
||||
char c = word.toCharArray()[i];
|
||||
|
||||
if ((String.valueOf(c).equals("§")) && (i < word.toCharArray().length - 1)) {
|
||||
lastColorCode = word.toCharArray()[(i + 1)];
|
||||
}
|
||||
}
|
||||
|
||||
if (getStringWidth(currentWord + word + " ") < width) {
|
||||
currentWord = currentWord + word + " ";
|
||||
} else {
|
||||
finalWords.add(currentWord);
|
||||
currentWord = "" + lastColorCode + word + " ";
|
||||
}
|
||||
}
|
||||
|
||||
if (currentWord.length() > 0) if (getStringWidth(currentWord) < width) {
|
||||
finalWords.add("" + lastColorCode + currentWord + " ");
|
||||
currentWord = "";
|
||||
} else {
|
||||
for (String s : formatString(currentWord, width)) {
|
||||
finalWords.add(s);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
finalWords.add(text);
|
||||
}
|
||||
|
||||
return finalWords;
|
||||
}
|
||||
|
||||
public List<String> formatString(String string, double width) {
|
||||
List finalWords = new ArrayList();
|
||||
String currentWord = "";
|
||||
char lastColorCode = 65535;
|
||||
char[] chars = string.toCharArray();
|
||||
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
char c = chars[i];
|
||||
|
||||
if ((String.valueOf(c).equals("§")) && (i < chars.length - 1))//Why does intelij replace "§" with §
|
||||
{
|
||||
lastColorCode = chars[(i + 1)];
|
||||
}
|
||||
|
||||
if (getStringWidth(currentWord + c) < width) {
|
||||
currentWord = currentWord + c;
|
||||
} else {
|
||||
finalWords.add(currentWord);
|
||||
currentWord = "" + lastColorCode + String.valueOf(c);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentWord.length() > 0) {
|
||||
finalWords.add(currentWord);
|
||||
}
|
||||
|
||||
return finalWords;
|
||||
}
|
||||
|
||||
private void setupMinecraftColorcodes() {
|
||||
for (int index = 0; index < 32; index++) {
|
||||
int noClue = (index >> 3 & 0x1) * 85;
|
||||
int red = (index >> 2 & 0x1) * 170 + noClue;
|
||||
int green = (index >> 1 & 0x1) * 170 + noClue;
|
||||
int blue = (index >> 0 & 0x1) * 170 + noClue;
|
||||
|
||||
if (index == 6) {
|
||||
red += 85;
|
||||
}
|
||||
|
||||
if (index >= 16) {
|
||||
red /= 4;
|
||||
green /= 4;
|
||||
blue /= 4;
|
||||
}
|
||||
|
||||
this.colorCode[index] = ((red & 0xFF) << 16 | (green & 0xFF) << 8 | blue & 0xFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.InputStream;
|
||||
|
||||
|
||||
public class FontUtil {
|
||||
|
||||
public static Font getFontFromTTF(InputStream inputStream, float fontSize, int fontType) {
|
||||
Font output = null;
|
||||
try {
|
||||
output = Font.createFont(fontType, inputStream);
|
||||
output = output.deriveFont(fontSize);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font;
|
||||
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class GlImageTexture {
|
||||
public int width;
|
||||
public int height;
|
||||
public int textureId;
|
||||
|
||||
public GlImageTexture() {
|
||||
this.textureId = GL11.glGenTextures();
|
||||
}
|
||||
|
||||
public GlImageTexture(int textureId) {
|
||||
this.textureId = textureId;
|
||||
}
|
||||
|
||||
public void bind() {
|
||||
GlStateManager.bindTexture(this.textureId);
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
GL11.glDeleteTextures(this.textureId);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font;
|
||||
|
||||
import cn.xiaozhou233.orangex.font.shader.ShaderProgram;
|
||||
|
||||
public class LegacyFontShaderProgram extends ShaderProgram {
|
||||
private static final String VERTEX_SHADER_SOURCE;
|
||||
private static final String FRAGMENT_SHADER_SOURCE;
|
||||
|
||||
public LegacyFontShaderProgram() {
|
||||
super(VERTEX_SHADER_SOURCE, FRAGMENT_SHADER_SOURCE);
|
||||
}
|
||||
|
||||
static {
|
||||
FRAGMENT_SHADER_SOURCE = "#version 120\nuniform sampler2D texture;\nvoid main() {\n vec2 coords = gl_TexCoord[0].xy;\n float alpha = texture2D(texture, coords).x;\n alpha = max(0.0, alpha + 0.25 * (1.0 - alpha));\n float smoothenAlpha = smoothstep(0.2, 0.8, alpha);\n alpha = mix(alpha, 0.0, 1.0 - smoothenAlpha);\n gl_FragColor = vec4(gl_Color.rgb, alpha * gl_Color.a);\n}";
|
||||
VERTEX_SHADER_SOURCE = "#version 120\nvoid main(void) {\n gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;\n gl_FrontColor = gl_Color;\n}";
|
||||
}
|
||||
}
|
||||
@@ -1,382 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font;
|
||||
|
||||
import cn.xiaozhou233.orangex.font.stb.StbTrueTypeFontInfo;
|
||||
import cn.xiaozhou233.orangex.font.stb.StbTrueTypePackContext;
|
||||
import cn.xiaozhou233.orangex.font.stb.StbTrueTypePackRange;
|
||||
import cn.xiaozhou233.orangex.font.stb.StbTrueTypePackedChar;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
public class LegacySmoothFontRenderer extends SmoothFontRenderer {
|
||||
private float ascent;
|
||||
private Map<Integer, SmoothFontGlyph> glyphs = new HashMap<Integer, SmoothFontGlyph>();
|
||||
private int textureId;
|
||||
private float pixelScale;
|
||||
private float renderScale = 0.6f;
|
||||
private LegacyFontShaderProgram shader;
|
||||
|
||||
public LegacySmoothFontRenderer(byte[] fontData, int fontSize, String fontName) {
|
||||
this.fontSize = fontSize;
|
||||
buildFont(fontData, fontSize, fontName);
|
||||
}
|
||||
|
||||
public LegacySmoothFontRenderer(String resourcePath, int fontSize) {
|
||||
this.fontSize = fontSize;
|
||||
try {
|
||||
byte[] fontData = readResource(resourcePath);
|
||||
buildFont(fontData, fontSize, resourcePath);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] readResource(String path) {
|
||||
try {
|
||||
String resourcePath = "fonts/" + path;
|
||||
InputStream is = LegacySmoothFontRenderer.class.getClassLoader().getResourceAsStream(resourcePath);
|
||||
if (is == null) {
|
||||
is = Minecraft.getMinecraft().getResourceManager().getResource(new ResourceLocation("fonts/" + path)).getInputStream();
|
||||
}
|
||||
if (is == null) return null;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
byte[] buf = new byte[8192];
|
||||
int len;
|
||||
while ((len = is.read(buf)) != -1) {
|
||||
baos.write(buf, 0, len);
|
||||
}
|
||||
is.close();
|
||||
return baos.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void buildFont(byte[] fontData, int fontSize, String fontName) {
|
||||
if (fontData == null) return;
|
||||
|
||||
HashSet<Integer> charSet = new HashSet<Integer>();
|
||||
for (int i = 32; i <= 126; ++i) {
|
||||
charSet.add(i);
|
||||
}
|
||||
charSet.add(0);
|
||||
|
||||
try {
|
||||
byte[] chineseData = readResource("chinese.properties.txt");
|
||||
if (chineseData != null) {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(chineseData), StandardCharsets.UTF_8));
|
||||
int ch;
|
||||
while ((ch = reader.read()) != -1) {
|
||||
if (ch >= 32) charSet.add(ch);
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
int[] chars = charSet.stream().mapToInt(Integer::intValue).toArray();
|
||||
Arrays.sort(chars);
|
||||
|
||||
int atlasSize = 4096;
|
||||
StbTrueTypeFontInfo fontInfo = new StbTrueTypeFontInfo();
|
||||
if (SmoothFontRasterState.z(fontInfo, fontData, 0) == 0) {
|
||||
System.err.println("Failed to init font: " + fontName);
|
||||
return;
|
||||
}
|
||||
|
||||
int[] ascentArr = new int[1], descentArr = new int[1], lineGap = new int[1];
|
||||
SmoothFontRasterState.x(fontInfo, ascentArr, descentArr, lineGap);
|
||||
this.ascent = ascentArr[0];
|
||||
|
||||
int[] fw = new int[1], fh = new int[1], fx = new int[1], fy = new int[1];
|
||||
SmoothFontRasterState.s(fontInfo, 72, fw, fh, fx, fy);
|
||||
float glyphHeight = fy[0] - fh[0];
|
||||
float fontHeight = ascentArr[0] - descentArr[0];
|
||||
float aspect = glyphHeight / fontHeight;
|
||||
float pixelHeight = (float) this.fontSize * (0.6f / aspect);
|
||||
|
||||
byte[] atlasData = new byte[atlasSize * atlasSize];
|
||||
StbTrueTypePackContext packCtx = new StbTrueTypePackContext();
|
||||
if (SmoothFontRasterState.C(packCtx, atlasData, atlasSize, atlasSize, 0, 1) == 0) {
|
||||
System.err.println("Failed to begin packing font");
|
||||
return;
|
||||
}
|
||||
|
||||
int oversampleX = 2, oversampleY = 2;
|
||||
SmoothFontRasterState.n(packCtx, oversampleX, oversampleY);
|
||||
|
||||
try {
|
||||
StbTrueTypePackedChar[] packedChars = new StbTrueTypePackedChar[chars.length];
|
||||
for (int i = 0; i < packedChars.length; ++i) {
|
||||
packedChars[i] = new StbTrueTypePackedChar();
|
||||
}
|
||||
StbTrueTypePackRange range = new StbTrueTypePackRange();
|
||||
range.E = pixelHeight;
|
||||
range.R = 0;
|
||||
range.N = chars;
|
||||
range.b = chars.length;
|
||||
range.M = packedChars;
|
||||
range.i = (byte) oversampleX;
|
||||
range.y = (byte) oversampleY;
|
||||
SmoothFontRasterState.c(packCtx, fontData, 0, new StbTrueTypePackRange[]{range}, 1);
|
||||
SmoothFontRasterState.S(packCtx);
|
||||
|
||||
this.pixelScale = SmoothFontRasterState.V(fontInfo, pixelHeight);
|
||||
for (int i = 0; i < chars.length; ++i) {
|
||||
int cp = chars[i];
|
||||
StbTrueTypePackedChar pc = packedChars[i];
|
||||
float invW = 1.0f / (float) atlasSize;
|
||||
float invH = 1.0f / (float) atlasSize;
|
||||
this.glyphs.put(cp, new SmoothFontGlyph(
|
||||
pc.s, pc.G, pc.t, pc.R,
|
||||
(float) pc.b * invW, (float) pc.k * invH,
|
||||
(float) pc.q * invW, (float) pc.p * invH,
|
||||
pc.A
|
||||
));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
ByteBuffer buffer = BufferUtils.createByteBuffer(atlasData.length + 128);
|
||||
buffer.put(atlasData);
|
||||
buffer.flip();
|
||||
|
||||
this.textureId = GL11.glGenTextures();
|
||||
GlStateManager.bindTexture(this.textureId);
|
||||
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
|
||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_LUMINANCE, atlasSize, atlasSize, 0, GL11.GL_LUMINANCE, GL11.GL_UNSIGNED_BYTE, buffer);
|
||||
|
||||
shader = new LegacyFontShaderProgram();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawVerticalString(String text, double x, double y, Color color) {
|
||||
char[] chars = text.toCharArray();
|
||||
for (int i = 0; i < chars.length; ++i) {
|
||||
drawStringWithShadow(String.valueOf(chars[i]), x, y, color);
|
||||
y += getStringHeight(String.valueOf(chars[i])) * 0.9;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderString(String text, double x, double y, int color, boolean fallbackToVanilla) {
|
||||
if (!fallbackToVanilla) {
|
||||
if (text == null || text.length() == 0 || textureId == 0) return;
|
||||
|
||||
int r = (color >> 16) & 0xFF;
|
||||
int g = (color >> 8) & 0xFF;
|
||||
int b = color & 0xFF;
|
||||
int a = (color >> 24) & 0xFF;
|
||||
if (a < 0) a += 256;
|
||||
if (a == 0) a = 255;
|
||||
Color baseColor = new Color(r, g, b, a);
|
||||
|
||||
char[] colorCodes = new char[text.length()];
|
||||
Arrays.fill(colorCodes, '\u0000');
|
||||
StringBuilder sb = new StringBuilder();
|
||||
char[] chars = text.toCharArray();
|
||||
int codeIdx = 0;
|
||||
for (int i = 0; i < chars.length; ++i) {
|
||||
char c = chars[i];
|
||||
if (c == '\u00a7') {
|
||||
if (++i >= chars.length) continue;
|
||||
colorCodes[codeIdx] = chars[i];
|
||||
continue;
|
||||
}
|
||||
sb.append(c);
|
||||
++codeIdx;
|
||||
}
|
||||
text = sb.toString();
|
||||
|
||||
float f = renderScale;
|
||||
y += (double)(this.ascent * this.pixelScale * f);
|
||||
Color currentColor = baseColor;
|
||||
|
||||
int prevTex = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
|
||||
boolean blendEnabled = GL11.glIsEnabled(GL11.GL_BLEND);
|
||||
boolean texEnabled = GL11.glIsEnabled(GL11.GL_TEXTURE_2D);
|
||||
boolean lightingEnabled = GL11.glIsEnabled(GL11.GL_LIGHTING);
|
||||
boolean alphaEnabled = GL11.glIsEnabled(GL11.GL_ALPHA_TEST);
|
||||
boolean cullEnabled = GL11.glIsEnabled(GL11.GL_CULL_FACE);
|
||||
|
||||
if (!blendEnabled) GlStateManager.enableBlend();
|
||||
if (!texEnabled) GlStateManager.enableTexture2D();
|
||||
if (lightingEnabled) GlStateManager.disableLighting();
|
||||
if (!alphaEnabled) GlStateManager.enableAlpha();
|
||||
if (cullEnabled) GlStateManager.disableCull();
|
||||
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GlStateManager.bindTexture(this.textureId);
|
||||
|
||||
if (shader != null) shader.bind();
|
||||
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
for (int i = 0; i < text.length(); ++i) {
|
||||
char c = text.charAt(i);
|
||||
SmoothFontGlyph glyph = this.glyphs.get((int) c);
|
||||
if (glyph == null) glyph = this.glyphs.get(32);
|
||||
if (glyph == null) continue;
|
||||
|
||||
char cc = colorCodes[i];
|
||||
if (cc != '\u0000') {
|
||||
float[] rgb = new float[3];
|
||||
applyColorCode(cc, rgb);
|
||||
currentColor = new Color(rgb[0], rgb[1], rgb[2]);
|
||||
if (cc == 'r') currentColor = baseColor;
|
||||
}
|
||||
|
||||
float x1 = (float) x + glyph.xOffset * f;
|
||||
float y1 = (float) y + glyph.yOffset * f;
|
||||
float x2 = (float) x + glyph.xMax * f;
|
||||
float y2 = (float) y + glyph.yMax * f;
|
||||
|
||||
GL11.glColor4f(
|
||||
(float) currentColor.getRed() / 255.0f,
|
||||
(float) currentColor.getGreen() / 255.0f,
|
||||
(float) currentColor.getBlue() / 255.0f,
|
||||
(float) baseColor.getAlpha() / 255.0f
|
||||
);
|
||||
GL11.glTexCoord2f(glyph.uMin, glyph.vMin);
|
||||
GL11.glVertex2f(x1, y1);
|
||||
GL11.glTexCoord2f(glyph.uMin, glyph.vMax);
|
||||
GL11.glVertex2f(x1, y2);
|
||||
GL11.glTexCoord2f(glyph.uMax, glyph.vMax);
|
||||
GL11.glVertex2f(x2, y2);
|
||||
GL11.glTexCoord2f(glyph.uMax, glyph.vMin);
|
||||
GL11.glVertex2f(x2, y1);
|
||||
|
||||
x += glyph.advance * f;
|
||||
}
|
||||
GL11.glEnd();
|
||||
|
||||
if (shader != null) shader.restorePreviousProgram();
|
||||
|
||||
GlStateManager.bindTexture(prevTex);
|
||||
if (!alphaEnabled) GlStateManager.disableAlpha();
|
||||
if (lightingEnabled) GlStateManager.enableLighting();
|
||||
if (!blendEnabled) GlStateManager.disableBlend();
|
||||
if (!texEnabled) GlStateManager.disableTexture2D();
|
||||
if (cullEnabled) GlStateManager.enableCull();
|
||||
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
} else {
|
||||
float f = (float) this.fontSize / 16.0f;
|
||||
float inv = 1.0f / f;
|
||||
x = Math.ceil(x * inv);
|
||||
y = Math.ceil(y * inv);
|
||||
GL11.glPushMatrix();
|
||||
GL11.glScalef(f, f, f);
|
||||
Minecraft.getMinecraft().fontRendererObj.drawStringWithShadow(text, (float) x, (float) y, color);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawStringWithShadow(String text, double x, double y, int color) {
|
||||
drawString(text, x + 0.5, y + 0.5, Integer.MIN_VALUE);
|
||||
renderString(text, x, y, color, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawStringWithShadow(String text, double x, double y, Color color, boolean fallbackToVanilla) {
|
||||
if (!fallbackToVanilla) {
|
||||
drawString(text, x + 0.5, y + 0.5, Integer.MIN_VALUE);
|
||||
drawString(text, x, y, color);
|
||||
} else {
|
||||
float f = (float) this.fontSize / 16.0f;
|
||||
float inv = 1.0f / f;
|
||||
x = Math.ceil(x * inv);
|
||||
y = Math.ceil(y * inv);
|
||||
GL11.glPushMatrix();
|
||||
GL11.glScalef(f, f, f);
|
||||
Minecraft.getMinecraft().fontRendererObj.drawStringWithShadow(text, (float) x, (float) y, color.getRGB());
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getStringHeight(String text, boolean fallbackToVanilla) {
|
||||
if (!fallbackToVanilla) {
|
||||
float f = 0.6f;
|
||||
return (float) this.fontSize * f;
|
||||
}
|
||||
float f = (float) this.fontSize / 16.0f;
|
||||
return 8.0f * f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getStringWidth(String text, boolean fallbackToVanilla) {
|
||||
String stripped = this.strippedStringCache.get(text);
|
||||
if (stripped == null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (char c : text.toCharArray()) {
|
||||
if (c == '\u00a7') continue;
|
||||
sb.append(c);
|
||||
}
|
||||
stripped = sb.toString();
|
||||
this.strippedStringCache.put(text, stripped);
|
||||
}
|
||||
text = stripped;
|
||||
|
||||
if (!fallbackToVanilla) {
|
||||
Double cached = this.stringWidthCache.get(text);
|
||||
if (cached != null) return cached;
|
||||
|
||||
float f = 0.6f;
|
||||
double width = 0.0;
|
||||
for (int i = 0; i < text.length(); ++i) {
|
||||
char c = text.charAt(i);
|
||||
SmoothFontGlyph glyph = this.glyphs.get((int) c);
|
||||
if (glyph == null) glyph = this.glyphs.get(32);
|
||||
if (glyph == null) continue;
|
||||
width += glyph.advance * f;
|
||||
}
|
||||
this.stringWidthCache.put(text, width);
|
||||
return width;
|
||||
}
|
||||
|
||||
float f = (float) this.fontSize / 16.0f;
|
||||
return Minecraft.getMinecraft().fontRendererObj.getStringWidth(text) * f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderStringWithShadow(String text, double x, double y, Color color, Color shadowColor, boolean fallbackToVanilla) {
|
||||
int n = color.getRGB();
|
||||
int n2 = shadowColor.getRGB();
|
||||
if (!fallbackToVanilla) {
|
||||
drawString(text, x + 0.5, y + 0.5, n2);
|
||||
drawString(text, x, y, color);
|
||||
} else {
|
||||
float f = (float) this.fontSize / 16.0f;
|
||||
float inv = 1.0f / f;
|
||||
x = Math.ceil(x * inv);
|
||||
y = Math.ceil(y * inv);
|
||||
GL11.glPushMatrix();
|
||||
GL11.glScalef(f, f, f);
|
||||
Minecraft.getMinecraft().fontRendererObj.drawStringWithShadow(text, (float) x, (float) y, n);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font;
|
||||
|
||||
public class SmoothFontGlyph {
|
||||
public float uMin;
|
||||
public float vMin;
|
||||
public float uMax;
|
||||
public float vMax;
|
||||
public float xOffset;
|
||||
public float yOffset;
|
||||
public float xMax;
|
||||
public float yMax;
|
||||
public float advance;
|
||||
|
||||
public SmoothFontGlyph(float xOffset, float yOffset, float xMax, float yMax, float uMin, float vMin, float uMax, float vMax, float advance) {
|
||||
this.xOffset = xOffset;
|
||||
this.xMax = xMax;
|
||||
this.yOffset = yOffset;
|
||||
this.yMax = yMax;
|
||||
this.uMin = uMin;
|
||||
this.uMax = uMax;
|
||||
this.vMin = vMin;
|
||||
this.vMax = vMax;
|
||||
this.advance = advance;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,128 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class SmoothFontRenderer {
|
||||
protected Map<String, String> strippedStringCache;
|
||||
protected Map<String, Double> stringWidthCache = new SmoothFontRendererWidthCache(this, 16, 0.75f, true);
|
||||
protected boolean fontSelectorEnabled = true;
|
||||
protected int fontSize;
|
||||
|
||||
public void drawString(String text, double x, double y, int color) {
|
||||
drawStringStripped(text, x, y, color, false);
|
||||
}
|
||||
|
||||
public abstract void drawVerticalString(String text, double x, double y, Color color);
|
||||
|
||||
protected void applyColorCode(char code, float[] rgb) {
|
||||
if (code == '4') { rgb[0] = 1.0f; rgb[1] = 0.0f; rgb[2] = 0.0f; }
|
||||
if (code == 'c') { rgb[0] = 1.0f; rgb[1] = 0.33f; rgb[2] = 0.33f; }
|
||||
if (code == '6') { rgb[0] = 1.0f; rgb[1] = 0.66f; rgb[2] = 0.0f; }
|
||||
if (code == 'e') { rgb[0] = 1.0f; rgb[1] = 1.0f; rgb[2] = 0.33f; }
|
||||
if (code == '2') { rgb[0] = 0.0f; rgb[1] = 0.66f; rgb[2] = 0.0f; }
|
||||
if (code == 'a') { rgb[0] = 0.33f; rgb[1] = 1.0f; rgb[2] = 0.33f; }
|
||||
if (code == 'b') { rgb[0] = 0.33f; rgb[1] = 1.0f; rgb[2] = 1.0f; }
|
||||
if (code == '3') { rgb[0] = 0.0f; rgb[1] = 0.66f; rgb[2] = 0.66f; }
|
||||
if (code == '1') { rgb[0] = 0.0f; rgb[1] = 0.0f; rgb[2] = 0.66f; }
|
||||
if (code == '9') { rgb[0] = 0.33f; rgb[1] = 0.33f; rgb[2] = 1.0f; }
|
||||
if (code == 'd') { rgb[0] = 1.0f; rgb[1] = 0.33f; rgb[2] = 1.0f; }
|
||||
if (code == '5') { rgb[0] = 0.66f; rgb[1] = 0.0f; rgb[2] = 0.66f; }
|
||||
if (code == 'f') { rgb[0] = 1.0f; rgb[1] = 1.0f; rgb[2] = 1.0f; }
|
||||
if (code == '7') { rgb[0] = 0.66f; rgb[1] = 0.66f; rgb[2] = 0.66f; }
|
||||
if (code == '8') { rgb[0] = 0.33f; rgb[1] = 0.33f; rgb[2] = 0.33f; }
|
||||
if (code == '0') { rgb[0] = 0.0f; rgb[1] = 0.0f; rgb[2] = 0.0f; }
|
||||
}
|
||||
|
||||
public void clearCaches() {
|
||||
this.stringWidthCache.clear();
|
||||
this.strippedStringCache.clear();
|
||||
}
|
||||
|
||||
public void drawString(String text, double x, double y, Color color) {
|
||||
drawString(text, x, y, color.getRGB());
|
||||
}
|
||||
|
||||
public int getStrippedStringCacheSize() {
|
||||
return this.strippedStringCache.size();
|
||||
}
|
||||
|
||||
public void drawCenteredString(String text, double x, double y, int color) {
|
||||
drawString(text, x - getStringWidth(text) / 2.0, y, color);
|
||||
}
|
||||
|
||||
public void setFontSelectorEnabled(boolean enabled) {
|
||||
this.fontSelectorEnabled = enabled;
|
||||
}
|
||||
|
||||
public abstract void drawStringWithShadow(String text, double x, double y, int color);
|
||||
|
||||
public abstract void renderString(String text, double x, double y, int color, boolean fallbackToVanilla);
|
||||
|
||||
public double getStringWidth(String text) {
|
||||
return getStringWidth(text, false);
|
||||
}
|
||||
|
||||
public double getStringHeight(String text) {
|
||||
return getStringHeight(text, false);
|
||||
}
|
||||
|
||||
public void drawString(String text, double x, double y, Color color, boolean fallbackToVanilla) {
|
||||
int rgb = color.getRGB();
|
||||
renderString(text, x, y, rgb, fallbackToVanilla);
|
||||
}
|
||||
|
||||
public abstract double getStringHeight(String text, boolean fallbackToVanilla);
|
||||
|
||||
public void drawStringStripped(String text, double x, double y, int color, boolean shadow) {
|
||||
String stripped = this.strippedStringCache.get(text);
|
||||
if (stripped == null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
char[] chars = text.toCharArray();
|
||||
for (int i = 0; i < chars.length; ++i) {
|
||||
char c = chars[i];
|
||||
if (c == '\u00a7') {
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
sb.append(c);
|
||||
}
|
||||
stripped = sb.toString();
|
||||
this.strippedStringCache.put(text, stripped);
|
||||
}
|
||||
text = stripped;
|
||||
renderString(text, x, y, color, shadow);
|
||||
}
|
||||
|
||||
public int getWidthCacheSize() {
|
||||
return this.stringWidthCache.size();
|
||||
}
|
||||
|
||||
public void drawStringWithShadow(String text, double x, double y, Color color) {
|
||||
drawString(text, x + 0.5, y + 0.5, Integer.MIN_VALUE);
|
||||
drawString(text, x, y, color.getRGB());
|
||||
}
|
||||
|
||||
public abstract void renderStringWithShadow(String text, double x, double y, Color color, Color shadowColor, boolean fallbackToVanilla);
|
||||
|
||||
public void drawCenteredString(String text, double x, double y, Color color) {
|
||||
drawCenteredString(text, x, y, color.getRGB());
|
||||
}
|
||||
|
||||
public abstract void drawStringWithShadow(String text, double x, double y, Color color, boolean fallbackToVanilla);
|
||||
|
||||
public int getFontSize() {
|
||||
return this.fontSize;
|
||||
}
|
||||
|
||||
public void drawStringWithShadow(String text, double x, double y, Color color, Color shadowColor) {
|
||||
renderStringWithShadow(text, x, y, color, shadowColor, false);
|
||||
}
|
||||
|
||||
public SmoothFontRenderer() {
|
||||
this.strippedStringCache = new SmoothFontRendererStringCache(this, 16, 0.75f, true);
|
||||
}
|
||||
|
||||
public abstract double getStringWidth(String text, boolean fallbackToVanilla);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SmoothFontRendererStringCache extends LinkedHashMap<String, String> {
|
||||
final SmoothFontRenderer L;
|
||||
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Map.Entry<String, String> entry) {
|
||||
return this.size() > 5120;
|
||||
}
|
||||
|
||||
public SmoothFontRendererStringCache(SmoothFontRenderer smoothFontRenderer, int n, float f, boolean bl) {
|
||||
super(n, f, bl);
|
||||
this.L = smoothFontRenderer;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SmoothFontRendererWidthCache extends LinkedHashMap<String, Double> {
|
||||
final SmoothFontRenderer s;
|
||||
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Map.Entry<String, Double> entry) {
|
||||
return this.size() > 5120;
|
||||
}
|
||||
|
||||
public SmoothFontRendererWidthCache(SmoothFontRenderer smoothFontRenderer, int n, float f, boolean bl) {
|
||||
super(n, f, bl);
|
||||
this.s = smoothFontRenderer;
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public class StbFontManager {
|
||||
private byte[] proximaData;
|
||||
private byte[] proximaBoldData;
|
||||
private byte[] notoData;
|
||||
private byte[] poppinsData;
|
||||
private byte[] jelloMediumData;
|
||||
|
||||
private final ConcurrentMap<Integer, SmoothFontRenderer> regularFonts = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<Integer, SmoothFontRenderer> boldFonts = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<Integer, SmoothFontRenderer> notoFonts = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<Integer, SmoothFontRenderer> poppinsFonts = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<Integer, SmoothFontRenderer> jelloMediumFonts = new ConcurrentHashMap<>();
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
public void loadFonts() {
|
||||
this.proximaData = readResource("proxima.ttf");
|
||||
this.proximaBoldData = readResource("proximabd.ttf");
|
||||
this.notoData = readResource("noto.ttf");
|
||||
this.poppinsData = readResource("poppins_rg.ttf");
|
||||
this.jelloMediumData = readResource("JelloMedium.ttf");
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
private byte[] readResource(String path) {
|
||||
try {
|
||||
InputStream is = StbFontManager.class.getClassLoader().getResourceAsStream("fonts/" + path);
|
||||
if (is == null) return null;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
byte[] buf = new byte[8192];
|
||||
int len;
|
||||
while ((len = is.read(buf)) != -1) {
|
||||
baos.write(buf, 0, len);
|
||||
}
|
||||
is.close();
|
||||
return baos.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public SmoothFontRenderer getProxima(int size) {
|
||||
return getFont(regularFonts, proximaData, size, "Proxima");
|
||||
}
|
||||
|
||||
public SmoothFontRenderer getProximaBold(int size) {
|
||||
return getFont(boldFonts, proximaBoldData, size, "Proxima Bold");
|
||||
}
|
||||
|
||||
public SmoothFontRenderer getNoto(int size) {
|
||||
return getFont(notoFonts, notoData, size, "Noto");
|
||||
}
|
||||
|
||||
public SmoothFontRenderer getPoppins(int size) {
|
||||
return getFont(poppinsFonts, poppinsData, size, "Poppins");
|
||||
}
|
||||
|
||||
public SmoothFontRenderer getJelloMedium(int size) {
|
||||
return getFont(jelloMediumFonts, jelloMediumData, size, "Jello Medium");
|
||||
}
|
||||
|
||||
private SmoothFontRenderer getFont(ConcurrentMap<Integer, SmoothFontRenderer> cache, byte[] data, int size, String name) {
|
||||
if (!cache.containsKey(size)) {
|
||||
if (data == null) return null;
|
||||
LegacySmoothFontRenderer renderer = new LegacySmoothFontRenderer(data, size, name);
|
||||
cache.put(size, renderer);
|
||||
return renderer;
|
||||
}
|
||||
return cache.get(size);
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font.shader;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
public class ShaderProgram {
|
||||
private static int currentProgramId = -1;
|
||||
int previousProgramId;
|
||||
int vertexShaderId = 0;
|
||||
int fragmentShaderId = 0;
|
||||
boolean linked;
|
||||
int programId = GL20.glCreateProgram();
|
||||
|
||||
public ShaderProgram(String vertexShaderSource, String fragmentShaderSource) {
|
||||
this.vertexShaderId = GL20.glCreateShader(GL20.GL_VERTEX_SHADER);
|
||||
this.fragmentShaderId = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER);
|
||||
|
||||
GL20.glShaderSource(this.vertexShaderId, vertexShaderSource);
|
||||
GL20.glShaderSource(this.fragmentShaderId, fragmentShaderSource);
|
||||
GL20.glCompileShader(this.vertexShaderId);
|
||||
GL20.glCompileShader(this.fragmentShaderId);
|
||||
|
||||
GL20.glAttachShader(this.programId, this.vertexShaderId);
|
||||
GL20.glAttachShader(this.programId, this.fragmentShaderId);
|
||||
GL20.glLinkProgram(this.programId);
|
||||
|
||||
IntBuffer linkStatus = BufferUtils.createIntBuffer(1);
|
||||
GL20.glGetProgram(this.programId, GL20.GL_LINK_STATUS, linkStatus);
|
||||
this.linked = linkStatus.get(0) == 1;
|
||||
}
|
||||
|
||||
public boolean isLinked() {
|
||||
return this.linked;
|
||||
}
|
||||
|
||||
public int getProgramId() {
|
||||
return this.programId;
|
||||
}
|
||||
|
||||
public void restorePreviousProgram() {
|
||||
useProgram(this.previousProgramId);
|
||||
}
|
||||
|
||||
public static void useProgram(int programId) {
|
||||
GL20.glUseProgram(programId);
|
||||
currentProgramId = programId;
|
||||
}
|
||||
|
||||
public static int getCurrentProgramId() {
|
||||
if (currentProgramId == -1) {
|
||||
currentProgramId = GL11.glGetInteger(GL20.GL_CURRENT_PROGRAM);
|
||||
}
|
||||
return currentProgramId;
|
||||
}
|
||||
|
||||
public boolean bind() {
|
||||
if (!this.linked) return false;
|
||||
this.previousProgramId = getCurrentProgramId();
|
||||
useProgram(this.programId);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font.stb;
|
||||
|
||||
public final class StbByteBufferView {
|
||||
public byte[] f;
|
||||
public int y;
|
||||
public int C;
|
||||
public int h;
|
||||
|
||||
public StbByteBufferView() {
|
||||
this(null, 0, 0);
|
||||
}
|
||||
|
||||
public StbByteBufferView(byte[] data, int offset, int length) {
|
||||
this.f = data;
|
||||
this.C = offset;
|
||||
this.h = 0;
|
||||
this.y = length;
|
||||
}
|
||||
|
||||
public StbByteBufferView k() {
|
||||
StbByteBufferView copy = new StbByteBufferView();
|
||||
copy.f = this.f;
|
||||
copy.C = this.C;
|
||||
copy.h = this.h;
|
||||
copy.y = this.y;
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font.stb;
|
||||
|
||||
public class StbTrueTypeActiveEdge {
|
||||
public float j;
|
||||
public float e;
|
||||
public float N;
|
||||
public float m;
|
||||
public StbTrueTypeActiveEdge l;
|
||||
public float T;
|
||||
public float L;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font.stb;
|
||||
|
||||
public class StbTrueTypeAlignedQuad {
|
||||
public float K;
|
||||
public float G;
|
||||
public float C;
|
||||
public float x;
|
||||
public float v;
|
||||
public float M;
|
||||
public float O;
|
||||
public float S;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font.stb;
|
||||
|
||||
public class StbTrueTypeBakedChar {
|
||||
public int V;
|
||||
public float k;
|
||||
public float l;
|
||||
public int D;
|
||||
public float B;
|
||||
public int U;
|
||||
public int Q;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font.stb;
|
||||
|
||||
public class StbTrueTypeBitmap {
|
||||
public byte[] E;
|
||||
public int c;
|
||||
public int K;
|
||||
public int h;
|
||||
public int A;
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font.stb;
|
||||
|
||||
public class StbTrueTypeCharStringContext {
|
||||
public int Z;
|
||||
public int c;
|
||||
public int q;
|
||||
public float p;
|
||||
public int v;
|
||||
public float o;
|
||||
public float s;
|
||||
public float C;
|
||||
public int J;
|
||||
public int y;
|
||||
public int f;
|
||||
public StbTrueTypeVertex[] V;
|
||||
|
||||
public StbTrueTypeCharStringContext(int n) {
|
||||
this.J = n;
|
||||
this.v = 0;
|
||||
this.s = 0.0f;
|
||||
this.p = 0.0f;
|
||||
this.C = 0.0f;
|
||||
this.o = 0.0f;
|
||||
this.y = 0;
|
||||
this.c = 0;
|
||||
this.Z = 0;
|
||||
this.f = 0;
|
||||
this.V = null;
|
||||
this.q = 0;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font.stb;
|
||||
|
||||
public class StbTrueTypeEdge {
|
||||
public float u;
|
||||
public float d;
|
||||
public int W;
|
||||
public float X;
|
||||
public float i;
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font.stb;
|
||||
|
||||
public class StbTrueTypeFontInfo {
|
||||
public int h;
|
||||
public int G;
|
||||
public StbByteBufferView H;
|
||||
public int Y;
|
||||
public int L;
|
||||
public int Q;
|
||||
public int U;
|
||||
public StbByteBufferView g = new StbByteBufferView();
|
||||
public int c;
|
||||
public StbByteBufferView j;
|
||||
public byte[] S;
|
||||
public StbByteBufferView z = new StbByteBufferView();
|
||||
public StbByteBufferView J;
|
||||
public int d;
|
||||
public int T;
|
||||
public int w;
|
||||
public StbByteBufferView N;
|
||||
public int v;
|
||||
public int p;
|
||||
|
||||
public StbTrueTypeFontInfo() {
|
||||
this.j = new StbByteBufferView();
|
||||
this.J = new StbByteBufferView();
|
||||
this.H = new StbByteBufferView();
|
||||
this.N = new StbByteBufferView();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font.stb;
|
||||
|
||||
public class StbTrueTypeGlyphPackNode {
|
||||
public int z;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font.stb;
|
||||
|
||||
public class StbTrueTypeKerningEntry {
|
||||
public int y;
|
||||
public int q;
|
||||
public int o;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font.stb;
|
||||
|
||||
public class StbTrueTypePackAtlasState {
|
||||
public int F;
|
||||
public int a;
|
||||
public int n;
|
||||
public int f;
|
||||
public int t;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font.stb;
|
||||
|
||||
public class StbTrueTypePackContext {
|
||||
public int d;
|
||||
public StbTrueTypeGlyphPackNode[] j;
|
||||
public int m;
|
||||
public int h;
|
||||
public int G;
|
||||
public int b;
|
||||
public StbTrueTypePackAtlasState J;
|
||||
public int c;
|
||||
public int w;
|
||||
public byte[] X;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font.stb;
|
||||
|
||||
public class StbTrueTypePackRange {
|
||||
public int y;
|
||||
public int R;
|
||||
public int[] N;
|
||||
public StbTrueTypePackedChar[] M;
|
||||
public int i;
|
||||
public float E;
|
||||
private static String[] j;
|
||||
public int b;
|
||||
|
||||
public static void t(String[] stringArray) {
|
||||
j = stringArray;
|
||||
}
|
||||
|
||||
public static String[] x() {
|
||||
return j;
|
||||
}
|
||||
|
||||
static {
|
||||
if (StbTrueTypePackRange.x() != null) {
|
||||
StbTrueTypePackRange.t(new String[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font.stb;
|
||||
|
||||
public class StbTrueTypePackRectangle {
|
||||
public int e;
|
||||
public int J;
|
||||
public int P;
|
||||
public int M;
|
||||
public int N;
|
||||
public int q;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font.stb;
|
||||
|
||||
public class StbTrueTypePackedChar {
|
||||
public int p;
|
||||
public int q;
|
||||
public float R;
|
||||
public int k;
|
||||
public float A;
|
||||
public int b;
|
||||
public float G;
|
||||
public float t;
|
||||
public float s;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font.stb;
|
||||
|
||||
public class StbTrueTypePoint {
|
||||
public float E;
|
||||
public float M;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.font.stb;
|
||||
|
||||
public class StbTrueTypeVertex {
|
||||
public short h;
|
||||
public int O;
|
||||
public short H;
|
||||
public short a;
|
||||
public short D;
|
||||
public short s;
|
||||
public int v;
|
||||
public short f;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.manager;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.event.impl.EventTimerThread;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class ThreadManager {
|
||||
|
||||
private Thread timerThread;
|
||||
private volatile boolean running = false;
|
||||
|
||||
private static final long TIMER_INTERVAL_MS = 5L;
|
||||
|
||||
public void init() {
|
||||
if (running) {
|
||||
return;
|
||||
}
|
||||
|
||||
running = true;
|
||||
|
||||
timerThread = new Thread(() -> {
|
||||
while (running && !Thread.currentThread().isInterrupted()) {
|
||||
OrangeX.getInstance()
|
||||
.getEventBus()
|
||||
.post(new EventTimerThread());
|
||||
|
||||
try {
|
||||
Thread.sleep(TIMER_INTERVAL_MS);
|
||||
} catch (InterruptedException e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, "OrangeX-Timer");
|
||||
|
||||
timerThread.start();
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(
|
||||
new Thread(this::shutdown, "OrangeX-Timer-Shutdown")
|
||||
);
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
running = false;
|
||||
if (timerThread != null) {
|
||||
timerThread.interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.mixin;
|
||||
|
||||
import cn.xiaozhou233.orangex.utils.IOUtils;
|
||||
import cn.xiaozhou233.orangex.mixin.impl.*;
|
||||
import cn.xiaozhou233.orangex.utils.JuiceAgentFacade;
|
||||
import cn.yapeteam.ymixin.Transformer;
|
||||
import cn.yapeteam.ymixin.YMixin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public final class MixinManager {
|
||||
|
||||
public void start() {
|
||||
|
||||
ClassLoader cl = MixinManager.class.getClassLoader();
|
||||
|
||||
// Check Obfuscation
|
||||
String content = null;
|
||||
try {
|
||||
Class.forName("net.minecraft.client.Minecraft");
|
||||
} catch (ClassNotFoundException e) {
|
||||
System.out.println("[OrangeX] Obfuscation detected, use mapping.");
|
||||
InputStream stream = MixinManager.class.getResourceAsStream("/joined.srg");
|
||||
|
||||
try {
|
||||
content = new String(
|
||||
IOUtils.toByteArray(stream),
|
||||
StandardCharsets.UTF_8
|
||||
);
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
YMixin.init(
|
||||
className -> {
|
||||
try {
|
||||
return Class.forName(
|
||||
className.replace("/", "."),
|
||||
false,
|
||||
cl
|
||||
);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
},
|
||||
clazz -> {
|
||||
byte[] classBytes = JuiceAgentFacade.getClassBytes(clazz);
|
||||
if (classBytes == null) {
|
||||
throw new RuntimeException(
|
||||
"ClassBytes null: " + clazz.getName()
|
||||
);
|
||||
}
|
||||
return classBytes;
|
||||
},
|
||||
null,
|
||||
null,
|
||||
content
|
||||
);
|
||||
|
||||
Transformer transformer = new Transformer();
|
||||
try {
|
||||
transformer.addMixin(MixinMinecraft.class);
|
||||
transformer.addMixin(MixinGuiIngame.class);
|
||||
transformer.addMixin(MixinEntityRenderer.class);
|
||||
transformer.addMixin(MixinNetHandlerPlayClient.class);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Failed to add mixin", e);
|
||||
}
|
||||
|
||||
transformer.transform().forEach((name, bytes) -> {
|
||||
try {
|
||||
Class<?> targetClass = Class.forName(name, false, cl);
|
||||
boolean ok = JuiceAgentFacade.retransformClass(targetClass, bytes);
|
||||
if (!ok) {
|
||||
throw new RuntimeException("Redefine failed: " + name);
|
||||
}
|
||||
System.out.println("[OrangeX] Redefined class: " + name);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(
|
||||
"Failed to redefine class: " + name,
|
||||
e
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.mixin.impl;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.event.impl.EventRender3D;
|
||||
import cn.yapeteam.ymixin.annotations.Inject;
|
||||
import cn.yapeteam.ymixin.annotations.Local;
|
||||
import cn.yapeteam.ymixin.annotations.Mixin;
|
||||
import cn.yapeteam.ymixin.annotations.Target;
|
||||
import net.minecraft.client.renderer.EntityRenderer;
|
||||
|
||||
@Mixin(EntityRenderer.class)
|
||||
public class MixinEntityRenderer {
|
||||
|
||||
@Inject(
|
||||
method = "renderWorldPass", desc = "(IFJ)V",
|
||||
target = @Target(
|
||||
value = "INVOKESTATIC",
|
||||
target = "net/minecraft/client/renderer/GlStateManager.disableFog()V",
|
||||
shift = Target.Shift.AFTER
|
||||
)
|
||||
)
|
||||
private void render(@Local(source = "partialTicks", index = 2) float partialTicks) {
|
||||
OrangeX.getInstance().getEventBus().post(new EventRender3D(partialTicks));
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.mixin.impl;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.event.impl.EventRender2D;
|
||||
import cn.xiaozhou233.orangex.font.SmoothFontRenderer;
|
||||
import cn.yapeteam.ymixin.annotations.Inject;
|
||||
import cn.yapeteam.ymixin.annotations.Local;
|
||||
import cn.yapeteam.ymixin.annotations.Mixin;
|
||||
import cn.yapeteam.ymixin.annotations.Target;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiIngame;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
@Mixin(GuiIngame.class)
|
||||
public class MixinGuiIngame {
|
||||
|
||||
@Inject(method = "renderGameOverlay", desc = "(F)V", target = @Target("HEAD"))
|
||||
public void onRenderGameOverlay(@Local(source = "partialTicks", index = 1) float partialTicks) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ScaledResolution sr = new ScaledResolution(mc);
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.disableDepth();
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.tryBlendFuncSeparate(
|
||||
GL11.GL_SRC_ALPHA,
|
||||
GL11.GL_ONE_MINUS_SRC_ALPHA,
|
||||
GL11.GL_ONE,
|
||||
GL11.GL_ZERO
|
||||
);
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
mc.entityRenderer.setupOverlayRendering();
|
||||
|
||||
OrangeX.getInstance().getEventBus().post(new EventRender2D(partialTicks));
|
||||
|
||||
GlStateManager.enableDepth();
|
||||
GlStateManager.disableBlend();
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.mixin.impl;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.event.impl.*;
|
||||
import cn.yapeteam.ymixin.annotations.Inject;
|
||||
import cn.yapeteam.ymixin.annotations.Local;
|
||||
import cn.yapeteam.ymixin.annotations.Mixin;
|
||||
import cn.yapeteam.ymixin.annotations.Target;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
@Mixin(Minecraft.class)
|
||||
public class MixinMinecraft {
|
||||
int i = 0;
|
||||
|
||||
@Inject(method = "runGameLoop", desc = "()V", target = @Target("HEAD"))
|
||||
private void onLoop() {
|
||||
OrangeX.getInstance().getEventBus().post(new EventLoop());
|
||||
}
|
||||
|
||||
@Inject(method = "runTick", desc = "()V", target = @Target("HEAD"))
|
||||
public void onTick() {
|
||||
OrangeX.getInstance().getEventBus().post(new EventTick());
|
||||
}
|
||||
|
||||
@Inject(method = "shutdownMinecraftApplet", desc = "()V", target = @Target("HEAD"))
|
||||
public void onShutdown() {
|
||||
OrangeX.getInstance().stop();
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "runTick", desc = "()V",
|
||||
target = @Target(
|
||||
value = "INVOKESTATIC",
|
||||
target = "org/lwjgl/input/Keyboard.getEventKeyState()Z",
|
||||
shift = Target.Shift.AFTER
|
||||
)
|
||||
)
|
||||
public void onKey(@Local(source = "key", index = 1) int key) {
|
||||
if (Minecraft.getMinecraft().currentScreen == null && Keyboard.getEventKeyState())
|
||||
OrangeX.getInstance().getEventBus().post(new EventKey(key));
|
||||
}
|
||||
|
||||
@Inject(method = "loadWorld", desc = "(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V", target = @Target("HEAD"))
|
||||
public void onLoadWorld() {
|
||||
OrangeX.getInstance().getEventBus().post(new EventWorldLoad());
|
||||
}
|
||||
}
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.mixin.impl;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.event.impl.EventPacketSend;
|
||||
import cn.yapeteam.ymixin.annotations.Inject;
|
||||
import cn.yapeteam.ymixin.annotations.Local;
|
||||
import cn.yapeteam.ymixin.annotations.Mixin;
|
||||
import cn.yapeteam.ymixin.annotations.Target;
|
||||
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||
import net.minecraft.network.Packet;
|
||||
|
||||
@Mixin(NetHandlerPlayClient.class)
|
||||
public class MixinNetHandlerPlayClient {
|
||||
@Inject(
|
||||
method = "addToSendQueue",
|
||||
desc = "(Lnet/minecraft/network/Packet;)V",
|
||||
target = @Target("HEAD")
|
||||
)
|
||||
public void onSendPacket(@Local(source = "packet", index = 1) Packet packet) {
|
||||
EventPacketSend eventPacketSend = new EventPacketSend(packet);
|
||||
OrangeX.getInstance().getEventBus().post(eventPacketSend);
|
||||
|
||||
if (eventPacketSend.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.module;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.module.option.Option;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public class Module {
|
||||
protected static final Minecraft mc = Minecraft.getMinecraft();
|
||||
protected final String name;
|
||||
protected final String description;
|
||||
protected final ModuleCategory category;
|
||||
@Setter
|
||||
protected int key = Keyboard.KEY_NONE;
|
||||
protected boolean enabled = false;
|
||||
protected final List<Option<?>> options = new ArrayList<>();
|
||||
|
||||
public Module(String name, String description, ModuleCategory category) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public Module(String name, String description, ModuleCategory category, int key) {
|
||||
this(name, description, category);
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public Module(String name, String description, ModuleCategory category, int key, boolean enabled) {
|
||||
this(name, description, category, key);
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public void addOption(Option<?> option) {
|
||||
options.add(option);
|
||||
}
|
||||
|
||||
protected void onEnable() {
|
||||
System.out.println("[OrangeX] Enable " + name);
|
||||
}
|
||||
|
||||
protected void onDisable() {
|
||||
System.out.println("[OrangeX] Disable " + name);
|
||||
}
|
||||
|
||||
public void setEnabled(boolean setEnabled) {
|
||||
if (this.enabled == setEnabled) return;
|
||||
|
||||
this.enabled = setEnabled;
|
||||
|
||||
if (this.enabled) {
|
||||
if (OrangeX.getInstance().getEventBus().isRegistered(this))
|
||||
return;
|
||||
try { OrangeX.getInstance().getEventBus().register(this); } catch (Exception ignored) {}
|
||||
onEnable();
|
||||
} else {
|
||||
if (!OrangeX.getInstance().getEventBus().isRegistered(this))
|
||||
return;
|
||||
try { OrangeX.getInstance().getEventBus().unregister(this); } catch (Exception ignored) {}
|
||||
onDisable();
|
||||
}
|
||||
}
|
||||
|
||||
public void toggle() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.module;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum ModuleCategory {
|
||||
RENDER("Render"),
|
||||
COMBAT("Combat"),
|
||||
WORLD("World"),
|
||||
MOVEMENT("Movement"),
|
||||
PLAYER("Player"),
|
||||
MISC("Misc"),
|
||||
FUN("Fun"),
|
||||
MINIGAME("Minigame");
|
||||
|
||||
|
||||
private final String name;
|
||||
|
||||
|
||||
ModuleCategory(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.module;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.config.ModuleConfig;
|
||||
import cn.xiaozhou233.orangex.event.impl.EventKey;
|
||||
import cn.xiaozhou233.orangex.module.impl.TestModule;
|
||||
import cn.xiaozhou233.orangex.module.impl.render.*;
|
||||
import lombok.Getter;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
@Getter
|
||||
public class ModuleManager {
|
||||
public static String userHome = System.getProperty("user.home");
|
||||
private final List<Module> modules = new CopyOnWriteArrayList<>();
|
||||
private final ModuleConfig config;
|
||||
|
||||
public ModuleManager() {
|
||||
config = new ModuleConfig(userHome + "/.orangex/profile.json");
|
||||
}
|
||||
|
||||
public void addModule(Module module) {
|
||||
modules.add(module);
|
||||
}
|
||||
|
||||
public void registerModules() {
|
||||
OrangeX.getInstance().getEventBus().register(this);
|
||||
addModule(new TestModule());
|
||||
|
||||
// Combat
|
||||
|
||||
// Render
|
||||
addModule(new HUD());
|
||||
addModule(new ClickGUI());
|
||||
addModule(new ESP());
|
||||
addModule(new NameTag());
|
||||
}
|
||||
|
||||
public List<Module> getModulesByCategory(ModuleCategory category) {
|
||||
List<Module> result = new ArrayList<>();
|
||||
for (Module module : modules) {
|
||||
if (module.getCategory() == category) {
|
||||
result.add(module);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Module> T getModule(Class<T> clazz) {
|
||||
for (Module module : modules) {
|
||||
if (module.getClass() == clazz) {
|
||||
return (T) module;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Module getModule(String name) {
|
||||
for (Module module : modules) {
|
||||
if (module.getName().equalsIgnoreCase(name)) {
|
||||
return module;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
config.save(modules);
|
||||
}
|
||||
|
||||
public void loadConfig() {
|
||||
config.load(modules);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onKeyDown(EventKey event) {
|
||||
for (Module module : OrangeX.getInstance().getModuleManager().getModules()) {
|
||||
if (module.getKey() == event.getKey()) {
|
||||
module.toggle();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.module.impl;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.ModuleCategory;
|
||||
import cn.xiaozhou233.orangex.module.option.impl.*;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
public class TestModule extends Module {
|
||||
public TestModule() {
|
||||
super("Test", "A test module", ModuleCategory.MISC);
|
||||
|
||||
addOption(new BooleanOption("boolean", "Boolean option", this, true));
|
||||
addOption(new DoubleOption("double", "Double slider", this, 0.5, 0.0, 1.0, 0.05, 2));
|
||||
addOption(new IntOption("int", "Int slider", this, 10, 1, 100, 5));
|
||||
addOption(new ModeOption("mode", "Mode selector", this, "A", "A", "B", "C"));
|
||||
addOption(new ColorOption("color", "ARGB color", this, 0xFFFF0000));
|
||||
addOption(new StringOption("string", "Text input", this, "hello", 32));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEnable() {
|
||||
System.out.println("[OrangeX] TestModule enabled");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDisable() {
|
||||
System.out.println("[OrangeX] TestModule disabled");
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onKey(KeyEvent event) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.module.impl.render;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.ModuleCategory;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.ClickGUIScreen;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public class ClickGUI extends Module {
|
||||
public ClickGUI() {
|
||||
super("ClickGUI", "ClickGUI", ModuleCategory.RENDER);
|
||||
setEnabled(false);
|
||||
setKey(Keyboard.KEY_RSHIFT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEnable() {
|
||||
mc.displayGuiScreen(new ClickGUIScreen());
|
||||
setEnabled(false);
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.module.impl.render;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.event.impl.EventRender2D;
|
||||
import cn.xiaozhou233.orangex.font.SmoothFontRenderer;
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.ModuleCategory;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class HUD extends Module {
|
||||
|
||||
private SmoothFontRenderer font;
|
||||
private SmoothFontRenderer listFont;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private int x = 10;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private int y = 10;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private int listOffsetY = 10;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean rainbow = true;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean showList = true;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean listBackground = true;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private int backgroundAlpha = 140;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private int barWidth = 3;
|
||||
|
||||
public HUD() {
|
||||
super("HUD", "Render HUD", ModuleCategory.RENDER);
|
||||
setEnabled(true);
|
||||
}
|
||||
|
||||
private void renderLogo() {
|
||||
font.drawString("Orange",x,y,0xFFFFA500);
|
||||
font.drawString("X",x + font.getStringWidth("Orange"),y,getRainbow(1500));
|
||||
}
|
||||
|
||||
private void renderList() {
|
||||
if (!showList)
|
||||
return;
|
||||
|
||||
List<Module> modules =
|
||||
OrangeX.getInstance()
|
||||
.getModuleManager()
|
||||
.getModules()
|
||||
.stream()
|
||||
.filter(Module::isEnabled)
|
||||
.sorted(Comparator.comparingDouble(m -> -listFont.getStringWidth(m.getName())))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
int lineHeight = (int) listFont.getStringHeight("LOL");
|
||||
int listY = y + (int) font.getStringHeight("Orange") + listOffsetY;
|
||||
|
||||
int height = modules.size() * lineHeight;
|
||||
int width = 0;
|
||||
|
||||
for (Module module : modules) {
|
||||
width = (int) Math.max(width,listFont.getStringWidth(module.getName()));
|
||||
}
|
||||
|
||||
width += 12;
|
||||
|
||||
if (listBackground) {
|
||||
Gui.drawRect(
|
||||
x - 5,
|
||||
listY - 3,
|
||||
x + width,
|
||||
listY + height + 3,
|
||||
(backgroundAlpha << 24)
|
||||
);
|
||||
|
||||
for (int i = 0; i < height + 6; i++) {
|
||||
Gui.drawRect(
|
||||
x - 5,
|
||||
listY - 3 + i,
|
||||
x - 5 + barWidth,
|
||||
listY - 2 + i,
|
||||
getRainbow(i * 20)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
|
||||
for (Module module : modules) {
|
||||
int color = rainbow ? getRainbow(index * 350) : 0xFFFFFFFF;
|
||||
|
||||
listFont.drawString(module.getName(),x + 5,listY,color);
|
||||
|
||||
listY += lineHeight;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onRender2D(EventRender2D event) {
|
||||
if (font == null) {
|
||||
font = OrangeX.getInstance().getStbFontManager().getJelloMedium(44);
|
||||
listFont = OrangeX.getInstance().getStbFontManager().getProxima(22);
|
||||
}
|
||||
|
||||
renderLogo();
|
||||
renderList();
|
||||
}
|
||||
|
||||
private int getRainbow(long offset) {
|
||||
float hue = ((System.currentTimeMillis() + offset) % 8000L) / 8000.0f;
|
||||
return Color.HSBtoRGB(hue,0.7f,1.0f);
|
||||
}
|
||||
}
|
||||
@@ -1,191 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.module.impl.render;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.event.impl.EventRender2D;
|
||||
import cn.xiaozhou233.orangex.event.impl.EventRender3D;
|
||||
import cn.xiaozhou233.orangex.font.SmoothFontRenderer;
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.ModuleCategory;
|
||||
import cn.xiaozhou233.orangex.module.option.impl.BooleanOption;
|
||||
import cn.xiaozhou233.orangex.module.option.impl.ColorOption;
|
||||
import cn.xiaozhou233.orangex.module.option.impl.IntOption;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class NameTag extends Module {
|
||||
private SmoothFontRenderer font;
|
||||
private final IntBuffer viewport = BufferUtils.createIntBuffer(16);
|
||||
private final FloatBuffer modelview = BufferUtils.createFloatBuffer(16);
|
||||
private final FloatBuffer projection = BufferUtils.createFloatBuffer(16);
|
||||
private final FloatBuffer screenCoords = BufferUtils.createFloatBuffer(3);
|
||||
private final List<NametagEntry> renderQueue = new ArrayList<>();
|
||||
|
||||
public NameTag() {
|
||||
super("NameTag", "Render name tag", ModuleCategory.RENDER);
|
||||
addOption(new BooleanOption("Render Players", "Render players", this, true));
|
||||
addOption(new BooleanOption("Render Self", "Render self", this, false));
|
||||
addOption(new BooleanOption("Show Health", "Show health", this, true));
|
||||
addOption(new BooleanOption("Background", "Show background", this, true));
|
||||
addOption(new IntOption("Font Size", "Font size", this, 18, 12, 30, 2));
|
||||
addOption(new ColorOption("Text Color", "Text color", this, 0xFFFFFFFF));
|
||||
addOption(new ColorOption("Background Color", "Background color", this, 0x80000000));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onRender3D(EventRender3D event) {
|
||||
if (mc.theWorld == null || mc.thePlayer == null) return;
|
||||
|
||||
renderQueue.clear();
|
||||
|
||||
BooleanOption renderPlayers = getOption("Render Players", BooleanOption.class);
|
||||
BooleanOption renderSelf = getOption("Render Self", BooleanOption.class);
|
||||
BooleanOption showHealth = getOption("Show Health", BooleanOption.class);
|
||||
|
||||
GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelview);
|
||||
GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projection);
|
||||
GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);
|
||||
|
||||
for (Object obj : mc.theWorld.loadedEntityList) {
|
||||
if (!(obj instanceof EntityPlayer)) continue;
|
||||
EntityPlayer player = (EntityPlayer) obj;
|
||||
|
||||
if (player == mc.thePlayer && !renderSelf.getValue()) continue;
|
||||
if (player != mc.thePlayer && !renderPlayers.getValue()) continue;
|
||||
if (player.isDead) continue;
|
||||
|
||||
double x = player.lastTickPosX + (player.posX - player.lastTickPosX) * event.getPartialTicks();
|
||||
double y = player.lastTickPosY + (player.posY - player.lastTickPosY) * event.getPartialTicks();
|
||||
double z = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.getPartialTicks();
|
||||
|
||||
float height = player.height + 0.5f;
|
||||
|
||||
project(
|
||||
(float) (x - mc.getRenderManager().viewerPosX),
|
||||
(float) (y - mc.getRenderManager().viewerPosY + height),
|
||||
(float) (z - mc.getRenderManager().viewerPosZ),
|
||||
modelview, projection, viewport, screenCoords
|
||||
);
|
||||
|
||||
float screenZ = screenCoords.get(2);
|
||||
if (screenZ >= 1.0f) continue;
|
||||
|
||||
int scaleFactor = new ScaledResolution(mc).getScaleFactor();
|
||||
float screenX = (float) Math.floor(screenCoords.get(0) / scaleFactor);
|
||||
float screenY = (float) Math.floor((mc.displayHeight - screenCoords.get(1)) / scaleFactor);
|
||||
|
||||
String name = player.getDisplayName().getFormattedText();
|
||||
String healthText = "";
|
||||
|
||||
if (showHealth.getValue()) {
|
||||
float health = player.getHealth();
|
||||
float maxHealth = player.getMaxHealth();
|
||||
String healthColor = health > maxHealth * 0.5f ? "\u00a7a" :
|
||||
health > maxHealth * 0.25f ? "\u00a7e" : "\u00a7c";
|
||||
healthText = " " + healthColor + "[" + (int) Math.ceil(health) + "/" + (int) Math.ceil(maxHealth) + "]";
|
||||
}
|
||||
|
||||
String fullText = name + healthText;
|
||||
renderQueue.add(new NametagEntry(fullText, screenX, screenY));
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onRender2D(EventRender2D event) {
|
||||
if (renderQueue.isEmpty()) return;
|
||||
|
||||
IntOption fontSize = getOption("Font Size", IntOption.class);
|
||||
int size = fontSize.getValue();
|
||||
if (font == null || font.getFontSize() != size) {
|
||||
font = OrangeX.getInstance().getStbFontManager().getProxima(size);
|
||||
}
|
||||
|
||||
BooleanOption showBackground = getOption("Background", BooleanOption.class);
|
||||
ColorOption textColor = getOption("Text Color", ColorOption.class);
|
||||
ColorOption bgColor = getOption("Background Color", ColorOption.class);
|
||||
|
||||
for (NametagEntry entry : renderQueue) {
|
||||
String fullText = entry.text;
|
||||
double textWidth = font.getStringWidth(fullText);
|
||||
double textHeight = font.getStringHeight(fullText);
|
||||
|
||||
double renderX = entry.screenX - textWidth / 2;
|
||||
double renderY = entry.screenY - textHeight;
|
||||
|
||||
if (showBackground.getValue()) {
|
||||
GlStateManager.disableTexture2D();
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
|
||||
int bg = bgColor.getValue();
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
GL11.glColor4f(
|
||||
(float) (bg >> 16 & 0xFF) / 255.0f,
|
||||
(float) (bg >> 8 & 0xFF) / 255.0f,
|
||||
(float) (bg & 0xFF) / 255.0f,
|
||||
(float) (bg >> 24 & 0xFF) / 255.0f
|
||||
);
|
||||
double bw = textWidth / 2 + 3;
|
||||
double bh = textHeight + 1;
|
||||
GL11.glVertex2d(entry.screenX - bw, renderY - 1);
|
||||
GL11.glVertex2d(entry.screenX - bw, renderY + bh);
|
||||
GL11.glVertex2d(entry.screenX + bw, renderY + bh);
|
||||
GL11.glVertex2d(entry.screenX + bw, renderY - 1);
|
||||
GL11.glEnd();
|
||||
GlStateManager.disableBlend();
|
||||
GlStateManager.enableTexture2D();
|
||||
}
|
||||
|
||||
font.renderString(fullText, renderX + 0.5, renderY + 0.5, 0x80000000, false);
|
||||
font.renderString(fullText, renderX, renderY, textColor.getValue(), false);
|
||||
}
|
||||
|
||||
renderQueue.clear();
|
||||
}
|
||||
|
||||
private static void project(float x, float y, float z,
|
||||
FloatBuffer modelview, FloatBuffer projection,
|
||||
IntBuffer viewport, FloatBuffer screenCoords) {
|
||||
float[] v = new float[4];
|
||||
float[] c = new float[4];
|
||||
|
||||
v[0] = modelview.get(0) * x + modelview.get(4) * y + modelview.get(8) * z + modelview.get(12);
|
||||
v[1] = modelview.get(1) * x + modelview.get(5) * y + modelview.get(9) * z + modelview.get(13);
|
||||
v[2] = modelview.get(2) * x + modelview.get(6) * y + modelview.get(10) * z + modelview.get(14);
|
||||
v[3] = modelview.get(3) * x + modelview.get(7) * y + modelview.get(11) * z + modelview.get(15);
|
||||
|
||||
c[0] = projection.get(0) * v[0] + projection.get(4) * v[1] + projection.get(8) * v[2] + projection.get(12) * v[3];
|
||||
c[1] = projection.get(1) * v[0] + projection.get(5) * v[1] + projection.get(9) * v[2] + projection.get(13) * v[3];
|
||||
c[2] = projection.get(2) * v[0] + projection.get(6) * v[1] + projection.get(10) * v[2] + projection.get(14) * v[3];
|
||||
c[3] = projection.get(3) * v[0] + projection.get(7) * v[1] + projection.get(11) * v[2] + projection.get(15) * v[3];
|
||||
|
||||
if (c[3] == 0.0f) return;
|
||||
|
||||
float ndcX = c[0] / c[3];
|
||||
float ndcY = c[1] / c[3];
|
||||
float ndcZ = c[2] / c[3];
|
||||
|
||||
screenCoords.put(0, viewport.get(0) + viewport.get(2) * (ndcX + 1.0f) / 2.0f);
|
||||
screenCoords.put(1, viewport.get(1) + viewport.get(3) * (ndcY + 1.0f) / 2.0f);
|
||||
screenCoords.put(2, (ndcZ + 1.0f) / 2.0f);
|
||||
}
|
||||
|
||||
private static class NametagEntry {
|
||||
final String text;
|
||||
final float screenX;
|
||||
final float screenY;
|
||||
|
||||
NametagEntry(String text, float screenX, float screenY) {
|
||||
this.text = text;
|
||||
this.screenX = screenX;
|
||||
this.screenY = screenY;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.module.option;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import com.google.gson.JsonElement;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
public abstract class Option<T> {
|
||||
protected final String name;
|
||||
protected final String description;
|
||||
protected final Module parent;
|
||||
@Setter
|
||||
protected T value;
|
||||
protected final T defaultValue;
|
||||
|
||||
public Option(String name, String description, Module parent, T defaultValue) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.parent = parent;
|
||||
this.defaultValue = defaultValue;
|
||||
this.value = defaultValue;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.value = defaultValue;
|
||||
}
|
||||
|
||||
public abstract JsonElement serialize();
|
||||
public abstract void deserialize(JsonElement element);
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.module.option;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OptionSerializer {
|
||||
public static JsonObject toJson(List<Option<?>> options) {
|
||||
JsonObject json = new JsonObject();
|
||||
for (Option<?> option : options) {
|
||||
json.add(option.getName(), option.serialize());
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
public static void fromJson(JsonObject json, List<Option<?>> options) {
|
||||
if (json == null) return;
|
||||
for (Option<?> option : options) {
|
||||
JsonElement element = json.get(option.getName());
|
||||
if (element != null) {
|
||||
option.deserialize(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.module.option.impl;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.option.Option;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
public class BooleanOption extends Option<Boolean> {
|
||||
public BooleanOption(String name, String description, Module parent, Boolean defaultValue) {
|
||||
super(name, description, parent, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize() {
|
||||
return new JsonPrimitive(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(JsonElement element) {
|
||||
this.value = element.getAsBoolean();
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.module.option.impl;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.option.Option;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
public class ColorOption extends Option<Integer> {
|
||||
public ColorOption(String name, String description, Module parent, Integer defaultValue) {
|
||||
super(name, description, parent, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize() {
|
||||
return new JsonPrimitive(String.format("0x%08X", value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(JsonElement element) {
|
||||
String raw = element.getAsString();
|
||||
if (raw.startsWith("0x") || raw.startsWith("0X")) {
|
||||
this.value = (int) Long.parseLong(raw.substring(2), 16);
|
||||
} else {
|
||||
this.value = Integer.parseUnsignedInt(raw);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.module.option.impl;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.option.Option;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class DoubleOption extends Option<Double> {
|
||||
private final double min;
|
||||
private final double max;
|
||||
private final double step;
|
||||
private final int precision;
|
||||
|
||||
public DoubleOption(String name, String description, Module parent,
|
||||
Double defaultValue, double min, double max, double step, int precision) {
|
||||
super(name, description, parent, clamp(defaultValue, min, max));
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.step = step;
|
||||
this.precision = precision;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Double value) {
|
||||
double clamped = clamp(value, min, max);
|
||||
double stepped = Math.round(clamped / step) * step;
|
||||
double factor = Math.pow(10, precision);
|
||||
this.value = Math.round(stepped * factor) / factor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize() {
|
||||
return new JsonPrimitive(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(JsonElement element) {
|
||||
setValue(element.getAsDouble());
|
||||
}
|
||||
|
||||
private static double clamp(double v, double min, double max) {
|
||||
return Math.min(max, Math.max(min, v));
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.module.option.impl;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.option.Option;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class IntOption extends Option<Integer> {
|
||||
private final int min;
|
||||
private final int max;
|
||||
private final int step;
|
||||
|
||||
public IntOption(String name, String description, Module parent,
|
||||
Integer defaultValue, int min, int max, int step) {
|
||||
super(name, description, parent, clamp(defaultValue, min, max));
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.step = step;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Integer value) {
|
||||
this.value = clamp(value, min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize() {
|
||||
return new JsonPrimitive(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(JsonElement element) {
|
||||
setValue(element.getAsInt());
|
||||
}
|
||||
|
||||
private static int clamp(int v, int min, int max) {
|
||||
return Math.min(max, Math.max(min, v));
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.module.option.impl;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.option.Option;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Getter
|
||||
public class ModeOption extends Option<String> {
|
||||
private final String[] modes;
|
||||
|
||||
public ModeOption(String name, String description, Module parent,
|
||||
String defaultValue, String... modes) {
|
||||
super(name, description, parent, defaultValue);
|
||||
this.modes = modes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String value) {
|
||||
for (String mode : modes) {
|
||||
if (mode.equalsIgnoreCase(value)) {
|
||||
this.value = mode;
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.value = modes.length > 0 ? modes[0] : value;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
for (int i = 0; i < modes.length; i++) {
|
||||
if (modes[i].equals(value)) return i;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void cycle() {
|
||||
int next = (getIndex() + 1) % modes.length;
|
||||
this.value = modes[next];
|
||||
}
|
||||
|
||||
public void cycleReverse() {
|
||||
int prev = (getIndex() - 1 + modes.length) % modes.length;
|
||||
this.value = modes[prev];
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize() {
|
||||
return new JsonPrimitive(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(JsonElement element) {
|
||||
setValue(element.getAsString());
|
||||
}
|
||||
|
||||
public void next() {
|
||||
|
||||
int index = getIndex();
|
||||
|
||||
index++;
|
||||
|
||||
if(index >= modes.length)
|
||||
index = 0;
|
||||
|
||||
setValue(modes[index]);
|
||||
}
|
||||
|
||||
|
||||
public void previous() {
|
||||
|
||||
int index = getIndex();
|
||||
|
||||
index--;
|
||||
|
||||
if(index < 0)
|
||||
index = modes.length - 1;
|
||||
|
||||
setValue(modes[index]);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.module.option.impl;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.option.Option;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
public class StringOption extends Option<String> {
|
||||
private final int maxLength;
|
||||
|
||||
public StringOption(String name, String description, Module parent,
|
||||
String defaultValue, int maxLength) {
|
||||
super(name, description, parent, defaultValue);
|
||||
this.maxLength = maxLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String value) {
|
||||
if (maxLength > 0 && value.length() > maxLength) {
|
||||
this.value = value.substring(0, maxLength);
|
||||
} else {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize() {
|
||||
return new JsonPrimitive(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(JsonElement element) {
|
||||
setValue(element.getAsString());
|
||||
}
|
||||
}
|
||||
@@ -1,222 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.ModuleCategory;
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.component.impl.ModuleButton;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ClickGUIScreen extends GuiScreen {
|
||||
|
||||
private final List<Panel> panels = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
panels.clear();
|
||||
|
||||
int x = 20;
|
||||
int y = 30;
|
||||
int panelWidth = 120;
|
||||
int gap = 20;
|
||||
int rowHeight = 30;
|
||||
|
||||
for (ModuleCategory category : ModuleCategory.values()) {
|
||||
List<Module> categoryModules = OrangeX.getInstance()
|
||||
.getModuleManager()
|
||||
.getModulesByCategory(category);
|
||||
|
||||
if (categoryModules.isEmpty())
|
||||
continue;
|
||||
|
||||
if (x + panelWidth > this.width) {
|
||||
x = 20;
|
||||
y += 300 + rowHeight;
|
||||
}
|
||||
|
||||
Panel panel = new Panel(
|
||||
category,
|
||||
x,
|
||||
y,
|
||||
panelWidth,
|
||||
20
|
||||
);
|
||||
|
||||
int moduleY = 20;
|
||||
|
||||
for (Module module : categoryModules) {
|
||||
panel.addComponent(
|
||||
new ModuleButton(
|
||||
panel,
|
||||
module,
|
||||
0,
|
||||
moduleY
|
||||
)
|
||||
);
|
||||
|
||||
moduleY += 20;
|
||||
}
|
||||
|
||||
panels.add(panel);
|
||||
|
||||
x += panelWidth + gap;
|
||||
}
|
||||
|
||||
loadPanelPositions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(
|
||||
int mouseX,
|
||||
int mouseY,
|
||||
float partialTicks
|
||||
) {
|
||||
Gui.drawRect(0, 0, width, height, new Color(50, 50, 50, 100).getRGB());
|
||||
|
||||
for (Panel panel : panels) {
|
||||
panel.drawScreen(
|
||||
mouseX,
|
||||
mouseY,
|
||||
partialTicks
|
||||
);
|
||||
}
|
||||
|
||||
super.drawScreen(
|
||||
mouseX,
|
||||
mouseY,
|
||||
partialTicks
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(
|
||||
int mouseX,
|
||||
int mouseY,
|
||||
int mouseButton
|
||||
) throws java.io.IOException {
|
||||
for (Panel panel : panels) {
|
||||
panel.mouseClicked(
|
||||
mouseX,
|
||||
mouseY,
|
||||
mouseButton
|
||||
);
|
||||
}
|
||||
|
||||
super.mouseClicked(
|
||||
mouseX,
|
||||
mouseY,
|
||||
mouseButton
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseReleased(
|
||||
int mouseX,
|
||||
int mouseY,
|
||||
int mouseButton
|
||||
) {
|
||||
for (Panel panel : panels) {
|
||||
panel.mouseReleased(
|
||||
mouseX,
|
||||
mouseY,
|
||||
mouseButton
|
||||
);
|
||||
}
|
||||
|
||||
super.mouseReleased(
|
||||
mouseX,
|
||||
mouseY,
|
||||
mouseButton
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(
|
||||
char typedChar,
|
||||
int keyCode
|
||||
) throws java.io.IOException {
|
||||
boolean consumed = false;
|
||||
for (Panel panel : panels) {
|
||||
if (panel.keyTyped(typedChar, keyCode))
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
if (keyCode == 1 && !consumed) {
|
||||
mc.displayGuiScreen(null);
|
||||
}
|
||||
|
||||
if (!consumed) {
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseInput() throws IOException {
|
||||
super.handleMouseInput();
|
||||
int wheel = Mouse.getEventDWheel();
|
||||
if (wheel != 0) {
|
||||
int mx = Mouse.getEventX() * this.width / this.mc.displayWidth;
|
||||
int my = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
|
||||
for (Panel panel : panels) {
|
||||
if (panel.isMouseOver(mx, my)) {
|
||||
panel.mouseWheel(wheel);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesGuiPauseGame() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
savePanelPositions();
|
||||
}
|
||||
|
||||
private void savePanelPositions() {
|
||||
JsonObject data = new JsonObject();
|
||||
|
||||
for (Panel panel : panels) {
|
||||
JsonObject panelObj = new JsonObject();
|
||||
panelObj.addProperty("x", panel.getX());
|
||||
panelObj.addProperty("y", panel.getY());
|
||||
panelObj.addProperty("open", panel.isOpen());
|
||||
data.add(panel.getCategory().getName(), panelObj);
|
||||
}
|
||||
|
||||
OrangeX.getInstance()
|
||||
.getModuleManager()
|
||||
.getConfig()
|
||||
.saveClickGui(data);
|
||||
}
|
||||
|
||||
private void loadPanelPositions() {
|
||||
JsonObject data = OrangeX.getInstance()
|
||||
.getModuleManager()
|
||||
.getConfig()
|
||||
.loadClickGui();
|
||||
|
||||
for (Panel panel : panels) {
|
||||
String categoryName = panel.getCategory().getName();
|
||||
if (data.has(categoryName)) {
|
||||
JsonObject panelObj = data.getAsJsonObject(categoryName);
|
||||
panel.setX(panelObj.get("x").getAsInt());
|
||||
panel.setY(panelObj.get("y").getAsInt());
|
||||
if (panelObj.has("open")) {
|
||||
panel.setOpen(panelObj.get("open").getAsBoolean());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,219 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.module.ModuleCategory;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.component.Component;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public class Panel {
|
||||
|
||||
private final ModuleCategory category;
|
||||
|
||||
@Setter
|
||||
private int x;
|
||||
@Setter
|
||||
private int y;
|
||||
|
||||
private final int width;
|
||||
private final int height;
|
||||
|
||||
private final int headerHeight = 20;
|
||||
|
||||
@Setter
|
||||
private boolean open = true;
|
||||
|
||||
private boolean dragging;
|
||||
|
||||
private int dragX;
|
||||
private int dragY;
|
||||
|
||||
private final List<Component> components = new ArrayList<>();
|
||||
|
||||
private int scrollOffset;
|
||||
|
||||
private static final int MAX_VISIBLE_CONTENT_HEIGHT = 300;
|
||||
|
||||
|
||||
public Panel(ModuleCategory category, int x, int y, int width, int height) {
|
||||
this.category = category;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
if (dragging) {
|
||||
x = mouseX - dragX;
|
||||
y = mouseY - dragY;
|
||||
}
|
||||
|
||||
int contentHeight = calculateContentHeight();
|
||||
int visibleHeight = getVisibleHeight(contentHeight);
|
||||
|
||||
if (open) {
|
||||
Gui.drawRect(x, y + headerHeight, x + width, y + headerHeight + visibleHeight, 0xff1a1a1a);
|
||||
|
||||
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||
ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
|
||||
int scale = sr.getScaleFactor();
|
||||
GL11.glScissor(
|
||||
x * scale,
|
||||
Minecraft.getMinecraft().displayHeight - ((y + headerHeight + visibleHeight) * scale),
|
||||
width * scale,
|
||||
visibleHeight * scale
|
||||
);
|
||||
|
||||
for (Component component : components) {
|
||||
component.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
// Header background
|
||||
boolean headerHovered = isHovered(mouseX, mouseY);
|
||||
Gui.drawRect(x + 1, y + 1, x + width - 1, y + headerHeight, headerHovered ? 0xff353535 : 0xff2d2d2d);
|
||||
|
||||
// Category name
|
||||
OrangeX.getInstance()
|
||||
.getStbFontManager()
|
||||
.getProxima(18)
|
||||
.drawString(category.getName(), x + 5, y + 5, 0xffffffff);
|
||||
|
||||
// Collapse indicator
|
||||
String indicator = open ? "-" : "+";
|
||||
int indicatorX = x + width - 5 -
|
||||
(int) OrangeX.getInstance()
|
||||
.getStbFontManager()
|
||||
.getProxima(18)
|
||||
.getStringWidth(indicator);
|
||||
OrangeX.getInstance()
|
||||
.getStbFontManager()
|
||||
.getProxima(18)
|
||||
.drawString(indicator, indicatorX, y + 5, 0xffaaaaaa);
|
||||
|
||||
// Borders
|
||||
int panelHeight = headerHeight + (open ? visibleHeight : 0);
|
||||
Gui.drawRect(x, y, x + width, y + 1, 0xff3d3d3d);
|
||||
Gui.drawRect(x, y + panelHeight - 1, x + width, y + panelHeight, 0xff3d3d3d);
|
||||
Gui.drawRect(x, y, x + 1, y + panelHeight, 0xff3d3d3d);
|
||||
Gui.drawRect(x + width - 1, y, x + width, y + panelHeight, 0xff3d3d3d);
|
||||
}
|
||||
|
||||
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if (isHovered(mouseX, mouseY)) {
|
||||
if (mouseButton == 0) {
|
||||
dragging = true;
|
||||
dragX = mouseX - x;
|
||||
dragY = mouseY - y;
|
||||
}
|
||||
if (mouseButton == 1) {
|
||||
open = !open;
|
||||
}
|
||||
}
|
||||
|
||||
if (!open)
|
||||
return;
|
||||
|
||||
int visibleHeight = getVisibleHeight(calculateContentHeight());
|
||||
if (mouseY < y + headerHeight || mouseY > y + headerHeight + visibleHeight)
|
||||
return;
|
||||
|
||||
for (Component component : components) {
|
||||
component.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void mouseReleased(int mouseX, int mouseY, int mouseButton) {
|
||||
if (mouseButton == 0)
|
||||
dragging = false;
|
||||
|
||||
for (Component component : components) {
|
||||
component.mouseReleased(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean keyTyped(char typedChar, int keyCode) {
|
||||
boolean consumed = false;
|
||||
for (Component component : components) {
|
||||
if (component.keyTyped(typedChar, keyCode))
|
||||
consumed = true;
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
|
||||
public void mouseWheel(int delta) {
|
||||
if (!open) return;
|
||||
int contentHeight = calculateContentHeight();
|
||||
int visibleHeight = getVisibleHeight(contentHeight);
|
||||
int maxScroll = Math.max(0, contentHeight - visibleHeight);
|
||||
scrollOffset = Math.max(0, Math.min(maxScroll, scrollOffset - delta / 2));
|
||||
}
|
||||
|
||||
|
||||
private int calculateContentHeight() {
|
||||
int total = 0;
|
||||
for (Component component : components) {
|
||||
total += component.getHeight();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
private int getVisibleHeight(int contentHeight) {
|
||||
return Math.min(MAX_VISIBLE_CONTENT_HEIGHT, contentHeight);
|
||||
}
|
||||
|
||||
|
||||
private boolean isHovered(int mouseX, int mouseY) {
|
||||
return mouseX >= x &&
|
||||
mouseX <= x + width &&
|
||||
mouseY >= y &&
|
||||
mouseY <= y + headerHeight;
|
||||
}
|
||||
|
||||
public boolean isMouseOver(int mouseX, int mouseY) {
|
||||
int visibleHeight = getVisibleHeight(calculateContentHeight());
|
||||
int panelHeight = headerHeight + (open ? visibleHeight : 0);
|
||||
return mouseX >= x &&
|
||||
mouseX <= x + width &&
|
||||
mouseY >= y &&
|
||||
mouseY <= y + panelHeight;
|
||||
}
|
||||
|
||||
|
||||
public void addComponent(Component component) {
|
||||
components.add(component);
|
||||
updateLayout();
|
||||
}
|
||||
|
||||
public void updateLayout() {
|
||||
int offset = headerHeight;
|
||||
|
||||
for (Component component : components) {
|
||||
component.setOffsetY(offset);
|
||||
offset += component.getHeight();
|
||||
}
|
||||
|
||||
int contentHeight = calculateContentHeight();
|
||||
int visibleHeight = getVisibleHeight(contentHeight);
|
||||
int maxScroll = Math.max(0, contentHeight - visibleHeight);
|
||||
if (scrollOffset > maxScroll) scrollOffset = maxScroll;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
public abstract class Component {
|
||||
|
||||
protected final Panel parent;
|
||||
|
||||
protected final int offsetX;
|
||||
@Setter
|
||||
protected int offsetY;
|
||||
|
||||
protected final int width;
|
||||
protected int height;
|
||||
|
||||
|
||||
public Component(
|
||||
Panel parent,
|
||||
int offsetX,
|
||||
int offsetY,
|
||||
int width,
|
||||
int height
|
||||
) {
|
||||
this.parent = parent;
|
||||
this.offsetX = offsetX;
|
||||
this.offsetY = offsetY;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
|
||||
public abstract void drawScreen(
|
||||
int mouseX,
|
||||
int mouseY,
|
||||
float partialTicks
|
||||
);
|
||||
|
||||
|
||||
public void mouseClicked(
|
||||
int mouseX,
|
||||
int mouseY,
|
||||
int mouseButton
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void mouseReleased(
|
||||
int mouseX,
|
||||
int mouseY,
|
||||
int mouseButton
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public boolean keyTyped(
|
||||
char typedChar,
|
||||
int keyCode
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public int getX() {
|
||||
return parent.getX() + offsetX;
|
||||
}
|
||||
|
||||
|
||||
public int getY() {
|
||||
return parent.getY() + offsetY - parent.getScrollOffset();
|
||||
}
|
||||
|
||||
|
||||
protected boolean isHovered(
|
||||
int mouseX,
|
||||
int mouseY
|
||||
) {
|
||||
|
||||
return mouseX >= getX()
|
||||
&& mouseX <= getX() + width
|
||||
&& mouseY >= getY()
|
||||
&& mouseY <= getY() + height;
|
||||
}
|
||||
|
||||
|
||||
protected void drawString(
|
||||
String text,
|
||||
int x,
|
||||
int y,
|
||||
int color
|
||||
) {
|
||||
|
||||
OrangeX.getInstance()
|
||||
.getStbFontManager()
|
||||
.getProxima(18)
|
||||
.drawString(
|
||||
text,
|
||||
x,
|
||||
y,
|
||||
color
|
||||
);
|
||||
}
|
||||
}
|
||||
-125
@@ -1,125 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component.impl;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.option.Option;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.component.Component;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.component.option.KeybindComponent;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.component.option.OptionComponent;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.component.option.OptionComponentFactory;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ModuleButton extends Component {
|
||||
|
||||
private final Module module;
|
||||
|
||||
@Getter
|
||||
private boolean expanded;
|
||||
@Getter
|
||||
private final List<OptionComponent> options = new ArrayList<>();
|
||||
|
||||
public ModuleButton(Panel parent, Module module, int offsetX, int offsetY) {
|
||||
super(parent, offsetX, offsetY, 120, 20);
|
||||
|
||||
this.module = module;
|
||||
|
||||
int optionY = 20;
|
||||
|
||||
for (Option<?> option : module.getOptions()) {
|
||||
OptionComponent component =
|
||||
OptionComponentFactory.create(
|
||||
parent,
|
||||
option,
|
||||
offsetX,
|
||||
offsetY + optionY
|
||||
);
|
||||
|
||||
if (component != null)
|
||||
options.add(component);
|
||||
|
||||
optionY += 18;
|
||||
}
|
||||
|
||||
options.add(new KeybindComponent(parent, module, offsetX, offsetY + optionY));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
if (module.isEnabled()) {
|
||||
GlStateManager.resetColor();
|
||||
Gui.drawRect(getX(), getY(), getX() + width, getY() + height, 0xff1a4a2a);
|
||||
}
|
||||
|
||||
drawString(
|
||||
module.getName(),
|
||||
getX() + 5,
|
||||
getY() + 5,
|
||||
0xffffffff
|
||||
);
|
||||
|
||||
if (expanded) {
|
||||
int optionY = 20;
|
||||
for (OptionComponent option : options) {
|
||||
option.setOffsetY(getOffsetY() + optionY);
|
||||
option.drawScreen(mouseX, mouseY, partialTicks);
|
||||
optionY += 18;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if (isHovered(mouseX, mouseY)) {
|
||||
if (mouseButton == 0)
|
||||
module.toggle();
|
||||
|
||||
if (mouseButton == 1) {
|
||||
expanded = !expanded;
|
||||
parent.updateLayout();
|
||||
}
|
||||
}
|
||||
|
||||
if (expanded) {
|
||||
int optionY = 20;
|
||||
for (OptionComponent option : options) {
|
||||
option.setOffsetY(getOffsetY() + optionY);
|
||||
option.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
optionY += 18;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mouseX, int mouseY, int mouseButton) {
|
||||
if (expanded) {
|
||||
for (OptionComponent option : options) {
|
||||
option.mouseReleased(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(char typedChar, int keyCode) {
|
||||
if (expanded) {
|
||||
for (OptionComponent option : options) {
|
||||
if (option.keyTyped(typedChar, keyCode))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
if (!expanded)
|
||||
return 20;
|
||||
|
||||
return 20 + options.size() * 18;
|
||||
}
|
||||
}
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component.option;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.option.impl.BooleanOption;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
|
||||
public class BooleanComponent extends OptionComponent{
|
||||
|
||||
private final BooleanOption option;
|
||||
|
||||
|
||||
public BooleanComponent(
|
||||
Panel parent,
|
||||
BooleanOption option,
|
||||
int offsetX,
|
||||
int offsetY
|
||||
) {
|
||||
super(parent,option,offsetX,offsetY,120,18);
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX,int mouseY,float partialTicks) {
|
||||
drawRect(getX(), getY(), getX() + width, getY() + height, 0xff252525);
|
||||
|
||||
drawString(
|
||||
option.getName(),
|
||||
getX() + 5,
|
||||
getY() + 5,
|
||||
0xffffffff
|
||||
);
|
||||
|
||||
|
||||
drawString(
|
||||
option.getValue() ? "ON" : "OFF",
|
||||
getX() + width - 25,
|
||||
getY() + 5,
|
||||
option.getValue()
|
||||
? 0xff55ffff
|
||||
: 0xffffffff
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX,int mouseY,int mouseButton) {
|
||||
|
||||
if (!isHovered(mouseX,mouseY))
|
||||
return;
|
||||
|
||||
|
||||
if (mouseButton == 0) {
|
||||
option.setValue(!option.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
-89
@@ -1,89 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component.option;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.option.impl.ColorOption;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class ColorComponent extends OptionComponent {
|
||||
|
||||
private final ColorOption option;
|
||||
|
||||
|
||||
public ColorComponent(
|
||||
Panel parent,
|
||||
ColorOption option,
|
||||
int offsetX,
|
||||
int offsetY
|
||||
) {
|
||||
super(parent,option,offsetX,offsetY,120,18);
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX,int mouseY,float partialTicks) {
|
||||
drawRect(getX(), getY(), getX() + width, getY() + height, 0xff252525);
|
||||
|
||||
drawString(
|
||||
option.getName(),
|
||||
getX() + 5,
|
||||
getY() + 5,
|
||||
0xffffffff
|
||||
);
|
||||
|
||||
|
||||
drawRect(
|
||||
getX() + width - 25,
|
||||
getY() + 3,
|
||||
getX() + width - 5,
|
||||
getY() + 15,
|
||||
option.getValue()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX,int mouseY,int mouseButton) {
|
||||
|
||||
if(!isHovered(mouseX,mouseY))
|
||||
return;
|
||||
|
||||
|
||||
if(mouseButton == 0) {
|
||||
|
||||
option.setValue(
|
||||
getNextColor()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int getNextColor() {
|
||||
|
||||
int color = option.getValue();
|
||||
|
||||
float[] hsb =
|
||||
Color.RGBtoHSB(
|
||||
(color >> 16) & 255,
|
||||
(color >> 8) & 255,
|
||||
color & 255,
|
||||
null
|
||||
);
|
||||
|
||||
|
||||
hsb[0] += 0.1f;
|
||||
|
||||
|
||||
if(hsb[0] > 1)
|
||||
hsb[0] = 0;
|
||||
|
||||
|
||||
return Color.HSBtoRGB(
|
||||
hsb[0],
|
||||
hsb[1],
|
||||
hsb[2]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
-66
@@ -1,66 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component.option;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public class KeybindComponent extends OptionComponent {
|
||||
|
||||
private final Module module;
|
||||
private boolean listening;
|
||||
|
||||
public KeybindComponent(Panel parent, Module module, int offsetX, int offsetY) {
|
||||
super(parent, null, offsetX, offsetY, 120, 16);
|
||||
this.module = module;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
drawRect(getX(), getY(), getX() + width, getY() + height, 0xff252525);
|
||||
drawString("Keybind", getX() + 4, getY() + 4, 0xffffffff);
|
||||
|
||||
String keyName;
|
||||
if (listening) {
|
||||
keyName = "...";
|
||||
} else {
|
||||
keyName = module.getKey() != Keyboard.KEY_NONE
|
||||
? Keyboard.getKeyName(module.getKey()) : "NONE";
|
||||
}
|
||||
|
||||
int keyX = getX() + width - 4 -
|
||||
(int) OrangeX.getInstance()
|
||||
.getStbFontManager()
|
||||
.getProxima(18)
|
||||
.getStringWidth(keyName);
|
||||
int keyColor = listening ? 0xff55ffff : 0xffaaaaaa;
|
||||
drawString(keyName, keyX, getY() + 4, keyColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if (!isHovered(mouseX, mouseY)) return;
|
||||
if (mouseButton == 0) {
|
||||
listening = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(char typedChar, int keyCode) {
|
||||
if (!listening) return false;
|
||||
|
||||
if (keyCode == 1) {
|
||||
module.setKey(0);
|
||||
listening = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
module.setKey(keyCode);
|
||||
listening = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mouseX, int mouseY, int mouseButton) {
|
||||
}
|
||||
}
|
||||
-61
@@ -1,61 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component.option;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.option.impl.ModeOption;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
|
||||
public class ModeComponent extends OptionComponent {
|
||||
|
||||
private final ModeOption option;
|
||||
|
||||
|
||||
public ModeComponent(
|
||||
Panel parent,
|
||||
ModeOption option,
|
||||
int offsetX,
|
||||
int offsetY
|
||||
) {
|
||||
super(parent,option,offsetX,offsetY,120,18);
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX,int mouseY,float partialTicks) {
|
||||
drawRect(getX(), getY(), getX() + width, getY() + height, 0xff252525);
|
||||
|
||||
drawString(
|
||||
option.getName(),
|
||||
getX() + 5,
|
||||
getY() + 5,
|
||||
0xffffffff
|
||||
);
|
||||
|
||||
|
||||
drawString(
|
||||
option.getValue(),
|
||||
getX() + width - 45,
|
||||
getY() + 5,
|
||||
0xff55ffff
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX,int mouseY,int mouseButton) {
|
||||
|
||||
if (!isHovered(mouseX,mouseY))
|
||||
return;
|
||||
|
||||
|
||||
if(mouseButton == 0) {
|
||||
|
||||
option.next();
|
||||
}
|
||||
|
||||
|
||||
if(mouseButton == 1) {
|
||||
|
||||
option.previous();
|
||||
}
|
||||
}
|
||||
}
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component.option;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.option.Option;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.component.Component;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
|
||||
@Getter
|
||||
public abstract class OptionComponent extends Component {
|
||||
|
||||
protected final Option<?> option;
|
||||
|
||||
|
||||
public OptionComponent(
|
||||
Panel parent,
|
||||
Option<?> option,
|
||||
int offsetX,
|
||||
int offsetY,
|
||||
int width,
|
||||
int height
|
||||
) {
|
||||
super(parent,offsetX,offsetY,width,height);
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
protected void drawRect(
|
||||
int left,
|
||||
int top,
|
||||
int right,
|
||||
int bottom,
|
||||
int color
|
||||
) {
|
||||
GlStateManager.resetColor();
|
||||
net.minecraft.client.gui.Gui.drawRect(
|
||||
left,
|
||||
top,
|
||||
right,
|
||||
bottom,
|
||||
color
|
||||
);
|
||||
}
|
||||
}
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component.option;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.option.Option;
|
||||
import cn.xiaozhou233.orangex.module.option.impl.*;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
|
||||
public class OptionComponentFactory {
|
||||
|
||||
public static OptionComponent create(
|
||||
Panel panel,
|
||||
Option<?> option,
|
||||
int x,
|
||||
int y
|
||||
) {
|
||||
|
||||
if (option instanceof BooleanOption) {
|
||||
return new BooleanComponent(
|
||||
panel,
|
||||
(BooleanOption) option,
|
||||
x,
|
||||
y
|
||||
);
|
||||
}
|
||||
|
||||
if (option instanceof IntOption) {
|
||||
return new SliderComponent(
|
||||
panel,
|
||||
(IntOption) option,
|
||||
x,
|
||||
y
|
||||
);
|
||||
}
|
||||
|
||||
if (option instanceof DoubleOption) {
|
||||
return new SliderComponent(
|
||||
panel,
|
||||
(DoubleOption) option,
|
||||
x,
|
||||
y
|
||||
);
|
||||
}
|
||||
|
||||
if (option instanceof ModeOption) {
|
||||
return new ModeComponent(
|
||||
panel,
|
||||
(ModeOption) option,
|
||||
x,
|
||||
y
|
||||
);
|
||||
}
|
||||
|
||||
if (option instanceof ColorOption) {
|
||||
return new ColorComponent(
|
||||
panel,
|
||||
(ColorOption) option,
|
||||
x,
|
||||
y
|
||||
);
|
||||
}
|
||||
|
||||
if (option instanceof StringOption) {
|
||||
return new StringComponent(
|
||||
panel,
|
||||
(StringOption) option,
|
||||
x,
|
||||
y
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
-159
@@ -1,159 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component.option;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.option.impl.DoubleOption;
|
||||
import cn.xiaozhou233.orangex.module.option.impl.IntOption;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
|
||||
public class SliderComponent extends OptionComponent {
|
||||
|
||||
private final double min;
|
||||
private final double max;
|
||||
|
||||
private boolean dragging;
|
||||
|
||||
|
||||
public SliderComponent(
|
||||
Panel parent,
|
||||
IntOption option,
|
||||
int offsetX,
|
||||
int offsetY
|
||||
) {
|
||||
super(parent,option,offsetX,offsetY,120,18);
|
||||
|
||||
this.min = option.getMin();
|
||||
this.max = option.getMax();
|
||||
}
|
||||
|
||||
public SliderComponent(
|
||||
Panel parent,
|
||||
DoubleOption option,
|
||||
int offsetX,
|
||||
int offsetY
|
||||
) {
|
||||
super(parent,option,offsetX,offsetY,120,18);
|
||||
|
||||
this.min = option.getMin();
|
||||
this.max = option.getMax();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX,int mouseY,float partialTicks) {
|
||||
drawRect(getX(), getY(), getX() + width, getY() + height, 0xff252525);
|
||||
|
||||
double value = getValue();
|
||||
|
||||
double percent =
|
||||
(value - min) / (max - min);
|
||||
|
||||
|
||||
int barWidth = width - 10;
|
||||
|
||||
|
||||
drawString(
|
||||
option.getName(),
|
||||
getX() + 5,
|
||||
getY() + 3,
|
||||
0xffffffff
|
||||
);
|
||||
|
||||
|
||||
// Background bar
|
||||
drawRect(
|
||||
getX() + 5,
|
||||
getY() + 15,
|
||||
getX() + 5 + barWidth,
|
||||
getY() + 18,
|
||||
0xff555555
|
||||
);
|
||||
|
||||
|
||||
// Value bar
|
||||
drawRect(
|
||||
getX() + 5,
|
||||
getY() + 15,
|
||||
getX() + 5 + (int)(barWidth * percent),
|
||||
getY() + 18,
|
||||
0xff55ffff
|
||||
);
|
||||
|
||||
|
||||
drawString(
|
||||
String.valueOf(value),
|
||||
getX() + width - 25,
|
||||
getY() + 3,
|
||||
0xffaaaaaa
|
||||
);
|
||||
|
||||
|
||||
if(dragging)
|
||||
updateValue(mouseX);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX,int mouseY,int mouseButton) {
|
||||
|
||||
if(mouseButton == 0 && isHovered(mouseX,mouseY)) {
|
||||
dragging = true;
|
||||
updateValue(mouseX);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mouseX,int mouseY,int mouseButton) {
|
||||
|
||||
if(mouseButton == 0)
|
||||
dragging = false;
|
||||
}
|
||||
|
||||
|
||||
private void updateValue(int mouseX) {
|
||||
|
||||
double percent =
|
||||
(mouseX - (getX() + 5))
|
||||
/ (double)(width - 10);
|
||||
|
||||
|
||||
percent = Math.max(0,Math.min(1,percent));
|
||||
|
||||
|
||||
double value =
|
||||
min + (max - min) * percent;
|
||||
|
||||
|
||||
if(option instanceof IntOption) {
|
||||
|
||||
((IntOption) option)
|
||||
.setValue((int)value);
|
||||
|
||||
} else if(option instanceof DoubleOption) {
|
||||
|
||||
((DoubleOption) option)
|
||||
.setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private double getValue() {
|
||||
|
||||
if(option instanceof IntOption) {
|
||||
|
||||
return ((IntOption) option)
|
||||
.getValue();
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(option instanceof DoubleOption) {
|
||||
|
||||
return ((DoubleOption) option)
|
||||
.getValue();
|
||||
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
-149
@@ -1,149 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component.option;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.module.option.impl.StringOption;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
|
||||
|
||||
public class StringComponent extends OptionComponent {
|
||||
|
||||
private final StringOption option;
|
||||
|
||||
private boolean typing;
|
||||
|
||||
|
||||
public StringComponent(
|
||||
Panel parent,
|
||||
StringOption option,
|
||||
int offsetX,
|
||||
int offsetY
|
||||
) {
|
||||
super(parent,option,offsetX,offsetY,120,18);
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX,int mouseY,float partialTicks) {
|
||||
drawRect(getX(), getY(), getX() + width, getY() + height, 0xff252525);
|
||||
|
||||
drawString(
|
||||
option.getName(),
|
||||
getX() + 5,
|
||||
getY() + 5,
|
||||
0xffffffff
|
||||
);
|
||||
|
||||
|
||||
String value = option.getValue();
|
||||
|
||||
if(typing)
|
||||
value += "_";
|
||||
|
||||
|
||||
int maxValueWidth = 50;
|
||||
int valueWidth = (int) OrangeX.getInstance()
|
||||
.getStbFontManager()
|
||||
.getProxima(18)
|
||||
.getStringWidth(value);
|
||||
|
||||
if (valueWidth > maxValueWidth) {
|
||||
while ((int) OrangeX.getInstance()
|
||||
.getStbFontManager()
|
||||
.getProxima(18)
|
||||
.getStringWidth("..." + value) > maxValueWidth
|
||||
&& value.length() > 0) {
|
||||
value = value.substring(1);
|
||||
}
|
||||
value = "..." + value;
|
||||
}
|
||||
|
||||
|
||||
drawString(
|
||||
value,
|
||||
getX() + width - 5 - maxValueWidth,
|
||||
getY() + 5,
|
||||
typing
|
||||
? 0xff55ffff
|
||||
: 0xffaaaaaa
|
||||
);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseClicked(
|
||||
int mouseX,
|
||||
int mouseY,
|
||||
int mouseButton
|
||||
) {
|
||||
if (typing && !isHovered(mouseX, mouseY)) {
|
||||
typing = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isHovered(mouseX,mouseY))
|
||||
return;
|
||||
|
||||
if(mouseButton == 0) {
|
||||
typing = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(
|
||||
char typedChar,
|
||||
int keyCode
|
||||
) {
|
||||
|
||||
if(!typing)
|
||||
return false;
|
||||
|
||||
|
||||
// Backspace
|
||||
if(keyCode == 14) {
|
||||
|
||||
String value = option.getValue();
|
||||
|
||||
if(value.length() > 0) {
|
||||
option.setValue(
|
||||
value.substring(
|
||||
0,
|
||||
value.length() - 1
|
||||
)
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Enter
|
||||
if(keyCode == 28) {
|
||||
typing = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if(Character.isISOControl(typedChar))
|
||||
return true;
|
||||
|
||||
|
||||
option.setValue(
|
||||
option.getValue() + typedChar
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseReleased(
|
||||
int mouseX,
|
||||
int mouseY,
|
||||
int mouseButton
|
||||
) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.utils;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class IOUtils {
|
||||
|
||||
public static byte[] toByteArray(InputStream input) throws IOException {
|
||||
if (input == null) {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
byte[] buffer = new byte[8192]; // 8KB buffer
|
||||
int len;
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
|
||||
while ((len = input.read(buffer)) != -1) {
|
||||
output.write(buffer, 0, len);
|
||||
}
|
||||
|
||||
return output.toByteArray();
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.utils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public final class JuiceAgentFacade {
|
||||
|
||||
private static final Class<?> JL;
|
||||
private static final Method GET_CLASS_BYTES;
|
||||
private static final Method REDEFINE_CLASS;
|
||||
private static final Method GET_LOADED_CLASSES;
|
||||
private static final Method RETRANSFORM_CLASS;
|
||||
|
||||
static {
|
||||
try {
|
||||
JL = Class.forName(
|
||||
"cn.xiaozhou233.juiceagent.api.JuiceAgent",
|
||||
true,
|
||||
ClassLoader.getSystemClassLoader()
|
||||
);
|
||||
|
||||
GET_CLASS_BYTES = JL.getMethod("getClassBytes", Class.class);
|
||||
REDEFINE_CLASS = JL.getMethod(
|
||||
"redefineClass",
|
||||
Class.class,
|
||||
byte[].class,
|
||||
int.class
|
||||
);
|
||||
GET_LOADED_CLASSES = JL.getMethod("getLoadedClasses");
|
||||
RETRANSFORM_CLASS = JL.getMethod("retransformClass", Class.class, byte[].class, int.class);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to init JuiceFacade", e);
|
||||
}
|
||||
}
|
||||
|
||||
private JuiceAgentFacade() {}
|
||||
|
||||
public static byte[] getClassBytes(Class<?> clazz) {
|
||||
try {
|
||||
return (byte[]) GET_CLASS_BYTES.invoke(null, clazz);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean redefineClass(Class<?> clazz, byte[] bytes) {
|
||||
try {
|
||||
return (boolean) REDEFINE_CLASS.invoke(null, clazz, bytes, bytes.length);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<?>[] getLoadedClasses() {
|
||||
try {
|
||||
return (Class<?>[]) GET_LOADED_CLASSES.invoke(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean retransformClass(Class<?> clazz, byte[] bytes) {
|
||||
try {
|
||||
return (boolean) RETRANSFORM_CLASS.invoke(null, clazz, bytes, bytes.length);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
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