Gui related ticking
This commit is contained in:
parent
c689991986
commit
053fd64bde
5 changed files with 49 additions and 24 deletions
|
@ -195,6 +195,9 @@ public class FMLClientHandler implements IFMLSidedHandler
|
|||
public void onPreWorldTick()
|
||||
{
|
||||
FMLCommonHandler.instance().worldTickStart();
|
||||
if (client.field_6313_p!=null && client.field_6324_e!=null) {
|
||||
FMLCommonHandler.instance().tickStart(TickType.WORLDGUI, 0.0f, client.field_6313_p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -203,16 +206,25 @@ public class FMLClientHandler implements IFMLSidedHandler
|
|||
public void onPostWorldTick()
|
||||
{
|
||||
FMLCommonHandler.instance().worldTickEnd();
|
||||
if (client.field_6313_p!=null && client.field_6324_e!=null) {
|
||||
FMLCommonHandler.instance().tickEnd(TickType.WORLDGUI, 0.0f, client.field_6313_p);
|
||||
}
|
||||
}
|
||||
|
||||
public void onRenderTickStart(float partialTickTime)
|
||||
{
|
||||
FMLCommonHandler.instance().tickStart(TickType.RENDER, partialTickTime);
|
||||
if (client.field_6313_p!=null && client.field_6324_e!=null) {
|
||||
FMLCommonHandler.instance().tickStart(TickType.GUI, partialTickTime, client.field_6313_p);
|
||||
}
|
||||
}
|
||||
|
||||
public void onRenderTickEnd(float partialTickTime)
|
||||
{
|
||||
FMLCommonHandler.instance().tickEnd(TickType.RENDER, partialTickTime);
|
||||
if (client.field_6313_p!=null && client.field_6324_e!=null) {
|
||||
FMLCommonHandler.instance().tickEnd(TickType.GUI, partialTickTime, client.field_6313_p);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the server instance
|
||||
|
|
|
@ -23,6 +23,7 @@ import cpw.mods.fml.common.INetworkHandler;
|
|||
import cpw.mods.fml.common.IPickupNotifier;
|
||||
import cpw.mods.fml.common.IPlayerTracker;
|
||||
import cpw.mods.fml.common.IWorldGenerator;
|
||||
import cpw.mods.fml.common.ModContainer.TickType;
|
||||
|
||||
public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDispenseHandler, ICraftingHandler, INetworkHandler, IConsoleHandler, IPlayerTracker
|
||||
{
|
||||
|
@ -32,22 +33,14 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp
|
|||
* @param minecraftInstance
|
||||
* @return
|
||||
*/
|
||||
public final boolean doTickInGame(Object minecraftInstance, Object... data)
|
||||
public final boolean doTickInGame(TickType tick, boolean tickEnd, Object minecraftInstance, Object... data)
|
||||
{
|
||||
Minecraft mc = (Minecraft) minecraftInstance;
|
||||
if (mc.field_6324_e != null)
|
||||
{
|
||||
// World and render ticks
|
||||
if ((tickEnd && tick==TickType.WORLD) || (!tickEnd && tick==TickType.RENDER)) {
|
||||
return onTickInGame((Float) data[0], mc);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public final boolean doTickInGui(Object minecraftInstance, Object... data)
|
||||
{
|
||||
Minecraft mc = (Minecraft) minecraftInstance;
|
||||
if (mc.field_40007_r != null)
|
||||
{
|
||||
return onTickInGUI((Float)data[0], mc, mc.field_6313_p);
|
||||
} else if (((tickEnd && tick==TickType.WORLDGUI) || (!tickEnd && tick==TickType.GUI))) {
|
||||
return onTickInGUI((Float) data[0], mc, (GuiScreen)data[1]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -207,6 +207,18 @@ public interface ModContainer
|
|||
|
||||
public enum TickType {
|
||||
WORLD, RENDER, GUI, WORLDGUI;
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public TickType partnerTick()
|
||||
{
|
||||
if (this==WORLD) return RENDER;
|
||||
if (this==RENDER) return WORLD;
|
||||
if (this==GUI) return WORLDGUI;
|
||||
if (this==WORLDGUI) return GUI;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
List<IKeyHandler> getKeys();
|
||||
|
|
|
@ -328,16 +328,24 @@ public class ModLoaderModContainer implements ModContainer
|
|||
@Override
|
||||
public void tickStart(TickType tick, Object ... data)
|
||||
{
|
||||
if (ticks.contains(tick) && tick==TickType.WORLD) {
|
||||
mod.doTickInGame(FMLCommonHandler.instance().getMinecraftInstance(), data);
|
||||
if (ticks.contains(tick)) {
|
||||
boolean keepTicking=mod.doTickInGame(tick, false, FMLCommonHandler.instance().getMinecraftInstance(), data);
|
||||
if (!keepTicking) {
|
||||
ticks.remove(tick);
|
||||
ticks.remove(tick.partnerTick());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tickEnd(TickType tick, Object ... data)
|
||||
{
|
||||
if (ticks.contains(tick) && tick!=TickType.WORLD) {
|
||||
mod.doTickInGame(FMLCommonHandler.instance().getMinecraftInstance(), data);
|
||||
if (ticks.contains(tick)) {
|
||||
boolean keepTicking=mod.doTickInGame(tick, true, FMLCommonHandler.instance().getMinecraftInstance(), data);
|
||||
if (!keepTicking) {
|
||||
ticks.remove(tick);
|
||||
ticks.remove(tick.partnerTick());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import cpw.mods.fml.common.INetworkHandler;
|
|||
import cpw.mods.fml.common.IPickupNotifier;
|
||||
import cpw.mods.fml.common.IPlayerTracker;
|
||||
import cpw.mods.fml.common.IWorldGenerator;
|
||||
import cpw.mods.fml.common.ModContainer.TickType;
|
||||
|
||||
public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDispenseHandler, ICraftingHandler, INetworkHandler, IConsoleHandler, IPlayerTracker
|
||||
{
|
||||
|
@ -32,14 +33,13 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp
|
|||
* @param minecraftInstance
|
||||
* @return
|
||||
*/
|
||||
public final boolean doTickInGame(Object minecraftInstance, Object... data)
|
||||
public final boolean doTickInGame(TickType tick, boolean tickEnd, Object minecraftInstance, Object... data)
|
||||
{
|
||||
return onTickInGame((MinecraftServer)minecraftInstance);
|
||||
}
|
||||
|
||||
public final boolean doTickInGui(Object minecraftInstance, Object... data)
|
||||
{
|
||||
return true;
|
||||
if (tick==TickType.WORLD && tickEnd) {
|
||||
return onTickInGame((MinecraftServer)minecraftInstance);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue