Skip to content

fix: fix Vector3 transfer between nodes#953

Open
Roll1r wants to merge 1 commit intoAlexProgrammerDE:mainfrom
Roll1r:vec3fix
Open

fix: fix Vector3 transfer between nodes#953
Roll1r wants to merge 1 commit intoAlexProgrammerDE:mainfrom
Roll1r:vec3fix

Conversation

@Roll1r
Copy link
Contributor

@Roll1r Roll1r commented Mar 1, 2026

Fix [WARN] Type mismatch at runtime when port 'destination' receives a String instead of VECTOR3. Without this fix, subsequent nodes such as pathfinding could fail.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a runtime type mismatch where ports declared as VECTOR3 could receive a String (via Vec3#toString() fallback), which could break downstream nodes like pathfinding.

Changes:

  • Convert net.minecraft.world.phys.Vec3 values in NodeValue.of(Object) into a JSON array [x, y, z] instead of falling back to string conversion.
  • Add a NodeValue.Vector3 variant and update NodeValueTypeChecker to recognize it as PortType.VECTOR3.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
mod/src/main/java/com/soulfiremc/server/script/NodeValueTypeChecker.java Adds explicit runtime type-checking and type description support for NodeValue.Vector3.
mod/src/main/java/com/soulfiremc/server/script/NodeValue.java Ensures Vec3 values are encoded in a VECTOR3-compatible format (JSON array) and introduces a Vector3 NodeValue variant + accessor.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +51 to +55
var arr = new JsonArray();
arr.add(v.x);
arr.add(v.y);
arr.add(v.z);
return new Json(arr);
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NodeValue.of(Vec3) currently converts vectors to a JSON array, but this PR also introduces a dedicated NodeValue.Vector3 type (and type-checker support) that is never constructed here. This creates two competing representations for VECTOR3 values and makes logs/type descriptions inconsistent (JSON arrays still describe as "List"). Consider either (a) removing the Vector3 NodeValue variant and keeping the JSON-array representation only, or (b) returning new Vector3(v) here and updating consumers (e.g. AbstractScriptNode#getInput) to also accept that representation.

Suggested change
var arr = new JsonArray();
arr.add(v.x);
arr.add(v.y);
arr.add(v.z);
return new Json(arr);
return new Vector3(v);

Copilot uses AI. Check for mistakes.
default Vec3 asVec3() {
if (this instanceof Vector3(Vec3 v)) {
return v;
}
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asVec3() only unwraps the new NodeValue.Vector3 record, but NodeValue.of(Vec3) encodes vectors as a JSON array. As a result, asVec3() will return null for the most common Vec3 values produced by nodes (e.g., result("vector", new Vec3(...))). Either expand asVec3() to also parse the JSON VECTOR3 representation (array/object), or align NodeValue.of(Vec3) to produce NodeValue.Vector3.

Suggested change
}
}
if (this instanceof Json(JsonElement element)) {
// Array representation: [x, y, z]
if (element.isJsonArray()) {
var array = element.getAsJsonArray();
if (array.size() == 3
&& array.get(0).isJsonPrimitive()
&& array.get(1).isJsonPrimitive()
&& array.get(2).isJsonPrimitive()) {
try {
double x = array.get(0).getAsDouble();
double y = array.get(1).getAsDouble();
double z = array.get(2).getAsDouble();
return new Vec3(x, y, z);
} catch (NumberFormatException | UnsupportedOperationException ignored) {
// Fall through to return null.
}
}
}
// Object representation: { "x": ..., "y": ..., "z": ... }
if (element.isJsonObject()) {
var obj = element.getAsJsonObject();
if (obj.has("x") && obj.has("y") && obj.has("z")) {
try {
double x = obj.get("x").getAsDouble();
double y = obj.get("y").getAsDouble();
double z = obj.get("z").getAsDouble();
return new Vec3(x, y, z);
} catch (ClassCastException | IllegalStateException | NumberFormatException ignored) {
// Fall through to return null.
}
}
}
}

Copilot uses AI. Check for mistakes.
Comment on lines +50 to +56
if (value instanceof Vec3 v) {
var arr = new JsonArray();
arr.add(v.x);
arr.add(v.y);
arr.add(v.z);
return new Json(arr);
}
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vector handling is being changed in NodeValue.of(Object) for Vec3. There are already unit tests for NodeValue creation/conversions; please add coverage to prevent regression (e.g., assert NodeValue.of(new Vec3(...)) produces a VECTOR3-compatible value and does not fall back to a string).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants