Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the correct partialTick when ticking animations #677

Open
wants to merge 1 commit into
base: 1.20.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void addAdditionalStateData(T animatable, long instanceId, BiConsumer<Dat
*/
@ApiStatus.Internal
@Override
public void handleAnimations(T animatable, long instanceId, AnimationState<T> animationState) {
public void handleAnimations(T animatable, long instanceId, AnimationState<T> animationState, float partialTick) {
Minecraft mc = Minecraft.getInstance();
AnimatableManager<T> animatableManager = animatable.getAnimatableInstanceCache().getManagerForId(instanceId);
Double currentTick = animationState.getData(DataTickets.TICK);
Expand All @@ -193,9 +193,9 @@ public void handleAnimations(T animatable, long instanceId, AnimationState<T> an
currentTick = animatable instanceof Entity entity ? (double)entity.tickCount : RenderUtils.getCurrentTick();

if (animatableManager.getFirstTickTime() == -1)
animatableManager.startedAt(currentTick + mc.getFrameTime());
animatableManager.startedAt(currentTick + partialTick);

double currentFrameTime = animatable instanceof Entity ? currentTick + mc.getFrameTime() : currentTick - animatableManager.getFirstTickTime();
double currentFrameTime = animatable instanceof Entity ? currentTick + partialTick : currentTick - animatableManager.getFirstTickTime();
boolean isReRender = !animatableManager.isFirstTick() && currentFrameTime == animatableManager.getLastUpdateTime();

if (isReRender && instanceId == this.lastRenderedInstance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public void actuallyRender(PoseStack poseStack, T animatable, BakedGeoModel mode
animationState.setData(DataTickets.ENTITY, this.currentEntity);
animationState.setData(DataTickets.EQUIPMENT_SLOT, this.currentSlot);
this.model.addAdditionalStateData(animatable, instanceId, animationState::setData);
this.model.handleAnimations(animatable, instanceId, animationState);
this.model.handleAnimations(animatable, instanceId, animationState, partialTick);
}

this.modelRenderTranslations = new Matrix4f(poseStack.last().pose());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void actuallyRender(PoseStack poseStack, T animatable, BakedGeoModel mode
currentModel.addAdditionalStateData(animatable, instanceId, animationState::setData);
poseStack.translate(0.5, 0, 0.5);
rotateBlock(getFacing(animatable), poseStack);
currentModel.handleAnimations(animatable, instanceId, animationState);
currentModel.handleAnimations(animatable, instanceId, animationState, partialTick);
}

this.modelRenderTranslations = new Matrix4f(poseStack.last().pose());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public void actuallyRender(PoseStack poseStack, T animatable, BakedGeoModel mode
animationState.setData(DataTickets.ENTITY, animatable);
animationState.setData(DataTickets.ENTITY_MODEL_DATA, new EntityModelData(shouldSit, livingEntity != null && livingEntity.isBaby(), -netHeadYaw, -headPitch));
currentModel.addAdditionalStateData(animatable, instanceId, animationState::setData);
currentModel.handleAnimations(animatable, instanceId, animationState);
currentModel.handleAnimations(animatable, instanceId, animationState, partialTick);
}

poseStack.translate(0, 0.01f, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public void actuallyRender(PoseStack poseStack, T animatable, BakedGeoModel mode
animationState.setData(DataTickets.ITEMSTACK, this.currentItemStack);
animatable.getAnimatableInstanceCache().getManagerForId(instanceId).setData(DataTickets.ITEM_RENDER_PERSPECTIVE, this.renderPerspective);
currentModel.addAdditionalStateData(animatable, instanceId, animationState::setData);
currentModel.handleAnimations(animatable, instanceId, animationState);
currentModel.handleAnimations(animatable, instanceId, animationState, partialTick);
}

this.modelRenderTranslations = new Matrix4f(poseStack.last().pose());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void actuallyRender(PoseStack poseStack, T animatable, BakedGeoModel mode
GeoModel<T> currentModel = getGeoModel();

currentModel.addAdditionalStateData(animatable, instanceId, animationState::setData);
currentModel.handleAnimations(animatable, instanceId, animationState);
currentModel.handleAnimations(animatable, instanceId, animationState, partialTick);
}

this.modelRenderTranslations = new Matrix4f(poseStack.last().pose());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public void actuallyRender(PoseStack poseStack, T animatable, BakedGeoModel mode
animationState.setData(DataTickets.ENTITY, this.currentEntity);
animationState.setData(DataTickets.ENTITY_MODEL_DATA, new EntityModelData(shouldSit, livingEntity != null && livingEntity.isBaby(), -netHeadYaw, -headPitch));
currentModel.addAdditionalStateData(animatable, instanceId, animationState::setData);
currentModel.handleAnimations(animatable, instanceId, animationState);
currentModel.handleAnimations(animatable, instanceId, animationState, partialTick);
}

poseStack.translate(0, 0.01f, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void addAdditionalStateData(T animatable, long instanceId, BiConsumer<Dat
*/
@ApiStatus.Internal
@Override
public void handleAnimations(T animatable, long instanceId, AnimationState<T> animationState) {
public void handleAnimations(T animatable, long instanceId, AnimationState<T> animationState, float partialTick) {
Minecraft mc = Minecraft.getInstance();
AnimatableManager<T> animatableManager = animatable.getAnimatableInstanceCache().getManagerForId(instanceId);
Double currentTick = animationState.getData(DataTickets.TICK);
Expand All @@ -193,9 +193,9 @@ public void handleAnimations(T animatable, long instanceId, AnimationState<T> an
currentTick = animatable instanceof Entity entity ? (double)entity.tickCount : RenderUtils.getCurrentTick();

if (animatableManager.getFirstTickTime() == -1)
animatableManager.startedAt(currentTick + mc.getFrameTime());
animatableManager.startedAt(currentTick + partialTick);

double currentFrameTime = animatable instanceof Entity ? currentTick + mc.getFrameTime() : currentTick - animatableManager.getFirstTickTime();
double currentFrameTime = animatable instanceof Entity ? currentTick + partialTick : currentTick - animatableManager.getFirstTickTime();
boolean isReRender = !animatableManager.isFirstTick() && currentFrameTime == animatableManager.getLastUpdateTime();

if (isReRender && instanceId == this.lastRenderedInstance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public void actuallyRender(PoseStack poseStack, T animatable, BakedGeoModel mode
animationState.setData(DataTickets.ENTITY, this.currentEntity);
animationState.setData(DataTickets.EQUIPMENT_SLOT, this.currentSlot);
this.model.addAdditionalStateData(animatable, instanceId, animationState::setData);
this.model.handleAnimations(animatable, instanceId, animationState);
this.model.handleAnimations(animatable, instanceId, animationState, partialTick);
}

this.modelRenderTranslations = new Matrix4f(poseStack.last().pose());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void actuallyRender(PoseStack poseStack, T animatable, BakedGeoModel mode
currentModel.addAdditionalStateData(animatable, instanceId, animationState::setData);
poseStack.translate(0.5, 0, 0.5);
rotateBlock(getFacing(animatable), poseStack);
currentModel.handleAnimations(animatable, instanceId, animationState);
currentModel.handleAnimations(animatable, instanceId, animationState, partialTick);
}

this.modelRenderTranslations = new Matrix4f(poseStack.last().pose());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public void actuallyRender(PoseStack poseStack, T animatable, BakedGeoModel mode
animationState.setData(DataTickets.ENTITY, animatable);
animationState.setData(DataTickets.ENTITY_MODEL_DATA, new EntityModelData(shouldSit, livingEntity != null && livingEntity.isBaby(), -netHeadYaw, -headPitch));
currentModel.addAdditionalStateData(animatable, instanceId, animationState::setData);
currentModel.handleAnimations(animatable, instanceId, animationState);
currentModel.handleAnimations(animatable, instanceId, animationState, partialTick);
}

poseStack.translate(0, 0.01f, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public void actuallyRender(PoseStack poseStack, T animatable, BakedGeoModel mode
animationState.setData(DataTickets.ITEMSTACK, this.currentItemStack);
animatable.getAnimatableInstanceCache().getManagerForId(instanceId).setData(DataTickets.ITEM_RENDER_PERSPECTIVE, this.renderPerspective);
currentModel.addAdditionalStateData(animatable, instanceId, animationState::setData);
currentModel.handleAnimations(animatable, instanceId, animationState);
currentModel.handleAnimations(animatable, instanceId, animationState, partialTick);
}

this.modelRenderTranslations = new Matrix4f(poseStack.last().pose());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void actuallyRender(PoseStack poseStack, T animatable, BakedGeoModel mode
GeoModel<T> currentModel = getGeoModel();

currentModel.addAdditionalStateData(animatable, instanceId, animationState::setData);
currentModel.handleAnimations(animatable, instanceId, animationState);
currentModel.handleAnimations(animatable, instanceId, animationState, partialTick);
}

this.modelRenderTranslations = new Matrix4f(poseStack.last().pose());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public void actuallyRender(PoseStack poseStack, T animatable, BakedGeoModel mode
animationState.setData(DataTickets.ENTITY, this.currentEntity);
animationState.setData(DataTickets.ENTITY_MODEL_DATA, new EntityModelData(shouldSit, livingEntity != null && livingEntity.isBaby(), -netHeadYaw, -headPitch));
currentModel.addAdditionalStateData(animatable, instanceId, animationState::setData);
currentModel.handleAnimations(animatable, instanceId, animationState);
currentModel.handleAnimations(animatable, instanceId, animationState, partialTick);
}

poseStack.translate(0, 0.01f, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public void addAdditionalStateData(T animatable, long instanceId, BiConsumer<Dat
*/
@ApiStatus.Internal
@Override
public void handleAnimations(T animatable, long instanceId, AnimationState<T> animationState) {
public void handleAnimations(T animatable, long instanceId, AnimationState<T> animationState, float partialTick) {
Minecraft mc = Minecraft.getInstance();
AnimatableManager<T> animatableManager = animatable.getAnimatableInstanceCache().getManagerForId(instanceId);
Double currentTick = animationState.getData(DataTickets.TICK);
Expand All @@ -192,9 +192,9 @@ public void handleAnimations(T animatable, long instanceId, AnimationState<T> an
currentTick = animatable instanceof Entity entity ? (double)entity.tickCount : RenderUtils.getCurrentTick();

if (animatableManager.getFirstTickTime() == -1)
animatableManager.startedAt(currentTick + mc.getFrameTime());
animatableManager.startedAt(currentTick + partialTick);

double currentFrameTime = animatable instanceof Entity ? currentTick + mc.getFrameTime() : currentTick - animatableManager.getFirstTickTime();
double currentFrameTime = animatable instanceof Entity ? currentTick + partialTick : currentTick - animatableManager.getFirstTickTime();
boolean isReRender = !animatableManager.isFirstTick() && currentFrameTime == animatableManager.getLastUpdateTime();

if (isReRender && instanceId == this.lastRenderedInstance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public void actuallyRender(PoseStack poseStack, T animatable, BakedGeoModel mode
animationState.setData(DataTickets.ENTITY, this.currentEntity);
animationState.setData(DataTickets.EQUIPMENT_SLOT, this.currentSlot);
this.model.addAdditionalStateData(animatable, instanceId, animationState::setData);
this.model.handleAnimations(animatable, instanceId, animationState);
this.model.handleAnimations(animatable, instanceId, animationState, partialTick);
}

this.modelRenderTranslations = new Matrix4f(poseStack.last().pose());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void actuallyRender(PoseStack poseStack, T animatable, BakedGeoModel mode
currentModel.addAdditionalStateData(animatable, instanceId, animationState::setData);
poseStack.translate(0.5, 0, 0.5);
rotateBlock(getFacing(animatable), poseStack);
currentModel.handleAnimations(animatable, instanceId, animationState);
currentModel.handleAnimations(animatable, instanceId, animationState, partialTick);
}

this.modelRenderTranslations = new Matrix4f(poseStack.last().pose());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public void actuallyRender(PoseStack poseStack, T animatable, BakedGeoModel mode
animationState.setData(DataTickets.ENTITY, animatable);
animationState.setData(DataTickets.ENTITY_MODEL_DATA, new EntityModelData(shouldSit, livingEntity != null && livingEntity.isBaby(), -netHeadYaw, -headPitch));
currentModel.addAdditionalStateData(animatable, instanceId, animationState::setData);
currentModel.handleAnimations(animatable, instanceId, animationState);
currentModel.handleAnimations(animatable, instanceId, animationState, partialTick);
}

poseStack.translate(0, 0.01f, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void actuallyRender(PoseStack poseStack, T animatable, BakedGeoModel mode
animationState.setData(DataTickets.ITEMSTACK, this.currentItemStack);
animatable.getAnimatableInstanceCache().getManagerForId(instanceId).setData(DataTickets.ITEM_RENDER_PERSPECTIVE, this.renderPerspective);
currentModel.addAdditionalStateData(animatable, instanceId, animationState::setData);
currentModel.handleAnimations(animatable, instanceId, animationState);
currentModel.handleAnimations(animatable, instanceId, animationState, partialTick);
}

this.modelRenderTranslations = new Matrix4f(poseStack.last().pose());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void actuallyRender(PoseStack poseStack, T animatable, BakedGeoModel mode
GeoModel<T> currentModel = getGeoModel();

currentModel.addAdditionalStateData(animatable, instanceId, animationState::setData);
currentModel.handleAnimations(animatable, instanceId, animationState);
currentModel.handleAnimations(animatable, instanceId, animationState, partialTick);
}

this.modelRenderTranslations = new Matrix4f(poseStack.last().pose());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public void actuallyRender(PoseStack poseStack, T animatable, BakedGeoModel mode
animationState.setData(DataTickets.ENTITY, this.currentEntity);
animationState.setData(DataTickets.ENTITY_MODEL_DATA, new EntityModelData(shouldSit, livingEntity != null && livingEntity.isBaby(), -netHeadYaw, -headPitch));
currentModel.addAdditionalStateData(animatable, instanceId, animationState::setData);
currentModel.handleAnimations(animatable, instanceId, animationState);
currentModel.handleAnimations(animatable, instanceId, animationState, partialTick);
}

poseStack.translate(0, 0.01f, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ default Optional<? extends CoreGeoBone> getBone(String name) {
* This method is called once per render frame for each {@link GeoAnimatable} being rendered.<br>
* It is an internal method for automated animation parsing. Use {@link CoreGeoModel#setCustomAnimations(GeoAnimatable, long, AnimationState)} for custom animation work
*/
void handleAnimations(E animatable, long instanceId, AnimationState<E> animationState);
void handleAnimations(E animatable, long instanceId, AnimationState<E> animationState, float partialTick);

/**
* This method is called once per render frame for each {@link GeoAnimatable} being rendered.<br>
Expand Down