Skip to content

Commit

Permalink
improved slope and bogie alignment logic
Browse files Browse the repository at this point in the history
- bogie alignment seems to work more or less how it should now, it's a little jittery, but not enough to tell unless you're actually staring at the hitboxes.
- Fixed bogie logic for interacting with slopes, should improve performance a little and it's also dramatically more reliable.
  • Loading branch information
EternalBlueFlame committed Aug 8, 2023
1 parent 5481295 commit 8dacc62
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
26 changes: 16 additions & 10 deletions src/main/java/ebf/tim/entities/EntityBogie.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,22 @@ public void minecartMove(GenericRailTransport host) {
//update using spline movement
//} else if (block instanceof BlockRailBase)

if(!(block instanceof BlockRailBase)){
if(CommonUtil.getBlockAt(getWorld(), xFloor, yFloor+1, zFloor) instanceof BlockRailBase) {
prevPosY=posY;
posY++;
yFloor++;
block = CommonUtil.getBlockAt(getWorld(), xFloor, yFloor, zFloor);
} else if(CommonUtil.getBlockAt(getWorld(), xFloor, yFloor-1, zFloor) instanceof BlockRailBase) {
prevPosY=posY;
posY--;
yFloor--;
block = CommonUtil.getBlockAt(getWorld(), xFloor, yFloor, zFloor);
} else if(block instanceof BlockAir) {
moveOffRail();
}
}

//update on normal rails
if (block instanceof BlockRailBase) {
this.yOffset=(block instanceof BlockRailCore?0.425f:0.3425f);
Expand All @@ -256,16 +272,6 @@ public void minecartMove(GenericRailTransport host) {
//} else if (block instanceof ITrackBase) {
//update position for ZnD rails.
//moveBogieZnD(motionX, motionZ, floorX, floorY, floorZ, (ITrackBase) block);
} else if(CommonUtil.getBlockAt(getWorld(), xFloor, yFloor+1, zFloor) instanceof BlockRailBase) {
prevPosY=posY;
posY++;
yFloor++;
} else if(CommonUtil.getBlockAt(getWorld(), xFloor, yFloor-1, zFloor) instanceof BlockRailBase) {
prevPosY=posY;
posY--;
yFloor--;
} else if(block instanceof BlockAir) {
moveOffRail();
}
velocity[2]=0;velocity[3]=0;
}
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/ebf/tim/entities/GenericRailTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -954,12 +954,12 @@ public void addLinkingMove(double velocity){
* if X or Z is null, the bogie's existing motion velocity will be used
*/
public void finalMove(){
backBogie.minecartMove(this);
cachedVectors[1] = new Vec3f(-rotationPoints()[0], 0, 0).rotatePoint(0, rotationYaw, 0)
.addVector(backBogie.posX,backBogie.posY,backBogie.posZ);
setPosition(cachedVectors[1].xCoord, cachedVectors[1].yCoord,cachedVectors[1].zCoord);

frontBogie.minecartMove(this);
backBogie.minecartMove(this);
//reset the y coord so they will re-calculate the yaw
if(hasDrag()) {
applyDrag();
Expand Down Expand Up @@ -1220,13 +1220,11 @@ else if (backBogie !=null && frontBogie != null && ticksExisted>5){
if(backLinkedID!=null && getWorld().getEntityByID(backLinkedID) instanceof GenericRailTransport){
manageLink((GenericRailTransport) getWorld().getEntityByID(backLinkedID));
}
double x2=frontBogie.posX- posX;
double z2=frontBogie.posZ- posZ;
double dist=Math.abs(Math.sqrt(x2*x2+z2*z2)+rotationPoints()[1]);
if(Math.sqrt(x2*x2+z2*z2)<0){
dist*=-1;
}
frontBogie.addLinking(this, dist*0.000625);
//for some off reason, this madness works pretty reliably from my tests.
cachedVectors[1]=new Vec3f(rotationPoints()[1],0,0).rotatePoint(0,rotationYaw,0)
.addVector(posX,0,posZ).subtract((float)frontBogie.posX,0,(float)frontBogie.posZ);
frontBogie.velocity[2]+=cachedVectors[1].xCoord;
frontBogie.velocity[3]+=cachedVectors[1].zCoord;
updatePosition();

if(collisionHandler!=null){
Expand Down

0 comments on commit 8dacc62

Please sign in to comment.