From a5370cb1bd5904c08d4fe15db246684fe442db87 Mon Sep 17 00:00:00 2001 From: Kam Date: Wed, 12 Mar 2025 22:24:58 -0400 Subject: [PATCH] d --- build.gradle | 2 +- src/api | 2 +- .../npcs/client/gui/util/GuiDiagram.java | 212 ++++++++++-------- .../npcs/controllers/MagicController.java | 7 +- .../noppes/npcs/controllers/data/Magic.java | 20 ++ .../npcs/controllers/data/MagicCycle.java | 23 +- .../java/noppes/npcs/scripted/NpcAPI.java | 4 + todo.txt | 31 ++- 8 files changed, 183 insertions(+), 118 deletions(-) diff --git a/build.gradle b/build.gradle index 49ae6b8b6..e57af3300 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { id 'idea' } -version = "1.10-testingbeta1" +version = "1.10-testingbeta4" group= "kamkeel.customnpc-plus" archivesBaseName = "CustomNPC-Plus" diff --git a/src/api b/src/api index afb5f1d64..0841aab8f 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit afb5f1d64576b978d75938a514b211a9f4430371 +Subproject commit 0841aab8f8f515818c42d6e4aca9be4fff04e429 diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiDiagram.java b/src/main/java/noppes/npcs/client/gui/util/GuiDiagram.java index ab03b8330..118677d5c 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiDiagram.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiDiagram.java @@ -683,39 +683,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; + 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.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(); } } @@ -729,19 +752,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); @@ -794,45 +826,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 --- /** @@ -1067,6 +1060,37 @@ public abstract class GuiDiagram extends Gui { ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); int factor = sr.getScaleFactor(); Map 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); @@ -1090,7 +1114,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); @@ -1100,15 +1123,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); } @@ -1267,6 +1290,7 @@ public abstract class GuiDiagram extends Gui { public int idFrom, idTo; public float percent; public String hoverText; + public List polyline = null; public DiagramConnection(int idFrom, int idTo, float percent, String hoverText) { this.idFrom = idFrom; diff --git a/src/main/java/noppes/npcs/controllers/MagicController.java b/src/main/java/noppes/npcs/controllers/MagicController.java index 606006dec..02dac4690 100644 --- a/src/main/java/noppes/npcs/controllers/MagicController.java +++ b/src/main/java/noppes/npcs/controllers/MagicController.java @@ -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.MagicAssociation; import noppes.npcs.controllers.data.MagicCycle; @@ -17,7 +18,7 @@ import java.io.*; import java.util.HashMap; import java.util.zip.GZIPInputStream; -public class MagicController { +public class MagicController implements IMagicHandler { public HashMap magics = new HashMap<>(); public HashMap magicSync = new HashMap<>(); @@ -37,10 +38,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); } @@ -322,6 +325,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) @@ -340,6 +344,7 @@ public class MagicController { saveCycle(cat); } + @Override public void removeMagicFromCycle(int magicId, int cycleId) { MagicCycle cat = cycles.get(cycleId); if (cat == null) return; diff --git a/src/main/java/noppes/npcs/controllers/data/Magic.java b/src/main/java/noppes/npcs/controllers/data/Magic.java index d641f935c..fda3a4edc 100644 --- a/src/main/java/noppes/npcs/controllers/data/Magic.java +++ b/src/main/java/noppes/npcs/controllers/data/Magic.java @@ -117,14 +117,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); } @@ -157,4 +160,21 @@ public class Magic implements IMagic { public Map 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; + } } diff --git a/src/main/java/noppes/npcs/controllers/data/MagicCycle.java b/src/main/java/noppes/npcs/controllers/data/MagicCycle.java index 2e7ea8004..e1074891c 100644 --- a/src/main/java/noppes/npcs/controllers/data/MagicCycle.java +++ b/src/main/java/noppes/npcs/controllers/data/MagicCycle.java @@ -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,15 +11,14 @@ 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 = ""; public EnumDiagramLayout layout = EnumDiagramLayout.CIRCULAR; public HashMap associations = new HashMap<>(); - public MagicCycle() { - } + public MagicCycle(){} public void readNBT(NBTTagCompound compound) { id = compound.getInteger("ID"); @@ -53,22 +53,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; } @@ -77,10 +82,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 getAssociations() { return associations; } diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index 6f7e47493..9f553611d 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -253,6 +253,10 @@ public class NpcAPI extends AbstractNpcAPI { return CustomEffectController.Instance; } + public IMagicHandler getMagicHandler() { + return MagicController.getInstance(); + } + public IPartyHandler getPartyHandler() { return PartyController.Instance(); } diff --git a/todo.txt b/todo.txt index 77405e892..8a657ebb4 100644 --- a/todo.txt +++ b/todo.txt @@ -1,20 +1,15 @@ -TODO List - -Magic: -- Create MagicData Class -- Done --- Magic Data: Magic ID, % Split, Bonus Damage - -- Store Magic on PlayerData and NPCs -- Done - -Profile: -- On Profile Slot Change Event -- WIP -- On Profile Slot Create Event -- WIP -- On Profile Slot Delete Event -- WIP - -ScriptPlayer and ScriptNPC --- Apply, Removing and Checking Magic Types - Interfaces: -- IMagic -- Done - IProfile -- Need Work -- ISlot -- Done +- ISlot -- Need Work + +-- Fix Default Magic Cycle Load Up + +--- FIX MAGIC CYCLE +---- Add Two Way arrows in Diagram Support + +Item Attribute Scripting +-- Item Attribute Recalc +-- Durability Attribute +-- Get Attributes +-- View Attributes on Profiles +--