Skip to content

Commit

Permalink
Fix wrong timing of DK3 door animation
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Dec 4, 2022
1 parent a6af226 commit 0b594f6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ public void renderCar(int carIndex, double x, double y, double z, float yaw, flo
renderingCarNum = carNum;

if (trailingCarRenderer != null && carNum != 0) {
matrices.pushPose();
int carNumToRender;
if (trailingCarRenderer instanceof RenderTrainDK3) {
if (carNum == 1) {
carNumToRender = (train.trainCars < 3) ? 1 : 0;
} else if (carNum == 2) {
carNumToRender = 2;
matrices.translate(0, 0, 1);
carNumToRender = train.trainCars - 1;
// matrices.translate(0, 0, train.isReversed() ? 1 : 0);
} else {
matrices.popPose();
return;
}
} else {
Expand All @@ -86,6 +88,7 @@ public void renderCar(int carIndex, double x, double y, double z, float yaw, flo

int carIndexToRender = !train.isReversed() ? carNumToRender : (train.trainCars - carNumToRender - 1);
trailingCarRenderer.renderCar(carIndexToRender, x, y, z, yaw, pitch, doorLeftOpen, doorRightOpen);
matrices.popPose();
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
import cn.zbx1425.sowcerext.multipart.mi.MiScheduleHelper;
import com.google.common.collect.ImmutableSet;
import com.mojang.math.Vector3f;
import mtr.MTRClient;
import mtr.client.TrainClientRegistry;
import mtr.client.TrainProperties;
import mtr.data.TrainClient;
import mtr.model.ModelBogie;
import mtr.render.RenderTrains;
import mtr.render.TrainRendererBase;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -74,6 +77,10 @@ public TrainRendererBase createTrainInstance(TrainClient trainClient) {
return new RenderTrainDK3(trainClient);
}

private float elapsedDwellTicks = 0;
private float totalDwellTicks = 0;
private float lastRenderedTick = 0;

@Override
public void renderCar(int carIndex, double x, double y, double z, float yaw, float pitch, boolean doorLeftOpen, boolean doorRightOpen) {
if (RenderUtil.shouldSkipRenderTrain(train)) return;
Expand All @@ -93,9 +100,23 @@ public void renderCar(int carIndex, double x, double y, double z, float yaw, flo
return;
}

final float lastFrameDuration = MTRClient.getLastFrameDuration();
final float ticksElapsed = Minecraft.getInstance().isPaused() || lastRenderedTick == MTRClient.getGameTick() ? 0 : lastFrameDuration;
lastRenderedTick = MTRClient.getGameTick();
elapsedDwellTicks += ticksElapsed;
if (train.justOpening()) {
elapsedDwellTicks = 0;
totalDwellTicks = train.getTotalDwellTicks();
}

// Get door delay of the first sec off
final int dwellTicks = train.getTotalDwellTicks() - 20;
final float stopTicks = train.getElapsedDwellTicks() - 20;
final float dwellTicks = totalDwellTicks - 20;
final float stopTicks = elapsedDwellTicks - 20;

if (train.getDoorValue() == 0) {
doorLeftOpen = false;
doorRightOpen = false;
}

if (train.isReversed()) {
boolean t = doorLeftOpen;
Expand Down Expand Up @@ -123,6 +144,8 @@ public void renderCar(int carIndex, double x, double y, double z, float yaw, flo
scheduleHelper.play(34, 34);
}
}
} else if (stopTicks > dwellTicks + 8 * 20) {
scheduleHelper.play(0, 0);
}

matrices.pushPose();
Expand Down

0 comments on commit 0b594f6

Please sign in to comment.