diff --git a/client/cpw/mods/fml/client/FMLClientHandler.java b/client/cpw/mods/fml/client/FMLClientHandler.java index 16d78f2404..81210f3012 100644 --- a/client/cpw/mods/fml/client/FMLClientHandler.java +++ b/client/cpw/mods/fml/client/FMLClientHandler.java @@ -25,6 +25,7 @@ import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; @@ -266,8 +267,8 @@ public class FMLClientHandler implements IFMLSidedHandler public void onPreWorldTick() { if (client.field_6324_e != null) { - FMLCommonHandler.instance().worldTickStart(client.field_6324_e); - FMLCommonHandler.instance().tickStart(TickType.WORLDGUI, 0.0f, client.field_6313_p); + // For the client world ticks and game ticks are the same + FMLCommonHandler.instance().tickStart(EnumSet.of(TickType.WORLD,TickType.GAME,TickType.WORLDGUI), 0.0f, client.field_6324_e, client.field_6313_p); } } @@ -277,8 +278,8 @@ public class FMLClientHandler implements IFMLSidedHandler public void onPostWorldTick() { if (client.field_6324_e != null) { - FMLCommonHandler.instance().worldTickEnd(client.field_6324_e); - FMLCommonHandler.instance().tickEnd(TickType.WORLDGUI, 0.0f, client.field_6313_p); + // For the client world ticks and game ticks are the same + FMLCommonHandler.instance().tickEnd(EnumSet.of(TickType.WORLD,TickType.GAME,TickType.WORLDGUI), 0.0f, client.field_6324_e, client.field_6313_p); } for (IKeyHandler entry : keyHandlers) { @@ -294,21 +295,18 @@ public class FMLClientHandler implements IFMLSidedHandler loadTextures(fallbackTexturePack); firstTick = false; } - FMLCommonHandler.instance().tickStart(TickType.WORLDLOADTICK); - FMLCommonHandler.instance().tickStart(TickType.GUILOADTICK); + FMLCommonHandler.instance().tickStart(EnumSet.of(TickType.WORLDLOAD,TickType.GUILOAD)); } } public void onRenderTickStart(float partialTickTime) { - FMLCommonHandler.instance().tickStart(TickType.RENDER, partialTickTime); - FMLCommonHandler.instance().tickStart(TickType.GUI, partialTickTime, client.field_6313_p); + FMLCommonHandler.instance().tickStart(EnumSet.of(TickType.RENDER,TickType.GUI), partialTickTime, client.field_6313_p); } public void onRenderTickEnd(float partialTickTime) { - FMLCommonHandler.instance().tickEnd(TickType.RENDER, partialTickTime); - FMLCommonHandler.instance().tickEnd(TickType.GUI, partialTickTime, client.field_6313_p); + FMLCommonHandler.instance().tickEnd(EnumSet.of(TickType.RENDER,TickType.GUI), partialTickTime, client.field_6313_p); } /** * Get the server instance diff --git a/client/net/minecraft/src/BaseMod.java b/client/net/minecraft/src/BaseMod.java index cf60b1382e..f26d1620b1 100644 --- a/client/net/minecraft/src/BaseMod.java +++ b/client/net/minecraft/src/BaseMod.java @@ -44,13 +44,13 @@ 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.WORLD) || (tickEnd && tick==TickType.RENDER)) && hasWorld) { + if (((tickEnd && tick==TickType.GAME) || (tickEnd && tick==TickType.RENDER)) && 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]); - } else if (tick == TickType.WORLDLOADTICK && hasWorld) { + } else if (tick == TickType.WORLDLOAD && hasWorld) { return onTickInGame(0.0f, mc); - } else if (tick == TickType.GUILOADTICK) { + } else if (tick == TickType.GUILOAD) { return onTickInGUI(0.0f, mc, mc.field_6313_p); } return true; diff --git a/common/cpw/mods/fml/common/FMLCommonHandler.java b/common/cpw/mods/fml/common/FMLCommonHandler.java index 23e7ecc7f8..24352b9890 100644 --- a/common/cpw/mods/fml/common/FMLCommonHandler.java +++ b/common/cpw/mods/fml/common/FMLCommonHandler.java @@ -20,6 +20,7 @@ import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -89,78 +90,38 @@ public class FMLCommonHandler sidedDelegate = handler; } - /** - * Pre-tick the mods - */ - public void worldTickStart(Object world) + public void tickStart(EnumSet ticks, Object ... data) { - tickStart(TickType.WORLD,0.0f, world); - } - - /** - * Post-tick the mods - */ - public void worldTickEnd(Object world) - { - tickEnd(TickType.WORLD,0.0f); - } - - public void tickStart(TickType type, Object ... data) - { - sidedDelegate.profileStart("modTickStart"); - sidedDelegate.profileStart(type.name()); - for (ModContainer mod : Loader.getModList()) - { - sidedDelegate.profileStart(mod.getName()); - mod.tickStart(type, data); - sidedDelegate.profileEnd(); - } - for (ModContainer mod : auxilliaryContainers) - { - sidedDelegate.profileStart(mod.getMod().getClass().getSimpleName()); - mod.tickStart(type, data); - sidedDelegate.profileEnd(); - } + sidedDelegate.profileStart("modTickStart$"+ticks); for (ITickHandler ticker : tickHandlers) { - if (ticker.ticks().contains(type)) + EnumSet ticksToRun = EnumSet.copyOf(ticker.ticks()); + ticksToRun.removeAll(EnumSet.complementOf(ticks)); + if (!ticksToRun.isEmpty()) { - sidedDelegate.profileStart(ticker.getClass().getSimpleName()); - ticker.tickStart(type, data); + sidedDelegate.profileStart(ticker.getLabel()); + ticker.tickStart(ticksToRun, data); sidedDelegate.profileEnd(); } } sidedDelegate.profileEnd(); - sidedDelegate.profileEnd(); } - public void tickEnd(TickType type, Object ... data) + public void tickEnd(EnumSet ticks, Object ... data) { - sidedDelegate.profileStart("modTickEnd"); - sidedDelegate.profileStart(type.name()); - for (ModContainer mod : Loader.getModList()) - { - sidedDelegate.profileStart(mod.getName()); - mod.tickEnd(type, data); - sidedDelegate.profileEnd(); - } - for (ModContainer mod : auxilliaryContainers) - { - sidedDelegate.profileStart(mod.getMod().getClass().getSimpleName()); - mod.tickEnd(type, data); - sidedDelegate.profileEnd(); - } + sidedDelegate.profileStart("modTickEnd$"+ticks); for (ITickHandler ticker : tickHandlers) { - if (ticker.ticks().contains(type)) + EnumSet ticksToRun = EnumSet.copyOf(ticker.ticks()); + ticksToRun.removeAll(EnumSet.complementOf(ticks)); + if (!ticksToRun.isEmpty()) { - sidedDelegate.profileStart(ticker.getClass().getSimpleName()); - ticker.tickEnd(type, data); + sidedDelegate.profileStart(ticker.getLabel()); + ticker.tickEnd(ticksToRun, data); sidedDelegate.profileEnd(); } } sidedDelegate.profileEnd(); - sidedDelegate.profileEnd(); } public List gatherKeyBindings() { diff --git a/common/cpw/mods/fml/common/FMLModContainer.java b/common/cpw/mods/fml/common/FMLModContainer.java index a695509ec5..2562800e1a 100644 --- a/common/cpw/mods/fml/common/FMLModContainer.java +++ b/common/cpw/mods/fml/common/FMLModContainer.java @@ -112,17 +112,6 @@ public class FMLModContainer implements ModContainer // TODO Auto-generated method stub return null; } - @Override - public void tickStart(TickType type, Object ... data) - { - // TODO Auto-generated method stub - } - - @Override - public void tickEnd(TickType type, Object ... data) - { - // TODO Auto-generated method stub - } @Override public boolean matches(Object mod) diff --git a/common/cpw/mods/fml/common/ITickHandler.java b/common/cpw/mods/fml/common/ITickHandler.java index 51deb7fe5f..436fd54170 100644 --- a/common/cpw/mods/fml/common/ITickHandler.java +++ b/common/cpw/mods/fml/common/ITickHandler.java @@ -31,17 +31,23 @@ public interface ITickHandler /** * Called at the "start" phase of a tick + * + * Multiple ticks may fire simultaneously- you will only be called once with all the firing ticks + * * @param type * @param tickData */ - public void tickStart(TickType type, Object... tickData); + public void tickStart(EnumSet type, Object... tickData); /** * Called at the "end" phase of a tick + * + * Multiple ticks may fire simultaneously- you will only be called once with all the firing ticks + * * @param type * @param tickData */ - public void tickEnd(TickType type, Object... tickData); + public void tickEnd(EnumSet type, Object... tickData); /** * Returns the list of ticks this tick handler is interested in receiving at the minute @@ -49,4 +55,10 @@ public interface ITickHandler * @return */ public EnumSet ticks(); + + /** + * A profiling label for this tick handler + * @return + */ + public String getLabel(); } diff --git a/common/cpw/mods/fml/common/ModContainer.java b/common/cpw/mods/fml/common/ModContainer.java index a5fe1d3fb1..1b423008ba 100644 --- a/common/cpw/mods/fml/common/ModContainer.java +++ b/common/cpw/mods/fml/common/ModContainer.java @@ -82,14 +82,6 @@ public interface ModContainer * Move to the next mod state */ void nextState(); - /** - * A tick has started - */ - void tickStart(TickType tick, Object ... data); - /** - * A tick has ended - */ - void tickEnd(TickType tick, Object ... data); /** * Does this mod match the supplied mod? * @param mod diff --git a/common/cpw/mods/fml/common/TickType.java b/common/cpw/mods/fml/common/TickType.java index ea3280b0fd..92576306ba 100644 --- a/common/cpw/mods/fml/common/TickType.java +++ b/common/cpw/mods/fml/common/TickType.java @@ -19,10 +19,9 @@ import java.util.EnumSet; public enum TickType { /** * Fired during the world evaluation loop - * server and client side + * server side * - * arg 0 : a float zero (the "render time") - * arg 1 : The world that is ticking + * arg 0 : The world that is ticking */ WORLD, /** @@ -48,13 +47,18 @@ public enum TickType { * client side * Fired once as the world loads from disk */ - WORLDLOADTICK, + WORLDLOAD, /** * client side * Fired once as the world loads from disk * arg 0 : the open gui */ - GUILOADTICK; + GUILOAD, + /** + * client and server side + * Fired once per "global tick loop" + */ + GAME; /** * Partner ticks that are also cancelled by returning false from onTickInGame @@ -63,12 +67,12 @@ public enum TickType { */ public EnumSet partnerTicks() { - if (this==WORLD) return EnumSet.of(RENDER,WORLDLOADTICK); - if (this==RENDER) return EnumSet.of(WORLD, WORLDLOADTICK); - if (this==GUI) return EnumSet.of(WORLDGUI, GUILOADTICK); - if (this==WORLDGUI) return EnumSet.of(GUI, GUILOADTICK); - if (this==WORLDLOADTICK) return EnumSet.of(WORLD, RENDER); - if (this==GUILOADTICK) return EnumSet.of(GUI, WORLDGUI); + if (this==WORLD) return EnumSet.of(RENDER,WORLDLOAD); + if (this==RENDER) return EnumSet.of(WORLD, WORLDLOAD); + if (this==GUI) return EnumSet.of(WORLDGUI, GUILOAD); + if (this==WORLDGUI) return EnumSet.of(GUI, GUILOAD); + if (this==WORLDLOAD) return EnumSet.of(WORLD, RENDER); + if (this==GUILOAD) return EnumSet.of(GUI, WORLDGUI); return null; } } \ No newline at end of file diff --git a/common/cpw/mods/fml/common/modloader/BaseModTicker.java b/common/cpw/mods/fml/common/modloader/BaseModTicker.java new file mode 100644 index 0000000000..941c52c1b6 --- /dev/null +++ b/common/cpw/mods/fml/common/modloader/BaseModTicker.java @@ -0,0 +1,93 @@ +/* + * The FML Forge Mod Loader suite. + * Copyright (C) 2012 cpw + * + * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package cpw.mods.fml.common.modloader; + +import java.util.EnumSet; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.ITickHandler; +import cpw.mods.fml.common.TickType; + +/** + * @author cpw + * + */ +public class BaseModTicker implements ITickHandler +{ + + private BaseMod mod; + private EnumSet ticks; + + + BaseModTicker(BaseMod mod) + { + this.mod = mod; + this.ticks = EnumSet.noneOf(TickType.class); + } + + BaseModTicker(EnumSet ticks) + { + this.ticks = ticks; + } + + @Override + public void tickStart(EnumSet types, Object... tickData) + { + tickBaseMod(types, false, tickData); + } + + @Override + public void tickEnd(EnumSet types, Object... tickData) + { + tickBaseMod(ticks, true, tickData); + } + + private void tickBaseMod(EnumSet types, boolean end, Object... tickData) + { + for (TickType type : types) + { + if (!ticks.contains(type)) + { + continue; + } + boolean keepTicking=mod.doTickInGame(type, end, FMLCommonHandler.instance().getMinecraftInstance(), tickData); + if (!keepTicking) { + ticks.remove(type); + ticks.removeAll(type.partnerTicks()); + } + } + } + + @Override + public EnumSet ticks() + { + return ticks; + } + + @Override + public String getLabel() + { + return mod.getClass().getSimpleName(); + } + + /** + * @param mod2 + */ + public void setMod(BaseMod mod) + { + this.mod = mod; + } + +} diff --git a/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java b/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java index 14b2641a5f..8d60341968 100644 --- a/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java +++ b/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java @@ -32,7 +32,8 @@ public class ModLoaderHelper public static void updateStandardTicks(BaseMod mod, boolean enable, boolean useClock) { ModLoaderModContainer mlmc = findOrBuildModContainer(mod); - EnumSet ticks = mlmc.getTickTypes(); + BaseModTicker ticker = mlmc.getTickHandler(); + EnumSet ticks = ticker.ticks(); // If we're enabled and we don't want clock ticks we get render ticks if (enable && !useClock && FMLCommonHandler.instance().getSide().isClient()) { ticks.add(TickType.RENDER); @@ -47,14 +48,14 @@ public class ModLoaderHelper } if (enable) { - ticks.add(TickType.WORLDLOADTICK); + ticks.add(TickType.WORLDLOAD); } } public static void updateGUITicks(BaseMod mod, boolean enable, boolean useClock) { ModLoaderModContainer mlmc = findOrBuildModContainer(mod); - EnumSet ticks = mlmc.getTickTypes(); + EnumSet ticks = mlmc.getTickHandler().ticks(); // If we're enabled and we don't want clock ticks we get render ticks if (enable && !useClock && FMLCommonHandler.instance().getSide().isClient()) { ticks.add(TickType.GUI); @@ -68,7 +69,7 @@ public class ModLoaderHelper ticks.remove(TickType.WORLDGUI); } if (enable) { - ticks.add(TickType.GUILOADTICK); + ticks.add(TickType.GUILOAD); } } diff --git a/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java b/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java index 5403ae2f80..57e758119b 100644 --- a/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java +++ b/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java @@ -54,7 +54,6 @@ public class ModLoaderModContainer implements ModContainer private static final ProxyInjector NULLPROXY = new ProxyInjector("","","",null); private Class modClazz; private BaseMod mod; - private EnumSet ticks; private File modSource; private ArrayList dependencies; private ArrayList preDependencies; @@ -64,12 +63,12 @@ public class ModLoaderModContainer implements ModContainer private SourceType sourceType; private ModMetadata metadata; private ProxyInjector sidedProxy; + private BaseModTicker tickHandler; public ModLoaderModContainer(Class modClazz, File modSource) { this.modClazz = modClazz; this.modSource = modSource; - this.ticks = EnumSet.noneOf(TickType.class); // We are unloaded nextState(); } @@ -81,7 +80,7 @@ public class ModLoaderModContainer implements ModContainer ModLoaderModContainer(BaseMod instance) { FMLCommonHandler.instance().addAuxilliaryModContainer(this); this.mod=instance; - this.ticks = EnumSet.noneOf(TickType.class); + this.tickHandler = new BaseModTicker(instance); } @Override @@ -101,8 +100,11 @@ public class ModLoaderModContainer implements ModContainer { try { + EnumSet ticks = EnumSet.noneOf(TickType.class); + this.tickHandler = new BaseModTicker(ticks); configureMod(); mod = modClazz.newInstance(); + this.tickHandler.setMod(mod); } catch (Exception e) { @@ -325,30 +327,6 @@ public class ModLoaderModContainer implements ModContainer mod.modsLoaded(); } - @Override - public void tickStart(TickType tick, Object ... data) - { - if (ticks.contains(tick)) { - boolean keepTicking=mod.doTickInGame(tick, false, FMLCommonHandler.instance().getMinecraftInstance(), data); - if (!keepTicking) { - ticks.remove(tick); - ticks.removeAll(tick.partnerTicks()); - } - } - } - - @Override - public void tickEnd(TickType tick, Object ... data) - { - if (ticks.contains(tick)) { - boolean keepTicking=mod.doTickInGame(tick, true, FMLCommonHandler.instance().getMinecraftInstance(), data); - if (!keepTicking) { - ticks.remove(tick); - ticks.removeAll(tick.partnerTicks()); - } - } - } - @Override public String getName() { @@ -383,11 +361,6 @@ public class ModLoaderModContainer implements ModContainer return modClazz.isInstance(mod); } - public void setTickType(EnumSet type) - { - this.ticks=EnumSet.copyOf(type); - } - /** * Find all the BaseMods in the system * @param @@ -601,14 +574,6 @@ public class ModLoaderModContainer implements ModContainer return mod; } - /** - * @return - */ - public EnumSet getTickTypes() - { - return ticks; - } - /** * @param keyHandler * @param allowRepeat @@ -709,4 +674,12 @@ public class ModLoaderModContainer implements ModContainer { mod.keyBindingEvent(keybinding); } + + /** + * @return + */ + public BaseModTicker getTickHandler() + { + return this.tickHandler; + } } diff --git a/patches/minecraft_server/net/minecraft/server/MinecraftServer.java.patch b/patches/minecraft_server/net/minecraft/server/MinecraftServer.java.patch index f7864feed1..cdf54240fb 100644 --- a/patches/minecraft_server/net/minecraft/server/MinecraftServer.java.patch +++ b/patches/minecraft_server/net/minecraft/server/MinecraftServer.java.patch @@ -26,7 +26,15 @@ this.field_6033_f = new ServerConfigurationManager(this); this.field_6028_k[0] = new EntityTracker(this, 0); this.field_6028_k[1] = new EntityTracker(this, -1); -@@ -487,7 +492,9 @@ +@@ -447,6 +452,7 @@ + long var1 = System.nanoTime(); + ArrayList var3 = new ArrayList(); + Iterator var4 = field_6037_b.keySet().iterator(); ++ FMLServerHandler.instance().onPreServerTick(); + + while (var4.hasNext()) + { +@@ -487,7 +493,9 @@ this.field_6033_f.func_28169_a(new Packet4UpdateTime(var7.func_22080_k()), var7.field_4272_q.field_6165_g); } @@ -36,3 +44,11 @@ while (true) { +@@ -533,6 +541,7 @@ + this.field_48076_G = Packet.field_48101_l; + this.field_48082_x[this.field_9014_h % 100] = Packet.field_48102_m - this.field_48077_H; + this.field_48077_H = Packet.field_48102_m; ++ FMLServerHandler.instance().onPostServerTick(); + } + + public void func_6010_a(String p_6010_1_, ICommandListener p_6010_2_) diff --git a/server/cpw/mods/fml/server/FMLServerHandler.java b/server/cpw/mods/fml/server/FMLServerHandler.java index acdcda3315..66ea32043d 100644 --- a/server/cpw/mods/fml/server/FMLServerHandler.java +++ b/server/cpw/mods/fml/server/FMLServerHandler.java @@ -18,6 +18,7 @@ import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.EnumSet; import java.util.List; import java.util.Properties; import java.util.Random; @@ -54,6 +55,7 @@ import cpw.mods.fml.common.ModMetadata; import cpw.mods.fml.common.ProxyInjector; import cpw.mods.fml.common.ReflectionHelper; import cpw.mods.fml.common.Side; +import cpw.mods.fml.common.TickType; import cpw.mods.fml.common.modloader.ModLoaderModContainer; import cpw.mods.fml.common.modloader.ModProperty; import cpw.mods.fml.common.registry.FMLRegistry; @@ -145,12 +147,21 @@ public class FMLServerHandler implements IFMLSidedHandler Loader.instance().initializeMods(); } + public void onPreServerTick() + { + FMLCommonHandler.instance().tickStart(EnumSet.of(TickType.GAME)); + } + + public void onPostServerTick() + { + FMLCommonHandler.instance().tickEnd(EnumSet.of(TickType.GAME)); + } /** * Every tick just before world and other ticks occur */ public void onPreWorldTick(World world) { - FMLCommonHandler.instance().worldTickStart(world); + FMLCommonHandler.instance().tickStart(EnumSet.of(TickType.WORLD), world); } /** @@ -158,7 +169,7 @@ public class FMLServerHandler implements IFMLSidedHandler */ public void onPostWorldTick(World world) { - FMLCommonHandler.instance().worldTickEnd(world); + FMLCommonHandler.instance().tickEnd(EnumSet.of(TickType.WORLD), world); } /** diff --git a/server/net/minecraft/src/BaseMod.java b/server/net/minecraft/src/BaseMod.java index f330d2f48d..ac7a4d66d9 100644 --- a/server/net/minecraft/src/BaseMod.java +++ b/server/net/minecraft/src/BaseMod.java @@ -37,7 +37,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod @Override public final boolean doTickInGame(TickType tick, boolean tickEnd, Object minecraftInstance, Object... data) { - if (tick==TickType.WORLD && tickEnd) { + if (tick==TickType.GAME && tickEnd) { return onTickInGame((MinecraftServer)minecraftInstance); } else { return true;