From 8dacc62bbd5a5595315b5daa443a56d29d22bf1f Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 8 Aug 2023 17:56:47 -0500 Subject: [PATCH] improved slope and bogie alignment logic - 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. --- .../java/ebf/tim/entities/EntityBogie.java | 26 ++++++++++++------- .../tim/entities/GenericRailTransport.java | 14 +++++----- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/main/java/ebf/tim/entities/EntityBogie.java b/src/main/java/ebf/tim/entities/EntityBogie.java index fa07fce0a..eb3892688 100644 --- a/src/main/java/ebf/tim/entities/EntityBogie.java +++ b/src/main/java/ebf/tim/entities/EntityBogie.java @@ -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); @@ -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; } diff --git a/src/main/java/ebf/tim/entities/GenericRailTransport.java b/src/main/java/ebf/tim/entities/GenericRailTransport.java index 3f424b6bc..5696bc28a 100644 --- a/src/main/java/ebf/tim/entities/GenericRailTransport.java +++ b/src/main/java/ebf/tim/entities/GenericRailTransport.java @@ -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(); @@ -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){