Skip to content

Commit

Permalink
renaming, new icons, fixes - renamed the variables in moveOnTCCurvedS…
Browse files Browse the repository at this point in the history
…lope so it is easier to understand from just looking. - added new icon for the parallel switches; previously they shared one. - reworked "switch lengths" so the normal switches now function properly
  • Loading branch information
broscolotos committed Aug 12, 2024
1 parent 8f8d356 commit 980dc03
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 67 deletions.
86 changes: 45 additions & 41 deletions src/main/java/train/common/api/EntityRollingStock.java
Original file line number Diff line number Diff line change
Expand Up @@ -1353,69 +1353,73 @@ private void moveOnTCDiagonal(int i, int j, int k, double cx, double cz, int met
}


private void moveOnTCCurvedSlope(int i, int j, int k, double r, double cx, double cz, int tilex, int tilez, int meta, double slopeHeight, double slopeAngle) {
double newTilex = tilex;
double newTilez = tilez;
private void moveOnTCCurvedSlope(int floor_X, int floor_Y, int floor_Z, double tileRadius, double circleX, double circleZ, int tileX, int tileZ, int meta, double slopeHeight, double slopeAngle) {
double newTileX = tileX;
double newTileZ = tileZ;
if (meta == 2) {
newTilez += 1;
newTilex += 0.5;
newTileZ += 1;
newTileX += 0.5;
}
if (meta == 0) {
newTilex += 0.5;
newTileX += 0.5;
}
if (meta == 1) {
newTilex += 1;
newTilez += 0.5;
newTileX += 1;
newTileZ += 0.5;
}
if (meta == 3) {
newTilez += 0.5;
newTileZ += 0.5;
}
double cpx = posX - cx;
double cpz = posZ - cz;
double tpx = newTilex - posX;
double tpz = newTilez - posZ;
double circlePosX = posX - circleX;
double circlePosZ = posZ - circleZ;

double tpnorm = Math.sqrt(tpx * tpx + tpz * tpz);
double tilePositionNormalized = Math.sqrt(Math.pow((newTileX - posX),2) + Math.pow((newTileZ - posZ),2));

double cp_norm = Math.sqrt(cpx * cpx + cpz * cpz);
double vnorm = Math.sqrt(motionX * motionX + motionZ * motionZ);
double circlePositionNormalized = Math.sqrt(circlePosX * circlePosX + circlePosZ * circlePosZ);
double velocityNormalized = Math.sqrt(motionX * motionX + motionZ * motionZ);

double norm_cpx = cpx / cp_norm; //u
double norm_cpz = cpz / cp_norm; //v
double normCirclePosX = circlePosX / circlePositionNormalized; //u
double normCirclePosZ = circlePosZ / circlePositionNormalized; //v

double vx2 = -norm_cpz * vnorm;//-v
double vz2 = norm_cpx * vnorm;//u

double px2 = posX + motionX;
double pz2 = posZ + motionZ;
double negVelNormX = -normCirclePosZ * velocityNormalized;//-v
double velNormZ = normCirclePosX * velocityNormalized;//u

double px2_cx = px2 - cx;
double pz2_cz = pz2 - cz;
double positionX = posX + motionX;
double positionZ = posZ + motionZ;

double p2_c_norm = Math.sqrt((px2_cx * px2_cx) + (pz2_cz * pz2_cz));
double positionXOffsetByCircle = positionX - circleX;
double positionZOffsetByCircle = positionZ - circleZ;

double px2_cx_norm = px2_cx / p2_c_norm;
double pz2_cz_norm = pz2_cz / p2_c_norm;
double offsetPositionNormalized = Math.sqrt((positionXOffsetByCircle * positionXOffsetByCircle) + (positionZOffsetByCircle * positionZOffsetByCircle));

double px3 = cx + (px2_cx_norm * r);
double pz3 = cz + (pz2_cz_norm * r);
double offsetPositionNormX = positionXOffsetByCircle / offsetPositionNormalized;
double offsetPositionNormZ = positionZOffsetByCircle / offsetPositionNormalized;

double signX = px3 - posX;
double signZ = pz3 - posZ;
double posX3 = circleX + (offsetPositionNormX * tileRadius);
double posZ3 = circleZ + (offsetPositionNormZ * tileRadius);

vx2 = Math.copySign(vx2, signX);
vz2 = Math.copySign(vz2, signZ);
double signX = posX3 - posX;
double signZ = posZ3 - posZ;

double p_corr_x = cx + ((cpx / cp_norm) * r);
double p_corr_z = cz + ((cpz / cp_norm) * r);
motionX = vx2;
motionZ = vz2;
negVelNormX = Math.copySign(negVelNormX, signX);
velNormZ = Math.copySign(velNormZ, signZ);

double newYPos = Math.abs(j + Math.min(1, (slopeAngle * Math.abs(tpnorm))) + yOffset + 0.34f);
setPosition(p_corr_x, newYPos, p_corr_z);
moveEntity(vx2, 0, vz2);
double correctedPosX = circleX + ((circlePosX / circlePositionNormalized) * tileRadius);
double correctedPosZ = circleZ + ((circlePosZ / circlePositionNormalized) * tileRadius);
double newYPos = Math.abs(floor_Y + Math.min(1, (slopeAngle * Math.abs(tilePositionNormalized))) + yOffset + 0.34f);
setPosition(correctedPosX, newYPos, correctedPosZ);

/* slope speed-up. it works* but not in a desired fashion. will come back to it.
double normalizedSlopeVelocity = Math.sqrt((negVelNormX*negVelNormX)+(velNormZ*velNormZ));
normalizedSlopeVelocity = getSlopeAdjustedSpeed(normalizedSlopeVelocity, slopeAngle);
double slopeVelopcityX = negVelNormX / normalizedSlopeVelocity;
double slopeVelopcityZ = velNormZ / normalizedSlopeVelocity;
motionX = Math.copySign(slopeVelopcityX, motionX);
motionZ = Math.copySign(slopeVelopcityZ, motionZ);
System.out.println(slopeAngle);
*/

moveEntity(negVelNormX, 0, velNormZ);
}

private void moveOnTCStraight(int i, int j, int k, double cx, double cz, int meta) {
Expand Down
48 changes: 24 additions & 24 deletions src/main/java/train/common/library/EnumTracks.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,21 @@ public enum EnumTracks implements TrackRecord {
DIAGONAL_TWO_WAYS_CROSSING("DIAGONAL_TWO_WAYS_CROSSING", DIAGONAL_CROSSING, "NORMAL", ItemIDs.tcRailDiagonalTwoWaysCrossing, 0,"3x3"),
FOUR_WAYS_CROSSING("FOUR_WAYS_CROSSING", DIAGONAL_CROSSING, "NORMAL", ItemIDs.tcRailFourWaysCrossing, 0,"3x3"),

MEDIUM_SWITCH("MEDIUM_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailMediumSwitch, 1, "4x4"),
MEDIUM_RIGHT_SWITCH("MEDIUM_RIGHT_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailMediumSwitch, 1,""),
MEDIUM_LEFT_SWITCH("MEDIUM_LEFT_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailMediumSwitch,1, ""),
MEDIUM_SWITCH("MEDIUM_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailMediumSwitch, 2, "4x4"),
MEDIUM_RIGHT_SWITCH("MEDIUM_RIGHT_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailMediumSwitch, 2,""),
MEDIUM_LEFT_SWITCH("MEDIUM_LEFT_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailMediumSwitch,2, ""),

LARGE_SWITCH("LARGE_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailLargeSwitch, 2,"6x6"),
LARGE_RIGHT_SWITCH("LARGE_RIGHT_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailLargeSwitch, 2,""),
LARGE_LEFT_SWITCH("LARGE_LEFT_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailLargeSwitch, 2,""),
LARGE_SWITCH("LARGE_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailLargeSwitch, 3,"6x6"),
LARGE_RIGHT_SWITCH("LARGE_RIGHT_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailLargeSwitch, 3,""),
LARGE_LEFT_SWITCH("LARGE_LEFT_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailLargeSwitch, 3,""),

VERY_LARGE_SWITCH("VERY_LARGE_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailVeryLargeSwitch, 3,"11x11"),
VERY_LARGE_RIGHT_SWITCH("VERY_LARGE_RIGHT_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailVeryLargeSwitch,3, ""),
VERY_LARGE_LEFT_SWITCH("VERY_LARGE_LEFT_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailVeryLargeSwitch, 3,""),
VERY_LARGE_SWITCH("VERY_LARGE_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailVeryLargeSwitch, 4,"11x11"),
VERY_LARGE_RIGHT_SWITCH("VERY_LARGE_RIGHT_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailVeryLargeSwitch,4, ""),
VERY_LARGE_LEFT_SWITCH("VERY_LARGE_LEFT_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailVeryLargeSwitch, 4,""),

MEDIUM_PARALLEL_SWITCH("MEDIUM_PARALLEL_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailMediumParallelSwitch, 2,"4x11"),
MEDIUM_RIGHT_PARALLEL_SWITCH("MEDIUM_RIGHT_PARALLEL_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailMediumParallelSwitch, 2,""),
MEDIUM_LEFT_PARALLEL_SWITCH("MEDIUM_LEFT_PARALLEL_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailMediumParallelSwitch, 2, ""),
MEDIUM_PARALLEL_SWITCH("MEDIUM_PARALLEL_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailMediumParallelSwitch, 3,"4x11"),
MEDIUM_RIGHT_PARALLEL_SWITCH("MEDIUM_RIGHT_PARALLEL_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailMediumParallelSwitch, 3,""),
MEDIUM_LEFT_PARALLEL_SWITCH("MEDIUM_LEFT_PARALLEL_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailMediumParallelSwitch, 3, ""),

LARGE_PARALLEL_SWITCH("LARGE_PARALLEL_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailLargeParallelSwitch, 4,"4x17"),
LARGE_RIGHT_PARALLEL_SWITCH("LARGE_RIGHT_PARALLEL_SWITCH", SWITCH, "NORMAL", ItemIDs.tcRailLargeParallelSwitch, 4,""),
Expand Down Expand Up @@ -241,21 +241,21 @@ public enum EnumTracks implements TrackRecord {
EMBEDDED_DOUBLE_DIAMOND_CROSSING("EMBEDDED_DOUBLE_DIAMOND_CROSSING", DIAGONAL_CROSSING, "EMBEDDED", ItemIDs.tcRailEmbeddedDoubleDiamondCrossing, 0,"3x3"),


EMBEDDED_MEDIUM_SWITCH("EMBEDDED_MEDIUM_RIGHT_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedMediumSwitch, 1,"4x4"),
EMBEDDED_MEDIUM_RIGHT_SWITCH("EMBEDDED_MEDIUM_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedMediumSwitch, 1, ""),
EMBEDDED_MEDIUM_LEFT_SWITCH("EMBEDDED_MEDIUM_LEFT_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedMediumSwitch, 1, ""),
EMBEDDED_MEDIUM_SWITCH("EMBEDDED_MEDIUM_RIGHT_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedMediumSwitch, 2,"4x4"),
EMBEDDED_MEDIUM_RIGHT_SWITCH("EMBEDDED_MEDIUM_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedMediumSwitch, 2, ""),
EMBEDDED_MEDIUM_LEFT_SWITCH("EMBEDDED_MEDIUM_LEFT_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedMediumSwitch, 2, ""),

EMBEDDED_LARGE_SWITCH("EMBEDDED_LARGE_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedLargeSwitch, 2, "6x6"),
EMBEDDED_LARGE_RIGHT_SWITCH("EMBEDDED_LARGE_RIGHT_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedLargeSwitch, 2, ""),
EMBEDDED_LARGE_LEFT_SWITCH("EMBEDDED_LARGE_LEFT_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedLargeSwitch, 2, ""),
EMBEDDED_LARGE_SWITCH("EMBEDDED_LARGE_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedLargeSwitch, 3, "6x6"),
EMBEDDED_LARGE_RIGHT_SWITCH("EMBEDDED_LARGE_RIGHT_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedLargeSwitch, 3, ""),
EMBEDDED_LARGE_LEFT_SWITCH("EMBEDDED_LARGE_LEFT_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedLargeSwitch, 3, ""),

EMBEDDED_VERY_LARGE_SWITCH("EMBEDDED_VERY_LARGE_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedVeryLargeSwitch, 3, "11x11"),
EMBEDDED_VERY_LARGE_RIGHT_SWITCH("EMBEDDED_VERY_LARGE_RIGHT_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedVeryLargeSwitch, 3, ""),
EMBEDDED_VERY_LARGE_LEFT_SWITCH("EMBEDDED_VERY_LARGE_LEFT_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedVeryLargeSwitch, 3, ""),
EMBEDDED_VERY_LARGE_SWITCH("EMBEDDED_VERY_LARGE_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedVeryLargeSwitch, 4, "11x11"),
EMBEDDED_VERY_LARGE_RIGHT_SWITCH("EMBEDDED_VERY_LARGE_RIGHT_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedVeryLargeSwitch, 4, ""),
EMBEDDED_VERY_LARGE_LEFT_SWITCH("EMBEDDED_VERY_LARGE_LEFT_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedVeryLargeSwitch, 4, ""),

EMBEDDED_MEDIUM_PARALLEL_SWITCH("EMBEDDED_", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedMediumParallelSwitch, 2, "4x11"),
EMBEDDED_MEDIUM_RIGHT_PARALLEL_SWITCH("EMBEDDED_MEDIUM_RIGHT_PARALLEL_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedMediumParallelSwitch, 2, ""),
EMBEDDED_MEDIUM_LEFT_PARALLEL_SWITCH("EMBEDDED_MEDIUM_LEFT_PARALLEL_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedMediumParallelSwitch, 2, ""),
EMBEDDED_MEDIUM_PARALLEL_SWITCH("EMBEDDED_", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedMediumParallelSwitch, 3, "4x11"),
EMBEDDED_MEDIUM_RIGHT_PARALLEL_SWITCH("EMBEDDED_MEDIUM_RIGHT_PARALLEL_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedMediumParallelSwitch, 3, ""),
EMBEDDED_MEDIUM_LEFT_PARALLEL_SWITCH("EMBEDDED_MEDIUM_LEFT_PARALLEL_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedMediumParallelSwitch, 3, ""),

EMBEDDED_LARGE_PARALLEL_SWITCH("EMBEDDED_LARGE_PARALLEL_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedLargeParallelSwitch, 4, "4x17"),
EMBEDDED_LARGE_RIGHT_PARALLEL_SWITCH("EMBEDDED_LARGE_RIGHT_PARALLEL_SWITCH", SWITCH, "EMBEDDED", ItemIDs.tcRailEmbeddedLargeParallelSwitch, 4, ""),
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/train/common/library/ItemIDs.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ public enum ItemIDs {
tcRailLargeSwitch("ItemTCRail", "item_rail_switch_large", 5),
tcRailVeryLargeSwitch("ItemTCRail", "item_rail_switch_very_large", 5),

tcRailMediumParallelSwitch("ItemTCRail", "item_rail_switch_parallel", 5),
tcRailLargeParallelSwitch("ItemTCRail", "item_rail_switch_parallel", 5),
tcRailMediumParallelSwitch("ItemTCRail", "item_rail_switch_parallel_4x11", 5),
tcRailLargeParallelSwitch("ItemTCRail", "item_rail_switch_parallel_4x17", 5),
tcRailMedium45DegreeSwitch("ItemTCRail","item_rail_switch_45degree_medium", 5 ),
tcRailLarge45DegreeSwitch("ItemTCRail", "item_rail_switch_45degree_large", 5),

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 980dc03

Please sign in to comment.