mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 09:09:08 +00:00
Fix
This commit is contained in:
1 parent
250edf099c
commit
7c38852a3a
8 files changed
+182
-105
No files matched your search
@@ -650,35 +650,62 @@ public abstract class GuiDiagram extends Gui {
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glPopAttrib();
|
||||
} else {
|
||||
Point start = new Point(x1, y1);
|
||||
Point end = new Point(x2, y2);
|
||||
double dx = x2 - x1, dy = y2 - y1;
|
||||
double len = Math.sqrt(dx * dx + dy * dy);
|
||||
if (len == 0) len = 1;
|
||||
double angleRad = Math.toRadians(curveAngle);
|
||||
double offset = len * Math.tan(angleRad) / 2;
|
||||
double perpX = -dy / len, perpY = dx / len;
|
||||
Point control = new Point((x1 + x2) / 2 + (int)(perpX * offset),
|
||||
(y1 + y2) / 2 + (int)(perpY * offset));
|
||||
int segments = 100;
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glLineWidth(2.0F);
|
||||
float rr = ((color >> 16) & 0xFF) / 255f;
|
||||
float gg = ((color >> 8) & 0xFF) / 255f;
|
||||
float bb = (color & 0xFF) / 255f;
|
||||
if (dim) { rr *= 0.4f; gg *= 0.4f; bb *= 0.4f; }
|
||||
GL11.glColor4f(rr, gg, bb, 1f);
|
||||
GL11.glBegin(GL11.GL_LINE_STRIP);
|
||||
for (int i = 0; i <= segments; i++) {
|
||||
double t = (double)i / segments;
|
||||
int bx = (int)((1 - t) * (1 - t) * start.x + 2 * (1 - t) * t * control.x + t * t * end.x);
|
||||
int by = (int)((1 - t) * (1 - t) * start.y + 2 * (1 - t) * t * control.y + t * t * end.y);
|
||||
GL11.glVertex2i(bx, by);
|
||||
if (conn.polyline != null && !conn.polyline.isEmpty()) {
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glLineWidth(2.0F);
|
||||
float r = ((color >> 16) & 0xFF) / 255f;
|
||||
float g = ((color >> 8) & 0xFF) / 255f;
|
||||
float b = (color & 0xFF) / 255f;
|
||||
if (dim) {
|
||||
r *= 0.4f;
|
||||
g *= 0.4f;
|
||||
b *= 0.4f;
|
||||
}
|
||||
GL11.glColor4f(r, g, b, 1f);
|
||||
GL11.glBegin(GL11.GL_LINE_STRIP);
|
||||
for (Point p : conn.polyline) {
|
||||
GL11.glVertex2i(p.x, p.y);
|
||||
}
|
||||
GL11.glEnd();
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glPopAttrib();
|
||||
} else {
|
||||
// Fallback to original method if polyline isn’t computed
|
||||
Point start = new Point(x1, y1);
|
||||
Point end = new Point(x2, y2);
|
||||
double dx = x2 - x1, dy = y2 - y1;
|
||||
double len = Math.sqrt(dx * dx + dy * dy);
|
||||
if (len == 0) len = 1;
|
||||
double angleRad = Math.toRadians(curveAngle);
|
||||
double offset = len * Math.tan(angleRad) / 2;
|
||||
double perpX = -dy / len, perpY = dx / len;
|
||||
Point control = new Point((x1 + x2) / 2 + (int) (perpX * offset),
|
||||
(y1 + y2) / 2 + (int) (perpY * offset));
|
||||
int segments = 100;
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glLineWidth(2.0F);
|
||||
float rr = ((color >> 16) & 0xFF) / 255f;
|
||||
float gg = ((color >> 8) & 0xFF) / 255f;
|
||||
float bb = (color & 0xFF) / 255f;
|
||||
if (dim) {
|
||||
rr *= 0.4f;
|
||||
gg *= 0.4f;
|
||||
bb *= 0.4f;
|
||||
}
|
||||
GL11.glColor4f(rr, gg, bb, 1f);
|
||||
GL11.glBegin(GL11.GL_LINE_STRIP);
|
||||
for (int i = 0; i <= segments; i++) {
|
||||
double t = (double) i / segments;
|
||||
int bx = (int) ((1 - t) * (1 - t) * start.x + 2 * (1 - t) * t * control.x + t * t * end.x);
|
||||
int by = (int) ((1 - t) * (1 - t) * start.y + 2 * (1 - t) * t * control.y + t * t * end.y);
|
||||
GL11.glVertex2i(bx, by);
|
||||
}
|
||||
GL11.glEnd();
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
GL11.glEnd();
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -692,19 +719,28 @@ public abstract class GuiDiagram extends Gui {
|
||||
if (!curvedArrows) {
|
||||
angle = Math.atan2(y2 - y1, x2 - x1);
|
||||
} else {
|
||||
double dx = x2 - x1, dy = y2 - y1;
|
||||
double len = Math.sqrt(dx * dx + dy * dy);
|
||||
if (len == 0) len = 1;
|
||||
double offset = len * Math.tan(Math.toRadians(curveAngle)) / 2;
|
||||
double perpX = -dy / len, perpY = dx / len;
|
||||
int cx = (x1 + x2) / 2 + (int)(perpX * offset);
|
||||
int cy = (y1 + y2) / 2 + (int)(perpY * offset);
|
||||
double t = 0.95;
|
||||
double bx = (1 - t) * (1 - t) * x1 + 2 * (1 - t) * t * cx + t * t * x2;
|
||||
double by = (1 - t) * (1 - t) * y1 + 2 * (1 - t) * t * cy + t * t * y2;
|
||||
double dBx = 2 * (1 - t) * (cx - x1) + 2 * t * (x2 - cx);
|
||||
double dBy = 2 * (1 - t) * (cy - y1) + 2 * t * (y2 - cy);
|
||||
angle = Math.atan2(dBy, dBx);
|
||||
if (conn.polyline != null && conn.polyline.size() >= 2) {
|
||||
Point last = conn.polyline.get(conn.polyline.size() - 1);
|
||||
Point secondLast = conn.polyline.get(conn.polyline.size() - 2);
|
||||
double dx = last.x - secondLast.x;
|
||||
double dy = last.y - secondLast.y;
|
||||
angle = Math.atan2(dy, dx);
|
||||
} else {
|
||||
// Fallback to original method
|
||||
double dx = x2 - x1, dy = y2 - y1;
|
||||
double len = Math.sqrt(dx * dx + dy * dy);
|
||||
if (len == 0) len = 1;
|
||||
double offset = len * Math.tan(Math.toRadians(curveAngle)) / 2;
|
||||
double perpX = -dy / len, perpY = dx / len;
|
||||
int cx = (x1 + x2) / 2 + (int) (perpX * offset);
|
||||
int cy = (y1 + y2) / 2 + (int) (perpY * offset);
|
||||
double t = 0.95;
|
||||
double bx = (1 - t) * (1 - t) * x1 + 2 * (1 - t) * t * cx + t * t * x2;
|
||||
double by = (1 - t) * (1 - t) * y1 + 2 * (1 - t) * t * cy + t * t * y2;
|
||||
double dBx = 2 * (1 - t) * (cx - x1) + 2 * t * (x2 - cx);
|
||||
double dBy = 2 * (1 - t) * (cy - y1) + 2 * t * (y2 - cy);
|
||||
angle = Math.atan2(dBy, dBx);
|
||||
}
|
||||
}
|
||||
float defenderEdgeX = x2 - (slotSize / 2f) * (float)Math.cos(angle);
|
||||
float defenderEdgeY = y2 - (slotSize / 2f) * (float)Math.sin(angle);
|
||||
@@ -752,37 +788,6 @@ public abstract class GuiDiagram extends Gui {
|
||||
return (a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
// --- Hit-detection helpers ---
|
||||
private double distanceToBezier(Point start, Point control, Point end, int segments, int px, int py) {
|
||||
double minDist = Double.MAX_VALUE;
|
||||
Point prev = null;
|
||||
for (int i = 0; i <= segments; i++) {
|
||||
double t = (double)i / segments;
|
||||
int x = (int)((1 - t) * (1 - t) * start.x + 2 * (1 - t) * t * control.x + t * t * end.x);
|
||||
int y = (int)((1 - t) * (1 - t) * start.y + 2 * (1 - t) * t * control.y + t * t * end.y);
|
||||
Point curr = new Point(x, y);
|
||||
if (prev != null) {
|
||||
double d = distancePointToSegment(px, py, prev, curr);
|
||||
if(d < minDist) minDist = d;
|
||||
}
|
||||
prev = curr;
|
||||
}
|
||||
return minDist;
|
||||
}
|
||||
private double distancePointToSegment(int px, int py, Point a, Point b) {
|
||||
double A = px - a.x, B = py - a.y;
|
||||
double C = b.x - a.x, D = b.y - a.y;
|
||||
double dot = A * C + B * D;
|
||||
double lenSq = C * C + D * D;
|
||||
double param = (lenSq != 0) ? (dot / lenSq) : -1;
|
||||
double xx, yy;
|
||||
if(param < 0){ xx = a.x; yy = a.y; }
|
||||
else if(param > 1){ xx = b.x; yy = b.y; }
|
||||
else { xx = a.x + param * C; yy = a.y + param * D; }
|
||||
double dx = px - xx, dy = py - yy;
|
||||
return Math.sqrt(dx * dx + dy * dy);
|
||||
}
|
||||
|
||||
// --- CHART Layout Drawing ---
|
||||
/**
|
||||
* Draws the CHART layout.
|
||||
@@ -1019,6 +1024,37 @@ public abstract class GuiDiagram extends Gui {
|
||||
ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int factor = sr.getScaleFactor();
|
||||
Map<Integer, Point> positions = calculatePositions();
|
||||
if (layout != EnumDiagramLayout.CHART) {
|
||||
for (DiagramConnection conn : getConnections()) {
|
||||
if (conn.polyline == null && curvedArrows) {
|
||||
DiagramIcon iconFrom = getIconById(conn.idFrom);
|
||||
DiagramIcon iconTo = getIconById(conn.idTo);
|
||||
if (iconFrom == null || iconTo == null || !iconFrom.enabled || !iconTo.enabled)
|
||||
continue;
|
||||
Point pFrom = positions.get(conn.idFrom);
|
||||
Point pTo = positions.get(conn.idTo);
|
||||
if (pFrom == null || pTo == null) continue;
|
||||
int x1 = pFrom.x, y1 = pFrom.y, x2 = pTo.x, y2 = pTo.y;
|
||||
double dx = x2 - x1, dy = y2 - y1;
|
||||
double len = Math.sqrt(dx * dx + dy * dy);
|
||||
if (len == 0) len = 1;
|
||||
double angleRad = Math.toRadians(curveAngle);
|
||||
double offset = len * Math.tan(angleRad) / 2;
|
||||
double perpX = -dy / len, perpY = dx / len;
|
||||
int cx = (x1 + x2) / 2 + (int) (perpX * offset);
|
||||
int cy = (y1 + y2) / 2 + (int) (perpY * offset);
|
||||
conn.polyline = new ArrayList<>();
|
||||
int segments = 50; // Reduced from 100 for performance
|
||||
for (int i = 0; i <= segments; i++) {
|
||||
double t = (double) i / segments;
|
||||
int bx = (int) ((1 - t) * (1 - t) * x1 + 2 * (1 - t) * t * cx + t * t * x2);
|
||||
int by = (int) ((1 - t) * (1 - t) * y1 + 2 * (1 - t) * t * cy + t * t * y2);
|
||||
conn.polyline.add(new Point(bx, by));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int centerX = x + width / 2, centerY = y + height / 2;
|
||||
int effectiveMouseX = (int)(((float)mouseX - (centerX + panX)) / zoom + centerX);
|
||||
int effectiveMouseY = (int)(((float)mouseY - (centerY + panY)) / zoom + centerY);
|
||||
@@ -1042,7 +1078,6 @@ public abstract class GuiDiagram extends Gui {
|
||||
// If no icon was hovered, check connections.
|
||||
if (hoveredIconId == null) {
|
||||
final double threshold = 5.0;
|
||||
outer:
|
||||
for (DiagramConnection conn : getConnections()) {
|
||||
DiagramIcon iconFrom = getIconById(conn.idFrom);
|
||||
DiagramIcon iconTo = getIconById(conn.idTo);
|
||||
@@ -1052,15 +1087,15 @@ public abstract class GuiDiagram extends Gui {
|
||||
Point pTo = positions.get(conn.idTo);
|
||||
if (pFrom == null || pTo == null) continue;
|
||||
double dist;
|
||||
if (curvedArrows) {
|
||||
double dx = pTo.x - pFrom.x, dy = pTo.y - pFrom.y;
|
||||
double len = Math.sqrt(dx * dx + dy * dy);
|
||||
if (len == 0) len = 1;
|
||||
double offset = len * Math.tan(Math.toRadians(curveAngle)) / 2;
|
||||
double perpX = -dy / len, perpY = dx / len;
|
||||
Point control = new Point((pFrom.x + pTo.x) / 2 + (int)(perpX * offset),
|
||||
(pFrom.y + pTo.y) / 2 + (int)(perpY * offset));
|
||||
dist = distanceToBezier(pFrom, control, pTo, 200, effectiveMouseX, effectiveMouseY);
|
||||
if (curvedArrows && conn.polyline != null && !conn.polyline.isEmpty()) {
|
||||
double minDist = Double.MAX_VALUE;
|
||||
for (int i = 0; i < conn.polyline.size() - 1; i++) {
|
||||
Point a = conn.polyline.get(i);
|
||||
Point b = conn.polyline.get(i + 1);
|
||||
double d = pointLineDistance(effectiveMouseX, effectiveMouseY, a.x, a.y, b.x, b.y);
|
||||
if (d < minDist) minDist = d;
|
||||
}
|
||||
dist = minDist;
|
||||
} else {
|
||||
dist = pointLineDistance(effectiveMouseX, effectiveMouseY, pFrom.x, pFrom.y, pTo.x, pTo.y);
|
||||
}
|
||||
@@ -1070,7 +1105,6 @@ public abstract class GuiDiagram extends Gui {
|
||||
selectedIconIds.add(conn.idFrom);
|
||||
selectedIconIds.add(conn.idTo);
|
||||
onConnectionHover(conn);
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1204,6 +1238,8 @@ public abstract class GuiDiagram extends Gui {
|
||||
public int idFrom, idTo;
|
||||
public float percent;
|
||||
public String hoverText;
|
||||
public List<Point> polyline = null;
|
||||
|
||||
public DiagramConnection(int idFrom, int idTo, float percent, String hoverText) {
|
||||
this.idFrom = idFrom;
|
||||
this.idTo = idTo;
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.CustomItems;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.api.handler.IMagicHandler;
|
||||
import noppes.npcs.controllers.data.Magic;
|
||||
import noppes.npcs.controllers.data.MagicCycle;
|
||||
import noppes.npcs.controllers.data.MagicAssociation;
|
||||
@@ -22,7 +23,7 @@ import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class MagicController {
|
||||
public class MagicController implements IMagicHandler {
|
||||
public HashMap<Integer, Magic> magics = new HashMap<>();
|
||||
public HashMap<Integer, Magic> magicSync = new HashMap<>();
|
||||
|
||||
@@ -42,10 +43,12 @@ public class MagicController {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Magic getMagic(int magicId) {
|
||||
return magics.get(magicId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MagicCycle getCycle(int cycleID) {
|
||||
return cycles.get(cycleID);
|
||||
}
|
||||
@@ -326,6 +329,7 @@ public class MagicController {
|
||||
/**
|
||||
* Associates a magic with a category along with its per-category ordering data.
|
||||
*/
|
||||
@Override
|
||||
public void addMagicToCycle(int magicId, int cycleId, int index, int priority) {
|
||||
MagicCycle cat = cycles.get(cycleId);
|
||||
if (cat == null)
|
||||
@@ -344,6 +348,7 @@ public class MagicController {
|
||||
saveCycle(cat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeMagicFromCycle(int magicId, int cycleId) {
|
||||
MagicCycle cat = cycles.get(cycleId);
|
||||
if (cat == null) return;
|
||||
|
||||
@@ -116,14 +116,17 @@ public class Magic implements IMagic {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
MagicController.getInstance().saveMagic(this);
|
||||
}
|
||||
@@ -156,4 +159,21 @@ public class Magic implements IMagic {
|
||||
public Map<Integer, Float> getInteractions() {
|
||||
return this.interactions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasInteraction(int magicID) {
|
||||
return interactions.containsKey(magicID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInteraction(int magicID, float value) {
|
||||
interactions.put(magicID, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getInteraction(int magicID, float value) {
|
||||
if(hasInteraction(magicID))
|
||||
return interactions.get(magicID);
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.api.handler.data.IMagicCycle;
|
||||
import noppes.npcs.constants.EnumDiagramLayout;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -10,7 +11,7 @@ import java.util.HashMap;
|
||||
* Holds category information for magic.
|
||||
* Each category can have many magic associations.
|
||||
*/
|
||||
public class MagicCycle {
|
||||
public class MagicCycle implements IMagicCycle {
|
||||
public int id = -1;
|
||||
public String name = "";
|
||||
public String displayName = "";
|
||||
@@ -51,22 +52,27 @@ public class MagicCycle {
|
||||
compound.setTag("Associations", list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
@@ -75,10 +81,22 @@ public class MagicCycle {
|
||||
return layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutType() {
|
||||
return layout.ordinal();
|
||||
}
|
||||
|
||||
public void setLayout(EnumDiagramLayout layout) {
|
||||
this.layout = layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLayoutType(int layout) {
|
||||
if(layout < 0 || layout > EnumDiagramLayout.values().length - 1)
|
||||
return;
|
||||
this.layout = EnumDiagramLayout.values()[layout];
|
||||
}
|
||||
|
||||
public HashMap<Integer, MagicAssociation> getAssociations() {
|
||||
return associations;
|
||||
}
|
||||
|
||||
@@ -248,6 +248,9 @@ public class NpcAPI extends AbstractNpcAPI {
|
||||
public ICustomEffectHandler getCustomEffectHandler() { return CustomEffectController.Instance; }
|
||||
|
||||
public IPartyHandler getPartyHandler() { return PartyController.Instance(); }
|
||||
public IMagicHandler getMagicHandler() {
|
||||
return MagicController.getInstance();
|
||||
}
|
||||
|
||||
public ITransportHandler getLocations() {
|
||||
return TransportController.getInstance();
|
||||
|
||||
Reference in new issue
Block a user