Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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()
}
Expand All @@ -30,15 +30,15 @@ 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.
// snapshot_YYYYMMDD snapshot are built nightly.
// 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.
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/main/java/trackapi/TrackAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
51 changes: 31 additions & 20 deletions src/main/java/trackapi/compat/MinecraftRail.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import trackapi.lib.Gauges;
import trackapi.lib.ITrack;
import trackapi.lib.*;

import java.util.HashMap;
import java.util.Map;

public class MinecraftRail implements ITrack {
private static Map<EnumRailDirection, Vec3d> vectors = new HashMap<>();
private static Map<EnumRailDirection, Vec3d> centers = new HashMap<>();
/**
* Wrapper for vanilla rail
*/
public class MinecraftRail implements ITrackV2 {
private static final Map<EnumRailDirection, Vec3d> vectors = new HashMap<>();
private static final Map<EnumRailDirection, Vec3d> centers = new HashMap<>();
static {
Vec3d north = new Vec3d(0, 0, 1);
Vec3d south = new Vec3d(0, 0, -1);
Expand Down Expand Up @@ -46,8 +48,8 @@ public class MinecraftRail implements ITrack {
}


private EnumRailDirection direction;
private BlockPos pos;
private final EnumRailDirection direction;
private final BlockPos pos;

public MinecraftRail(World world, BlockPos pos) {
this.pos = pos;
Expand All @@ -57,33 +59,42 @@ public MinecraftRail(World world, BlockPos pos) {
}

@Override
public double getTrackGauge() {
return Gauges.MINECRAFT;
public double[] getTrackGauges() {
return new double[]{Gauges.MINECRAFT};
}

@Override
public Vec3d getNextPosition(Vec3d currentPosition, Vec3d motion) {
Vec3d trackMovement = vectors.get(direction);
public boolean getNextPosition(PathingData inputData, Vec3d motion, double gauge) {
Vec3d currentPosition = inputData.getVanillaPos();

Vec3d trackMovement = vectors.get(direction);
Vec3d trackCenter = centers.get(direction);

Vec3d posRelativeToCenter = currentPosition.subtractReverse(new Vec3d(pos).add(trackCenter));
double distanceToCenter = posRelativeToCenter.lengthVector();
Vec3d pos = new Vec3d(this.pos).add(trackCenter);
Vec3d posRelativeToCenter = currentPosition.subtractReverse(pos);
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);

boolean trackMotionInverted = motion.distanceTo(trackMovement) > motion.scale(-1).distanceTo(trackMovement);

Vec3d newPosition = new Vec3d(pos).add(trackCenter);
//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()));
return newPosition;
Vec3d newPosition = pos;
double factor =
//Correct new pos to track alignment
(trackPosMotionInverted ? -distanceToCenter : distanceToCenter)
// Move new pos along track alignment
+ (trackMotionInverted ? -motion.length() : motion.length());
if (Math.abs(factor) > 1E-4) {
//If it's significantly enough, update it
newPosition = newPosition.add(trackMovement.scale(factor));
inputData.setVanillaPos(newPosition).setRoll(0d);
return true;
}
return false;
}

public static boolean isRail(World world, BlockPos pos) {
return BlockRailBase.isRailBlock(world, pos);
}

}
39 changes: 36 additions & 3 deletions src/main/java/trackapi/lib/Gauges.java
Original file line number Diff line number Diff line change
@@ -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;
}
17 changes: 7 additions & 10 deletions src/main/java/trackapi/lib/ITrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@ public interface ITrack {
/**
* The distance between the rails measured in meters
*
* @see Gauges#STANDARD
* @see Gauges#MINECRAFT
* @see Gauges
*/
public double getTrackGauge();
double getTrackGauge();

/**
* Used by rolling stock to look up their next position.
* Used by rolling stocks 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
* @param currentPosition Current position of entity or bogey
* @param motion Current velocity of entity or bogey
* @return Next found position on the track
*/
public Vec3d getNextPosition(Vec3d currentPosition, Vec3d motion);
Vec3d getNextPosition(Vec3d currentPosition, Vec3d motion);
}
27 changes: 14 additions & 13 deletions src/main/java/trackapi/lib/ITrackBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,28 @@
import net.minecraft.world.World;

/**
* Compatibility layer for block only tracks
*
* Compatibility layer between <code>ITrack</code> and blocks which only contain tracks
* <p>
* use <code>ITrackV2</code> instead
*/
@Deprecated
public interface ITrackBlock {

/**
* The distance between the rails measured in meters
*
* @see Gauges#STANDARD
* @see Gauges#MINECRAFT
* @see Gauges
*/
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
* Used by rolling stock to look up their next position (and related data).
*
* @param world World to query
* @param pos Position of the block
* @param currentPosition Current entity or bogey position
* @param motion Current velocity of entity or bogey
* @return Next found position on the track
*/
public Vec3d getNextPosition(World world, BlockPos pos, Vec3d currentPosition, Vec3d motion);
Vec3d getNextPosition(World world, BlockPos pos, Vec3d currentPosition, Vec3d motion);
}
40 changes: 40 additions & 0 deletions src/main/java/trackapi/lib/ITrackV2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package trackapi.lib;

import net.minecraft.util.math.Vec3d;

public interface ITrackV2 extends ITrack {

/**
* Find available gauges within this track
*
* @return All available gauges
*/
double[] getTrackGauges();

/**
* Used by rolling stocks to look up their next position and related data
* @param inputData Mutable PathingData contains input parameters, like position and roll, and will be overridden with output data
* @param motion Current velocity of entity or bogey
* @param gauge Gauge of the pathing stock
* @return True if inputData is successfully overridden, false if cannot find next path
*/
<D extends PathingData> boolean getNextPosition(D inputData, Vec3d motion, double gauge);

//Overrides for forward compatibility, don't use
@Override
@Deprecated
default double getTrackGauge() {
return getTrackGauges()[0];
}

@Override
@Deprecated
default Vec3d getNextPosition(Vec3d currentPosition, Vec3d motion) {
//Create another PathingData impl may confuse user and that action is discouraged, so don't process V1 logic in V2
PathingData data = new PathingData(currentPosition, 0d);
if (getNextPosition(data, motion, getTrackGauge())) {
return data.getVanillaPos();
}
return currentPosition;
}
}
35 changes: 35 additions & 0 deletions src/main/java/trackapi/lib/PathingData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package trackapi.lib;

import net.minecraft.util.math.Vec3d;

/**
* Mutable data storaging object used by stocks to query data
*/
public class PathingData {
//Reserve position/pos name for mods that may not use MC's Vec3d
private Vec3d vanillaPos;
private double roll;

public PathingData(Vec3d vanillaPos, double roll) {
this.vanillaPos = vanillaPos;
this.roll = roll;
}

public Vec3d getVanillaPos() {
return vanillaPos;
}

public PathingData setVanillaPos(Vec3d vanillaPos) {
this.vanillaPos = vanillaPos;
return this;
}

public double getRoll() {
return roll;
}

public PathingData setRoll(double roll) {
this.roll = roll;
return this;
}
}
Loading