mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
Compare commits
2
Commits
8183eae9d1
...
51a232d7ac
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51a232d7ac | ||
|
|
29eb7609e9 |
No files matched your search
@@ -13,6 +13,7 @@ import cn.xiaozhou233.orangex.runtime.RuntimeDetector;
|
|||||||
import cn.xiaozhou233.orangex.runtime.RuntimeInfo;
|
import cn.xiaozhou233.orangex.runtime.RuntimeInfo;
|
||||||
import cn.xiaozhou233.orangex.wrapper.MinecraftFactory;
|
import cn.xiaozhou233.orangex.wrapper.MinecraftFactory;
|
||||||
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
|
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.api.WorldView;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
@@ -35,6 +36,8 @@ public class OrangeX {
|
|||||||
private ModuleManager moduleManager = new ModuleManager();
|
private ModuleManager moduleManager = new ModuleManager();
|
||||||
@Getter
|
@Getter
|
||||||
private Minecraft minecraft;
|
private Minecraft minecraft;
|
||||||
|
@Getter
|
||||||
|
private WorldView worldView;
|
||||||
|
|
||||||
public OrangeX() {
|
public OrangeX() {
|
||||||
System.out.println("OrangeX <init> start!");
|
System.out.println("OrangeX <init> start!");
|
||||||
@@ -52,6 +55,17 @@ public class OrangeX {
|
|||||||
this.minecraft = minecraft;
|
this.minecraft = minecraft;
|
||||||
System.out.println(minecraft.getMinecraft());
|
System.out.println(minecraft.getMinecraft());
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.worldView = MinecraftFactory.createWorld(
|
||||||
|
runtimeInfo, MappingManager.getResolver(), minecraft);
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
// The client must keep running even when a version cannot expose
|
||||||
|
// world data; world-dependent modules simply stay inactive.
|
||||||
|
System.err.println("[OrangeX] World wrapper unavailable: "
|
||||||
|
+ throwable.getMessage());
|
||||||
|
throwable.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
render2DManager = new Render2DManager(
|
render2DManager = new Render2DManager(
|
||||||
runtimeInfo, MappingManager.getResolver(), minecraft.getMinecraft());
|
runtimeInfo, MappingManager.getResolver(), minecraft.getMinecraft());
|
||||||
System.out.println("[OrangeX] Font backend: " + render2DManager.getBackendName());
|
System.out.println("[OrangeX] Font backend: " + render2DManager.getBackendName());
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package cn.xiaozhou233.orangex.modules;
|
|||||||
import cn.xiaozhou233.orangex.OrangeX;
|
import cn.xiaozhou233.orangex.OrangeX;
|
||||||
import cn.xiaozhou233.orangex.event.impl.EventKey;
|
import cn.xiaozhou233.orangex.event.impl.EventKey;
|
||||||
import cn.xiaozhou233.orangex.modules.impl.render.ClickGUI;
|
import cn.xiaozhou233.orangex.modules.impl.render.ClickGUI;
|
||||||
|
import cn.xiaozhou233.orangex.modules.impl.render.ESP;
|
||||||
import cn.xiaozhou233.orangex.modules.impl.render.HUD;
|
import cn.xiaozhou233.orangex.modules.impl.render.HUD;
|
||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ public class ModuleManager {
|
|||||||
public void registerAll() {
|
public void registerAll() {
|
||||||
register(new HUD());
|
register(new HUD());
|
||||||
register(new ClickGUI());
|
register(new ClickGUI());
|
||||||
|
register(new ESP());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(Module module) {
|
public void register(Module module) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import cn.xiaozhou233.orangex.input.ClientInput;
|
|||||||
import cn.xiaozhou233.orangex.input.KeyCodes;
|
import cn.xiaozhou233.orangex.input.KeyCodes;
|
||||||
import cn.xiaozhou233.orangex.modules.Module;
|
import cn.xiaozhou233.orangex.modules.Module;
|
||||||
import cn.xiaozhou233.orangex.modules.ModuleCategory;
|
import cn.xiaozhou233.orangex.modules.ModuleCategory;
|
||||||
|
import cn.xiaozhou233.orangex.ui.clickgui.ClickGuiRender;
|
||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,6 +34,7 @@ public class ClickGUI extends Module {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
justEnabled = true;
|
justEnabled = true;
|
||||||
|
ClickGuiRender.reset();
|
||||||
// Defer opening to EventTickPost: opening inside the keyboard callback
|
// Defer opening to EventTickPost: opening inside the keyboard callback
|
||||||
// would let the same RSHIFT event reach the new screen and close it.
|
// would let the same RSHIFT event reach the new screen and close it.
|
||||||
ClientInput.requestOpen();
|
ClientInput.requestOpen();
|
||||||
@@ -41,6 +43,7 @@ public class ClickGUI extends Module {
|
|||||||
@Override
|
@Override
|
||||||
protected void onDisable() {
|
protected void onDisable() {
|
||||||
justEnabled = false;
|
justEnabled = false;
|
||||||
|
ClickGuiRender.reset();
|
||||||
ClientInput.requestClose();
|
ClientInput.requestClose();
|
||||||
super.onDisable();
|
super.onDisable();
|
||||||
}
|
}
|
||||||
@@ -65,8 +68,6 @@ public class ClickGUI extends Module {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: draw the ClickGUI here.
|
ClickGuiRender.render(event);
|
||||||
// Cursor: ClientInput.getMouseX() / getMouseY()
|
|
||||||
// Buttons: ClientInput.isLeftDown() / isRightDown() / isMiddleDown()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,243 @@
|
|||||||
|
package cn.xiaozhou233.orangex.modules.impl.render;
|
||||||
|
|
||||||
|
import cn.xiaozhou233.orangex.OrangeX;
|
||||||
|
import cn.xiaozhou233.orangex.event.impl.EventRender2D;
|
||||||
|
import cn.xiaozhou233.orangex.modules.Module;
|
||||||
|
import cn.xiaozhou233.orangex.modules.ModuleCategory;
|
||||||
|
import cn.xiaozhou233.orangex.render.api.FontRenderer;
|
||||||
|
import cn.xiaozhou233.orangex.render.api.Render2D;
|
||||||
|
import cn.xiaozhou233.orangex.value.BooleanValue;
|
||||||
|
import cn.xiaozhou233.orangex.value.ModeValue;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.api.WorldView;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.common.EntityTarget;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.common.ScreenPoint;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.common.Vec3;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.common.WorldSnapshot;
|
||||||
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2D ESP: projects players to the screen and draws a box, name, distance and
|
||||||
|
* health bar around each one.
|
||||||
|
*
|
||||||
|
* <p>All drawing happens in GUI pixel space through {@link Render2D}, so it
|
||||||
|
* works with both the 1.8.9 and the modern font backends. World data comes
|
||||||
|
* from the cross-version {@link WorldView} wrapper, never from game classes
|
||||||
|
* directly.</p>
|
||||||
|
*/
|
||||||
|
public class ESP extends Module {
|
||||||
|
|
||||||
|
private static final float NAME_FONT_SIZE = 9.0F;
|
||||||
|
|
||||||
|
private static final double NAME_GAP = 2.0D;
|
||||||
|
private static final double BOX_PADDING = 0.5D;
|
||||||
|
private static final double CORNER_LENGTH = 4.0D;
|
||||||
|
private static final double HEALTH_BAR_WIDTH = 2.0D;
|
||||||
|
private static final double HEALTH_BAR_GAP = 2.0D;
|
||||||
|
|
||||||
|
private static final double MIN_BOX_HEIGHT = 2.0D;
|
||||||
|
private static final double MIN_BOX_WIDTH = 2.0D;
|
||||||
|
|
||||||
|
private static final int ORANGE = 0xFFFF8A00;
|
||||||
|
private static final int FILL_ALPHA = 32;
|
||||||
|
private static final int HEALTH_BACKGROUND = 0x80000000;
|
||||||
|
|
||||||
|
private final BooleanValue box = addBoolean("Box", true);
|
||||||
|
private final BooleanValue fill = addBoolean("Fill", true);
|
||||||
|
private final BooleanValue health = addBoolean("Health", true);
|
||||||
|
private final BooleanValue name = addBoolean("Name", true);
|
||||||
|
private final BooleanValue distance = addBoolean("Distance", true);
|
||||||
|
private final ModeValue style = addMode("Style", "Box", "Box", "Corners");
|
||||||
|
private final ModeValue colorMode = addMode("Color", "Orange", "Orange", "Health", "Rainbow");
|
||||||
|
|
||||||
|
public ESP() {
|
||||||
|
super("ESP", ModuleCategory.RENDER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onRender2D(EventRender2D event) {
|
||||||
|
if (!event.isInWorld()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
WorldView world = OrangeX.getInstance().getWorldView();
|
||||||
|
if (world == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
WorldSnapshot snapshot;
|
||||||
|
try {
|
||||||
|
snapshot = world.snapshot();
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
// A broken wrapper must not kill the whole HUD frame.
|
||||||
|
System.err.println("[ESP] Failed to read world snapshot: "
|
||||||
|
+ throwable.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (snapshot == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Render2D graphics = event.getRender2D();
|
||||||
|
int screenWidth = graphics.getWidth();
|
||||||
|
int screenHeight = graphics.getHeight();
|
||||||
|
|
||||||
|
FontRenderer font = graphics.getFont(NAME_FONT_SIZE);
|
||||||
|
double fontHeight = font.getStringHeight();
|
||||||
|
|
||||||
|
List<EntityTarget> targets = snapshot.getTargets();
|
||||||
|
for (int index = 0; index < targets.size(); index++) {
|
||||||
|
EntityTarget target = targets.get(index);
|
||||||
|
renderTarget(graphics, font, fontHeight, snapshot, target, index,
|
||||||
|
screenWidth, screenHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderTarget(Render2D graphics,
|
||||||
|
FontRenderer font,
|
||||||
|
double fontHeight,
|
||||||
|
WorldSnapshot snapshot,
|
||||||
|
EntityTarget target,
|
||||||
|
int index,
|
||||||
|
int screenWidth,
|
||||||
|
int screenHeight) {
|
||||||
|
if (target.getHeight() <= 0.0D) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3 feet = target.getPosition();
|
||||||
|
Vec3 head = new Vec3(feet.getX(), feet.getY() + target.getHeight(), feet.getZ());
|
||||||
|
|
||||||
|
ScreenPoint feetPoint = snapshot.project(feet, screenWidth, screenHeight);
|
||||||
|
ScreenPoint headPoint = snapshot.project(head, screenWidth, screenHeight);
|
||||||
|
|
||||||
|
if (!feetPoint.isVisible() || !headPoint.isVisible()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double boxHeight = feetPoint.getY() - headPoint.getY();
|
||||||
|
if (boxHeight < MIN_BOX_HEIGHT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double boxWidth = Math.max(MIN_BOX_WIDTH,
|
||||||
|
boxHeight * (target.getWidth() / target.getHeight()));
|
||||||
|
double centerX = (feetPoint.getX() + headPoint.getX()) * 0.5D;
|
||||||
|
double left = centerX - boxWidth * 0.5D;
|
||||||
|
double top = headPoint.getY();
|
||||||
|
|
||||||
|
int color = color(target, index);
|
||||||
|
|
||||||
|
if (fill.isEnabled()) {
|
||||||
|
graphics.fillRect(left, top, boxWidth, boxHeight,
|
||||||
|
(color & 0x00FFFFFF) | (FILL_ALPHA << 24));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (box.isEnabled()) {
|
||||||
|
if (style.is("Corners")) {
|
||||||
|
drawCorners(graphics, left, top, boxWidth, boxHeight, color);
|
||||||
|
} else {
|
||||||
|
graphics.drawRect(left - BOX_PADDING, top - BOX_PADDING,
|
||||||
|
boxWidth + BOX_PADDING * 2.0D,
|
||||||
|
boxHeight + BOX_PADDING * 2.0D,
|
||||||
|
1.0D, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (health.isEnabled()) {
|
||||||
|
drawHealthBar(graphics, target, left - HEALTH_BAR_GAP, top, boxHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
String label = label(target);
|
||||||
|
if (label == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double textWidth = font.getStringWidth(label);
|
||||||
|
double textY = top - fontHeight - NAME_GAP;
|
||||||
|
font.drawStringWithShadow(label, centerX - textWidth * 0.5D, textY, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawCorners(Render2D graphics, double left, double top,
|
||||||
|
double width, double height, int color) {
|
||||||
|
double length = Math.min(CORNER_LENGTH, Math.min(width, height) * 0.5D);
|
||||||
|
if (length <= 0.0D) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double right = left + width;
|
||||||
|
double bottom = top + height;
|
||||||
|
|
||||||
|
// Top-left
|
||||||
|
graphics.fillRect(left, top, length, 1.0D, color);
|
||||||
|
graphics.fillRect(left, top, 1.0D, length, color);
|
||||||
|
|
||||||
|
// Top-right
|
||||||
|
graphics.fillRect(right - length, top, length, 1.0D, color);
|
||||||
|
graphics.fillRect(right - 1.0D, top, 1.0D, length, color);
|
||||||
|
|
||||||
|
// Bottom-left
|
||||||
|
graphics.fillRect(left, bottom - 1.0D, length, 1.0D, color);
|
||||||
|
graphics.fillRect(left, bottom - length, 1.0D, length, color);
|
||||||
|
|
||||||
|
// Bottom-right
|
||||||
|
graphics.fillRect(right - length, bottom - 1.0D, length, 1.0D, color);
|
||||||
|
graphics.fillRect(right - 1.0D, bottom - length, 1.0D, length, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawHealthBar(Render2D graphics, EntityTarget target,
|
||||||
|
double x, double top, double height) {
|
||||||
|
if (target.getMaxHealth() <= 0.0F) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float fraction = target.getHealth() / target.getMaxHealth();
|
||||||
|
fraction = Math.max(0.0F, Math.min(1.0F, fraction));
|
||||||
|
|
||||||
|
double filled = height * fraction;
|
||||||
|
|
||||||
|
graphics.fillRect(x, top, HEALTH_BAR_WIDTH, height, HEALTH_BACKGROUND);
|
||||||
|
graphics.fillRect(x, top + height - filled, HEALTH_BAR_WIDTH, filled,
|
||||||
|
healthColor(fraction));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String label(EntityTarget target) {
|
||||||
|
String nameText = name.isEnabled() ? target.getName() : null;
|
||||||
|
String distanceText = distance.isEnabled()
|
||||||
|
? String.format(Locale.ROOT, "%.1fm", target.getDistance())
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if (nameText == null) {
|
||||||
|
return distanceText;
|
||||||
|
}
|
||||||
|
if (distanceText == null) {
|
||||||
|
return nameText;
|
||||||
|
}
|
||||||
|
return nameText + " " + distanceText;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int color(EntityTarget target, int index) {
|
||||||
|
if (colorMode.is("Health")) {
|
||||||
|
float fraction = target.getMaxHealth() <= 0.0F
|
||||||
|
? 1.0F
|
||||||
|
: target.getHealth() / target.getMaxHealth();
|
||||||
|
return healthColor(Math.max(0.0F, Math.min(1.0F, fraction)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (colorMode.is("Rainbow")) {
|
||||||
|
float hue = ((System.currentTimeMillis() % 4000L) / 4000.0F)
|
||||||
|
+ index * 0.05F;
|
||||||
|
return Color.HSBtoRGB(hue - (float) Math.floor(hue), 0.85F, 1.0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ORANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int healthColor(float fraction) {
|
||||||
|
return Color.HSBtoRGB(0.33F * fraction, 0.85F, 1.0F);
|
||||||
|
}
|
||||||
|
}
|
||||||
+43
-6
@@ -11,6 +11,18 @@ import java.lang.reflect.Method;
|
|||||||
*/
|
*/
|
||||||
final class V26_2GlyphDrawer implements GlyphDrawer {
|
final class V26_2GlyphDrawer implements GlyphDrawer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum distance (in logical pixels) that still counts as "sitting on the
|
||||||
|
* baseline" rather than being a descender or a raised glyph.
|
||||||
|
*
|
||||||
|
* <p>The atlas is packed with 2x oversampling, so a normal glyph's baked
|
||||||
|
* bottom is 0.25/0.75px away from the baseline. 26.2 blits use integer
|
||||||
|
* coordinates, and rounding those offsets per glyph made some letters drop
|
||||||
|
* onto the next pixel while their neighbours stayed put. Snapping
|
||||||
|
* near-baseline bottoms to one shared value keeps a line visually level.</p>
|
||||||
|
*/
|
||||||
|
private static final double BASELINE_SNAP = 0.9;
|
||||||
|
|
||||||
private final Object extractor;
|
private final Object extractor;
|
||||||
private final Method innerBlit;
|
private final Method innerBlit;
|
||||||
private final Object guiPipeline;
|
private final Object guiPipeline;
|
||||||
@@ -28,12 +40,36 @@ final class V26_2GlyphDrawer implements GlyphDrawer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int x0 = (int) Math.round(penX + glyph.getX0() * scale);
|
// Snap both horizontal edges the same way (downwards). Rounding each
|
||||||
int y0 = (int) Math.round(baseline + glyph.getY0() * scale);
|
// edge independently made neighbouring glyphs drift apart or together
|
||||||
int x1 = (int) Math.round(penX + glyph.getX1() * scale);
|
// by one pixel, which is most visible around narrow letters such as I.
|
||||||
int y1 = (int) Math.round(baseline + glyph.getY1() * scale);
|
int x0 = (int) Math.floor(penX + glyph.getX0() * scale + 0.0001);
|
||||||
if (x1 <= x0 || y1 <= y0) {
|
int x1 = (int) Math.floor(penX + glyph.getX1() * scale + 0.0001);
|
||||||
return;
|
|
||||||
|
// Anchor both edges to one rounded baseline so every glyph in a line
|
||||||
|
// shares the same pixel origin.
|
||||||
|
int base = (int) Math.round(baseline);
|
||||||
|
// Round the top down: curved letters (C, G, o...) overshoot the flat
|
||||||
|
// cap/x-height by half a pixel in the atlas. Rounding split them onto
|
||||||
|
// different rows, which made "CLICK GUI" look uneven.
|
||||||
|
int y0 = base + (int) Math.floor(glyph.getY0() * scale + 0.0001);
|
||||||
|
double bottomOffset = glyph.getY1() * scale;
|
||||||
|
int y1;
|
||||||
|
if (bottomOffset >= 0.0 && bottomOffset < BASELINE_SNAP) {
|
||||||
|
// Normal letter/punctuation: sit exactly on the baseline.
|
||||||
|
y1 = base;
|
||||||
|
} else {
|
||||||
|
// Descenders (g, p, y...) and raised glyphs keep their offset.
|
||||||
|
y1 = base + (int) Math.round(bottomOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Thin strokes (l, I, | ...) can be narrower than one GUI pixel at high
|
||||||
|
// GUI scales. Keep them visible with at least one pixel.
|
||||||
|
if (x1 <= x0) {
|
||||||
|
x1 = x0 + 1;
|
||||||
|
}
|
||||||
|
if (y1 <= y0) {
|
||||||
|
y1 = y0 + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
V26_2FontTexture fontTexture = (V26_2FontTexture) texture;
|
V26_2FontTexture fontTexture = (V26_2FontTexture) texture;
|
||||||
@@ -49,3 +85,4 @@ final class V26_2GlyphDrawer implements GlyphDrawer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package cn.xiaozhou233.orangex.ui.clickgui;
|
||||||
|
|
||||||
|
import java.util.IdentityHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smooths hover and toggle values for ClickGUI elements.
|
||||||
|
*
|
||||||
|
* <p>Keys are compared by identity so equal-but-distinct modules or values do
|
||||||
|
* not share an animation.</p>
|
||||||
|
*/
|
||||||
|
public final class ClickGuiAnimator {
|
||||||
|
|
||||||
|
private static final float HOVER_SPEED = 14.0f;
|
||||||
|
private static final float STATE_SPEED = 16.0f;
|
||||||
|
|
||||||
|
private final Map<Object, Float> hoverAnimations =
|
||||||
|
new IdentityHashMap<Object, Float>();
|
||||||
|
private final Map<Object, Float> stateAnimations =
|
||||||
|
new IdentityHashMap<Object, Float>();
|
||||||
|
|
||||||
|
public float hover(Object key, boolean hovered, float delta) {
|
||||||
|
if (!hoverAnimations.containsKey(key)) {
|
||||||
|
hoverAnimations.put(key, 0.0f);
|
||||||
|
}
|
||||||
|
return animate(hoverAnimations, key, hovered ? 1.0f : 0.0f,
|
||||||
|
delta, HOVER_SPEED);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float state(Object key, boolean state, float delta) {
|
||||||
|
return animate(stateAnimations, key, state ? 1.0f : 0.0f,
|
||||||
|
delta, STATE_SPEED);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float animate(Map<Object, Float> animations, Object key,
|
||||||
|
float target, float delta, float speed) {
|
||||||
|
Float stored = animations.get(key);
|
||||||
|
float current = stored == null ? target : stored.floatValue();
|
||||||
|
|
||||||
|
if (Math.abs(target - current) < 0.001f) {
|
||||||
|
animations.put(key, target);
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
float factor = 1.0f - (float) Math.exp(-speed * delta);
|
||||||
|
float next = current + (target - current) * factor;
|
||||||
|
if (Math.abs(target - next) < 0.002f) {
|
||||||
|
next = target;
|
||||||
|
}
|
||||||
|
animations.put(key, next);
|
||||||
|
return next;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package cn.xiaozhou233.orangex.ui.clickgui;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Immutable geometry for one ClickGUI frame.
|
||||||
|
*
|
||||||
|
* <p>The panel keeps its own bounds and category-row height; this class turns
|
||||||
|
* them into the positions and sizes used by the individual renderers.</p>
|
||||||
|
*/
|
||||||
|
public final class ClickGuiLayout {
|
||||||
|
|
||||||
|
private final float x;
|
||||||
|
private final float y;
|
||||||
|
private final float width;
|
||||||
|
private final float height;
|
||||||
|
private final float categoryRowHeight;
|
||||||
|
private final int screenWidth;
|
||||||
|
private final int screenHeight;
|
||||||
|
|
||||||
|
public ClickGuiLayout(float x, float y, float width, float height,
|
||||||
|
float categoryRowHeight, int screenWidth,
|
||||||
|
int screenHeight) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
this.categoryRowHeight = categoryRowHeight;
|
||||||
|
this.screenWidth = screenWidth;
|
||||||
|
this.screenHeight = screenHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float x() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float y() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float width() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float height() {
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float categoryRowHeight() {
|
||||||
|
return categoryRowHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int screenWidth() {
|
||||||
|
return screenWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int screenHeight() {
|
||||||
|
return screenHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float contentX() {
|
||||||
|
return x + ClickGuiStyle.SIDEBAR_CARD_X
|
||||||
|
+ ClickGuiStyle.SIDEBAR_WIDTH + 14.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float contentWidth() {
|
||||||
|
return x + width - 12.0f - contentX();
|
||||||
|
}
|
||||||
|
|
||||||
|
public float listTop() {
|
||||||
|
return y + ClickGuiStyle.HEADER_HEIGHT + 38.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float listBottom() {
|
||||||
|
return y + height - 8.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float categoryRowX() {
|
||||||
|
return x + ClickGuiStyle.SIDEBAR_CARD_X + 6.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float categoryRowWidth() {
|
||||||
|
return ClickGuiStyle.SIDEBAR_WIDTH - 12.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float categoryRowTop() {
|
||||||
|
return y + ClickGuiStyle.SIDEBAR_CARD_Y + 9.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package cn.xiaozhou233.orangex.ui.clickgui;
|
||||||
|
|
||||||
|
import cn.xiaozhou233.orangex.modules.Module;
|
||||||
|
import cn.xiaozhou233.orangex.modules.ModuleCategory;
|
||||||
|
import cn.xiaozhou233.orangex.value.KeybindValue;
|
||||||
|
import cn.xiaozhou233.orangex.value.Value;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module and category helpers shared by the ClickGUI renderers.
|
||||||
|
*/
|
||||||
|
public final class ClickGuiModules {
|
||||||
|
|
||||||
|
private ClickGuiModules() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Value<?>> settingsOf(Module module) {
|
||||||
|
List<Value<?>> settings = new ArrayList<Value<?>>();
|
||||||
|
for (Value<?> value : module.getVisibleValues()) {
|
||||||
|
// The module keybind is shown on the collapsed row instead.
|
||||||
|
if (!(value instanceof KeybindValue)) {
|
||||||
|
settings.add(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String displayName(ModuleCategory category) {
|
||||||
|
String name = category.name();
|
||||||
|
return name.substring(0, 1) + name.substring(1).toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package cn.xiaozhou233.orangex.ui.clickgui;
|
||||||
|
|
||||||
|
import cn.xiaozhou233.orangex.event.impl.EventRender2D;
|
||||||
|
import cn.xiaozhou233.orangex.input.ClientInput;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders and drives the ClickGUI while the empty input screen is open.
|
||||||
|
*
|
||||||
|
* <p>The input screen only records the raw mouse state in
|
||||||
|
* {@link ClientInput}; this class turns button transitions into component
|
||||||
|
* callbacks and then renders {@link MainPanel}.</p>
|
||||||
|
*/
|
||||||
|
public final class ClickGuiRender {
|
||||||
|
|
||||||
|
private static final MainPanel MAIN_PANEL = new MainPanel();
|
||||||
|
|
||||||
|
private static boolean lastLeftDown;
|
||||||
|
private static boolean lastRightDown;
|
||||||
|
|
||||||
|
private ClickGuiRender() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void render(EventRender2D event) {
|
||||||
|
if (!ClientInput.isOpen()) {
|
||||||
|
reset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float mouseX = (float) ClientInput.getMouseX();
|
||||||
|
float mouseY = (float) ClientInput.getMouseY();
|
||||||
|
boolean leftDown = ClientInput.isLeftDown();
|
||||||
|
boolean rightDown = ClientInput.isRightDown();
|
||||||
|
|
||||||
|
if (leftDown && !lastLeftDown) {
|
||||||
|
MAIN_PANEL.mouseClicked(mouseX, mouseY, 0);
|
||||||
|
}
|
||||||
|
if (rightDown && !lastRightDown) {
|
||||||
|
MAIN_PANEL.mouseClicked(mouseX, mouseY, 1);
|
||||||
|
}
|
||||||
|
if (leftDown && lastLeftDown) {
|
||||||
|
MAIN_PANEL.mouseDragged(mouseX, mouseY, 0);
|
||||||
|
}
|
||||||
|
if (!leftDown && lastLeftDown) {
|
||||||
|
MAIN_PANEL.mouseReleased(mouseX, mouseY, 0);
|
||||||
|
}
|
||||||
|
if (!rightDown && lastRightDown) {
|
||||||
|
MAIN_PANEL.mouseReleased(mouseX, mouseY, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
MAIN_PANEL.render(event);
|
||||||
|
|
||||||
|
lastLeftDown = leftDown;
|
||||||
|
lastRightDown = rightDown;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drops transient input state. Called when the GUI closes or reopens so a
|
||||||
|
* button held across screens does not produce a stale drag.
|
||||||
|
*/
|
||||||
|
public static void reset() {
|
||||||
|
MAIN_PANEL.resetInteraction();
|
||||||
|
lastLeftDown = false;
|
||||||
|
lastRightDown = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
package cn.xiaozhou233.orangex.ui.clickgui;
|
||||||
|
|
||||||
|
import cn.xiaozhou233.orangex.render.api.FontRenderer;
|
||||||
|
import cn.xiaozhou233.orangex.render.api.Render2D;
|
||||||
|
import cn.xiaozhou233.orangex.render.font.FontFamily;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shared colours, metrics and drawing primitives for the ClickGUI.
|
||||||
|
*
|
||||||
|
* <p>All colours are ARGB and all coordinates are Minecraft GUI pixels.</p>
|
||||||
|
*/
|
||||||
|
public final class ClickGuiStyle {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Font family used only by the ClickGUI. Other screens keep using the
|
||||||
|
* globally configured default family.
|
||||||
|
*/
|
||||||
|
public static final FontFamily FONT_FAMILY = FontFamily.MONTSERRAT;
|
||||||
|
|
||||||
|
public static final float DESIGN_WIDTH = 448f;
|
||||||
|
public static final float DESIGN_HEIGHT = 306f;
|
||||||
|
public static final float MARGIN = 12f;
|
||||||
|
public static final float PANEL_RADIUS = 9f;
|
||||||
|
|
||||||
|
public static final float HEADER_HEIGHT = 46f;
|
||||||
|
|
||||||
|
public static final float SIDEBAR_WIDTH = 112f;
|
||||||
|
public static final float SIDEBAR_CARD_X = 10f;
|
||||||
|
public static final float SIDEBAR_CARD_Y = HEADER_HEIGHT + 8f;
|
||||||
|
public static final float CATEGORY_HEIGHT = 26f;
|
||||||
|
public static final float CATEGORY_GAP = 2f;
|
||||||
|
|
||||||
|
public static final float MODULE_HEIGHT = 27f;
|
||||||
|
public static final float MODULE_GAP = 3f;
|
||||||
|
|
||||||
|
public static final float TOGGLE_WIDTH = 26f;
|
||||||
|
public static final float TOGGLE_HEIGHT = 12f;
|
||||||
|
public static final float SMALL_TOGGLE_WIDTH = 20f;
|
||||||
|
public static final float SMALL_TOGGLE_HEIGHT = 9f;
|
||||||
|
|
||||||
|
public static final int COLOR_PANEL = 0xF218181D;
|
||||||
|
public static final int COLOR_BORDER = 0xFF2C2C37;
|
||||||
|
public static final int COLOR_TEXT = 0xFFEDEDF2;
|
||||||
|
public static final int COLOR_TEXT_DIM = 0xFF9A9AA8;
|
||||||
|
public static final int COLOR_TEXT_MUTED = 0xFF61616F;
|
||||||
|
public static final int COLOR_ACCENT = 0xFFFF8A3D;
|
||||||
|
public static final int COLOR_ACCENT_RGB = 0x00FF8A3D;
|
||||||
|
public static final int COLOR_DIVIDER = 0xFF272730;
|
||||||
|
public static final int COLOR_SIDEBAR_BG = 0xFF15151A;
|
||||||
|
public static final int COLOR_SIDEBAR_BORDER = 0xFF24242C;
|
||||||
|
public static final int COLOR_SWITCH_OFF = 0xFF34343F;
|
||||||
|
public static final int COLOR_KNOB_OFF = 0xFF9A9AA8;
|
||||||
|
|
||||||
|
private ClickGuiStyle() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FontRenderer font(Render2D graphics, float size) {
|
||||||
|
return graphics.getFont(FONT_FAMILY, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FontRenderer font(Render2D graphics, float size, boolean bold) {
|
||||||
|
return graphics.getFont(FONT_FAMILY, size, bold);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void drawSwitch(Render2D graphics, float switchX, float switchY,
|
||||||
|
float switchWidth, float switchHeight,
|
||||||
|
float progress) {
|
||||||
|
int track = lerpColor(COLOR_SWITCH_OFF, COLOR_ACCENT, progress);
|
||||||
|
graphics.fillRoundedRect(switchX, switchY, switchWidth, switchHeight,
|
||||||
|
switchHeight / 2.0f, track);
|
||||||
|
|
||||||
|
float knobSize = switchHeight - 4.0f;
|
||||||
|
float knobX = switchX + 2.0f
|
||||||
|
+ (switchWidth - knobSize - 4.0f) * progress;
|
||||||
|
int knob = lerpColor(COLOR_KNOB_OFF, 0xFFFFFFFF, progress);
|
||||||
|
graphics.fillRoundedRect(knobX, switchY + 2.0f, knobSize, knobSize,
|
||||||
|
knobSize / 2.0f, knob);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double centeredY(FontRenderer font, float top, float height) {
|
||||||
|
return top + (height - font.getStringHeight()) / 2.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isInside(double mouseX, double mouseY,
|
||||||
|
double x, double y,
|
||||||
|
double width, double height) {
|
||||||
|
return mouseX >= x && mouseX <= x + width
|
||||||
|
&& mouseY >= y && mouseY <= y + height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float clamp(float value, float min, float max) {
|
||||||
|
return Math.max(min, Math.min(max, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int argb(int alpha, int rgb) {
|
||||||
|
int clamped = Math.max(0, Math.min(255, alpha));
|
||||||
|
return (clamped << 24) | (rgb & 0x00FFFFFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int lerpColor(int from, int to, float progress) {
|
||||||
|
float t = clamp(progress, 0.0f, 1.0f);
|
||||||
|
int a = lerpChannel(from >>> 24, to >>> 24, t);
|
||||||
|
int r = lerpChannel(from >> 16, to >> 16, t);
|
||||||
|
int g = lerpChannel(from >> 8, to >> 8, t);
|
||||||
|
int b = lerpChannel(from, to, t);
|
||||||
|
return (a << 24) | (r << 16) | (g << 8) | b;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int lerpChannel(int from, int to, float t) {
|
||||||
|
int fromChannel = from & 0xFF;
|
||||||
|
int toChannel = to & 0xFF;
|
||||||
|
return Math.round(fromChannel + (toChannel - fromChannel) * t);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
package cn.xiaozhou233.orangex.ui.clickgui;
|
||||||
|
|
||||||
|
import cn.xiaozhou233.orangex.modules.Module;
|
||||||
|
import cn.xiaozhou233.orangex.modules.ModuleCategory;
|
||||||
|
import cn.xiaozhou233.orangex.render.api.FontRenderer;
|
||||||
|
import cn.xiaozhou233.orangex.render.api.Render2D;
|
||||||
|
import cn.xiaozhou233.orangex.value.KeybindValue;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the module list for the selected category.
|
||||||
|
*
|
||||||
|
* <p>Module settings are not drawn inline; right-clicking a module opens the
|
||||||
|
* separate {@link SettingsWindow}.</p>
|
||||||
|
*/
|
||||||
|
public final class ContentRenderer {
|
||||||
|
|
||||||
|
private ContentRenderer() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void draw(Render2D graphics, ClickGuiLayout layout,
|
||||||
|
List<Module> modules, ModuleCategory category,
|
||||||
|
ClickGuiAnimator animator, float delta,
|
||||||
|
double mouseX, double mouseY) {
|
||||||
|
float x = layout.x();
|
||||||
|
float y = layout.y();
|
||||||
|
float contentX = layout.contentX();
|
||||||
|
float contentWidth = layout.contentWidth();
|
||||||
|
|
||||||
|
FontRenderer title = ClickGuiStyle.font(graphics, 13.0f, true);
|
||||||
|
title.drawString(ClickGuiModules.displayName(category), contentX,
|
||||||
|
y + ClickGuiStyle.HEADER_HEIGHT + 10,
|
||||||
|
ClickGuiStyle.COLOR_TEXT);
|
||||||
|
|
||||||
|
FontRenderer meta = ClickGuiStyle.font(graphics, 8.0f);
|
||||||
|
String metaText = modules.size()
|
||||||
|
+ (modules.size() == 1 ? " MODULE" : " MODULES");
|
||||||
|
meta.drawString(metaText,
|
||||||
|
contentX + contentWidth - meta.getStringWidth(metaText),
|
||||||
|
y + ClickGuiStyle.HEADER_HEIGHT + 14,
|
||||||
|
ClickGuiStyle.COLOR_TEXT_MUTED);
|
||||||
|
|
||||||
|
graphics.fillRect(contentX, y + ClickGuiStyle.HEADER_HEIGHT + 30,
|
||||||
|
contentWidth, 1, ClickGuiStyle.COLOR_DIVIDER);
|
||||||
|
|
||||||
|
float listTop = layout.listTop();
|
||||||
|
float listBottom = layout.listBottom();
|
||||||
|
|
||||||
|
graphics.enableScissor(contentX - 2, listTop - 2,
|
||||||
|
contentWidth + 4, listBottom - listTop + 4);
|
||||||
|
|
||||||
|
if (modules.isEmpty()) {
|
||||||
|
FontRenderer empty = ClickGuiStyle.font(graphics, 9.0f);
|
||||||
|
String text = "No modules here yet";
|
||||||
|
empty.drawString(text,
|
||||||
|
contentX + (contentWidth - empty.getStringWidth(text)) / 2.0,
|
||||||
|
listTop + 14, ClickGuiStyle.COLOR_TEXT_MUTED);
|
||||||
|
} else {
|
||||||
|
float rowY = listTop;
|
||||||
|
|
||||||
|
for (Module module : modules) {
|
||||||
|
boolean hovered = ClickGuiStyle.isInside(mouseX, mouseY,
|
||||||
|
contentX, rowY, contentWidth,
|
||||||
|
ClickGuiStyle.MODULE_HEIGHT);
|
||||||
|
float hover = animator.hover(module, hovered, delta);
|
||||||
|
|
||||||
|
drawModuleRow(graphics, layout, module, rowY, hover,
|
||||||
|
animator, delta);
|
||||||
|
|
||||||
|
rowY += ClickGuiStyle.MODULE_HEIGHT + ClickGuiStyle.MODULE_GAP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
graphics.disableScissor();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void drawModuleRow(Render2D graphics, ClickGuiLayout layout,
|
||||||
|
Module module, float rowY, float hover,
|
||||||
|
ClickGuiAnimator animator, float delta) {
|
||||||
|
float contentX = layout.contentX();
|
||||||
|
float contentWidth = layout.contentWidth();
|
||||||
|
float rowRight = contentX + contentWidth;
|
||||||
|
float moduleHeight = ClickGuiStyle.MODULE_HEIGHT;
|
||||||
|
|
||||||
|
int background = module.isEnabled()
|
||||||
|
? ClickGuiStyle.argb((int) (14.0f + 14.0f * hover),
|
||||||
|
ClickGuiStyle.COLOR_ACCENT_RGB)
|
||||||
|
: ClickGuiStyle.argb((int) (6.0f + 10.0f * hover),
|
||||||
|
0x00FFFFFF);
|
||||||
|
graphics.fillRoundedRect(contentX, rowY, contentWidth, moduleHeight,
|
||||||
|
5, background);
|
||||||
|
|
||||||
|
if (module.isEnabled()) {
|
||||||
|
graphics.fillRoundedRect(contentX + 2, rowY + 8, 2.0f,
|
||||||
|
moduleHeight - 16, 1.0f, ClickGuiStyle.COLOR_ACCENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
FontRenderer name = ClickGuiStyle.font(graphics, 10.0f,
|
||||||
|
module.isEnabled());
|
||||||
|
name.drawString(module.getName(), contentX + 10,
|
||||||
|
ClickGuiStyle.centeredY(name, rowY, moduleHeight),
|
||||||
|
module.isEnabled() ? ClickGuiStyle.COLOR_TEXT
|
||||||
|
: ClickGuiStyle.COLOR_TEXT_DIM);
|
||||||
|
|
||||||
|
KeybindValue keybind = module.getKeybind();
|
||||||
|
if (keybind.isBound()) {
|
||||||
|
FontRenderer keyFont = ClickGuiStyle.font(graphics, 8.0f);
|
||||||
|
String key = KeyNames.keyName(keybind.getKey());
|
||||||
|
keyFont.drawString(key,
|
||||||
|
rowRight - ClickGuiStyle.TOGGLE_WIDTH - 18
|
||||||
|
- keyFont.getStringWidth(key),
|
||||||
|
ClickGuiStyle.centeredY(keyFont, rowY, moduleHeight),
|
||||||
|
ClickGuiStyle.COLOR_TEXT_MUTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
float toggleX = rowRight - ClickGuiStyle.TOGGLE_WIDTH - 10;
|
||||||
|
float toggleY = rowY + (moduleHeight - ClickGuiStyle.TOGGLE_HEIGHT)
|
||||||
|
/ 2.0f;
|
||||||
|
ClickGuiStyle.drawSwitch(graphics, toggleX, toggleY,
|
||||||
|
ClickGuiStyle.TOGGLE_WIDTH, ClickGuiStyle.TOGGLE_HEIGHT,
|
||||||
|
animator.state(module, module.isEnabled(), delta));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
package cn.xiaozhou233.orangex.ui.clickgui;
|
||||||
|
|
||||||
|
import cn.xiaozhou233.orangex.input.KeyCodes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps raw GLFW-style key codes to the short labels shown in the ClickGUI.
|
||||||
|
*/
|
||||||
|
public final class KeyNames {
|
||||||
|
|
||||||
|
private KeyNames() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String keyName(int key) {
|
||||||
|
if (key == KeyCodes.NONE) {
|
||||||
|
return "NONE";
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (key) {
|
||||||
|
case 1: return "ESC";
|
||||||
|
case 2: return "1";
|
||||||
|
case 3: return "2";
|
||||||
|
case 4: return "3";
|
||||||
|
case 5: return "4";
|
||||||
|
case 6: return "5";
|
||||||
|
case 7: return "6";
|
||||||
|
case 8: return "7";
|
||||||
|
case 9: return "8";
|
||||||
|
case 10: return "9";
|
||||||
|
case 11: return "0";
|
||||||
|
case 12: return "MINUS";
|
||||||
|
case 13: return "EQUAL";
|
||||||
|
case 14: return "BACKSPACE";
|
||||||
|
case 15: return "TAB";
|
||||||
|
case 16: return "Q";
|
||||||
|
case 17: return "W";
|
||||||
|
case 18: return "E";
|
||||||
|
case 19: return "R";
|
||||||
|
case 20: return "T";
|
||||||
|
case 21: return "Y";
|
||||||
|
case 22: return "U";
|
||||||
|
case 23: return "I";
|
||||||
|
case 24: return "O";
|
||||||
|
case 25: return "P";
|
||||||
|
case 26: return "[";
|
||||||
|
case 27: return "]";
|
||||||
|
case 28: return "ENTER";
|
||||||
|
case 29: return "LCTRL";
|
||||||
|
case 30: return "A";
|
||||||
|
case 31: return "S";
|
||||||
|
case 32: return "D";
|
||||||
|
case 33: return "F";
|
||||||
|
case 34: return "G";
|
||||||
|
case 35: return "H";
|
||||||
|
case 36: return "J";
|
||||||
|
case 37: return "K";
|
||||||
|
case 38: return "L";
|
||||||
|
case 39: return ";";
|
||||||
|
case 40: return "'";
|
||||||
|
case 41: return "`";
|
||||||
|
case 42: return "LSHIFT";
|
||||||
|
case 43: return "\\";
|
||||||
|
case 44: return "Z";
|
||||||
|
case 45: return "X";
|
||||||
|
case 46: return "C";
|
||||||
|
case 47: return "V";
|
||||||
|
case 48: return "B";
|
||||||
|
case 49: return "N";
|
||||||
|
case 50: return "M";
|
||||||
|
case 51: return ",";
|
||||||
|
case 52: return ".";
|
||||||
|
case 53: return "/";
|
||||||
|
case 54: return "RSHIFT";
|
||||||
|
case 55: return "NUMPAD*";
|
||||||
|
case 56: return "LALT";
|
||||||
|
case 57: return "SPACE";
|
||||||
|
case 58: return "CAPS";
|
||||||
|
case 69: return "NUMLOCK";
|
||||||
|
case 70: return "SCROLL";
|
||||||
|
case 74: return "NUMPAD-";
|
||||||
|
case 78: return "NUMPAD+";
|
||||||
|
case 82: return "NUMPAD0";
|
||||||
|
case 79: return "NUMPAD1";
|
||||||
|
case 80: return "NUMPAD2";
|
||||||
|
case 81: return "NUMPAD3";
|
||||||
|
case 75: return "NUMPAD4";
|
||||||
|
case 76: return "NUMPAD5";
|
||||||
|
case 77: return "NUMPAD6";
|
||||||
|
case 71: return "NUMPAD7";
|
||||||
|
case 72: return "NUMPAD8";
|
||||||
|
case 73: return "NUMPAD9";
|
||||||
|
case 87: return "F11";
|
||||||
|
case 88: return "F12";
|
||||||
|
case 157: return "RCTRL";
|
||||||
|
case 184: return "RALT";
|
||||||
|
case 200: return "UP";
|
||||||
|
case 203: return "LEFT";
|
||||||
|
case 208: return "DOWN";
|
||||||
|
case 205: return "RIGHT";
|
||||||
|
case 210: return "INSERT";
|
||||||
|
case 211: return "DELETE";
|
||||||
|
case 199: return "HOME";
|
||||||
|
case 207: return "END";
|
||||||
|
case 201: return "PAGE UP";
|
||||||
|
case 209: return "PAGE DOWN";
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key >= 59 && key <= 68) {
|
||||||
|
return "F" + (key - 58);
|
||||||
|
}
|
||||||
|
return "KEY " + key;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,255 @@
|
|||||||
|
package cn.xiaozhou233.orangex.ui.clickgui;
|
||||||
|
|
||||||
|
import cn.xiaozhou233.orangex.OrangeX;
|
||||||
|
import cn.xiaozhou233.orangex.event.impl.EventRender2D;
|
||||||
|
import cn.xiaozhou233.orangex.input.ClientInput;
|
||||||
|
import cn.xiaozhou233.orangex.modules.Module;
|
||||||
|
import cn.xiaozhou233.orangex.modules.ModuleCategory;
|
||||||
|
import cn.xiaozhou233.orangex.modules.ModuleManager;
|
||||||
|
import cn.xiaozhou233.orangex.render.api.Render2D;
|
||||||
|
import cn.xiaozhou233.orangex.ui.clickgui.component.Component;
|
||||||
|
import cn.xiaozhou233.orangex.value.BooleanValue;
|
||||||
|
import cn.xiaozhou233.orangex.value.ModeValue;
|
||||||
|
import cn.xiaozhou233.orangex.value.Value;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main ClickGUI window.
|
||||||
|
*
|
||||||
|
* <p>A single rounded window with a category sidebar on the left and the
|
||||||
|
* selected category's modules on the right. Left-clicking a module toggles it;
|
||||||
|
* right-clicking a module opens its settings in the separate
|
||||||
|
* {@link SettingsWindow}. The window itself can be dragged by its header.</p>
|
||||||
|
*
|
||||||
|
* <p>All coordinates are Minecraft GUI pixels. Input is polled from
|
||||||
|
* {@link ClientInput} because the empty input screen does not forward
|
||||||
|
* callbacks to this class directly. This class owns the window state and input
|
||||||
|
* routing; drawing is delegated to the renderer classes in this package.</p>
|
||||||
|
*/
|
||||||
|
public final class MainPanel extends Component {
|
||||||
|
|
||||||
|
private static final ModuleCategory[] CATEGORIES = ModuleCategory.values();
|
||||||
|
|
||||||
|
private final ModuleManager moduleManager =
|
||||||
|
OrangeX.getInstance().getModuleManager();
|
||||||
|
|
||||||
|
private final ClickGuiAnimator animator = new ClickGuiAnimator();
|
||||||
|
private final SettingsWindow settingsWindow = new SettingsWindow();
|
||||||
|
|
||||||
|
private ModuleCategory selectedCategory = ModuleCategory.RENDER;
|
||||||
|
|
||||||
|
private boolean hasPosition;
|
||||||
|
private boolean dragging;
|
||||||
|
private float dragOffsetX;
|
||||||
|
private float dragOffsetY;
|
||||||
|
|
||||||
|
private int screenWidth = 854;
|
||||||
|
private int screenHeight = 480;
|
||||||
|
private float categoryRowHeight = ClickGuiStyle.CATEGORY_HEIGHT;
|
||||||
|
|
||||||
|
private long lastFrameNanos;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(EventRender2D event) {
|
||||||
|
Render2D graphics = event.getRender2D();
|
||||||
|
updateBounds(graphics);
|
||||||
|
|
||||||
|
ClickGuiLayout layout = layout();
|
||||||
|
float delta = updateDelta();
|
||||||
|
double mouseX = ClientInput.getMouseX();
|
||||||
|
double mouseY = ClientInput.getMouseY();
|
||||||
|
|
||||||
|
PanelChrome.drawShadow(graphics, layout);
|
||||||
|
graphics.fillRoundedRect(layout.x(), layout.y(), layout.width(),
|
||||||
|
layout.height(), ClickGuiStyle.PANEL_RADIUS, 1.0,
|
||||||
|
ClickGuiStyle.COLOR_PANEL, ClickGuiStyle.COLOR_BORDER);
|
||||||
|
|
||||||
|
PanelChrome.drawHeader(graphics, layout);
|
||||||
|
SidebarRenderer.draw(graphics, layout, selectedCategory,
|
||||||
|
moduleManager.getAllModules(), animator, delta, mouseX, mouseY);
|
||||||
|
ContentRenderer.draw(graphics, layout,
|
||||||
|
modulesOf(selectedCategory), selectedCategory,
|
||||||
|
animator, delta, mouseX, mouseY);
|
||||||
|
|
||||||
|
settingsWindow.render(graphics, delta, mouseX, mouseY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(float mouseX, float mouseY, int button) {
|
||||||
|
if (settingsWindow.isOpen()) {
|
||||||
|
if (settingsWindow.mouseClicked(mouseX, mouseY, button)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
settingsWindow.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ClickGuiStyle.isInside(mouseX, mouseY, x, y, width, height)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ClickGuiStyle.isInside(mouseX, mouseY, x, y, width,
|
||||||
|
ClickGuiStyle.HEADER_HEIGHT)) {
|
||||||
|
if (button == 0) {
|
||||||
|
dragging = true;
|
||||||
|
dragOffsetX = mouseX - x;
|
||||||
|
dragOffsetY = mouseY - y;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClickGuiLayout layout = layout();
|
||||||
|
ModuleCategory category = categoryAt(layout, mouseX, mouseY);
|
||||||
|
if (category != null) {
|
||||||
|
selectedCategory = category;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
handleContentClick(layout, mouseX, mouseY, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseDragged(float mouseX, float mouseY, int button) {
|
||||||
|
if (settingsWindow.isOpen()) {
|
||||||
|
settingsWindow.mouseDragged(mouseX, mouseY, button);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!dragging || button != 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float maxX = Math.max(4.0f, screenWidth - width - 4.0f);
|
||||||
|
float maxY = Math.max(4.0f, screenHeight - height - 4.0f);
|
||||||
|
|
||||||
|
x = ClickGuiStyle.clamp(mouseX - dragOffsetX, 4.0f, maxX);
|
||||||
|
y = ClickGuiStyle.clamp(mouseY - dragOffsetY, 4.0f, maxY);
|
||||||
|
// 26.2 glyph blits snap to whole pixels; a fractional panel origin
|
||||||
|
// makes every glyph round independently while dragging. Keep the
|
||||||
|
// window on the pixel grid so text moves as one stable block.
|
||||||
|
x = Math.round(x);
|
||||||
|
y = Math.round(y);
|
||||||
|
hasPosition = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(float mouseX, float mouseY, int button) {
|
||||||
|
settingsWindow.mouseReleased(mouseX, mouseY, button);
|
||||||
|
if (button == 0) {
|
||||||
|
dragging = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetInteraction() {
|
||||||
|
dragging = false;
|
||||||
|
settingsWindow.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
/* Interaction */
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
private boolean handleContentClick(ClickGuiLayout layout, float mouseX,
|
||||||
|
float mouseY, int button) {
|
||||||
|
if (mouseY < layout.listTop() || mouseY > layout.listBottom()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
float contentX = layout.contentX();
|
||||||
|
float contentWidth = layout.contentWidth();
|
||||||
|
float moduleHeight = ClickGuiStyle.MODULE_HEIGHT;
|
||||||
|
float rowY = layout.listTop();
|
||||||
|
|
||||||
|
for (Module module : modulesOf(selectedCategory)) {
|
||||||
|
if (ClickGuiStyle.isInside(mouseX, mouseY, contentX, rowY,
|
||||||
|
contentWidth, moduleHeight)) {
|
||||||
|
if (button == 0) {
|
||||||
|
module.toggle();
|
||||||
|
} else if (button == 1
|
||||||
|
&& !ClickGuiModules.settingsOf(module).isEmpty()) {
|
||||||
|
settingsWindow.open(module, layout);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
rowY += moduleHeight + ClickGuiStyle.MODULE_GAP;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ModuleCategory categoryAt(ClickGuiLayout layout, float mouseX,
|
||||||
|
float mouseY) {
|
||||||
|
float rowX = layout.categoryRowX();
|
||||||
|
float rowWidth = layout.categoryRowWidth();
|
||||||
|
float rowY = layout.categoryRowTop();
|
||||||
|
float rowHeight = layout.categoryRowHeight();
|
||||||
|
|
||||||
|
for (ModuleCategory category : CATEGORIES) {
|
||||||
|
if (ClickGuiStyle.isInside(mouseX, mouseY, rowX, rowY,
|
||||||
|
rowWidth, rowHeight)) {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
rowY += rowHeight + ClickGuiStyle.CATEGORY_GAP;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
/* Layout helpers */
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
private ClickGuiLayout layout() {
|
||||||
|
return new ClickGuiLayout(x, y, width, height, categoryRowHeight,
|
||||||
|
screenWidth, screenHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateBounds(Render2D graphics) {
|
||||||
|
screenWidth = graphics.getWidth();
|
||||||
|
screenHeight = graphics.getHeight();
|
||||||
|
|
||||||
|
width = Math.min(ClickGuiStyle.DESIGN_WIDTH,
|
||||||
|
Math.max(280.0f, screenWidth - ClickGuiStyle.MARGIN * 2.0f));
|
||||||
|
height = Math.min(ClickGuiStyle.DESIGN_HEIGHT,
|
||||||
|
Math.max(220.0f, screenHeight - ClickGuiStyle.MARGIN * 2.0f));
|
||||||
|
|
||||||
|
// Keep all seven category rows inside the sidebar card even when the
|
||||||
|
// panel is compressed by a small GUI-scaled screen.
|
||||||
|
float cardHeight = height - ClickGuiStyle.HEADER_HEIGHT - 16.0f;
|
||||||
|
float availableRows = cardHeight - 18.0f;
|
||||||
|
float rowHeight = (availableRows
|
||||||
|
- (CATEGORIES.length - 1) * ClickGuiStyle.CATEGORY_GAP)
|
||||||
|
/ CATEGORIES.length;
|
||||||
|
categoryRowHeight = Math.max(12.0f,
|
||||||
|
Math.min(ClickGuiStyle.CATEGORY_HEIGHT, rowHeight));
|
||||||
|
|
||||||
|
if (!hasPosition) {
|
||||||
|
x = (screenWidth - width) / 2.0f;
|
||||||
|
y = (screenHeight - height) / 2.0f;
|
||||||
|
hasPosition = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
x = ClickGuiStyle.clamp(x, 4.0f,
|
||||||
|
Math.max(4.0f, screenWidth - width - 4.0f));
|
||||||
|
y = ClickGuiStyle.clamp(y, 4.0f,
|
||||||
|
Math.max(4.0f, screenHeight - height - 4.0f));
|
||||||
|
x = Math.round(x);
|
||||||
|
y = Math.round(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
private float updateDelta() {
|
||||||
|
long now = System.nanoTime();
|
||||||
|
if (lastFrameNanos == 0L) {
|
||||||
|
lastFrameNanos = now;
|
||||||
|
return 0.016f;
|
||||||
|
}
|
||||||
|
float delta = (now - lastFrameNanos) / 1_000_000_000.0f;
|
||||||
|
lastFrameNanos = now;
|
||||||
|
return ClickGuiStyle.clamp(delta, 0.0f, 0.1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Module> modulesOf(ModuleCategory category) {
|
||||||
|
return moduleManager.getModulesByCategory(category);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package cn.xiaozhou233.orangex.ui.clickgui;
|
||||||
|
|
||||||
|
import cn.xiaozhou233.orangex.render.api.FontRenderer;
|
||||||
|
import cn.xiaozhou233.orangex.render.api.Render2D;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the parts of the window that never change with the selected category:
|
||||||
|
* the drop shadow and the header.
|
||||||
|
*/
|
||||||
|
public final class PanelChrome {
|
||||||
|
|
||||||
|
private PanelChrome() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void drawShadow(Render2D graphics, ClickGuiLayout layout) {
|
||||||
|
float x = layout.x();
|
||||||
|
float y = layout.y();
|
||||||
|
float width = layout.width();
|
||||||
|
float height = layout.height();
|
||||||
|
|
||||||
|
graphics.fillRoundedRect(x - 4, y + 3, width + 8, height + 6,
|
||||||
|
ClickGuiStyle.PANEL_RADIUS + 4, 0x1C000000);
|
||||||
|
graphics.fillRoundedRect(x - 2, y + 1, width + 4, height + 3,
|
||||||
|
ClickGuiStyle.PANEL_RADIUS + 2, 0x26000000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void drawHeader(Render2D graphics, ClickGuiLayout layout) {
|
||||||
|
float x = layout.x();
|
||||||
|
float y = layout.y();
|
||||||
|
float width = layout.width();
|
||||||
|
|
||||||
|
FontRenderer logo = ClickGuiStyle.font(graphics, 16.0f, true);
|
||||||
|
String brand = "Orange";
|
||||||
|
double brandX = x + 16;
|
||||||
|
double brandY = y + 9;
|
||||||
|
|
||||||
|
logo.drawString(brand, brandX, brandY, ClickGuiStyle.COLOR_TEXT);
|
||||||
|
logo.drawString("X", brandX + logo.getStringWidth(brand), brandY,
|
||||||
|
ClickGuiStyle.COLOR_ACCENT);
|
||||||
|
|
||||||
|
FontRenderer subtitle = ClickGuiStyle.font(graphics, 7.5f, true);
|
||||||
|
subtitle.drawString("CLICK GUI", x + 17, y + 28,
|
||||||
|
ClickGuiStyle.COLOR_TEXT_MUTED);
|
||||||
|
|
||||||
|
graphics.fillRect(x + 14, y + ClickGuiStyle.HEADER_HEIGHT - 1,
|
||||||
|
width - 28, 1, ClickGuiStyle.COLOR_DIVIDER);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,263 @@
|
|||||||
|
package cn.xiaozhou233.orangex.ui.clickgui;
|
||||||
|
|
||||||
|
import cn.xiaozhou233.orangex.modules.Module;
|
||||||
|
import cn.xiaozhou233.orangex.render.api.FontRenderer;
|
||||||
|
import cn.xiaozhou233.orangex.render.api.Render2D;
|
||||||
|
import cn.xiaozhou233.orangex.value.BooleanValue;
|
||||||
|
import cn.xiaozhou233.orangex.value.ModeValue;
|
||||||
|
import cn.xiaozhou233.orangex.value.Value;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A small draggable window that shows the settings of one module.
|
||||||
|
*
|
||||||
|
* <p>Opened by right-clicking a module row in {@link MainPanel}. Clicking
|
||||||
|
* outside the window, pressing its close button or closing the GUI dismisses
|
||||||
|
* it.</p>
|
||||||
|
*/
|
||||||
|
public final class SettingsWindow {
|
||||||
|
|
||||||
|
private static final Object CLOSE_HOVER_KEY = new Object();
|
||||||
|
|
||||||
|
private static final float WIDTH = 236f;
|
||||||
|
private static final float HEADER_HEIGHT = 30f;
|
||||||
|
private static final float ROW_HEIGHT = 22f;
|
||||||
|
private static final float BODY_PADDING = 8f;
|
||||||
|
private static final float RADIUS = 7f;
|
||||||
|
private static final float CLOSE_SIZE = 16f;
|
||||||
|
|
||||||
|
private final ClickGuiAnimator animator = new ClickGuiAnimator();
|
||||||
|
|
||||||
|
private Module module;
|
||||||
|
private List<Value<?>> settings;
|
||||||
|
|
||||||
|
private float x;
|
||||||
|
private float y;
|
||||||
|
private float width;
|
||||||
|
private float height;
|
||||||
|
|
||||||
|
private int screenWidth = 854;
|
||||||
|
private int screenHeight = 480;
|
||||||
|
|
||||||
|
private boolean dragging;
|
||||||
|
private float dragOffsetX;
|
||||||
|
private float dragOffsetY;
|
||||||
|
|
||||||
|
public boolean isOpen() {
|
||||||
|
return module != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void open(Module module, ClickGuiLayout layout) {
|
||||||
|
List<Value<?>> moduleSettings = ClickGuiModules.settingsOf(module);
|
||||||
|
if (moduleSettings.isEmpty()) {
|
||||||
|
close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.module = module;
|
||||||
|
this.settings = moduleSettings;
|
||||||
|
this.width = WIDTH;
|
||||||
|
this.height = HEADER_HEIGHT + BODY_PADDING * 2.0f
|
||||||
|
+ moduleSettings.size() * ROW_HEIGHT;
|
||||||
|
this.screenWidth = layout.screenWidth();
|
||||||
|
this.screenHeight = layout.screenHeight();
|
||||||
|
this.dragging = false;
|
||||||
|
|
||||||
|
this.x = layout.x() + (layout.width() - width) / 2.0f;
|
||||||
|
this.y = layout.y() + (layout.height() - height) / 2.0f;
|
||||||
|
this.x = ClickGuiStyle.clamp(x, 4.0f,
|
||||||
|
Math.max(4.0f, screenWidth - width - 4.0f));
|
||||||
|
this.y = ClickGuiStyle.clamp(y, 4.0f,
|
||||||
|
Math.max(4.0f, screenHeight - height - 4.0f));
|
||||||
|
this.x = Math.round(x);
|
||||||
|
this.y = Math.round(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
module = null;
|
||||||
|
settings = null;
|
||||||
|
dragging = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render(Render2D graphics, float delta,
|
||||||
|
double mouseX, double mouseY) {
|
||||||
|
if (!isOpen()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
graphics.fillRoundedRect(x - 3, y + 2, width + 6, height + 4,
|
||||||
|
RADIUS + 3, 0x26000000);
|
||||||
|
graphics.fillRoundedRect(x, y, width, height, RADIUS, 1.0,
|
||||||
|
ClickGuiStyle.COLOR_PANEL, ClickGuiStyle.COLOR_BORDER);
|
||||||
|
|
||||||
|
FontRenderer title = ClickGuiStyle.font(graphics, 11.0f, true);
|
||||||
|
title.drawString(module.getName(), x + 12, y + 7,
|
||||||
|
ClickGuiStyle.COLOR_TEXT);
|
||||||
|
|
||||||
|
FontRenderer subtitle = ClickGuiStyle.font(graphics, 7.0f, true);
|
||||||
|
subtitle.drawString("SETTINGS", x + 12, y + 19,
|
||||||
|
ClickGuiStyle.COLOR_TEXT_MUTED);
|
||||||
|
|
||||||
|
drawCloseButton(graphics, delta, mouseX, mouseY);
|
||||||
|
|
||||||
|
graphics.fillRect(x + 10, y + HEADER_HEIGHT - 1, width - 20, 1,
|
||||||
|
ClickGuiStyle.COLOR_DIVIDER);
|
||||||
|
|
||||||
|
float rowY = y + HEADER_HEIGHT + BODY_PADDING;
|
||||||
|
for (Value<?> value : settings) {
|
||||||
|
drawSettingRow(graphics, value, rowY, delta, mouseX, mouseY);
|
||||||
|
rowY += ROW_HEIGHT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawCloseButton(Render2D graphics, float delta,
|
||||||
|
double mouseX, double mouseY) {
|
||||||
|
float closeX = x + width - 12 - CLOSE_SIZE;
|
||||||
|
float closeY = y + (HEADER_HEIGHT - CLOSE_SIZE) / 2.0f;
|
||||||
|
boolean hovered = ClickGuiStyle.isInside(mouseX, mouseY, closeX,
|
||||||
|
closeY, CLOSE_SIZE, CLOSE_SIZE);
|
||||||
|
float hover = animator.hover(CLOSE_HOVER_KEY, hovered, delta);
|
||||||
|
|
||||||
|
if (hover > 0.01f) {
|
||||||
|
graphics.fillRoundedRect(closeX, closeY, CLOSE_SIZE, CLOSE_SIZE,
|
||||||
|
4, ClickGuiStyle.argb((int) (22.0f * hover),
|
||||||
|
ClickGuiStyle.COLOR_ACCENT_RGB));
|
||||||
|
}
|
||||||
|
|
||||||
|
FontRenderer close = ClickGuiStyle.font(graphics, 9.0f, true);
|
||||||
|
close.drawCenteredString("x", closeX + CLOSE_SIZE / 2.0,
|
||||||
|
closeY + (CLOSE_SIZE - close.getStringHeight()) / 2.0,
|
||||||
|
hovered ? ClickGuiStyle.COLOR_ACCENT
|
||||||
|
: ClickGuiStyle.COLOR_TEXT_MUTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawSettingRow(Render2D graphics, Value<?> value, float rowY,
|
||||||
|
float delta, double mouseX, double mouseY) {
|
||||||
|
boolean hovered = ClickGuiStyle.isInside(mouseX, mouseY, x + 6, rowY,
|
||||||
|
width - 12, ROW_HEIGHT);
|
||||||
|
float hover = animator.hover(value, hovered, delta);
|
||||||
|
|
||||||
|
if (hover > 0.01f) {
|
||||||
|
graphics.fillRoundedRect(x + 6, rowY, width - 12, ROW_HEIGHT, 4,
|
||||||
|
ClickGuiStyle.argb((int) (10.0f * hover), 0x00FFFFFF));
|
||||||
|
}
|
||||||
|
|
||||||
|
FontRenderer label = ClickGuiStyle.font(graphics, 9.0f);
|
||||||
|
label.drawString(value.getName(), x + 14,
|
||||||
|
ClickGuiStyle.centeredY(label, rowY, ROW_HEIGHT),
|
||||||
|
ClickGuiStyle.COLOR_TEXT_DIM);
|
||||||
|
|
||||||
|
float right = x + width - 12;
|
||||||
|
|
||||||
|
if (value instanceof BooleanValue) {
|
||||||
|
BooleanValue booleanValue = (BooleanValue) value;
|
||||||
|
float toggleWidth = ClickGuiStyle.SMALL_TOGGLE_WIDTH;
|
||||||
|
float toggleHeight = ClickGuiStyle.SMALL_TOGGLE_HEIGHT;
|
||||||
|
ClickGuiStyle.drawSwitch(graphics,
|
||||||
|
right - toggleWidth,
|
||||||
|
rowY + (ROW_HEIGHT - toggleHeight) / 2.0f,
|
||||||
|
toggleWidth, toggleHeight,
|
||||||
|
animator.state(value, booleanValue.isEnabled(), delta));
|
||||||
|
} else if (value instanceof ModeValue) {
|
||||||
|
ModeValue modeValue = (ModeValue) value;
|
||||||
|
FontRenderer modeFont = ClickGuiStyle.font(graphics, 9.0f);
|
||||||
|
String text = "< " + modeValue.getMode() + " >";
|
||||||
|
double pillWidth = modeFont.getStringWidth(text) + 10;
|
||||||
|
double pillX = right - pillWidth;
|
||||||
|
|
||||||
|
graphics.fillRoundedRect(pillX, rowY + 3, pillWidth,
|
||||||
|
ROW_HEIGHT - 6, 4,
|
||||||
|
ClickGuiStyle.argb(16, 0x00FFFFFF));
|
||||||
|
modeFont.drawString(text, pillX + 5,
|
||||||
|
ClickGuiStyle.centeredY(modeFont, rowY, ROW_HEIGHT),
|
||||||
|
ClickGuiStyle.COLOR_ACCENT);
|
||||||
|
} else {
|
||||||
|
FontRenderer valueFont = ClickGuiStyle.font(graphics, 9.0f);
|
||||||
|
String text = String.valueOf(value.getValue());
|
||||||
|
valueFont.drawString(text, right - valueFont.getStringWidth(text),
|
||||||
|
ClickGuiStyle.centeredY(valueFont, rowY, ROW_HEIGHT),
|
||||||
|
ClickGuiStyle.COLOR_TEXT_MUTED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {@code true} when the click was inside the window (and has been
|
||||||
|
* consumed), {@code false} when the caller should dismiss it.
|
||||||
|
*/
|
||||||
|
public boolean mouseClicked(float mouseX, float mouseY, int button) {
|
||||||
|
if (!isOpen()
|
||||||
|
|| !ClickGuiStyle.isInside(mouseX, mouseY, x, y,
|
||||||
|
width, height)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
float closeX = x + width - 12 - CLOSE_SIZE;
|
||||||
|
float closeY = y + (HEADER_HEIGHT - CLOSE_SIZE) / 2.0f;
|
||||||
|
if (button == 0 && ClickGuiStyle.isInside(mouseX, mouseY, closeX,
|
||||||
|
closeY, CLOSE_SIZE, CLOSE_SIZE)) {
|
||||||
|
close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ClickGuiStyle.isInside(mouseX, mouseY, x, y,
|
||||||
|
width, HEADER_HEIGHT)) {
|
||||||
|
if (button == 0) {
|
||||||
|
dragging = true;
|
||||||
|
dragOffsetX = mouseX - x;
|
||||||
|
dragOffsetY = mouseY - y;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
float rowY = y + HEADER_HEIGHT + BODY_PADDING;
|
||||||
|
for (Value<?> value : settings) {
|
||||||
|
if (ClickGuiStyle.isInside(mouseX, mouseY, x + 6, rowY,
|
||||||
|
width - 12, ROW_HEIGHT)) {
|
||||||
|
applySetting(value, button);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
rowY += ROW_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseDragged(float mouseX, float mouseY, int button) {
|
||||||
|
if (!isOpen() || !dragging || button != 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
x = ClickGuiStyle.clamp(mouseX - dragOffsetX, 4.0f,
|
||||||
|
Math.max(4.0f, screenWidth - width - 4.0f));
|
||||||
|
y = ClickGuiStyle.clamp(mouseY - dragOffsetY, 4.0f,
|
||||||
|
Math.max(4.0f, screenHeight - height - 4.0f));
|
||||||
|
x = Math.round(x);
|
||||||
|
y = Math.round(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseReleased(float mouseX, float mouseY, int button) {
|
||||||
|
if (button == 0) {
|
||||||
|
dragging = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applySetting(Value<?> value, int button) {
|
||||||
|
if (button != 0 && button != 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value instanceof BooleanValue) {
|
||||||
|
if (button == 0) {
|
||||||
|
((BooleanValue) value).toggle();
|
||||||
|
}
|
||||||
|
} else if (value instanceof ModeValue) {
|
||||||
|
ModeValue modeValue = (ModeValue) value;
|
||||||
|
if (button == 0) {
|
||||||
|
modeValue.next();
|
||||||
|
} else {
|
||||||
|
modeValue.previous();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package cn.xiaozhou233.orangex.ui.clickgui;
|
||||||
|
|
||||||
|
import cn.xiaozhou233.orangex.modules.Module;
|
||||||
|
import cn.xiaozhou233.orangex.modules.ModuleCategory;
|
||||||
|
import cn.xiaozhou233.orangex.render.api.FontRenderer;
|
||||||
|
import cn.xiaozhou233.orangex.render.api.Render2D;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the category card on the left of the ClickGUI window.
|
||||||
|
*/
|
||||||
|
public final class SidebarRenderer {
|
||||||
|
|
||||||
|
private static final ModuleCategory[] CATEGORIES = ModuleCategory.values();
|
||||||
|
|
||||||
|
private SidebarRenderer() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void draw(Render2D graphics, ClickGuiLayout layout,
|
||||||
|
ModuleCategory selectedCategory, List<Module> modules,
|
||||||
|
ClickGuiAnimator animator, float delta,
|
||||||
|
double mouseX, double mouseY) {
|
||||||
|
float x = layout.x();
|
||||||
|
float y = layout.y();
|
||||||
|
|
||||||
|
float cardX = x + ClickGuiStyle.SIDEBAR_CARD_X;
|
||||||
|
float cardY = y + ClickGuiStyle.SIDEBAR_CARD_Y;
|
||||||
|
float cardWidth = ClickGuiStyle.SIDEBAR_WIDTH;
|
||||||
|
float cardHeight = layout.height() - ClickGuiStyle.HEADER_HEIGHT
|
||||||
|
- 16;
|
||||||
|
|
||||||
|
graphics.fillRoundedRect(cardX, cardY, cardWidth, cardHeight, 6,
|
||||||
|
1.0, ClickGuiStyle.COLOR_SIDEBAR_BG,
|
||||||
|
ClickGuiStyle.COLOR_SIDEBAR_BORDER);
|
||||||
|
|
||||||
|
int[] counts = new int[CATEGORIES.length];
|
||||||
|
for (Module module : modules) {
|
||||||
|
counts[module.getCategory().ordinal()]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
float rowX = layout.categoryRowX();
|
||||||
|
float rowWidth = layout.categoryRowWidth();
|
||||||
|
float rowY = layout.categoryRowTop();
|
||||||
|
float rowHeight = layout.categoryRowHeight();
|
||||||
|
|
||||||
|
for (ModuleCategory category : CATEGORIES) {
|
||||||
|
boolean selected = category == selectedCategory;
|
||||||
|
boolean hovered = ClickGuiStyle.isInside(mouseX, mouseY, rowX, rowY,
|
||||||
|
rowWidth, rowHeight);
|
||||||
|
float hover = animator.hover(category, hovered, delta);
|
||||||
|
|
||||||
|
if (selected || hover > 0.01f) {
|
||||||
|
int alpha = selected
|
||||||
|
? (int) (22.0f + 10.0f * hover)
|
||||||
|
: (int) (10.0f * hover);
|
||||||
|
graphics.fillRoundedRect(rowX, rowY, rowWidth, rowHeight, 5,
|
||||||
|
ClickGuiStyle.argb(alpha,
|
||||||
|
ClickGuiStyle.COLOR_ACCENT_RGB));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selected) {
|
||||||
|
float barHeight = Math.max(4.0f, rowHeight - 12.0f);
|
||||||
|
graphics.fillRoundedRect(rowX + 3,
|
||||||
|
rowY + (rowHeight - barHeight) / 2.0f,
|
||||||
|
2.5f, barHeight, 1.25f, ClickGuiStyle.COLOR_ACCENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
FontRenderer label = ClickGuiStyle.font(graphics, 10.0f, selected);
|
||||||
|
label.drawString(ClickGuiModules.displayName(category), rowX + 12,
|
||||||
|
ClickGuiStyle.centeredY(label, rowY, rowHeight),
|
||||||
|
selected ? ClickGuiStyle.COLOR_TEXT
|
||||||
|
: ClickGuiStyle.COLOR_TEXT_DIM);
|
||||||
|
|
||||||
|
String count = String.valueOf(counts[category.ordinal()]);
|
||||||
|
FontRenderer countFont = ClickGuiStyle.font(graphics, 8.0f);
|
||||||
|
countFont.drawString(count,
|
||||||
|
rowX + rowWidth - 10 - countFont.getStringWidth(count),
|
||||||
|
ClickGuiStyle.centeredY(countFont, rowY, rowHeight),
|
||||||
|
selected ? ClickGuiStyle.COLOR_ACCENT
|
||||||
|
: ClickGuiStyle.COLOR_TEXT_MUTED);
|
||||||
|
|
||||||
|
rowY += rowHeight + ClickGuiStyle.CATEGORY_GAP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package cn.xiaozhou233.orangex.ui.clickgui.component;
|
||||||
|
|
||||||
|
import cn.xiaozhou233.orangex.event.impl.EventRender2D;
|
||||||
|
|
||||||
|
public abstract class Component {
|
||||||
|
|
||||||
|
protected float x;
|
||||||
|
protected float y;
|
||||||
|
|
||||||
|
protected float width;
|
||||||
|
protected float height;
|
||||||
|
|
||||||
|
protected boolean visible = true;
|
||||||
|
protected boolean enabled = true;
|
||||||
|
|
||||||
|
public abstract void render(EventRender2D event);
|
||||||
|
|
||||||
|
public void update() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseClicked(float mouseX, float mouseY, int button) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseReleased(float mouseX, float mouseY, int button) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseDragged(float mouseX, float mouseY, int button) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyTyped(char character, int keyCode) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBounds(
|
||||||
|
float x,
|
||||||
|
float y,
|
||||||
|
float width,
|
||||||
|
float height
|
||||||
|
) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(float mouseX, float mouseY) {
|
||||||
|
return mouseX >= x
|
||||||
|
&& mouseX <= x + width
|
||||||
|
&& mouseY >= y
|
||||||
|
&& mouseY <= y + height;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package cn.xiaozhou233.orangex.wrapper;
|
|||||||
import cn.xiaozhou233.orangex.mapping.MappingResolver;
|
import cn.xiaozhou233.orangex.mapping.MappingResolver;
|
||||||
import cn.xiaozhou233.orangex.runtime.RuntimeInfo;
|
import cn.xiaozhou233.orangex.runtime.RuntimeInfo;
|
||||||
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
|
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.api.WorldView;
|
||||||
import cn.xiaozhou233.orangex.wrapper.internal.WrapperContext;
|
import cn.xiaozhou233.orangex.wrapper.internal.WrapperContext;
|
||||||
import cn.xiaozhou233.orangex.wrapper.internal.WrapperRegistry;
|
import cn.xiaozhou233.orangex.wrapper.internal.WrapperRegistry;
|
||||||
|
|
||||||
@@ -19,6 +20,17 @@ public final class MinecraftFactory {
|
|||||||
new WrapperContext(runtimeInfo, mappingResolver));
|
new WrapperContext(runtimeInfo, mappingResolver));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the world/camera view that goes with an already created
|
||||||
|
* {@link Minecraft} wrapper.
|
||||||
|
*/
|
||||||
|
public static WorldView createWorld(RuntimeInfo runtimeInfo,
|
||||||
|
MappingResolver mappingResolver,
|
||||||
|
Minecraft minecraft) {
|
||||||
|
return WrapperRegistry.createWorld(
|
||||||
|
new WrapperContext(runtimeInfo, mappingResolver), minecraft);
|
||||||
|
}
|
||||||
|
|
||||||
private MinecraftFactory() {
|
private MinecraftFactory() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package cn.xiaozhou233.orangex.wrapper.api;
|
||||||
|
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.common.WorldSnapshot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cross-version view of the rendered world: camera state and nearby players.
|
||||||
|
*
|
||||||
|
* <p>Implementations read the game every time {@link #snapshot()} is called,
|
||||||
|
* so the result must only be used for the frame that produced it. Feature
|
||||||
|
* code (ESP, tracers, ...) should depend on this interface and on the
|
||||||
|
* {@code wrapper.common} value objects only.</p>
|
||||||
|
*/
|
||||||
|
public interface WorldView {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Captures the camera and player list for the current frame.
|
||||||
|
*
|
||||||
|
* @return {@code null} while no level is loaded (title screen, loading).
|
||||||
|
*/
|
||||||
|
WorldSnapshot snapshot();
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package cn.xiaozhou233.orangex.wrapper.common;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Version-independent snapshot of one player entity that feature code can
|
||||||
|
* render (for example an ESP target).
|
||||||
|
*/
|
||||||
|
public final class EntityTarget {
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final Vec3 position;
|
||||||
|
private final double width;
|
||||||
|
private final double height;
|
||||||
|
private final float health;
|
||||||
|
private final float maxHealth;
|
||||||
|
private final double distance;
|
||||||
|
|
||||||
|
public EntityTarget(String name,
|
||||||
|
Vec3 position,
|
||||||
|
double width,
|
||||||
|
double height,
|
||||||
|
float health,
|
||||||
|
float maxHealth,
|
||||||
|
double distance) {
|
||||||
|
this.name = name;
|
||||||
|
this.position = position;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
this.health = health;
|
||||||
|
this.maxHealth = maxHealth;
|
||||||
|
this.distance = distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interpolated feet position of the entity.
|
||||||
|
*/
|
||||||
|
public Vec3 getPosition() {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getWidth() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getHeight() {
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getHealth() {
|
||||||
|
return health;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getMaxHealth() {
|
||||||
|
return maxHealth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Distance between the entity feet and the camera.
|
||||||
|
*/
|
||||||
|
public double getDistance() {
|
||||||
|
return distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "EntityTarget{name='" + name + "', position=" + position
|
||||||
|
+ ", health=" + health + "/" + maxHealth
|
||||||
|
+ ", distance=" + distance + "}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
package cn.xiaozhou233.orangex.wrapper.common;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Camera-independent perspective projection.
|
||||||
|
*
|
||||||
|
* <p>Minecraft treats the perspective FOV as a <em>vertical</em> angle in
|
||||||
|
* degrees and uses a conventional right-handed view: yaw {@code 0} looks
|
||||||
|
* towards {@code +Z}, positive yaw turns towards {@code -X}, and positive
|
||||||
|
* pitch looks down. Both the 1.8.9 and the modern clients share these
|
||||||
|
* conventions, so the same math works on every version.</p>
|
||||||
|
*/
|
||||||
|
public final class Projection {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Points closer than this are treated as behind the camera. It matches the
|
||||||
|
* near plane Minecraft uses for its perspective projection.
|
||||||
|
*/
|
||||||
|
private static final double NEAR_PLANE = 0.05D;
|
||||||
|
|
||||||
|
private static final float DEFAULT_FOV = 70.0F;
|
||||||
|
|
||||||
|
public static ScreenPoint project(Vec3 camera,
|
||||||
|
float yawDegrees,
|
||||||
|
float pitchDegrees,
|
||||||
|
float fovDegrees,
|
||||||
|
int screenWidth,
|
||||||
|
int screenHeight,
|
||||||
|
Vec3 point) {
|
||||||
|
if (camera == null || point == null
|
||||||
|
|| screenWidth <= 0 || screenHeight <= 0) {
|
||||||
|
return ScreenPoint.behind();
|
||||||
|
}
|
||||||
|
|
||||||
|
double yaw = Math.toRadians(yawDegrees);
|
||||||
|
double pitch = Math.toRadians(pitchDegrees);
|
||||||
|
|
||||||
|
double sinYaw = Math.sin(yaw);
|
||||||
|
double cosYaw = Math.cos(yaw);
|
||||||
|
double sinPitch = Math.sin(pitch);
|
||||||
|
double cosPitch = Math.cos(pitch);
|
||||||
|
|
||||||
|
// Camera basis (camera looks along -forward, forwards is +Z at yaw 0).
|
||||||
|
double forwardX = -sinYaw * cosPitch;
|
||||||
|
double forwardY = -sinPitch;
|
||||||
|
double forwardZ = cosYaw * cosPitch;
|
||||||
|
|
||||||
|
double rightX = -cosYaw;
|
||||||
|
double rightZ = -sinYaw;
|
||||||
|
|
||||||
|
double upX = -sinYaw * sinPitch;
|
||||||
|
double upY = cosPitch;
|
||||||
|
double upZ = cosYaw * sinPitch;
|
||||||
|
|
||||||
|
double dx = point.getX() - camera.getX();
|
||||||
|
double dy = point.getY() - camera.getY();
|
||||||
|
double dz = point.getZ() - camera.getZ();
|
||||||
|
|
||||||
|
double depth = dx * forwardX + dy * forwardY + dz * forwardZ;
|
||||||
|
if (depth <= NEAR_PLANE) {
|
||||||
|
return ScreenPoint.behind();
|
||||||
|
}
|
||||||
|
|
||||||
|
double x = dx * rightX + dz * rightZ;
|
||||||
|
double y = dx * upX + dy * upY + dz * upZ;
|
||||||
|
|
||||||
|
float fov = fovDegrees > 1.0F ? fovDegrees : DEFAULT_FOV;
|
||||||
|
double tanHalfFov = Math.tan(Math.toRadians(fov) * 0.5D);
|
||||||
|
double aspect = (double) screenWidth / (double) screenHeight;
|
||||||
|
|
||||||
|
double ndcX = x / (depth * tanHalfFov * aspect);
|
||||||
|
double ndcY = y / (depth * tanHalfFov);
|
||||||
|
|
||||||
|
double screenX = (ndcX + 1.0D) * 0.5D * screenWidth;
|
||||||
|
double screenY = (1.0D - ndcY) * 0.5D * screenHeight;
|
||||||
|
|
||||||
|
return new ScreenPoint(screenX, screenY, depth, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Projection() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package cn.xiaozhou233.orangex.wrapper.common;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A world position projected into 2D GUI pixel space.
|
||||||
|
*
|
||||||
|
* <p>{@link #isVisible()} is {@code false} when the point is behind the
|
||||||
|
* camera (or outside the near plane); callers must not draw such a point.</p>
|
||||||
|
*/
|
||||||
|
public final class ScreenPoint {
|
||||||
|
|
||||||
|
private final double x;
|
||||||
|
private final double y;
|
||||||
|
private final double depth;
|
||||||
|
private final boolean visible;
|
||||||
|
|
||||||
|
public ScreenPoint(double x, double y, double depth, boolean visible) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.depth = depth;
|
||||||
|
this.visible = visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ScreenPoint behind() {
|
||||||
|
return new ScreenPoint(0.0D, 0.0D, -1.0D, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Distance along the camera forward axis.
|
||||||
|
*/
|
||||||
|
public double getDepth() {
|
||||||
|
return depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isVisible() {
|
||||||
|
return visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ScreenPoint{x=" + x + ", y=" + y + ", depth=" + depth
|
||||||
|
+ ", visible=" + visible + "}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package cn.xiaozhou233.orangex.wrapper.common;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One frame of world data: camera state plus the visible player list.
|
||||||
|
*
|
||||||
|
* <p>Snapshots are immutable and are produced on the render thread, so the
|
||||||
|
* partial tick is read only once and every position in this object belongs to
|
||||||
|
* the same frame.</p>
|
||||||
|
*/
|
||||||
|
public final class WorldSnapshot {
|
||||||
|
|
||||||
|
private final Vec3 cameraPosition;
|
||||||
|
private final float cameraYaw;
|
||||||
|
private final float cameraPitch;
|
||||||
|
private final float fieldOfView;
|
||||||
|
private final List<EntityTarget> targets;
|
||||||
|
|
||||||
|
public WorldSnapshot(Vec3 cameraPosition,
|
||||||
|
float cameraYaw,
|
||||||
|
float cameraPitch,
|
||||||
|
float fieldOfView,
|
||||||
|
List<EntityTarget> targets) {
|
||||||
|
this.cameraPosition = cameraPosition;
|
||||||
|
this.cameraYaw = cameraYaw;
|
||||||
|
this.cameraPitch = cameraPitch;
|
||||||
|
this.fieldOfView = fieldOfView;
|
||||||
|
this.targets = Collections.unmodifiableList(
|
||||||
|
new ArrayList<EntityTarget>(targets));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vec3 getCameraPosition() {
|
||||||
|
return cameraPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getCameraYaw() {
|
||||||
|
return cameraYaw;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getCameraPitch() {
|
||||||
|
return cameraPitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vertical field of view in degrees.
|
||||||
|
*/
|
||||||
|
public float getFieldOfView() {
|
||||||
|
return fieldOfView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<EntityTarget> getTargets() {
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScreenPoint project(Vec3 worldPoint, int screenWidth, int screenHeight) {
|
||||||
|
return Projection.project(cameraPosition, cameraYaw, cameraPitch,
|
||||||
|
fieldOfView, screenWidth, screenHeight, worldPoint);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
package cn.xiaozhou233.orangex.wrapper.internal;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reflective lookup helpers shared by the version-specific wrappers.
|
||||||
|
*
|
||||||
|
* <p>This class intentionally knows nothing about Minecraft: version packages
|
||||||
|
* pass the resolved member names in. Lookups walk the class hierarchy because
|
||||||
|
* Minecraft frequently declares a member on a base class and stores an
|
||||||
|
* instance of a subclass.</p>
|
||||||
|
*/
|
||||||
|
public final class ReflectionSupport {
|
||||||
|
|
||||||
|
public static Field findField(Class<?> type, String name) {
|
||||||
|
if (type == null || name == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Class<?> current = type; current != null; current = current.getSuperclass()) {
|
||||||
|
try {
|
||||||
|
Field field = current.getDeclaredField(name);
|
||||||
|
if (Modifier.isStatic(field.getModifiers())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
field.setAccessible(true);
|
||||||
|
return field;
|
||||||
|
} catch (NoSuchFieldException ignored) {
|
||||||
|
// Keep walking the superclass chain.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Field requireField(Class<?> type, String name, String ownerName) {
|
||||||
|
Field field = findField(type, name);
|
||||||
|
if (field == null) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Cannot find field '" + name + "' on " + ownerName);
|
||||||
|
}
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Method findMethod(Class<?> type,
|
||||||
|
String name,
|
||||||
|
Class<?> returnType,
|
||||||
|
Class<?>... parameterTypes) {
|
||||||
|
if (type == null || name == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Class<?> current = type; current != null; current = current.getSuperclass()) {
|
||||||
|
Method[] methods = current.getDeclaredMethods();
|
||||||
|
for (Method method : methods) {
|
||||||
|
if (!method.getName().equals(name)
|
||||||
|
|| Modifier.isStatic(method.getModifiers())
|
||||||
|
|| !sameParameters(method, parameterTypes)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (returnType != null && !returnType.equals(method.getReturnType())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
method.setAccessible(true);
|
||||||
|
return method;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Method requireMethod(Class<?> type,
|
||||||
|
String name,
|
||||||
|
Class<?> returnType,
|
||||||
|
String ownerName,
|
||||||
|
Class<?>... parameterTypes) {
|
||||||
|
Method method = findMethod(type, name, returnType, parameterTypes);
|
||||||
|
if (method == null) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Cannot find method '" + name + "' on " + ownerName);
|
||||||
|
}
|
||||||
|
return method;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object get(Field field, Object target) {
|
||||||
|
try {
|
||||||
|
return field.get(target);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Cannot read field '" + field.getName() + "'", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double getDouble(Field field, Object target) {
|
||||||
|
try {
|
||||||
|
return field.getDouble(target);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Cannot read field '" + field.getName() + "'", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float getFloat(Field field, Object target) {
|
||||||
|
try {
|
||||||
|
return field.getFloat(target);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Cannot read field '" + field.getName() + "'", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getInt(Field field, Object target) {
|
||||||
|
try {
|
||||||
|
return field.getInt(target);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Cannot read field '" + field.getName() + "'", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean getBoolean(Field field, Object target) {
|
||||||
|
try {
|
||||||
|
return field.getBoolean(target);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Cannot read field '" + field.getName() + "'", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object invoke(Method method, Object target, Object... arguments) {
|
||||||
|
try {
|
||||||
|
return method.invoke(target, arguments);
|
||||||
|
} catch (ReflectiveOperationException e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Cannot invoke method '" + method.getName() + "'", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean sameParameters(Method method, Class<?>[] parameterTypes) {
|
||||||
|
Class<?>[] actual = method.getParameterTypes();
|
||||||
|
if (actual.length != parameterTypes.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < actual.length; i++) {
|
||||||
|
if (!actual[i].equals(parameterTypes[i])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ReflectionSupport() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package cn.xiaozhou233.orangex.wrapper.internal;
|
package cn.xiaozhou233.orangex.wrapper.internal;
|
||||||
|
|
||||||
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
|
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.api.WorldView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the wrappers for one Minecraft version.
|
* Creates the wrappers for one Minecraft version.
|
||||||
@@ -18,4 +19,9 @@ public interface WrapperProvider {
|
|||||||
* Creates the wrapper for {@code net.minecraft.client.Minecraft}.
|
* Creates the wrapper for {@code net.minecraft.client.Minecraft}.
|
||||||
*/
|
*/
|
||||||
Minecraft createMinecraft(WrapperContext context);
|
Minecraft createMinecraft(WrapperContext context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the world/camera view backed by the given client instance.
|
||||||
|
*/
|
||||||
|
WorldView createWorld(WrapperContext context, Minecraft minecraft);
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ package cn.xiaozhou233.orangex.wrapper.internal;
|
|||||||
|
|
||||||
import cn.xiaozhou233.orangex.runtime.version.MinecraftVersion;
|
import cn.xiaozhou233.orangex.runtime.version.MinecraftVersion;
|
||||||
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
|
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.api.WorldView;
|
||||||
import cn.xiaozhou233.orangex.wrapper.internal.v1_8_9.V1_8_9WrapperProvider;
|
import cn.xiaozhou233.orangex.wrapper.internal.v1_8_9.V1_8_9WrapperProvider;
|
||||||
import cn.xiaozhou233.orangex.wrapper.internal.v26_2.V26_2WrapperProvider;
|
import cn.xiaozhou233.orangex.wrapper.internal.v26_2.V26_2WrapperProvider;
|
||||||
|
|
||||||
@@ -45,6 +46,14 @@ public final class WrapperRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Minecraft createMinecraft(WrapperContext context) {
|
public static Minecraft createMinecraft(WrapperContext context) {
|
||||||
|
return provider(context).createMinecraft(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WorldView createWorld(WrapperContext context, Minecraft minecraft) {
|
||||||
|
return provider(context).createWorld(context, minecraft);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static WrapperProvider provider(WrapperContext context) {
|
||||||
MinecraftVersion version = context.getRuntimeInfo().getMinecraftVersion();
|
MinecraftVersion version = context.getRuntimeInfo().getMinecraftVersion();
|
||||||
WrapperProvider provider = PROVIDERS.get(version);
|
WrapperProvider provider = PROVIDERS.get(version);
|
||||||
|
|
||||||
@@ -53,7 +62,7 @@ public final class WrapperRegistry {
|
|||||||
"Unsupported Minecraft version: " + version);
|
"Unsupported Minecraft version: " + version);
|
||||||
}
|
}
|
||||||
|
|
||||||
return provider.createMinecraft(context);
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
private WrapperRegistry() {
|
private WrapperRegistry() {
|
||||||
|
|||||||
+501
@@ -0,0 +1,501 @@
|
|||||||
|
package cn.xiaozhou233.orangex.wrapper.internal.v1_8_9;
|
||||||
|
|
||||||
|
import cn.xiaozhou233.orangex.mapping.MappingClass;
|
||||||
|
import cn.xiaozhou233.orangex.mapping.MappingField;
|
||||||
|
import cn.xiaozhou233.orangex.mapping.MappingMethod;
|
||||||
|
import cn.xiaozhou233.orangex.mapping.MappingResolver;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.api.WorldView;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.common.EntityTarget;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.common.Vec3;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.common.WorldSnapshot;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.internal.ReflectionSupport;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1.8.9 implementation of {@link WorldView}.
|
||||||
|
*
|
||||||
|
* <p>All names below are MCP (named) names and are translated through the
|
||||||
|
* active {@link MappingResolver}. The camera math mirrors
|
||||||
|
* {@code EntityRenderer#orientCamera}: the eye position of the render view
|
||||||
|
* entity plus an optional third-person offset along the camera forward
|
||||||
|
* vector.</p>
|
||||||
|
*/
|
||||||
|
public final class V1_8_9WorldView implements WorldView {
|
||||||
|
|
||||||
|
private static final String MINECRAFT = "net/minecraft/client/Minecraft";
|
||||||
|
private static final String GAME_SETTINGS = "net/minecraft/client/settings/GameSettings";
|
||||||
|
private static final String TIMER = "net/minecraft/util/Timer";
|
||||||
|
private static final String WORLD = "net/minecraft/world/World";
|
||||||
|
private static final String ENTITY = "net/minecraft/entity/Entity";
|
||||||
|
private static final String ENTITY_LIVING = "net/minecraft/entity/EntityLivingBase";
|
||||||
|
private static final String ENTITY_PLAYER = "net/minecraft/entity/player/EntityPlayer";
|
||||||
|
private static final String ENTITY_RENDERER = "net/minecraft/client/renderer/EntityRenderer";
|
||||||
|
|
||||||
|
private static final float DEFAULT_FOV = 70.0F;
|
||||||
|
private static final float DEFAULT_THIRD_PERSON_DISTANCE = 4.0F;
|
||||||
|
private static final double FIRST_PERSON_OFFSET = 0.1D;
|
||||||
|
|
||||||
|
private final MappingResolver resolver;
|
||||||
|
private final Object minecraft;
|
||||||
|
|
||||||
|
private final Field worldField;
|
||||||
|
private final Field playerField;
|
||||||
|
private final Field viewEntityField;
|
||||||
|
private final Field timerField;
|
||||||
|
private final Field gameSettingsField;
|
||||||
|
private final Field entityRendererField;
|
||||||
|
|
||||||
|
private final String partialTicksName;
|
||||||
|
private final String playerEntitiesName;
|
||||||
|
private final String thirdPersonViewName;
|
||||||
|
private final String fovSettingName;
|
||||||
|
private final String fovModifierMethodName;
|
||||||
|
private final String thirdPersonDistanceName;
|
||||||
|
private final String thirdPersonDistanceTempName;
|
||||||
|
|
||||||
|
private Field partialTicksField;
|
||||||
|
private Field playerEntitiesField;
|
||||||
|
private Field thirdPersonViewField;
|
||||||
|
private Field fovSettingField;
|
||||||
|
private Field thirdPersonDistanceField;
|
||||||
|
private Field thirdPersonDistanceTempField;
|
||||||
|
private Method fovModifierMethod;
|
||||||
|
private boolean optionalCameraFieldsResolved;
|
||||||
|
|
||||||
|
private final Map<Class<?>, EntityAccess> accessCache =
|
||||||
|
new HashMap<Class<?>, EntityAccess>();
|
||||||
|
|
||||||
|
public V1_8_9WorldView(MappingResolver resolver, Minecraft minecraft) {
|
||||||
|
this.resolver = resolver;
|
||||||
|
this.minecraft = minecraft.getMinecraft();
|
||||||
|
Class<?> minecraftClass = this.minecraft.getClass();
|
||||||
|
|
||||||
|
MappingClass minecraftMapping = resolver.mapClass(MINECRAFT);
|
||||||
|
this.worldField = resolveField(minecraftMapping, "theWorld", minecraftClass);
|
||||||
|
this.playerField = resolveField(minecraftMapping, "thePlayer", minecraftClass);
|
||||||
|
this.viewEntityField = resolveField(minecraftMapping, "renderViewEntity", minecraftClass);
|
||||||
|
this.timerField = resolveField(minecraftMapping, "timer", minecraftClass);
|
||||||
|
this.gameSettingsField = resolveField(minecraftMapping, "gameSettings", minecraftClass);
|
||||||
|
this.entityRendererField = resolveField(minecraftMapping, "entityRenderer", minecraftClass);
|
||||||
|
|
||||||
|
this.partialTicksName = fieldName(TIMER, "renderPartialTicks");
|
||||||
|
this.playerEntitiesName = fieldName(WORLD, "playerEntities");
|
||||||
|
this.thirdPersonViewName = fieldName(GAME_SETTINGS, "thirdPersonView");
|
||||||
|
this.fovSettingName = fieldName(GAME_SETTINGS, "fovSetting");
|
||||||
|
this.fovModifierMethodName = methodName(
|
||||||
|
ENTITY_RENDERER, "getFOVModifier", "(FZ)F");
|
||||||
|
this.thirdPersonDistanceName = optionalFieldName(
|
||||||
|
ENTITY_RENDERER, "thirdPersonDistance");
|
||||||
|
this.thirdPersonDistanceTempName = optionalFieldName(
|
||||||
|
ENTITY_RENDERER, "thirdPersonDistanceTemp");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WorldSnapshot snapshot() {
|
||||||
|
Object world = ReflectionSupport.get(worldField, minecraft);
|
||||||
|
Object viewEntity = ReflectionSupport.get(viewEntityField, minecraft);
|
||||||
|
Object localPlayer = ReflectionSupport.get(playerField, minecraft);
|
||||||
|
|
||||||
|
if (world == null || viewEntity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
float partialTicks = partialTicks();
|
||||||
|
EntityAccess view = accessFor(viewEntity.getClass());
|
||||||
|
|
||||||
|
double eyeX = interpolate(view.posX, view.lastTickPosX, viewEntity, partialTicks);
|
||||||
|
double eyeY = interpolate(view.posY, view.lastTickPosY, viewEntity, partialTicks)
|
||||||
|
+ invokeFloat(view.eyeHeight, viewEntity);
|
||||||
|
double eyeZ = interpolate(view.posZ, view.lastTickPosZ, viewEntity, partialTicks);
|
||||||
|
|
||||||
|
float yaw = interpolateAngle(view.rotationYaw, view.prevRotationYaw,
|
||||||
|
viewEntity, partialTicks);
|
||||||
|
float pitch = interpolateAngle(view.rotationPitch, view.prevRotationPitch,
|
||||||
|
viewEntity, partialTicks);
|
||||||
|
|
||||||
|
int thirdPerson = thirdPersonView();
|
||||||
|
float cameraYaw = yaw;
|
||||||
|
float cameraPitch = pitch;
|
||||||
|
|
||||||
|
if (thirdPerson == 2) {
|
||||||
|
// Front view: the camera sits in front of the player and looks
|
||||||
|
// back, so both axes are mirrored.
|
||||||
|
cameraYaw = yaw + 180.0F;
|
||||||
|
cameraPitch = -pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Third person moves the camera back by the configured distance;
|
||||||
|
// first person sits 0.1 blocks behind the eye (EntityRenderer).
|
||||||
|
double cameraOffset = thirdPerson > 0
|
||||||
|
? thirdPersonDistance(partialTicks)
|
||||||
|
: FIRST_PERSON_OFFSET;
|
||||||
|
|
||||||
|
double yawRadians = Math.toRadians(cameraYaw);
|
||||||
|
double pitchRadians = Math.toRadians(cameraPitch);
|
||||||
|
|
||||||
|
double forwardX = -Math.sin(yawRadians) * Math.cos(pitchRadians);
|
||||||
|
double forwardY = -Math.sin(pitchRadians);
|
||||||
|
double forwardZ = Math.cos(yawRadians) * Math.cos(pitchRadians);
|
||||||
|
|
||||||
|
double cameraX = eyeX - forwardX * cameraOffset;
|
||||||
|
double cameraY = eyeY - forwardY * cameraOffset;
|
||||||
|
double cameraZ = eyeZ - forwardZ * cameraOffset;
|
||||||
|
|
||||||
|
float fov = fieldOfView(partialTicks);
|
||||||
|
List<EntityTarget> targets = collectTargets(
|
||||||
|
world, localPlayer, cameraX, cameraY, cameraZ, partialTicks);
|
||||||
|
|
||||||
|
return new WorldSnapshot(new Vec3(cameraX, cameraY, cameraZ),
|
||||||
|
cameraYaw, cameraPitch, fov, targets);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<EntityTarget> collectTargets(Object world,
|
||||||
|
Object localPlayer,
|
||||||
|
double cameraX,
|
||||||
|
double cameraY,
|
||||||
|
double cameraZ,
|
||||||
|
float partialTicks) {
|
||||||
|
List<EntityTarget> targets = new ArrayList<EntityTarget>();
|
||||||
|
|
||||||
|
Field entitiesField = playerEntitiesField(world.getClass());
|
||||||
|
if (entitiesField == null) {
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object value = ReflectionSupport.get(entitiesField, world);
|
||||||
|
if (!(value instanceof List)) {
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Object entity : (List<?>) value) {
|
||||||
|
if (entity == null || entity == localPlayer) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityAccess access = accessFor(entity.getClass());
|
||||||
|
|
||||||
|
if (access.isAlive != null && !invokeBoolean(access.isAlive, entity)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (access.isInvisible != null && invokeBoolean(access.isInvisible, entity)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (access.isSpectator != null && invokeBoolean(access.isSpectator, entity)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
float health = invokeFloat(access.getHealth, entity);
|
||||||
|
if (health <= 0.0F) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
double x = interpolate(access.posX, access.lastTickPosX, entity, partialTicks);
|
||||||
|
double y = interpolate(access.posY, access.lastTickPosY, entity, partialTicks);
|
||||||
|
double z = interpolate(access.posZ, access.lastTickPosZ, entity, partialTicks);
|
||||||
|
|
||||||
|
double width = access.width == null ? 0.6D
|
||||||
|
: ReflectionSupport.getFloat(access.width, entity);
|
||||||
|
double height = access.height == null ? 1.8D
|
||||||
|
: ReflectionSupport.getFloat(access.height, entity);
|
||||||
|
|
||||||
|
double distance = distance(cameraX, cameraY, cameraZ, x, y, z);
|
||||||
|
|
||||||
|
targets.add(new EntityTarget(
|
||||||
|
String.valueOf(ReflectionSupport.invoke(access.getName, entity)),
|
||||||
|
new Vec3(x, y, z),
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
health,
|
||||||
|
invokeFloat(access.getMaxHealth, entity),
|
||||||
|
distance));
|
||||||
|
}
|
||||||
|
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
|
||||||
|
private float partialTicks() {
|
||||||
|
Object timer = ReflectionSupport.get(timerField, minecraft);
|
||||||
|
if (timer == null) {
|
||||||
|
return 0.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (partialTicksField == null) {
|
||||||
|
partialTicksField = ReflectionSupport.findField(
|
||||||
|
timer.getClass(), partialTicksName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return partialTicksField == null
|
||||||
|
? 0.0F
|
||||||
|
: ReflectionSupport.getFloat(partialTicksField, timer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int thirdPersonView() {
|
||||||
|
Object settings = ReflectionSupport.get(gameSettingsField, minecraft);
|
||||||
|
if (settings == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thirdPersonViewField == null) {
|
||||||
|
thirdPersonViewField = ReflectionSupport.findField(
|
||||||
|
settings.getClass(), thirdPersonViewName);
|
||||||
|
}
|
||||||
|
if (thirdPersonViewField == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1.8.9 stores an int (0/1/2); some 1.8 builds use a boolean flag.
|
||||||
|
if (thirdPersonViewField.getType() == boolean.class) {
|
||||||
|
return ReflectionSupport.getBoolean(thirdPersonViewField, settings) ? 1 : 0;
|
||||||
|
}
|
||||||
|
return ReflectionSupport.getInt(thirdPersonViewField, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
private float fieldOfView(float partialTicks) {
|
||||||
|
Object renderer = ReflectionSupport.get(entityRendererField, minecraft);
|
||||||
|
if (renderer != null && fovModifierMethod == null) {
|
||||||
|
fovModifierMethod = ReflectionSupport.findMethod(
|
||||||
|
renderer.getClass(), fovModifierMethodName,
|
||||||
|
float.class, float.class, boolean.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fovModifierMethod != null) {
|
||||||
|
return ((Number) ReflectionSupport.invoke(
|
||||||
|
fovModifierMethod, renderer, partialTicks, Boolean.TRUE))
|
||||||
|
.floatValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
Object settings = ReflectionSupport.get(gameSettingsField, minecraft);
|
||||||
|
if (settings != null) {
|
||||||
|
if (fovSettingField == null) {
|
||||||
|
fovSettingField = ReflectionSupport.findField(
|
||||||
|
settings.getClass(), fovSettingName);
|
||||||
|
}
|
||||||
|
if (fovSettingField != null) {
|
||||||
|
return ReflectionSupport.getFloat(fovSettingField, settings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return DEFAULT_FOV;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double thirdPersonDistance(float partialTicks) {
|
||||||
|
Object renderer = ReflectionSupport.get(entityRendererField, minecraft);
|
||||||
|
if (renderer == null || !resolveOptionalCameraFields(renderer.getClass())) {
|
||||||
|
return DEFAULT_THIRD_PERSON_DISTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
float previous = thirdPersonDistanceTempField == null
|
||||||
|
? DEFAULT_THIRD_PERSON_DISTANCE
|
||||||
|
: ReflectionSupport.getFloat(thirdPersonDistanceTempField, renderer);
|
||||||
|
float current = thirdPersonDistanceField == null
|
||||||
|
? DEFAULT_THIRD_PERSON_DISTANCE
|
||||||
|
: ReflectionSupport.getFloat(thirdPersonDistanceField, renderer);
|
||||||
|
|
||||||
|
return previous + (current - previous) * partialTicks;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean resolveOptionalCameraFields(Class<?> rendererClass) {
|
||||||
|
if (optionalCameraFieldsResolved) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
optionalCameraFieldsResolved = true;
|
||||||
|
|
||||||
|
if (thirdPersonDistanceName != null) {
|
||||||
|
thirdPersonDistanceField = ReflectionSupport.findField(
|
||||||
|
rendererClass, thirdPersonDistanceName);
|
||||||
|
}
|
||||||
|
if (thirdPersonDistanceTempName != null) {
|
||||||
|
thirdPersonDistanceTempField = ReflectionSupport.findField(
|
||||||
|
rendererClass, thirdPersonDistanceTempName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return thirdPersonDistanceField != null
|
||||||
|
|| thirdPersonDistanceTempField != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Field playerEntitiesField(Class<?> worldClass) {
|
||||||
|
if (playerEntitiesField == null) {
|
||||||
|
playerEntitiesField = ReflectionSupport.findField(
|
||||||
|
worldClass, playerEntitiesName);
|
||||||
|
}
|
||||||
|
return playerEntitiesField;
|
||||||
|
}
|
||||||
|
|
||||||
|
private EntityAccess accessFor(Class<?> entityClass) {
|
||||||
|
EntityAccess access = accessCache.get(entityClass);
|
||||||
|
if (access == null) {
|
||||||
|
access = new EntityAccess(entityClass);
|
||||||
|
accessCache.put(entityClass, access);
|
||||||
|
}
|
||||||
|
return access;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Field resolveField(MappingClass owner, String name, Class<?> runtimeOwner) {
|
||||||
|
MappingField mapping = owner.getField(name);
|
||||||
|
if (mapping == null) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"No mapping for field '" + name + "' on " + owner.getSourceName());
|
||||||
|
}
|
||||||
|
return ReflectionSupport.requireField(
|
||||||
|
runtimeOwner, mapping.getTargetName(), owner.getSourceName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String fieldName(String ownerClass, String name) {
|
||||||
|
MappingClass owner = resolver.mapClass(ownerClass);
|
||||||
|
MappingField mapping = owner.getField(name);
|
||||||
|
if (mapping == null) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"No mapping for field '" + name + "' on " + ownerClass);
|
||||||
|
}
|
||||||
|
return mapping.getTargetName();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String optionalFieldName(String ownerClass, String name) {
|
||||||
|
MappingClass owner = resolver.mapClass(ownerClass);
|
||||||
|
MappingField mapping = owner.getField(name);
|
||||||
|
return mapping == null ? null : mapping.getTargetName();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String methodName(String ownerClass, String name, String descriptor) {
|
||||||
|
MappingClass owner = resolver.mapClass(ownerClass);
|
||||||
|
MappingMethod mapping = owner.getMethod(name, descriptor);
|
||||||
|
if (mapping == null) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"No mapping for method '" + name + descriptor + "' on " + ownerClass);
|
||||||
|
}
|
||||||
|
return mapping.getTargetName();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String optionalMethodName(String ownerClass, String name, String descriptor) {
|
||||||
|
MappingClass owner = resolver.mapClass(ownerClass);
|
||||||
|
MappingMethod mapping = owner.getMethod(name, descriptor);
|
||||||
|
return mapping == null ? null : mapping.getTargetName();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double interpolate(Field current, Field previous,
|
||||||
|
Object entity, float partialTicks) {
|
||||||
|
double previousValue = ReflectionSupport.getDouble(previous, entity);
|
||||||
|
double currentValue = ReflectionSupport.getDouble(current, entity);
|
||||||
|
return previousValue + (currentValue - previousValue) * partialTicks;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float interpolateAngle(Field current, Field previous,
|
||||||
|
Object entity, float partialTicks) {
|
||||||
|
float previousValue = ReflectionSupport.getFloat(previous, entity);
|
||||||
|
float currentValue = ReflectionSupport.getFloat(current, entity);
|
||||||
|
return previousValue + (currentValue - previousValue) * partialTicks;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float invokeFloat(Method method, Object target) {
|
||||||
|
return ((Number) ReflectionSupport.invoke(method, target)).floatValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean invokeBoolean(Method method, Object target) {
|
||||||
|
return ((Boolean) ReflectionSupport.invoke(method, target)).booleanValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double distance(double x1, double y1, double z1,
|
||||||
|
double x2, double y2, double z2) {
|
||||||
|
double dx = x1 - x2;
|
||||||
|
double dy = y1 - y2;
|
||||||
|
double dz = z1 - z2;
|
||||||
|
return Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Per-class reflective member cache for entities. Resolving methods on
|
||||||
|
* every frame for every player would be needlessly slow.
|
||||||
|
*/
|
||||||
|
private final class EntityAccess {
|
||||||
|
|
||||||
|
private final Field posX;
|
||||||
|
private final Field posY;
|
||||||
|
private final Field posZ;
|
||||||
|
private final Field lastTickPosX;
|
||||||
|
private final Field lastTickPosY;
|
||||||
|
private final Field lastTickPosZ;
|
||||||
|
private final Field width;
|
||||||
|
private final Field height;
|
||||||
|
private final Field rotationYaw;
|
||||||
|
private final Field rotationPitch;
|
||||||
|
private final Field prevRotationYaw;
|
||||||
|
private final Field prevRotationPitch;
|
||||||
|
private final Method eyeHeight;
|
||||||
|
private final Method getName;
|
||||||
|
private final Method getHealth;
|
||||||
|
private final Method getMaxHealth;
|
||||||
|
private final Method isAlive;
|
||||||
|
private final Method isInvisible;
|
||||||
|
private final Method isSpectator;
|
||||||
|
|
||||||
|
private EntityAccess(Class<?> entityClass) {
|
||||||
|
MappingClass entity = resolver.mapClass(ENTITY);
|
||||||
|
MappingClass living = resolver.mapClass(ENTITY_LIVING);
|
||||||
|
MappingClass player = resolver.mapClass(ENTITY_PLAYER);
|
||||||
|
|
||||||
|
this.posX = mappedField(entity, "posX", entityClass);
|
||||||
|
this.posY = mappedField(entity, "posY", entityClass);
|
||||||
|
this.posZ = mappedField(entity, "posZ", entityClass);
|
||||||
|
this.lastTickPosX = mappedField(entity, "lastTickPosX", entityClass);
|
||||||
|
this.lastTickPosY = mappedField(entity, "lastTickPosY", entityClass);
|
||||||
|
this.lastTickPosZ = mappedField(entity, "lastTickPosZ", entityClass);
|
||||||
|
this.rotationYaw = mappedField(entity, "rotationYaw", entityClass);
|
||||||
|
this.rotationPitch = mappedField(entity, "rotationPitch", entityClass);
|
||||||
|
this.prevRotationYaw = mappedField(entity, "prevRotationYaw", entityClass);
|
||||||
|
this.prevRotationPitch = mappedField(entity, "prevRotationPitch", entityClass);
|
||||||
|
this.width = mappedField(entity, "width", entityClass);
|
||||||
|
this.height = mappedField(entity, "height", entityClass);
|
||||||
|
|
||||||
|
this.eyeHeight = mappedMethod(entity, "getEyeHeight", "()F",
|
||||||
|
float.class, entityClass);
|
||||||
|
this.isAlive = mappedMethod(entity, "isEntityAlive", "()Z",
|
||||||
|
boolean.class, entityClass);
|
||||||
|
this.isInvisible = mappedMethod(entity, "isInvisible", "()Z",
|
||||||
|
boolean.class, entityClass);
|
||||||
|
this.getHealth = mappedMethod(living, "getHealth", "()F",
|
||||||
|
float.class, entityClass);
|
||||||
|
this.getMaxHealth = mappedMethod(living, "getMaxHealth", "()F",
|
||||||
|
float.class, entityClass);
|
||||||
|
this.getName = mappedMethod(player, "getName", "()Ljava/lang/String;",
|
||||||
|
String.class, entityClass);
|
||||||
|
this.isSpectator = optionalMappedMethod(player, "isSpectator", "()Z",
|
||||||
|
boolean.class, entityClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Field mappedField(MappingClass owner, String name, Class<?> type) {
|
||||||
|
MappingField mapping = owner.getField(name);
|
||||||
|
if (mapping == null) {
|
||||||
|
throw new IllegalStateException("No mapping for field '" + name
|
||||||
|
+ "' on " + owner.getSourceName());
|
||||||
|
}
|
||||||
|
return ReflectionSupport.requireField(
|
||||||
|
type, mapping.getTargetName(), owner.getSourceName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Method mappedMethod(MappingClass owner, String name,
|
||||||
|
String descriptor, Class<?> returnType,
|
||||||
|
Class<?> type) {
|
||||||
|
String target = methodName(owner.getSourceName(), name, descriptor);
|
||||||
|
return ReflectionSupport.requireMethod(type, target, returnType,
|
||||||
|
owner.getSourceName(), new Class<?>[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Method optionalMappedMethod(MappingClass owner, String name,
|
||||||
|
String descriptor, Class<?> returnType,
|
||||||
|
Class<?> type) {
|
||||||
|
String target = optionalMethodName(owner.getSourceName(), name, descriptor);
|
||||||
|
if (target == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return ReflectionSupport.findMethod(type, target, returnType,
|
||||||
|
new Class<?>[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -1,6 +1,7 @@
|
|||||||
package cn.xiaozhou233.orangex.wrapper.internal.v1_8_9;
|
package cn.xiaozhou233.orangex.wrapper.internal.v1_8_9;
|
||||||
|
|
||||||
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
|
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.api.WorldView;
|
||||||
import cn.xiaozhou233.orangex.wrapper.internal.WrapperContext;
|
import cn.xiaozhou233.orangex.wrapper.internal.WrapperContext;
|
||||||
import cn.xiaozhou233.orangex.wrapper.internal.WrapperProvider;
|
import cn.xiaozhou233.orangex.wrapper.internal.WrapperProvider;
|
||||||
|
|
||||||
@@ -15,4 +16,9 @@ public final class V1_8_9WrapperProvider implements WrapperProvider {
|
|||||||
context.getRuntimeInfo(),
|
context.getRuntimeInfo(),
|
||||||
context.getMappingResolver());
|
context.getMappingResolver());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WorldView createWorld(WrapperContext context, Minecraft minecraft) {
|
||||||
|
return new V1_8_9WorldView(context.getMappingResolver(), minecraft);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+298
@@ -0,0 +1,298 @@
|
|||||||
|
package cn.xiaozhou233.orangex.wrapper.internal.v26_2;
|
||||||
|
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.api.WorldView;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.common.EntityTarget;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.common.Vec3;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.common.WorldSnapshot;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.internal.ReflectionSupport;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 26.2 implementation of {@link WorldView}.
|
||||||
|
*
|
||||||
|
* <p>The modern client already exposes an interpolated camera
|
||||||
|
* ({@code GameRenderer#mainCamera}) and its FOV, so no third-person math is
|
||||||
|
* needed here. Member names are the Mojang names the runtime uses.</p>
|
||||||
|
*/
|
||||||
|
public final class V26_2WorldView implements WorldView {
|
||||||
|
|
||||||
|
private static final float DEFAULT_FOV = 70.0F;
|
||||||
|
|
||||||
|
private final Object minecraft;
|
||||||
|
|
||||||
|
private final Field levelField;
|
||||||
|
private final Field playerField;
|
||||||
|
private final Field gameRendererField;
|
||||||
|
|
||||||
|
private Method deltaTrackerMethod;
|
||||||
|
private Method deltaPartialTickMethod;
|
||||||
|
private Method mainCameraMethod;
|
||||||
|
private Method cameraPositionMethod;
|
||||||
|
private Method cameraXRotMethod;
|
||||||
|
private Method cameraYRotMethod;
|
||||||
|
private Method cameraFovMethod;
|
||||||
|
|
||||||
|
private final Map<Class<?>, EntityAccess> accessCache =
|
||||||
|
new HashMap<Class<?>, EntityAccess>();
|
||||||
|
private final Map<Class<?>, Field[]> vectorFields =
|
||||||
|
new HashMap<Class<?>, Field[]>();
|
||||||
|
|
||||||
|
public V26_2WorldView(Minecraft minecraft) {
|
||||||
|
this.minecraft = minecraft.getMinecraft();
|
||||||
|
Class<?> minecraftClass = this.minecraft.getClass();
|
||||||
|
|
||||||
|
this.levelField = ReflectionSupport.requireField(
|
||||||
|
minecraftClass, "level", "net.minecraft.client.Minecraft");
|
||||||
|
this.playerField = ReflectionSupport.requireField(
|
||||||
|
minecraftClass, "player", "net.minecraft.client.Minecraft");
|
||||||
|
this.gameRendererField = ReflectionSupport.requireField(
|
||||||
|
minecraftClass, "gameRenderer", "net.minecraft.client.Minecraft");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WorldSnapshot snapshot() {
|
||||||
|
Object level = ReflectionSupport.get(levelField, minecraft);
|
||||||
|
Object localPlayer = ReflectionSupport.get(playerField, minecraft);
|
||||||
|
Object gameRenderer = ReflectionSupport.get(gameRendererField, minecraft);
|
||||||
|
|
||||||
|
if (level == null || gameRenderer == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
float partialTicks = partialTicks();
|
||||||
|
Object camera = camera(gameRenderer);
|
||||||
|
if (camera == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3 cameraPosition = readVec3(
|
||||||
|
ReflectionSupport.invoke(cameraPositionMethod, camera));
|
||||||
|
float yaw = invokeFloat(cameraYRotMethod, camera);
|
||||||
|
float pitch = invokeFloat(cameraXRotMethod, camera);
|
||||||
|
float fov = invokeFloat(cameraFovMethod, camera);
|
||||||
|
|
||||||
|
List<EntityTarget> targets = collectTargets(
|
||||||
|
level, localPlayer, cameraPosition, partialTicks);
|
||||||
|
|
||||||
|
return new WorldSnapshot(cameraPosition, yaw, pitch,
|
||||||
|
fov > 1.0F ? fov : DEFAULT_FOV, targets);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object camera(Object gameRenderer) {
|
||||||
|
if (mainCameraMethod == null) {
|
||||||
|
mainCameraMethod = ReflectionSupport.findMethod(
|
||||||
|
gameRenderer.getClass(), "mainCamera", null);
|
||||||
|
}
|
||||||
|
if (mainCameraMethod == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object camera = ReflectionSupport.invoke(mainCameraMethod, gameRenderer);
|
||||||
|
if (camera == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Class<?> cameraClass = camera.getClass();
|
||||||
|
if (cameraPositionMethod == null) {
|
||||||
|
cameraPositionMethod = ReflectionSupport.requireMethod(
|
||||||
|
cameraClass, "position", null, "net.minecraft.client.Camera");
|
||||||
|
cameraXRotMethod = ReflectionSupport.requireMethod(
|
||||||
|
cameraClass, "xRot", float.class, "net.minecraft.client.Camera");
|
||||||
|
cameraYRotMethod = ReflectionSupport.requireMethod(
|
||||||
|
cameraClass, "yRot", float.class, "net.minecraft.client.Camera");
|
||||||
|
cameraFovMethod = ReflectionSupport.requireMethod(
|
||||||
|
cameraClass, "getFov", float.class, "net.minecraft.client.Camera");
|
||||||
|
}
|
||||||
|
|
||||||
|
return camera;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<EntityTarget> collectTargets(Object level,
|
||||||
|
Object localPlayer,
|
||||||
|
Vec3 cameraPosition,
|
||||||
|
float partialTicks) {
|
||||||
|
List<EntityTarget> targets = new ArrayList<EntityTarget>();
|
||||||
|
|
||||||
|
Method playersMethod = ReflectionSupport.findMethod(
|
||||||
|
level.getClass(), "players", null);
|
||||||
|
if (playersMethod == null) {
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object value = ReflectionSupport.invoke(playersMethod, level);
|
||||||
|
if (!(value instanceof Iterable)) {
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Object entity : (Iterable<?>) value) {
|
||||||
|
if (entity == null || entity == localPlayer) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityAccess access = accessFor(entity.getClass());
|
||||||
|
|
||||||
|
if (!invokeBoolean(access.isAlive, entity)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (invokeBoolean(access.isInvisible, entity)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (access.isSpectator != null && invokeBoolean(access.isSpectator, entity)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
float health = invokeFloat(access.getHealth, entity);
|
||||||
|
if (health <= 0.0F) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3 position = readVec3(ReflectionSupport.invoke(
|
||||||
|
access.getPosition, entity, Float.valueOf(partialTicks)));
|
||||||
|
if (position == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
targets.add(new EntityTarget(
|
||||||
|
invokeString(access.getName, entity),
|
||||||
|
position,
|
||||||
|
invokeFloat(access.getBbWidth, entity),
|
||||||
|
invokeFloat(access.getBbHeight, entity),
|
||||||
|
health,
|
||||||
|
invokeFloat(access.getMaxHealth, entity),
|
||||||
|
distance(cameraPosition, position)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
|
||||||
|
private float partialTicks() {
|
||||||
|
if (deltaTrackerMethod == null) {
|
||||||
|
deltaTrackerMethod = ReflectionSupport.findMethod(
|
||||||
|
minecraft.getClass(), "getDeltaTracker", null);
|
||||||
|
}
|
||||||
|
if (deltaTrackerMethod == null) {
|
||||||
|
return 0.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object tracker = ReflectionSupport.invoke(deltaTrackerMethod, minecraft);
|
||||||
|
if (tracker == null) {
|
||||||
|
return 0.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deltaPartialTickMethod == null) {
|
||||||
|
deltaPartialTickMethod = ReflectionSupport.findMethod(
|
||||||
|
tracker.getClass(), "getGameTimeDeltaPartialTick", null,
|
||||||
|
boolean.class);
|
||||||
|
}
|
||||||
|
if (deltaPartialTickMethod == null) {
|
||||||
|
return 0.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
return invokeFloat(deltaPartialTickMethod, tracker, Boolean.FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private EntityAccess accessFor(Class<?> entityClass) {
|
||||||
|
EntityAccess access = accessCache.get(entityClass);
|
||||||
|
if (access == null) {
|
||||||
|
access = new EntityAccess(entityClass);
|
||||||
|
accessCache.put(entityClass, access);
|
||||||
|
}
|
||||||
|
return access;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Vec3 readVec3(Object nativeVec) {
|
||||||
|
if (nativeVec == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Class<?> type = nativeVec.getClass();
|
||||||
|
Field[] fields = vectorFields.get(type);
|
||||||
|
if (fields == null) {
|
||||||
|
fields = new Field[]{
|
||||||
|
ReflectionSupport.requireField(type, "x", type.getName()),
|
||||||
|
ReflectionSupport.requireField(type, "y", type.getName()),
|
||||||
|
ReflectionSupport.requireField(type, "z", type.getName())
|
||||||
|
};
|
||||||
|
vectorFields.put(type, fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Vec3(
|
||||||
|
ReflectionSupport.getDouble(fields[0], nativeVec),
|
||||||
|
ReflectionSupport.getDouble(fields[1], nativeVec),
|
||||||
|
ReflectionSupport.getDouble(fields[2], nativeVec));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String invokeString(Method method, Object target) {
|
||||||
|
Object value = ReflectionSupport.invoke(method, target);
|
||||||
|
if (value == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
Method getString = ReflectionSupport.findMethod(
|
||||||
|
value.getClass(), "getString", String.class);
|
||||||
|
if (getString == null) {
|
||||||
|
return String.valueOf(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object text = ReflectionSupport.invoke(getString, value);
|
||||||
|
return text == null ? "" : String.valueOf(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float invokeFloat(Method method, Object target, Object... arguments) {
|
||||||
|
return ((Number) ReflectionSupport.invoke(method, target, arguments))
|
||||||
|
.floatValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean invokeBoolean(Method method, Object target) {
|
||||||
|
return ((Boolean) ReflectionSupport.invoke(method, target)).booleanValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double distance(Vec3 first, Vec3 second) {
|
||||||
|
return first.distanceTo(second);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Per-class reflective member cache for entities.
|
||||||
|
*/
|
||||||
|
private static final class EntityAccess {
|
||||||
|
|
||||||
|
private final Method getPosition;
|
||||||
|
private final Method getName;
|
||||||
|
private final Method getHealth;
|
||||||
|
private final Method getMaxHealth;
|
||||||
|
private final Method getBbWidth;
|
||||||
|
private final Method getBbHeight;
|
||||||
|
private final Method isAlive;
|
||||||
|
private final Method isInvisible;
|
||||||
|
private final Method isSpectator;
|
||||||
|
|
||||||
|
private EntityAccess(Class<?> entityClass) {
|
||||||
|
this.getPosition = ReflectionSupport.requireMethod(
|
||||||
|
entityClass, "getPosition", null, entityClass.getName(),
|
||||||
|
float.class);
|
||||||
|
this.getName = ReflectionSupport.requireMethod(
|
||||||
|
entityClass, "getName", null, entityClass.getName());
|
||||||
|
this.getHealth = ReflectionSupport.requireMethod(
|
||||||
|
entityClass, "getHealth", float.class, entityClass.getName());
|
||||||
|
this.getMaxHealth = ReflectionSupport.requireMethod(
|
||||||
|
entityClass, "getMaxHealth", float.class, entityClass.getName());
|
||||||
|
this.getBbWidth = ReflectionSupport.requireMethod(
|
||||||
|
entityClass, "getBbWidth", float.class, entityClass.getName());
|
||||||
|
this.getBbHeight = ReflectionSupport.requireMethod(
|
||||||
|
entityClass, "getBbHeight", float.class, entityClass.getName());
|
||||||
|
this.isAlive = ReflectionSupport.requireMethod(
|
||||||
|
entityClass, "isAlive", boolean.class, entityClass.getName());
|
||||||
|
this.isInvisible = ReflectionSupport.requireMethod(
|
||||||
|
entityClass, "isInvisible", boolean.class, entityClass.getName());
|
||||||
|
this.isSpectator = ReflectionSupport.findMethod(
|
||||||
|
entityClass, "isSpectator", boolean.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -1,6 +1,7 @@
|
|||||||
package cn.xiaozhou233.orangex.wrapper.internal.v26_2;
|
package cn.xiaozhou233.orangex.wrapper.internal.v26_2;
|
||||||
|
|
||||||
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
|
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
|
||||||
|
import cn.xiaozhou233.orangex.wrapper.api.WorldView;
|
||||||
import cn.xiaozhou233.orangex.wrapper.internal.WrapperContext;
|
import cn.xiaozhou233.orangex.wrapper.internal.WrapperContext;
|
||||||
import cn.xiaozhou233.orangex.wrapper.internal.WrapperProvider;
|
import cn.xiaozhou233.orangex.wrapper.internal.WrapperProvider;
|
||||||
|
|
||||||
@@ -12,4 +13,9 @@ public final class V26_2WrapperProvider implements WrapperProvider {
|
|||||||
context.getRuntimeInfo(),
|
context.getRuntimeInfo(),
|
||||||
context.getMappingResolver());
|
context.getMappingResolver());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WorldView createWorld(WrapperContext context, Minecraft minecraft) {
|
||||||
|
return new V26_2WorldView(minecraft);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user