Skip to content

Commit

Permalink
still a little janky, but smoother.
Browse files Browse the repository at this point in the history
more work on the linking and movement logic, this will be right eventually.
  • Loading branch information
EternalBlueFlame committed Jul 12, 2023
1 parent 7c74c0e commit 5481295
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/main/java/ebf/tim/entities/EntityBogie.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,16 @@ 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(block instanceof BlockAir) {
moveOffRail();
} 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
25 changes: 17 additions & 8 deletions src/main/java/ebf/tim/entities/GenericRailTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ public void addLinkingMove(double velocity){
*/
public void finalMove(){
backBogie.minecartMove(this);
cachedVectors[1] = new Vec3f(-rotationPoints()[0], 0, 0).rotatePoint(rotationPitch, rotationYaw, 0)
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);

Expand Down Expand Up @@ -997,22 +997,32 @@ public void finalMove(){
*/
@Override
public void applyDrag(){
float drag = 0.9998f,brakeBuff=0,slope=0;
//iterate the consist to collect the stats, since only end units can do this.
boolean canSlope=true;
float drag = 0.9998f, brakeBuff = 0, slope = 0;
//check if lope things can be done at all
for(GenericRailTransport stock : getConsist()) {
if(stock.getBoolean(boolValues.BRAKE)){
if(stock!=this && getAccelerator()!=0){
canSlope=false;
break;
}
}
if(canSlope) {
if (getBoolean(boolValues.BRAKE)) {
//realistically would be more like 2.4, but 5 makes gameplay more dramatic
brakeBuff+=stock.weightKg()*5.0f;
brakeBuff += weightKg() * 5.0f;
}
if(stock.rotationPitch!=0){
if (rotationPitch != 0) {
//vanilla uses 0.0078125 per tick for slope speed.
//0.00017361 would be that divided by 45 since vanilla slopes are 45 degree angles.
//scale by entity pitch
//pitch goes from -90 to 90, so it's inherently directional, stop that.
slope+=(0.00017361f)*Math.abs(stock.rotationPitch);
slope += (0.00017361f) * Math.abs(rotationPitch);
}
appendMovement(slope * MathHelper.sin((rotationYaw-90)*radianF));
}

//now do drag stuff

//scale drag for derail, or air lateral friction. if you do both at the same time then it's way too much.
if(getBoolean(boolValues.DERAILED)){
drag*=CommonUtil.getBlockAt(getWorld(),posX,posY,posZ).slipperiness;
Expand All @@ -1032,7 +1042,6 @@ public void applyDrag(){
drag = 0f;
}

appendMovement(slope * MathHelper.sin((rotationYaw-90)*radianF));
for(GenericRailTransport t : getConsist()){
t.frontBogie.drag(t,drag);
t.backBogie.drag(t,drag);
Expand Down

0 comments on commit 5481295

Please sign in to comment.