Fixed minor race condition between mouse clicks and TESR in the animation example.

This commit is contained in:
RainWarrior 2016-01-25 17:39:43 +03:00
parent e929199758
commit 960717eb0c
3 changed files with 24 additions and 2 deletions

View File

@ -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.<String, ImmutableMap<String, float[]>>of(), ImmutableMap.<String, ModelBlockAnimation.MBClip>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;

View File

@ -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));
}

View File

@ -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");
}
}