Skip to content

Commit

Permalink
rider positions work now.
Browse files Browse the repository at this point in the history
many offsets are wrong, but progress.
  • Loading branch information
EternalBlueFlame committed Jan 13, 2025
1 parent afb11c1 commit 7828aba
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/main/java/ebf/tim/entities/EntitySeat.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void writeSpawnData(ByteBuf buffer) {
@Override
public void updateRiderPosition() {
if (this.getPassenger() != null) {
this.getPassenger().setPosition(this.posX, this.posY+(getWorld().isRemote?(this.getPassenger()==Minecraft.getMinecraft().thePlayer?0.4:-1.3):-1.5), this.posZ);
this.getPassenger().setPosition(this.posX, this.posY+1+(getWorld().isRemote?(this.getPassenger()==Minecraft.getMinecraft().thePlayer?-0.4:-1.3):-1.5), this.posZ);
}
}

Expand Down
18 changes: 8 additions & 10 deletions src/main/java/train/common/api/EntityRollingStock.java
Original file line number Diff line number Diff line change
Expand Up @@ -836,19 +836,13 @@ else if (seats.size() != 0 && worldObj.isRemote && Traincraft.proxy.getCurrentSc
setRotation(rotationYaw, rotationPitch);

}
if (seats.size() != 0) {
for (int i = 0; i < seats.size() && i<getRiderOffsets().length; i++) {
if (seats.get(i) != null) {
TraincraftUtil.updateRider(this, getRiderOffsets()[i][0], getRiderOffsets()[i][1] + 2, getRiderOffsets()[i][2], seats.get(i));
}
}
}

if(collisionHandler!=null){
collisionHandler.position(posX, posY, posZ, rotationPitch, getYaw());
collisionHandler.updateCollidingEntities(this);
collisionHandler.manageCollision(this);
}
positionSeats();
return;
}
/**
Expand Down Expand Up @@ -1040,6 +1034,13 @@ else if (seats.size() != 0 && worldObj.isRemote && Traincraft.proxy.getCurrentSc
}
this.dataWatcher.updateObject(14, (int) (motionX * 100));
this.dataWatcher.updateObject(21, (int) (motionZ * 100));
positionSeats();
if (ConfigHandler.ENABLE_LOGGING && !worldObj.isRemote && ticksExisted % 120 == 0) {
ServerLogger.writeWagonToFolder(this);
}
}

private void positionSeats(){
//rider updating isn't called if there's no driver/conductor, so just in case of that, we reposition the seats here too.
if (getRiderOffsets() != null) {
for (int i1 = 0; i1 < seats.size(); i1++) {
Expand All @@ -1057,9 +1058,6 @@ else if (seats.size() != 0 && worldObj.isRemote && Traincraft.proxy.getCurrentSc
seats.get(i1).setPosition(cachedVectors[0].xCoord, cachedVectors[0].yCoord, cachedVectors[0].zCoord);
}
}
if (ConfigHandler.ENABLE_LOGGING && !worldObj.isRemote && ticksExisted % 120 == 0) {
ServerLogger.writeWagonToFolder(this);
}
}

boolean flag, flag1;
Expand Down
38 changes: 0 additions & 38 deletions src/main/java/train/common/core/util/TraincraftUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,44 +78,6 @@ public static void updateRider(EntityRollingStock transport, double distance, do
transport.riddenByEntity.setPosition(bogieX1, pitch, bogieZ1);
}
}
public static void updateRider(EntityRollingStock transport, double xOffset, double yOffset, double zOffset, Entity rider) {
if (rider == null) {
return;
}
double pitchRads = transport.anglePitchClient * radian;
float rotationCos1 = (float) Math.cos(Math.toRadians(transport.renderYaw + ((transport instanceof Locomotive) ? 90 : 180)));
float rotationSin1 = (float) Math.sin(Math.toRadians(transport.renderYaw + ((transport instanceof Locomotive) ? 90 : 180)));
float rotationCosLR1 = (float) Math.cos(Math.toRadians(transport.renderYaw));
float rotationSinLR1 = (float) Math.sin(Math.toRadians((transport.renderYaw)));
if(transport.side.isServer()){
rotationCos1 = (float) Math.cos(Math.toRadians(transport.serverRealRotation + 90));
rotationSin1 = (float) Math.sin(Math.toRadians((transport.serverRealRotation + 90)));
rotationCosLR1 = (float) Math.cos(Math.toRadians(transport.serverRealRotation));
rotationSinLR1 = (float) Math.sin(Math.toRadians((transport.serverRealRotation)));
transport.anglePitchClient = transport.serverRealPitch*60;
}
float pitch = (float) (transport.posY + ((Math.tan(pitchRads) * xOffset) + transport.getMountedYOffset())
+ rider.getYOffset() + yOffset);
float pitch1 = (float) (transport.posY + transport.getMountedYOffset() + rider.getYOffset() + yOffset);
double bogieX1 = (transport.posX + (rotationCos1 * xOffset) + (rotationCosLR1 * zOffset));
double bogieZ1 = (transport.posZ + (rotationSin1* xOffset) + (rotationSinLR1 * zOffset));

//System.out.println(rotationCos1+" "+rotationSin1);
if (transport.anglePitchClient > 20 && rotationCos1 == 1) {
bogieX1 -= pitchRads * 2;
pitch -= (float) (pitchRads * 1.2);
}
if (transport.anglePitchClient > 20 && rotationSin1 == 1) {
bogieZ1 -= pitchRads * 2;
pitch -= (float) (pitchRads * 1.2);
}
if (pitchRads == 0.0) {
rider.setPosition(bogieX1, pitch1, bogieZ1);
}
if (pitchRads > -1.01 && pitchRads < 1.01) {
rider.setPosition(bogieX1, pitch, bogieZ1);
}
}

public static float atan2f(double x, double z) {
float pi = -3.141592653f;
Expand Down

0 comments on commit 7828aba

Please sign in to comment.