From 0f6379e1fcb6b661564de4279830d4d9ac3c10bf Mon Sep 17 00:00:00 2001 From: Goldenfield192 <1437356849@qq.com> Date: Fri, 20 Feb 2026 21:23:35 +0800 Subject: [PATCH 01/10] ref: modernize buildscript and mapping --- build.gradle | 10 +++++----- gradle/wrapper/gradle-wrapper.properties | 2 +- src/main/java/trackapi/compat/MinecraftRail.java | 4 ++-- src/main/java/trackapi/lib/ITrack.java | 7 ++----- src/main/java/trackapi/lib/ITrackBlock.java | 7 ++----- src/main/java/trackapi/lib/Util.java | 4 ++-- 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/build.gradle b/build.gradle index 1db0c5c..897f9e9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,9 +1,9 @@ -import cam72cam.universalmodcore.Util; +import cam72cam.universalmodcore.Util buildscript { repositories { - jcenter() - maven { url = "http://files.minecraftforge.net/maven" } + mavenCentral() + maven { url = "http://maven.minecraftforge.net/" } maven { url = "https://teamopenindustry.cc/maven" } } dependencies { @@ -30,7 +30,7 @@ compileJava { } minecraft { - version = "1.12.2-14.23.0.2529" + version = "1.12.2-14.23.5.2847" runDir = "run" // the mappings can be changed at any time, and must be in the following format. @@ -38,7 +38,7 @@ minecraft { // stable_# stables are built at the discretion of the MCP team. // Use non-default mappings at your own risk. they may not always work. // simply re-run your setup task after changing the mappings to update your workspace. - mappings = "snapshot_20171003" + mappings = "stable_39" // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e18cba7..92ae1fb 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-bin.zip diff --git a/src/main/java/trackapi/compat/MinecraftRail.java b/src/main/java/trackapi/compat/MinecraftRail.java index f691143..8fdebf8 100644 --- a/src/main/java/trackapi/compat/MinecraftRail.java +++ b/src/main/java/trackapi/compat/MinecraftRail.java @@ -67,7 +67,7 @@ public Vec3d getNextPosition(Vec3d currentPosition, Vec3d motion) { Vec3d trackCenter = centers.get(direction); Vec3d posRelativeToCenter = currentPosition.subtractReverse(new Vec3d(pos).add(trackCenter)); - double distanceToCenter = posRelativeToCenter.lengthVector(); + double distanceToCenter = posRelativeToCenter.length(); // Determine if trackMovement should be positive or negative as relative to block center boolean trackPosMotionInverted = posRelativeToCenter.distanceTo(trackMovement) < posRelativeToCenter.scale(-1).distanceTo(trackMovement); @@ -78,7 +78,7 @@ public Vec3d getNextPosition(Vec3d currentPosition, Vec3d motion) { //Correct new pos to track alignment newPosition = newPosition.add(trackMovement.scale(trackPosMotionInverted ? -distanceToCenter : distanceToCenter)); // Move new pos along track alignment - newPosition = newPosition.add(trackMovement.scale(trackMotionInverted ? -motion.lengthVector() : motion.lengthVector())); + newPosition = newPosition.add(trackMovement.scale(trackMotionInverted ? -motion.length() : motion.length())); return newPosition; } diff --git a/src/main/java/trackapi/lib/ITrack.java b/src/main/java/trackapi/lib/ITrack.java index ca2362f..8baff44 100644 --- a/src/main/java/trackapi/lib/ITrack.java +++ b/src/main/java/trackapi/lib/ITrack.java @@ -10,16 +10,13 @@ public interface ITrack { * @see Gauges#STANDARD * @see Gauges#MINECRAFT */ - public double getTrackGauge(); + double getTrackGauge(); /** * Used by rolling stock to look up their next position. * * @param currentPosition - Current entity or bogey position - * @param rotationYaw - Current entity rotation in degrees - * @param bogieYaw - Current bogey rotation in degrees (set to rotationYaw if unused) - * @param distance - Distanced traveled in meters * @return The new position of the entity or bogey */ - public Vec3d getNextPosition(Vec3d currentPosition, Vec3d motion); + Vec3d getNextPosition(Vec3d currentPosition, Vec3d motion); } diff --git a/src/main/java/trackapi/lib/ITrackBlock.java b/src/main/java/trackapi/lib/ITrackBlock.java index c478671..b1b4e88 100644 --- a/src/main/java/trackapi/lib/ITrackBlock.java +++ b/src/main/java/trackapi/lib/ITrackBlock.java @@ -16,16 +16,13 @@ public interface ITrackBlock { * @see Gauges#STANDARD * @see Gauges#MINECRAFT */ - public double getTrackGauge(World world, BlockPos pos); + double getTrackGauge(World world, BlockPos pos); /** * Used by rolling stock to look up their next position. * * @param currentPosition - Current entity or bogey position - * @param rotationYaw - Current entity rotation in degrees - * @param bogieYaw - Current bogey rotation in degrees (set to rotationYaw if unused) - * @param distance - Distanced traveled in meters * @return The new position of the entity or bogey */ - public Vec3d getNextPosition(World world, BlockPos pos, Vec3d currentPosition, Vec3d motion); + Vec3d getNextPosition(World world, BlockPos pos, Vec3d currentPosition, Vec3d motion); } diff --git a/src/main/java/trackapi/lib/Util.java b/src/main/java/trackapi/lib/Util.java index 63f2d4a..40a8410 100644 --- a/src/main/java/trackapi/lib/Util.java +++ b/src/main/java/trackapi/lib/Util.java @@ -46,11 +46,11 @@ public static ITrack getTileEntity(World world, Vec3d pos, boolean acceptMinecra return track; } // Allow a bit of vertical fuzziness - track = getInternalTileEntity(world, pos.addVector(0, 0.4, 0), acceptMinecraftRails); + track = getInternalTileEntity(world, pos.add(0, 0.4, 0), acceptMinecraftRails); if (track != null) { return track; } - track = getInternalTileEntity(world, pos.addVector(0, -0.4, 0), acceptMinecraftRails); + track = getInternalTileEntity(world, pos.add(0, -0.4, 0), acceptMinecraftRails); if (track != null) { return track; } From cd3208a6a1afad3036dad73a985581e84d11dbad Mon Sep 17 00:00:00 2001 From: Goldenfield192 <1437356849@qq.com> Date: Fri, 20 Feb 2026 21:54:37 +0800 Subject: [PATCH 02/10] feat: add PathingContext for better data organization --- .../java/trackapi/compat/MinecraftRail.java | 5 +- src/main/java/trackapi/lib/ITrack.java | 4 +- src/main/java/trackapi/lib/ITrackBlock.java | 2 +- .../java/trackapi/lib/PathingContext.java | 103 ++++++++++++++++++ src/main/java/trackapi/lib/Util.java | 2 +- 5 files changed, 110 insertions(+), 6 deletions(-) create mode 100644 src/main/java/trackapi/lib/PathingContext.java diff --git a/src/main/java/trackapi/compat/MinecraftRail.java b/src/main/java/trackapi/compat/MinecraftRail.java index 8fdebf8..124f4f8 100644 --- a/src/main/java/trackapi/compat/MinecraftRail.java +++ b/src/main/java/trackapi/compat/MinecraftRail.java @@ -8,6 +8,7 @@ import net.minecraft.world.World; import trackapi.lib.Gauges; import trackapi.lib.ITrack; +import trackapi.lib.PathingContext; import java.util.HashMap; import java.util.Map; @@ -62,7 +63,7 @@ public double getTrackGauge() { } @Override - public Vec3d getNextPosition(Vec3d currentPosition, Vec3d motion) { + public PathingContext getNextPosition(Vec3d currentPosition, Vec3d motion) { Vec3d trackMovement = vectors.get(direction); Vec3d trackCenter = centers.get(direction); @@ -79,7 +80,7 @@ public Vec3d getNextPosition(Vec3d currentPosition, Vec3d motion) { newPosition = newPosition.add(trackMovement.scale(trackPosMotionInverted ? -distanceToCenter : distanceToCenter)); // Move new pos along track alignment newPosition = newPosition.add(trackMovement.scale(trackMotionInverted ? -motion.length() : motion.length())); - return newPosition; + return new PathingContext(newPosition).with(PathingContext.MOVEMENT, newPosition.distanceTo(currentPosition)); } public static boolean isRail(World world, BlockPos pos) { diff --git a/src/main/java/trackapi/lib/ITrack.java b/src/main/java/trackapi/lib/ITrack.java index 8baff44..1b1a626 100644 --- a/src/main/java/trackapi/lib/ITrack.java +++ b/src/main/java/trackapi/lib/ITrack.java @@ -16,7 +16,7 @@ public interface ITrack { * Used by rolling stock to look up their next position. * * @param currentPosition - Current entity or bogey position - * @return The new position of the entity or bogey + * @return PathingContext object contains related data regarding next point found */ - Vec3d getNextPosition(Vec3d currentPosition, Vec3d motion); + PathingContext getNextPosition(Vec3d currentPosition, Vec3d motion); } diff --git a/src/main/java/trackapi/lib/ITrackBlock.java b/src/main/java/trackapi/lib/ITrackBlock.java index b1b4e88..f2cd328 100644 --- a/src/main/java/trackapi/lib/ITrackBlock.java +++ b/src/main/java/trackapi/lib/ITrackBlock.java @@ -24,5 +24,5 @@ public interface ITrackBlock { * @param currentPosition - Current entity or bogey position * @return The new position of the entity or bogey */ - Vec3d getNextPosition(World world, BlockPos pos, Vec3d currentPosition, Vec3d motion); + PathingContext getNextPosition(World world, BlockPos pos, Vec3d currentPosition, Vec3d motion); } diff --git a/src/main/java/trackapi/lib/PathingContext.java b/src/main/java/trackapi/lib/PathingContext.java new file mode 100644 index 0000000..b8412fb --- /dev/null +++ b/src/main/java/trackapi/lib/PathingContext.java @@ -0,0 +1,103 @@ +package trackapi.lib; + +import net.minecraft.util.math.Vec3d; + +import java.util.HashMap; +import java.util.IdentityHashMap; +import java.util.Map; +import java.util.Objects; + +/** + * Helper class for bundled pathing data transformation + */ +public final class PathingContext { + private static final Map> registered = new HashMap<>(); + + private final Map, Object> dataMap; + + //We have pos by default + private final Vec3d pos; + //And some built-in fields that are filled in + public static final TrackData MOVEMENT = createKey("movement", Double.class, 0d); + //And we expect you to fill in this + public static final TrackData ROLL_DEGREES = createKey("roll_degrees", Double.class, 0d); + + public PathingContext(Vec3d pos) { + this.pos = Objects.requireNonNull(pos, "pos cannot be null"); + this.dataMap = new IdentityHashMap<>(); + } + + public PathingContext with(TrackData key, T value) { + key.validate(value); + dataMap.put(key, value); + return this; + } + + public T get(TrackData key) { + Object value = dataMap.get(key); + if (value == null) { + return key.fallback(); + } + return key.type().cast(value); + } + + public Vec3d pos() { + return pos; + } + + //And for those don't want to use Minecraft's Vec3d directly + public double x() { + return pos.x; + } + public double y() { + return pos.y; + } + public double z() { + return pos.z; + } + + public static TrackData createKey(String name, Class type) { + return createKey(name, type, null); + } + + @SuppressWarnings("unchecked") + public static TrackData createKey(String name, Class type, T fallback) { + return (TrackData) registered.computeIfAbsent(name, str -> new TrackData<>(name, type, fallback)); + } + + public static class TrackData { + private final String name; + private final Class type; + private final T fallback; + + private TrackData(String name, Class type, T fallback) { + this.name = Objects.requireNonNull(name); + this.type = Objects.requireNonNull(type); + this.fallback = fallback; + } + + void validate(Object value) { + if (value != null && !type.isInstance(value)) { + throw new IllegalArgumentException("Invalid value for key '" + name + "', expected " + type.getSimpleName()); + } + } + + public Class type() { + return type; + } + + public T fallback() { + return fallback; + } + + @Override + public int hashCode() { + return Objects.hash(name, type, fallback); + } + + @Override + public String toString() { + return "[Name:" + name + ",Type:" + type.getName() + "]"; + } + } +} \ No newline at end of file diff --git a/src/main/java/trackapi/lib/Util.java b/src/main/java/trackapi/lib/Util.java index 40a8410..9230f0c 100644 --- a/src/main/java/trackapi/lib/Util.java +++ b/src/main/java/trackapi/lib/Util.java @@ -22,7 +22,7 @@ public double getTrackGauge() { return track.getTrackGauge(world, bp); } @Override - public Vec3d getNextPosition(Vec3d currentPosition, Vec3d motion) { + public PathingContext getNextPosition(Vec3d currentPosition, Vec3d motion) { return track.getNextPosition(world, bp, currentPosition, motion); } }; From 3e4e1fa4d147a6c5f43b6f43e0ef6edd64b14f06 Mon Sep 17 00:00:00 2001 From: Goldenfield192 <1437356849@qq.com> Date: Fri, 20 Feb 2026 21:55:37 +0800 Subject: [PATCH 03/10] bump version to 1.3 --- build.gradle | 2 +- src/main/java/trackapi/TrackAPI.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 897f9e9..df7a3b0 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ apply plugin: 'net.minecraftforge.gradle.forge' apply plugin: 'maven' -String baseVersion = "1.2" +String baseVersion = "1.3" if (!"release".equalsIgnoreCase(System.getProperty("target"))) { baseVersion += "-" + Util.GitRevision() } diff --git a/src/main/java/trackapi/TrackAPI.java b/src/main/java/trackapi/TrackAPI.java index a2241d7..8059599 100644 --- a/src/main/java/trackapi/TrackAPI.java +++ b/src/main/java/trackapi/TrackAPI.java @@ -6,5 +6,5 @@ public class TrackAPI { public static final String MODID = "trackapi"; - public static final String VERSION = "1.2"; + public static final String VERSION = "1.3"; } From 5342fda5893dceeab007f663d4b8f64e0179a4d0 Mon Sep 17 00:00:00 2001 From: Goldenfield192 <1437356849@qq.com> Date: Fri, 20 Feb 2026 22:11:45 +0800 Subject: [PATCH 04/10] ref: some cleanup --- .../java/trackapi/lib/PathingContext.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main/java/trackapi/lib/PathingContext.java b/src/main/java/trackapi/lib/PathingContext.java index b8412fb..b87c00f 100644 --- a/src/main/java/trackapi/lib/PathingContext.java +++ b/src/main/java/trackapi/lib/PathingContext.java @@ -2,16 +2,16 @@ import net.minecraft.util.math.Vec3d; -import java.util.HashMap; import java.util.IdentityHashMap; import java.util.Map; import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; /** * Helper class for bundled pathing data transformation */ public final class PathingContext { - private static final Map> registered = new HashMap<>(); + private static final Map> registered = new ConcurrentHashMap<>(); private final Map, Object> dataMap; @@ -41,6 +41,10 @@ public T get(TrackData key) { return key.type().cast(value); } + public void reset(TrackData key) { + dataMap.remove(key); + } + public Vec3d pos() { return pos; } @@ -62,9 +66,24 @@ public static TrackData createKey(String name, Class type) { @SuppressWarnings("unchecked") public static TrackData createKey(String name, Class type, T fallback) { - return (TrackData) registered.computeIfAbsent(name, str -> new TrackData<>(name, type, fallback)); + TrackData existing = registered.get(name); + if (existing != null) { + if (!existing.type().equals(type)) { + throw new IllegalStateException("Key '" + name + "' already registered with different type"); + } + return (TrackData) existing; + } + TrackData data = new TrackData<>(name, type, fallback); + registered.put(name, data); + return data; } + /** + * Typed key for PathingContext's data storage + *

+ * Please note this is only used in IdentityHashMap, and should not be used externally + * @param type of the value + */ public static class TrackData { private final String name; private final Class type; @@ -90,11 +109,6 @@ public T fallback() { return fallback; } - @Override - public int hashCode() { - return Objects.hash(name, type, fallback); - } - @Override public String toString() { return "[Name:" + name + ",Type:" + type.getName() + "]"; From c317e543b611b4ee6101af8d533d27cd57df39de Mon Sep 17 00:00:00 2001 From: Goldenfield192 <1437356849@qq.com> Date: Fri, 20 Feb 2026 22:50:14 +0800 Subject: [PATCH 05/10] update Gauges.java constants --- src/main/java/trackapi/lib/Gauges.java | 39 ++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/main/java/trackapi/lib/Gauges.java b/src/main/java/trackapi/lib/Gauges.java index 9f913c4..044824d 100644 --- a/src/main/java/trackapi/lib/Gauges.java +++ b/src/main/java/trackapi/lib/Gauges.java @@ -1,13 +1,46 @@ package trackapi.lib; +/** + * Some gauge constants in meters + */ public class Gauges { /** - * US Standard Gauge in meters + * Minecraft Gauge + */ + public static final double MINECRAFT = 0.632; + + /** + * 2 Foot 6 Inches Narrow Gauge + */ + public static final double TWO_FOOT_SIX_INCHES = 0.762; + + /** + * 3 Foot Narrow Gauge + */ + public static final double THREE_FOOT = 0.9144; + + /** + * Meter Gauge + */ + public static final double METER = 1.000; + + /** + * Cape gauge + */ + public static final double CAPE = 1.067; + + /** + * US Standard Gauge */ public static final double STANDARD = 1.435; /** - * Minecraft Gauge in meters + * Russian Standard Gauge */ - public static final double MINECRAFT = 0.632; + public static final double RU_STANDARD = 1.524; + + /** + * Brunel Gauge + */ + public static final double BRUNEL = 2.140; } From 25111012fcb6580a41558ce4995d98bb960f9ffe Mon Sep 17 00:00:00 2001 From: Goldenfield192 <1437356849@qq.com> Date: Fri, 20 Feb 2026 23:01:57 +0800 Subject: [PATCH 06/10] docs: refactor some javadoc --- src/main/java/trackapi/compat/MinecraftRail.java | 7 +++++-- src/main/java/trackapi/lib/ITrack.java | 10 +++++----- src/main/java/trackapi/lib/ITrackBlock.java | 13 +++++++------ src/main/java/trackapi/lib/PathingContext.java | 2 +- src/main/java/trackapi/lib/Util.java | 9 ++++++++- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/main/java/trackapi/compat/MinecraftRail.java b/src/main/java/trackapi/compat/MinecraftRail.java index 124f4f8..8454e15 100644 --- a/src/main/java/trackapi/compat/MinecraftRail.java +++ b/src/main/java/trackapi/compat/MinecraftRail.java @@ -13,9 +13,12 @@ import java.util.HashMap; import java.util.Map; +/** + * Wrapper for vanilla rail + */ public class MinecraftRail implements ITrack { - private static Map vectors = new HashMap<>(); - private static Map centers = new HashMap<>(); + private static final Map vectors = new HashMap<>(); + private static final Map centers = new HashMap<>(); static { Vec3d north = new Vec3d(0, 0, 1); Vec3d south = new Vec3d(0, 0, -1); diff --git a/src/main/java/trackapi/lib/ITrack.java b/src/main/java/trackapi/lib/ITrack.java index 1b1a626..206a02b 100644 --- a/src/main/java/trackapi/lib/ITrack.java +++ b/src/main/java/trackapi/lib/ITrack.java @@ -7,16 +7,16 @@ public interface ITrack { /** * The distance between the rails measured in meters * - * @see Gauges#STANDARD - * @see Gauges#MINECRAFT + * @see Gauges */ double getTrackGauge(); /** - * Used by rolling stock to look up their next position. + * Used by rolling stocks to look up their next position (and relative data). * - * @param currentPosition - Current entity or bogey position - * @return PathingContext object contains related data regarding next point found + * @param currentPosition - Current position of entity or bogey + * @param motion Current velocity of entity or bogey + * @return PathingContext object contains related data regarding next found point */ PathingContext getNextPosition(Vec3d currentPosition, Vec3d motion); } diff --git a/src/main/java/trackapi/lib/ITrackBlock.java b/src/main/java/trackapi/lib/ITrackBlock.java index f2cd328..524e09b 100644 --- a/src/main/java/trackapi/lib/ITrackBlock.java +++ b/src/main/java/trackapi/lib/ITrackBlock.java @@ -5,24 +5,25 @@ import net.minecraft.world.World; /** - * Compatibility layer for block only tracks - * + * Compatibility layer between ITrack and blocks which only contain tracks */ public interface ITrackBlock { /** * The distance between the rails measured in meters * - * @see Gauges#STANDARD - * @see Gauges#MINECRAFT + * @see Gauges */ double getTrackGauge(World world, BlockPos pos); /** * Used by rolling stock to look up their next position. - * + * + * @param world World to query + * @param pos Position of the block * @param currentPosition - Current entity or bogey position - * @return The new position of the entity or bogey + * @param motion Current velocity of entity or bogey + * @return PathingContext object contains related data regarding next found point */ PathingContext getNextPosition(World world, BlockPos pos, Vec3d currentPosition, Vec3d motion); } diff --git a/src/main/java/trackapi/lib/PathingContext.java b/src/main/java/trackapi/lib/PathingContext.java index b87c00f..f81ace1 100644 --- a/src/main/java/trackapi/lib/PathingContext.java +++ b/src/main/java/trackapi/lib/PathingContext.java @@ -8,7 +8,7 @@ import java.util.concurrent.ConcurrentHashMap; /** - * Helper class for bundled pathing data transformation + * Helper class for transferring bundled pathing data */ public final class PathingContext { private static final Map> registered = new ConcurrentHashMap<>(); diff --git a/src/main/java/trackapi/lib/Util.java b/src/main/java/trackapi/lib/Util.java index 9230f0c..bd2b0bd 100644 --- a/src/main/java/trackapi/lib/Util.java +++ b/src/main/java/trackapi/lib/Util.java @@ -39,7 +39,14 @@ public PathingContext getNextPosition(Vec3d currentPosition, Vec3d motion) { } return null; } - + + /** + * Used for finding acceptable track in given world + * @param world World to query + * @param pos Current position of stock or bogey + * @param acceptMinecraftRails Should we take vanilla rails into consideration? + * @return Potential ITrack, or null if failed to find a valid one + */ public static ITrack getTileEntity(World world, Vec3d pos, boolean acceptMinecraftRails) { ITrack track = getInternalTileEntity(world, pos, acceptMinecraftRails); if (track != null) { From 22ccc94fb22983faf65ed234cc2e5e1145bd650a Mon Sep 17 00:00:00 2001 From: Goldenfield192 <1437356849@qq.com> Date: Sat, 21 Feb 2026 10:46:42 +0800 Subject: [PATCH 07/10] patch typo --- src/main/java/trackapi/lib/ITrack.java | 2 +- src/main/java/trackapi/lib/ITrackBlock.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/trackapi/lib/ITrack.java b/src/main/java/trackapi/lib/ITrack.java index 206a02b..2054c6d 100644 --- a/src/main/java/trackapi/lib/ITrack.java +++ b/src/main/java/trackapi/lib/ITrack.java @@ -12,7 +12,7 @@ public interface ITrack { double getTrackGauge(); /** - * Used by rolling stocks to look up their next position (and relative data). + * Used by rolling stocks to look up their next position (and related data). * * @param currentPosition - Current position of entity or bogey * @param motion Current velocity of entity or bogey diff --git a/src/main/java/trackapi/lib/ITrackBlock.java b/src/main/java/trackapi/lib/ITrackBlock.java index 524e09b..4f4d727 100644 --- a/src/main/java/trackapi/lib/ITrackBlock.java +++ b/src/main/java/trackapi/lib/ITrackBlock.java @@ -17,7 +17,7 @@ public interface ITrackBlock { double getTrackGauge(World world, BlockPos pos); /** - * Used by rolling stock to look up their next position. + * Used by rolling stock to look up their next position (and related data). * * @param world World to query * @param pos Position of the block From f41c85d676bed4114f8414a097384962a7909e02 Mon Sep 17 00:00:00 2001 From: Goldenfield192 <1437356849@qq.com> Date: Sat, 21 Feb 2026 10:52:49 +0800 Subject: [PATCH 08/10] ref: renaming --- src/main/java/trackapi/compat/MinecraftRail.java | 2 +- src/main/java/trackapi/lib/PathingContext.java | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/trackapi/compat/MinecraftRail.java b/src/main/java/trackapi/compat/MinecraftRail.java index 8454e15..5089575 100644 --- a/src/main/java/trackapi/compat/MinecraftRail.java +++ b/src/main/java/trackapi/compat/MinecraftRail.java @@ -83,7 +83,7 @@ public PathingContext getNextPosition(Vec3d currentPosition, Vec3d motion) { newPosition = newPosition.add(trackMovement.scale(trackPosMotionInverted ? -distanceToCenter : distanceToCenter)); // Move new pos along track alignment newPosition = newPosition.add(trackMovement.scale(trackMotionInverted ? -motion.length() : motion.length())); - return new PathingContext(newPosition).with(PathingContext.MOVEMENT, newPosition.distanceTo(currentPosition)); + return new PathingContext(newPosition).with(PathingContext.DELTA_MOVEMENT, newPosition.distanceTo(currentPosition)); } public static boolean isRail(World world, BlockPos pos) { diff --git a/src/main/java/trackapi/lib/PathingContext.java b/src/main/java/trackapi/lib/PathingContext.java index f81ace1..6a3545f 100644 --- a/src/main/java/trackapi/lib/PathingContext.java +++ b/src/main/java/trackapi/lib/PathingContext.java @@ -9,17 +9,21 @@ /** * Helper class for transferring bundled pathing data + *

+ * Users could define associated data to pass from track to stock */ public final class PathingContext { private static final Map> registered = new ConcurrentHashMap<>(); private final Map, Object> dataMap; - //We have pos by default + //We have next found pos by default private final Vec3d pos; //And some built-in fields that are filled in - public static final TrackData MOVEMENT = createKey("movement", Double.class, 0d); - //And we expect you to fill in this + //Moved distance between current pos and next pos + public static final TrackData DELTA_MOVEMENT = createKey("delta_movement", Double.class, 0d); + //And we expect you to fill in these + //Track roll for stocks to do superelevation (rotated from middle of the rails) public static final TrackData ROLL_DEGREES = createKey("roll_degrees", Double.class, 0d); public PathingContext(Vec3d pos) { From d98e15e385731d28e0e1a000535d87389aef9f43 Mon Sep 17 00:00:00 2001 From: Goldenfield192 <1437356849@qq.com> Date: Sat, 21 Feb 2026 13:12:24 +0800 Subject: [PATCH 09/10] ref: renaming --- src/main/java/trackapi/lib/PathingContext.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/trackapi/lib/PathingContext.java b/src/main/java/trackapi/lib/PathingContext.java index 6a3545f..09f7cb9 100644 --- a/src/main/java/trackapi/lib/PathingContext.java +++ b/src/main/java/trackapi/lib/PathingContext.java @@ -21,10 +21,10 @@ public final class PathingContext { private final Vec3d pos; //And some built-in fields that are filled in //Moved distance between current pos and next pos - public static final TrackData DELTA_MOVEMENT = createKey("delta_movement", Double.class, 0d); + public static final TrackData DELTA_MOVEMENT = createOrGetKey("delta_movement", Double.class, 0d); //And we expect you to fill in these //Track roll for stocks to do superelevation (rotated from middle of the rails) - public static final TrackData ROLL_DEGREES = createKey("roll_degrees", Double.class, 0d); + public static final TrackData ROLL_DEGREES = createOrGetKey("roll_degrees", Double.class, 0d); public PathingContext(Vec3d pos) { this.pos = Objects.requireNonNull(pos, "pos cannot be null"); @@ -64,12 +64,12 @@ public double z() { return pos.z; } - public static TrackData createKey(String name, Class type) { - return createKey(name, type, null); + public static TrackData createOrGetKey(String name, Class type) { + return createOrGetKey(name, type, null); } @SuppressWarnings("unchecked") - public static TrackData createKey(String name, Class type, T fallback) { + public static TrackData createOrGetKey(String name, Class type, T fallback) { TrackData existing = registered.get(name); if (existing != null) { if (!existing.type().equals(type)) { From 2f04e6031e42fdaabafe89c48641cc308ee1c8fb Mon Sep 17 00:00:00 2001 From: Goldenfield192 <1437356849@qq.com> Date: Sat, 21 Feb 2026 13:15:42 +0800 Subject: [PATCH 10/10] ref: expose immutable field --- src/main/java/trackapi/lib/PathingContext.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/trackapi/lib/PathingContext.java b/src/main/java/trackapi/lib/PathingContext.java index 09f7cb9..d9db5b8 100644 --- a/src/main/java/trackapi/lib/PathingContext.java +++ b/src/main/java/trackapi/lib/PathingContext.java @@ -18,7 +18,7 @@ public final class PathingContext { private final Map, Object> dataMap; //We have next found pos by default - private final Vec3d pos; + public final Vec3d pos; //And some built-in fields that are filled in //Moved distance between current pos and next pos public static final TrackData DELTA_MOVEMENT = createOrGetKey("delta_movement", Double.class, 0d); @@ -49,11 +49,7 @@ public void reset(TrackData key) { dataMap.remove(key); } - public Vec3d pos() { - return pos; - } - - //And for those don't want to use Minecraft's Vec3d directly + //For those don't want to use Minecraft's Vec3d directly public double x() { return pos.x; }