From 960717eb0c57e56b99f978b843d2ab53e683055d Mon Sep 17 00:00:00 2001 From: RainWarrior Date: Mon, 25 Jan 2016 17:39:43 +0300 Subject: [PATCH] Fixed minor race condition between mouse clicks and TESR in the animation example. --- .../client/model/animation/Animation.java | 20 +++++++++++++++++++ .../fml/common/FMLCommonHandler.java | 2 ++ .../debug/ModelAnimationDebug.java | 4 ++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/minecraftforge/client/model/animation/Animation.java b/src/main/java/net/minecraftforge/client/model/animation/Animation.java index 00b231d7c..75cc9ccac 100644 --- a/src/main/java/net/minecraftforge/client/model/animation/Animation.java +++ b/src/main/java/net/minecraftforge/client/model/animation/Animation.java @@ -26,6 +26,8 @@ public enum Animation implements IResourceManagerReloadListener { INSTANCE; + private float clientPartialTickTime; + /** * Get the global world time for the current tick, in seconds. */ @@ -42,6 +44,14 @@ public enum Animation implements IResourceManagerReloadListener return (world.getTotalWorldTime() + tickProgress) / 20; } + /** + * Get current partialTickTime. + */ + public static float getPartialTickTime() + { + return INSTANCE.clientPartialTickTime; + } + /** * Load a new instance if AnimationStateMachine at specified location, with specified custom parameters. */ @@ -176,6 +186,16 @@ public enum Animation implements IResourceManagerReloadListener private final ModelBlockAnimation defaultModelBlockAnimation = new ModelBlockAnimation(ImmutableMap.>of(), ImmutableMap.of()); + /** + * Iternal hook, do not use. + */ + public static void setClientPartialTickTime(float clientPartialTickTime) { + Animation.INSTANCE.clientPartialTickTime = clientPartialTickTime; + } + + /** + * Iternal hook, do not use. + */ public void onResourceManagerReload(IResourceManager manager) { this.manager = manager; diff --git a/src/main/java/net/minecraftforge/fml/common/FMLCommonHandler.java b/src/main/java/net/minecraftforge/fml/common/FMLCommonHandler.java index 63d60cec4..d42da0f32 100644 --- a/src/main/java/net/minecraftforge/fml/common/FMLCommonHandler.java +++ b/src/main/java/net/minecraftforge/fml/common/FMLCommonHandler.java @@ -47,6 +47,7 @@ import net.minecraft.util.IThreadListener; import net.minecraft.world.World; import net.minecraft.world.storage.SaveHandler; import net.minecraft.world.storage.WorldInfo; +import net.minecraftforge.client.model.animation.Animation; import net.minecraftforge.common.ForgeVersion; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.eventhandler.EventBus; @@ -337,6 +338,7 @@ public class FMLCommonHandler public void onRenderTickStart(float timer) { + Animation.setClientPartialTickTime(timer); bus().post(new TickEvent.RenderTickEvent(Phase.START, timer)); } diff --git a/src/test/java/net/minecraftforge/debug/ModelAnimationDebug.java b/src/test/java/net/minecraftforge/debug/ModelAnimationDebug.java index 820ca941c..81eb2cfc2 100644 --- a/src/test/java/net/minecraftforge/debug/ModelAnimationDebug.java +++ b/src/test/java/net/minecraftforge/debug/ModelAnimationDebug.java @@ -314,7 +314,7 @@ public class ModelAnimationDebug }*/ else if(asm.currentState().equals("default")) { - float time = Animation.getWorldTime(getWorld()); + float time = Animation.getWorldTime(getWorld(), Animation.getPartialTickTime()); clickTime.setValue(time); //offset.setValue(time); //asm.transition("moving"); @@ -322,7 +322,7 @@ public class ModelAnimationDebug } else if(asm.currentState().equals("moving")) { - clickTime.setValue(Animation.getWorldTime(getWorld())); + clickTime.setValue(Animation.getWorldTime(getWorld(), Animation.getPartialTickTime())); asm.transition("stopping"); } }