Fix ticking properly - ML world ticks now fire once, properly

This commit is contained in:
Christian 2012-06-21 18:11:40 -04:00
parent 262c68a81d
commit 64d1b29c43
4 changed files with 75 additions and 33 deletions

View file

@ -44,7 +44,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod
Minecraft mc = (Minecraft) minecraftInstance;
boolean hasWorld = mc.field_6324_e != null;
// World and render ticks
if (((tickEnd && tick==TickType.GAME) || (tickEnd && tick==TickType.RENDER)) && hasWorld) {
if (tickEnd && ( tick==TickType.RENDER || tick==TickType.GAME ) && hasWorld) {
return onTickInGame((Float) data[0], mc);
} else if (((tickEnd && tick==TickType.WORLDGUI) || (tickEnd && tick==TickType.GUI))) {
return onTickInGUI((Float) data[0], mc, (GuiScreen)data[1]);

View file

@ -57,17 +57,28 @@ public class BaseModTicker implements ITickHandler
private void tickBaseMod(EnumSet<TickType> types, boolean end, Object... tickData)
{
if (end && (types.contains(TickType.GAME) && ticks.contains(TickType.GAME)) || (types.contains(TickType.WORLDLOAD) && ticks.contains(TickType.WORLDLOAD)))
if (FMLCommonHandler.instance().getSide().isServer() || ticks.contains(TickType.RENDER))
{
clockTickTrigger = true;
sendTick(types, end, tickData);
}
else
{
if (end && ticks.contains(TickType.GAME) && (types.contains(TickType.GAME) || types.contains(TickType.WORLDLOAD)))
{
clockTickTrigger = true;
}
if (end && clockTickTrigger && types.contains(TickType.RENDER))
{
clockTickTrigger = false;
sendTick(EnumSet.of(TickType.GAME),end,tickData);
}
}
if (end && clockTickTrigger && types.contains(TickType.RENDER))
{
types.add(TickType.GAME);
types.remove(TickType.RENDER);
clockTickTrigger = false;
}
}
private void sendTick(EnumSet<TickType> types, boolean end, Object... tickData)
{
for (TickType type : types)
{
if (!ticks.contains(type))
@ -85,7 +96,7 @@ public class BaseModTicker implements ITickHandler
@Override
public EnumSet<TickType> ticks()
{
return ticks;
return (clockTickTrigger ? EnumSet.of(TickType.RENDER) : ticks);
}
@Override

View file

@ -35,7 +35,7 @@ public class ModLoaderHelper
BaseModTicker ticker = mlmc.getTickHandler();
EnumSet<TickType> ticks = ticker.ticks();
// If we're enabled we get render ticks
if (enable) {
if (enable && !useClock) {
ticks.add(TickType.RENDER);
} else {
ticks.remove(TickType.RENDER);

View file

@ -1,22 +1,15 @@
package net.minecraft.src;
public class mod_testMod extends BaseMod {
import java.util.EnumSet;
@MLProp
public static byte byteptest = 5;
@MLProp
public static short shortptest = 5;
@MLProp
public static int intptest = 5;
@MLProp
public static long longptest = 5;
@MLProp
public static float floatptest = 5;
@MLProp
public static double doubleptest = 5;
@MLProp
public static boolean booleanptest = false;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;
import net.minecraft.client.Minecraft;
public class mod_testMod extends BaseMod implements ITickHandler {
private long ts;
private long tsg;
@Override
public String getVersion() {
return "test";
@ -24,13 +17,51 @@ public class mod_testMod extends BaseMod {
@Override
public void load() {
System.out.println("byte : "+byteptest);
System.out.println("short : "+shortptest);
System.out.println("int : "+intptest);
System.out.println("long : "+longptest);
System.out.println("float : "+floatptest);
System.out.println("double : "+doubleptest);
System.out.println("bool : "+booleanptest);
ModLoader.setInGameHook(this, true, true);
FMLCommonHandler.instance().registerTickHandler(this);
ts=System.currentTimeMillis();
tsg=ts;
}
@Override
public boolean onTickInGame(float time, Minecraft minecraftInstance)
{
long now = System.currentTimeMillis();
long del=now-ts;
ts=now;
System.out.printf("%d %d %d %d MLTICK\n",del, ts, tsg, now);
return true;
}
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
}
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
long now = System.currentTimeMillis();
long del=now-tsg;
tsg=now;
System.out.printf("%d %d %d %d GAMETICK\n",del, ts, tsg, now);
}
@Override
public EnumSet<TickType> ticks()
{
return EnumSet.of(TickType.GAME);
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ITickHandler#getLabel()
*/
@Override
public String getLabel()
{
// TODO Auto-generated method stub
return "TickTester";
}
}