From f7e07ca7d88e5542feeb8892c223c3a2c92508ad Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 3 Jul 2012 21:37:54 -0400 Subject: [PATCH 1/4] Change gui ticking and world load tick. Should close issue #40 and kill it deader than a very very dead thing. *$^*(#% Modloader ticking b#%$hit --- client/net/minecraft/src/BaseMod.java | 52 +++++++++---------- .../fml/common/modloader/BaseModTicker.java | 18 +++---- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/client/net/minecraft/src/BaseMod.java b/client/net/minecraft/src/BaseMod.java index 827c850049..fcbda39a0c 100644 --- a/client/net/minecraft/src/BaseMod.java +++ b/client/net/minecraft/src/BaseMod.java @@ -34,7 +34,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod { this.keyboardEvent((KeyBinding)keybinding); } - + /** * @param minecraftInstance * @return @@ -46,7 +46,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod // World and render ticks if (tickEnd && ( tick==TickType.RENDER || tick==TickType.GAME ) && hasWorld) { return onTickInGame((Float) data[0], mc); - } else if (tickEnd && (tick==TickType.WORLDGUI || tick==TickType.GUI) && data[1]!=null) { + } else if (tickEnd && (tick==TickType.WORLDGUI || tick==TickType.GUI)) { return onTickInGUI((Float) data[0], mc, (GuiScreen)data[1]); } return true; @@ -58,11 +58,11 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod public final void onRenderHarvest(Map renderers) { addRenderer((Map,Render>)renderers); - + } /** - * + * */ public final void onRegisterAnimations() { @@ -99,11 +99,11 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod public final void onServerLogin(Object handler) { serverConnect((NetClientHandler) handler); } - + public final void onServerLogout() { serverDisconnect(); } - + @Override public final void onPlayerLogin(Object player) { @@ -163,7 +163,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod // BASEMOD API /** * Override if you wish to provide a fuel item for the furnace and return the fuel value of the item - * + * * @param id * @param metadata * @return @@ -180,7 +180,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Override if you wish to perform some action other than just dispensing the item from the dispenser - * + * * @param world * @param x * @param y @@ -197,7 +197,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Override if you wish to generate Nether (Hell biome) blocks - * + * * @param world * @param random * @param chunkX @@ -209,7 +209,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Override if you wish to generate Overworld (not hell or the end) blocks - * + * * @param world * @param random * @param chunkX @@ -221,7 +221,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Return the name of your mod. Defaults to the class name - * + * * @return */ public String getName() @@ -231,7 +231,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Get your mod priorities - * + * * @return */ public String getPriorities() @@ -241,7 +241,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Return the version of your mod - * + * * @return */ public abstract String getVersion(); @@ -265,7 +265,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Handle item pickup - * + * * @param player * @param item */ @@ -275,7 +275,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Ticked every game tick if you have subscribed to tick events through {@link ModLoader#setInGameHook(BaseMod, boolean, boolean)} - * + * * @param time the rendering subtick time (0.0-1.0) * @param minecraftInstance the client * @return true to continue receiving ticks @@ -293,7 +293,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Only implemented on the client side * {@link #onChatMessageReceived(EntityPlayer, Packet3Chat)} - * + * * @param text */ public void receiveChatPacket(String text) @@ -304,7 +304,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Only called on the client side * {@link #onPacket250Received(EntityPlayer, Packet250CustomPayload)} - * + * * @param packet */ public void receiveCustomPacket(Packet250CustomPayload packet) @@ -329,15 +329,15 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod } public void serverConnect(NetClientHandler handler) { - + } - + public void serverDisconnect() { - + } /** * Called when someone crafts an item from a crafting table - * + * * @param player * @param item * @param matrix @@ -377,7 +377,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Called when a chat message is received. Return true to stop further processing - * + * * @param source * @param chat * @return true if you want to consume the message so it is not available for further processing @@ -398,7 +398,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Called when a new client logs in. - * + * * @param player */ public void onClientLogin(EntityPlayer player) @@ -407,7 +407,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Called when a client logs out of the server. - * + * * @param player */ public void onClientLogout(EntityPlayer player) @@ -416,9 +416,9 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod } /** - * + * * Called when a client changes dimensions on the server. - * + * * @param player */ public void onClientDimensionChanged(EntityPlayer player) diff --git a/common/cpw/mods/fml/common/modloader/BaseModTicker.java b/common/cpw/mods/fml/common/modloader/BaseModTicker.java index 5e96272f30..af231d8151 100644 --- a/common/cpw/mods/fml/common/modloader/BaseModTicker.java +++ b/common/cpw/mods/fml/common/modloader/BaseModTicker.java @@ -30,25 +30,25 @@ public class BaseModTicker implements ITickHandler private BaseMod mod; private EnumSet ticks; private boolean clockTickTrigger; - - + + BaseModTicker(BaseMod mod) { this.mod = mod; this.ticks = EnumSet.of(TickType.WORLDLOAD); } - + 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) { @@ -60,14 +60,14 @@ public class BaseModTicker implements ITickHandler if (FMLCommonHandler.instance().getSide().isClient() && ( ticks.contains(TickType.GAME) || ticks.contains(TickType.WORLDGUI))) { EnumSet cTypes=EnumSet.copyOf(types); - if (end && ( types.contains(TickType.GAME) || types.contains(TickType.WORLDLOAD) || types.contains(TickType.WORLDGUI))) + if ( ( end && ( types.contains(TickType.GAME) || types.contains(TickType.WORLDGUI))) || types.contains(TickType.WORLDLOAD) ) { clockTickTrigger = true; cTypes.remove(TickType.GAME); cTypes.remove(TickType.WORLDLOAD); cTypes.remove(TickType.WORLDGUI); } - + if (end && clockTickTrigger && types.contains(TickType.RENDER)) { clockTickTrigger = false; @@ -75,7 +75,7 @@ public class BaseModTicker implements ITickHandler if (ticks.contains(TickType.GAME)) cTypes.add(TickType.GAME); if (ticks.contains(TickType.WORLDGUI)) cTypes.add(TickType.WORLDGUI); } - + sendTick(cTypes, end, tickData); } else @@ -83,7 +83,7 @@ public class BaseModTicker implements ITickHandler sendTick(types, end, tickData); } } - + private void sendTick(EnumSet types, boolean end, Object... tickData) { for (TickType type : types) From ba46389a8706eebbc85464c11ee0709359b4d000 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 3 Jul 2012 22:39:35 -0400 Subject: [PATCH 2/4] Separate gui ticking completely. send it as if it's a world tick. ML gui ticks are epically dumb. Fix Worldload being filtered from the trigger arming. Also, improve errors going to an error screen. There should be more information now. --- .../cpw/mods/fml/client/FMLClientHandler.java | 28 +++++++++- client/net/minecraft/src/BaseMod.java | 11 +++- .../cpw/mods/fml/common/FMLCommonHandler.java | 5 +- .../cpw/mods/fml/common/IFMLSidedHandler.java | 1 + common/cpw/mods/fml/common/Loader.java | 10 +++- .../mods/fml/common/modloader/BaseMod.java | 11 ++-- .../fml/common/modloader/BaseModTicker.java | 25 ++++++--- .../fml/common/modloader/ModLoaderHelper.java | 14 ++--- .../modloader/ModLoaderModContainer.java | 26 ++++++--- .../server/MinecraftServer.java.patch | 9 ++++ .../cpw/mods/fml/server/FMLServerHandler.java | 54 ++++++++++--------- server/net/minecraft/src/BaseMod.java | 48 +++++++++-------- 12 files changed, 163 insertions(+), 79 deletions(-) diff --git a/client/cpw/mods/fml/client/FMLClientHandler.java b/client/cpw/mods/fml/client/FMLClientHandler.java index 73d9f3dd29..9262b51752 100644 --- a/client/cpw/mods/fml/client/FMLClientHandler.java +++ b/client/cpw/mods/fml/client/FMLClientHandler.java @@ -59,6 +59,7 @@ import net.minecraft.src.Item; import net.minecraft.src.ItemStack; import net.minecraft.src.KeyBinding; import net.minecraft.src.MLProp; +import net.minecraft.src.MinecraftImpl; import net.minecraft.src.ModTextureStatic; import net.minecraft.src.NetClientHandler; import net.minecraft.src.NetworkManager; @@ -76,6 +77,7 @@ import net.minecraft.src.SidedProxy; import net.minecraft.src.StringTranslate; import net.minecraft.src.TextureFX; import net.minecraft.src.TexturePackBase; +import net.minecraft.src.UnexpectedThrowable; import net.minecraft.src.World; import net.minecraft.src.WorldType; import argo.jdom.JdomParser; @@ -85,6 +87,7 @@ import cpw.mods.fml.common.FMLModLoaderContainer; import cpw.mods.fml.common.IFMLSidedHandler; import cpw.mods.fml.common.IKeyHandler; import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.LoaderException; import cpw.mods.fml.common.ModContainer; import cpw.mods.fml.common.ModMetadata; import cpw.mods.fml.common.ProxyInjector; @@ -190,9 +193,22 @@ public class FMLClientHandler implements IFMLSidedHandler } FMLCommonHandler.instance().getFMLLogger().info(String.format("Forge Mod Loader has detected optifine %s, enabling compatibility features",optifineContainer.getVersion())); } - Loader.instance().loadMods(); + try + { + Loader.instance().loadMods(); + } + catch (LoaderException le) + { + haltGame("There was a severe problem during mod loading that has caused the game to fail", le); + return; + } } + @Override + public void haltGame(String message, Throwable t) + { + client.func_28003_b(new UnexpectedThrowable(message, t)); + } /** * Called a bit later on during initialization to finish loading mods * Also initializes key bindings @@ -200,7 +216,15 @@ public class FMLClientHandler implements IFMLSidedHandler */ public void onLoadComplete() { - Loader.instance().initializeMods(); + try + { + Loader.instance().initializeMods(); + } + catch (LoaderException le) + { + haltGame("There was a severe problem during mod loading that has caused the game to fail", le); + return; + } for (ModContainer mod : Loader.getModList()) { mod.gatherRenderers(RenderManager.field_1233_a.getRendererList()); for (Render r : RenderManager.field_1233_a.getRendererList().values()) { diff --git a/client/net/minecraft/src/BaseMod.java b/client/net/minecraft/src/BaseMod.java index fcbda39a0c..1801236129 100644 --- a/client/net/minecraft/src/BaseMod.java +++ b/client/net/minecraft/src/BaseMod.java @@ -46,8 +46,15 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod // World and render ticks if (tickEnd && ( tick==TickType.RENDER || tick==TickType.GAME ) && hasWorld) { return onTickInGame((Float) data[0], mc); - } else if (tickEnd && (tick==TickType.WORLDGUI || tick==TickType.GUI)) { - return onTickInGUI((Float) data[0], mc, (GuiScreen)data[1]); + } + return true; + } + + public final boolean doTickInGUI(TickType tick, boolean tickEnd, Object minecraftInstance, Object... data) + { + Minecraft mc = (Minecraft) minecraftInstance; + if (tickEnd && ( tick==TickType.RENDER || tick==TickType.GAME )) { + return onTickInGUI((Float) data[0], 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 252b4eb438..8a4d72ea4f 100644 --- a/common/cpw/mods/fml/common/FMLCommonHandler.java +++ b/common/cpw/mods/fml/common/FMLCommonHandler.java @@ -481,7 +481,10 @@ public class FMLCommonHandler public void raiseException(Throwable exception, String message, boolean stopGame) { FMLCommonHandler.instance().getFMLLogger().throwing("FMLHandler", "raiseException", exception); - throw new RuntimeException(exception); + if (stopGame) + { + getSidedDelegate().haltGame(message,exception); + } } diff --git a/common/cpw/mods/fml/common/IFMLSidedHandler.java b/common/cpw/mods/fml/common/IFMLSidedHandler.java index 2724bce76b..3eda416c36 100644 --- a/common/cpw/mods/fml/common/IFMLSidedHandler.java +++ b/common/cpw/mods/fml/common/IFMLSidedHandler.java @@ -27,4 +27,5 @@ public interface IFMLSidedHandler List getAdditionalBrandingInformation(); Side getSide(); ProxyInjector findSidedProxyOn(BaseMod mod); + void haltGame(String message, Throwable exception); } diff --git a/common/cpw/mods/fml/common/Loader.java b/common/cpw/mods/fml/common/Loader.java index 89db560172..b82c2e8c50 100644 --- a/common/cpw/mods/fml/common/Loader.java +++ b/common/cpw/mods/fml/common/Loader.java @@ -234,7 +234,15 @@ public class Loader if (mod.wantsPreInit()) { log.finer(String.format("Pre-initializing %s", mod.getSource())); - mod.preInit(); + try + { + mod.preInit(); + } + catch (Throwable t) + { + log.log(Level.SEVERE, String.format("The mod from file %s has failed to load. This is likely a mod installation error.", mod.getSource().getName()), t); + throw new LoaderException(t); + } namedMods.put(mod.getName(), mod); } mod.nextState(); diff --git a/common/cpw/mods/fml/common/modloader/BaseMod.java b/common/cpw/mods/fml/common/modloader/BaseMod.java index 8ab4e107e3..209e037db0 100644 --- a/common/cpw/mods/fml/common/modloader/BaseMod.java +++ b/common/cpw/mods/fml/common/modloader/BaseMod.java @@ -26,9 +26,9 @@ import cpw.mods.fml.common.IWorldGenerator; import cpw.mods.fml.common.TickType; /** - * + * * Marker interface for BaseMod - * + * * @author cpw * */ @@ -36,12 +36,12 @@ public interface BaseMod extends IWorldGenerator, IPickupNotifier, IDispenseHand { /** - * + * */ void modsLoaded(); /** - * + * */ void load(); @@ -54,6 +54,7 @@ public interface BaseMod extends IWorldGenerator, IPickupNotifier, IDispenseHand */ boolean doTickInGame(TickType tick, boolean b, Object minecraftInstance, Object... data); + boolean doTickInGUI(TickType tick, boolean b, Object minecraftInstance, Object... data); /** * @return */ @@ -77,7 +78,7 @@ public interface BaseMod extends IWorldGenerator, IPickupNotifier, IDispenseHand void onRenderHarvest(Map renderers); /** - * + * */ void onRegisterAnimations(); diff --git a/common/cpw/mods/fml/common/modloader/BaseModTicker.java b/common/cpw/mods/fml/common/modloader/BaseModTicker.java index af231d8151..99fee83e35 100644 --- a/common/cpw/mods/fml/common/modloader/BaseModTicker.java +++ b/common/cpw/mods/fml/common/modloader/BaseModTicker.java @@ -30,17 +30,20 @@ public class BaseModTicker implements ITickHandler private BaseMod mod; private EnumSet ticks; private boolean clockTickTrigger; + private boolean sendGuiTicks; - BaseModTicker(BaseMod mod) + BaseModTicker(BaseMod mod, boolean guiTicker) { this.mod = mod; this.ticks = EnumSet.of(TickType.WORLDLOAD); + this.sendGuiTicks = guiTicker; } - BaseModTicker(EnumSet ticks) + BaseModTicker(EnumSet ticks, boolean guiTicker) { this.ticks = ticks; + this.sendGuiTicks = guiTicker; } @Override @@ -57,15 +60,14 @@ public class BaseModTicker implements ITickHandler private void tickBaseMod(EnumSet types, boolean end, Object... tickData) { - if (FMLCommonHandler.instance().getSide().isClient() && ( ticks.contains(TickType.GAME) || ticks.contains(TickType.WORLDGUI))) + if (FMLCommonHandler.instance().getSide().isClient() && ( ticks.contains(TickType.GAME) || ticks.contains(TickType.WORLDLOAD))) { EnumSet cTypes=EnumSet.copyOf(types); - if ( ( end && ( types.contains(TickType.GAME) || types.contains(TickType.WORLDGUI))) || types.contains(TickType.WORLDLOAD) ) + if ( ( end && types.contains(TickType.GAME)) || types.contains(TickType.WORLDLOAD)) { clockTickTrigger = true; cTypes.remove(TickType.GAME); cTypes.remove(TickType.WORLDLOAD); - cTypes.remove(TickType.WORLDGUI); } if (end && clockTickTrigger && types.contains(TickType.RENDER)) @@ -73,7 +75,6 @@ public class BaseModTicker implements ITickHandler clockTickTrigger = false; cTypes.remove(TickType.RENDER); if (ticks.contains(TickType.GAME)) cTypes.add(TickType.GAME); - if (ticks.contains(TickType.WORLDGUI)) cTypes.add(TickType.WORLDGUI); } sendTick(cTypes, end, tickData); @@ -92,7 +93,16 @@ public class BaseModTicker implements ITickHandler { continue; } - boolean keepTicking=mod.doTickInGame(type, end, FMLCommonHandler.instance().getMinecraftInstance(), tickData); + + boolean keepTicking=true; + if (sendGuiTicks) + { + mod.doTickInGUI(type, end, FMLCommonHandler.instance().getMinecraftInstance(), tickData); + } + else + { + mod.doTickInGame(type, end, FMLCommonHandler.instance().getMinecraftInstance(), tickData); + } if (!keepTicking) { ticks.remove(type); ticks.removeAll(type.partnerTicks()); @@ -119,5 +129,4 @@ public class BaseModTicker implements ITickHandler { this.mod = mod; } - } diff --git a/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java b/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java index 22d06a8a56..bb57909ceb 100644 --- a/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java +++ b/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java @@ -32,7 +32,7 @@ public class ModLoaderHelper public static void updateStandardTicks(BaseMod mod, boolean enable, boolean useClock) { ModLoaderModContainer mlmc = findOrBuildModContainer(mod); - BaseModTicker ticker = mlmc.getTickHandler(); + BaseModTicker ticker = mlmc.getGameTickHandler(); EnumSet ticks = ticker.ticks(); // If we're enabled we get render ticks if (enable && !useClock) { @@ -51,18 +51,18 @@ public class ModLoaderHelper public static void updateGUITicks(BaseMod mod, boolean enable, boolean useClock) { ModLoaderModContainer mlmc = findOrBuildModContainer(mod); - EnumSet ticks = mlmc.getTickHandler().ticks(); + EnumSet ticks = mlmc.getGUITickHandler().ticks(); // If we're enabled and we don't want clock ticks we get render ticks if (enable && !useClock) { - ticks.add(TickType.GUI); + ticks.add(TickType.RENDER); } else { - ticks.remove(TickType.GUI); + ticks.remove(TickType.RENDER); } // If we're enabled but we want clock ticks, or we're server side we get world ticks - if (enable && (useClock || FMLCommonHandler.instance().getSide().isServer())) { - ticks.add(TickType.WORLDGUI); + if (enable && useClock) { + ticks.add(TickType.GAME); } else { - ticks.remove(TickType.WORLDGUI); + ticks.remove(TickType.GAME); } } diff --git a/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java b/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java index 611fded95e..06855ae5ed 100644 --- a/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java +++ b/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java @@ -64,7 +64,8 @@ public class ModLoaderModContainer implements ModContainer private SourceType sourceType; private ModMetadata metadata; private ProxyInjector sidedProxy; - private BaseModTicker tickHandler; + private BaseModTicker gameTickHandler; + private BaseModTicker guiTickHandler; public ModLoaderModContainer(Class modClazz, File modSource) { @@ -81,7 +82,8 @@ public class ModLoaderModContainer implements ModContainer ModLoaderModContainer(BaseMod instance) { FMLCommonHandler.instance().addAuxilliaryModContainer(this); this.mod=instance; - this.tickHandler = new BaseModTicker(instance); + this.gameTickHandler = new BaseModTicker(instance, false); + this.guiTickHandler = new BaseModTicker(instance, true); } @Override @@ -102,11 +104,14 @@ public class ModLoaderModContainer implements ModContainer try { EnumSet ticks = EnumSet.noneOf(TickType.class); - this.tickHandler = new BaseModTicker(ticks); + this.gameTickHandler = new BaseModTicker(ticks, false); + this.guiTickHandler = new BaseModTicker(ticks.clone(), true); configureMod(); mod = modClazz.newInstance(); - this.tickHandler.setMod(mod); - FMLCommonHandler.instance().registerTickHandler(this.tickHandler); + this.gameTickHandler.setMod(mod); + this.guiTickHandler.setMod(mod); + FMLCommonHandler.instance().registerTickHandler(this.gameTickHandler); + FMLCommonHandler.instance().registerTickHandler(this.guiTickHandler); FMLCommonHandler.instance().registerWorldGenerator(this.mod); } catch (Exception e) @@ -707,8 +712,15 @@ public class ModLoaderModContainer implements ModContainer /** * @return */ - public BaseModTicker getTickHandler() + public BaseModTicker getGameTickHandler() { - return this.tickHandler; + return this.gameTickHandler; + } + /** + * @return + */ + public BaseModTicker getGUITickHandler() + { + return this.guiTickHandler; } } diff --git a/patches/minecraft_server/net/minecraft/server/MinecraftServer.java.patch b/patches/minecraft_server/net/minecraft/server/MinecraftServer.java.patch index 683e9c6e76..8ad16aef5d 100644 --- a/patches/minecraft_server/net/minecraft/server/MinecraftServer.java.patch +++ b/patches/minecraft_server/net/minecraft/server/MinecraftServer.java.patch @@ -73,3 +73,12 @@ } public void func_6010_a(String p_6010_1_, ICommandListener p_6010_2_) +@@ -715,7 +729,7 @@ + + public String func_52003_getServerModName() + { +- return "vanilla"; ++ return "fml"; + } + + public static boolean func_6015_a(MinecraftServer p_6015_0_) diff --git a/server/cpw/mods/fml/server/FMLServerHandler.java b/server/cpw/mods/fml/server/FMLServerHandler.java index 5b554e8fb7..853ca4fd4a 100644 --- a/server/cpw/mods/fml/server/FMLServerHandler.java +++ b/server/cpw/mods/fml/server/FMLServerHandler.java @@ -62,22 +62,22 @@ import cpw.mods.fml.common.registry.FMLRegistry; /** * Handles primary communication from hooked code into the system - * + * * The FML entry point is {@link #onPreLoad(MinecraftServer)} called from * {@link MinecraftServer} - * + * * Obfuscated code should focus on this class and other members of the "server" * (or "client") code - * + * * The actual mod loading is handled at arms length by {@link Loader} - * + * * It is expected that a similar class will exist for each target environment: * Bukkit and Client side. - * + * * It should not be directly modified. - * + * * @author cpw - * + * */ public class FMLServerHandler implements IFMLSidedHandler { @@ -99,7 +99,7 @@ public class FMLServerHandler implements IFMLSidedHandler /** * Called to start the whole game off from * {@link MinecraftServer#startServer} - * + * * @param minecraftServer */ public void onPreLoad(MinecraftServer minecraftServer) @@ -147,11 +147,17 @@ public class FMLServerHandler implements IFMLSidedHandler Loader.instance().initializeMods(); } + @Override + public void haltGame(String message, Throwable exception) + { + throw new RuntimeException(message, exception); + } + public void onPreServerTick() { FMLCommonHandler.instance().tickStart(EnumSet.of(TickType.GAME)); } - + public void onPostServerTick() { FMLCommonHandler.instance().tickEnd(EnumSet.of(TickType.GAME)); @@ -178,7 +184,7 @@ public class FMLServerHandler implements IFMLSidedHandler } /** * Get the server instance - * + * * @return */ public MinecraftServer getServer() @@ -196,10 +202,10 @@ public class FMLServerHandler implements IFMLSidedHandler /** * Called from ChunkProviderServer when a chunk needs to be populated - * + * * To avoid polluting the worldgen seed, we generate a new random from the * world seed and generate a seed from that - * + * * @param chunkProvider * @param chunkX * @param chunkZ @@ -213,7 +219,7 @@ public class FMLServerHandler implements IFMLSidedHandler /** * Called from the furnace to lookup fuel values - * + * * @param itemId * @param itemDamage * @return @@ -251,7 +257,7 @@ public class FMLServerHandler implements IFMLSidedHandler /** * Called to notify that an item was picked up from the world - * + * * @param entityItem * @param entityPlayer */ @@ -268,7 +274,7 @@ public class FMLServerHandler implements IFMLSidedHandler /** * Raise an exception - * + * * @param exception * @param message * @param stopGame @@ -282,7 +288,7 @@ public class FMLServerHandler implements IFMLSidedHandler /** * Attempt to dispense the item as an entity other than just as a the item * itself - * + * * @param world * @param x * @param y @@ -315,7 +321,7 @@ public class FMLServerHandler implements IFMLSidedHandler /** * Build a list of default overworld biomes - * + * * @return */ public BiomeGenBase[] getDefaultOverworldBiomes() @@ -343,7 +349,7 @@ public class FMLServerHandler implements IFMLSidedHandler /** * Called when an item is crafted - * + * * @param player * @param craftedItem * @param craftingGrid @@ -361,7 +367,7 @@ public class FMLServerHandler implements IFMLSidedHandler /** * Called when an item is smelted - * + * * @param player * @param smeltedItem */ @@ -378,7 +384,7 @@ public class FMLServerHandler implements IFMLSidedHandler /** * Called when a chat packet is received - * + * * @param chat * @param player * @return true if you want the packet to stop processing and not echo to @@ -399,7 +405,7 @@ public class FMLServerHandler implements IFMLSidedHandler /** * Called when a packet 250 packet is received from the player - * + * * @param packet * @param player */ @@ -421,7 +427,7 @@ public class FMLServerHandler implements IFMLSidedHandler /** * Handle register requests for packet 250 channels - * + * * @param packet */ private void handleClientRegistration(Packet250CustomPayload packet, EntityPlayer player) @@ -458,7 +464,7 @@ public class FMLServerHandler implements IFMLSidedHandler /** * Handle a login - * + * * @param loginPacket * @param networkManager */ @@ -592,7 +598,7 @@ public class FMLServerHandler implements IFMLSidedHandler objectName+=".name"; return objectName; } - + /* (non-Javadoc) * @see cpw.mods.fml.common.IFMLSidedHandler#readMetadataFrom(java.io.InputStream, cpw.mods.fml.common.ModContainer) */ diff --git a/server/net/minecraft/src/BaseMod.java b/server/net/minecraft/src/BaseMod.java index ac7a4d66d9..6c3ff8fe08 100644 --- a/server/net/minecraft/src/BaseMod.java +++ b/server/net/minecraft/src/BaseMod.java @@ -29,7 +29,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod { // CALLBACK MECHANISMS public void keyBindingEvent(Object keybinding){} - + /** * @param minecraftInstance * @return @@ -43,6 +43,10 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod return true; } } + public final boolean doTickInGUI(TickType tick, boolean tickEnd, Object minecraftInstance, Object... data) + { + return false; + } @Override public final void onCrafting(Object... craftingParameters) @@ -72,7 +76,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod public final void onServerLogin(Object handler) { // NOOP } - + public final void onServerLogout() { // NOOP } @@ -135,7 +139,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod // BASEMOD API /** * Override if you wish to provide a fuel item for the furnace and return the fuel value of the item - * + * * @param id * @param metadata * @return @@ -152,7 +156,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Override if you wish to perform some action other than just dispensing the item from the dispenser - * + * * @param world * @param x * @param y @@ -169,7 +173,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Override if you wish to generate Nether (Hell biome) blocks - * + * * @param world * @param random * @param chunkX @@ -181,7 +185,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Override if you wish to generate Overworld (not hell or the end) blocks - * + * * @param world * @param random * @param chunkX @@ -193,7 +197,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Return the name of your mod. Defaults to the class name - * + * * @return */ public String getName() @@ -203,7 +207,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Get your mod priorities - * + * * @return */ public String getPriorities() @@ -213,7 +217,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Return the version of your mod - * + * * @return */ public abstract String getVersion(); @@ -237,7 +241,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Handle item pickup - * + * * @param player * @param item */ @@ -247,7 +251,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Ticked every game tick if you have subscribed to tick events through {@link ModLoader#setInGameHook(BaseMod, boolean, boolean)} - * + * * @param minecraftServer the server * @return true to continue receiving ticks */ @@ -264,23 +268,23 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Only implemented on the client side * {@link #onChatMessageReceived(EntityPlayer, Packet3Chat)} - * + * * @param text */ public void receiveChatPacket(String text) { - + } /** * Only called on the client side * {@link #onPacket250Received(EntityPlayer, Packet250CustomPayload)} - * + * * @param packet */ public void receiveCustomPacket(Packet250CustomPayload packet) { - + } public void registerAnimation(Object game) @@ -301,7 +305,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Called when someone crafts an item from a crafting table - * + * * @param player * @param item * @param matrix @@ -341,7 +345,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Called when a chat message is received. Return true to stop further processing - * + * * @param source * @param chat * @return true if you want to consume the message so it is not available for further processing @@ -362,7 +366,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Called when a new client logs in. - * + * * @param player */ public void onClientLogin(EntityPlayer player) @@ -371,7 +375,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod /** * Called when a client logs out of the server. - * + * * @param player */ public void onClientLogout(EntityPlayer player) @@ -380,9 +384,9 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod } /** - * + * * Called when a client changes dimensions on the server. - * + * * @param player */ public void onClientDimensionChanged(EntityPlayer player) @@ -399,7 +403,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod } /** - * + * */ public void onRegisterAnimations() { From a4ce90a9186194a64a9846ff77aa41a7cf0dcca0 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 3 Jul 2012 23:03:51 -0400 Subject: [PATCH 3/4] FFS let this fix that bloody ticking mess that is ML compatibility. --- common/cpw/mods/fml/common/modloader/BaseModTicker.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/cpw/mods/fml/common/modloader/BaseModTicker.java b/common/cpw/mods/fml/common/modloader/BaseModTicker.java index 99fee83e35..866b139316 100644 --- a/common/cpw/mods/fml/common/modloader/BaseModTicker.java +++ b/common/cpw/mods/fml/common/modloader/BaseModTicker.java @@ -60,7 +60,7 @@ public class BaseModTicker implements ITickHandler private void tickBaseMod(EnumSet types, boolean end, Object... tickData) { - if (FMLCommonHandler.instance().getSide().isClient() && ( ticks.contains(TickType.GAME) || ticks.contains(TickType.WORLDLOAD))) + if (FMLCommonHandler.instance().getSide().isClient() && ( ticks.contains(TickType.GAME) || ticks.contains(TickType.WORLDLOAD)) || ticks.contains(TickType.RENDER)) { EnumSet cTypes=EnumSet.copyOf(types); if ( ( end && types.contains(TickType.GAME)) || types.contains(TickType.WORLDLOAD)) @@ -74,7 +74,7 @@ public class BaseModTicker implements ITickHandler { clockTickTrigger = false; cTypes.remove(TickType.RENDER); - if (ticks.contains(TickType.GAME)) cTypes.add(TickType.GAME); + cTypes.add(TickType.GAME); } sendTick(cTypes, end, tickData); @@ -97,11 +97,11 @@ public class BaseModTicker implements ITickHandler boolean keepTicking=true; if (sendGuiTicks) { - mod.doTickInGUI(type, end, FMLCommonHandler.instance().getMinecraftInstance(), tickData); + keepTicking = mod.doTickInGUI(type, end, FMLCommonHandler.instance().getMinecraftInstance(), tickData); } else { - mod.doTickInGame(type, end, FMLCommonHandler.instance().getMinecraftInstance(), tickData); + keepTicking = mod.doTickInGame(type, end, FMLCommonHandler.instance().getMinecraftInstance(), tickData); } if (!keepTicking) { ticks.remove(type); From 3e311fd4c1148bbad544403b6a7f1469f19241f9 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 4 Jul 2012 00:16:30 -0400 Subject: [PATCH 4/4] Tweak ticking YET AGAIN. Should fire a solitary GUILOAD tick right as the game screen loads. Hopefully fixes worldload tick issue too --- client/cpw/mods/fml/client/FMLClientHandler.java | 10 +++++++++- client/net/minecraft/src/BaseMod.java | 2 +- .../cpw/mods/fml/common/modloader/ModLoaderHelper.java | 7 +++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/client/cpw/mods/fml/client/FMLClientHandler.java b/client/cpw/mods/fml/client/FMLClientHandler.java index 9262b51752..4b1ef000b9 100644 --- a/client/cpw/mods/fml/client/FMLClientHandler.java +++ b/client/cpw/mods/fml/client/FMLClientHandler.java @@ -163,6 +163,8 @@ public class FMLClientHandler implements IFMLSidedHandler private OptifineModContainer optifineContainer; + private boolean guiLoaded; + public void onPreLoad(Minecraft minecraft) { client = minecraft; @@ -293,7 +295,7 @@ public class FMLClientHandler implements IFMLSidedHandler loadTextures(fallbackTexturePack); firstTick = false; } - FMLCommonHandler.instance().tickStart(EnumSet.of(TickType.WORLDLOAD,TickType.GUILOAD)); + FMLCommonHandler.instance().tickStart(EnumSet.of(TickType.WORLDLOAD)); } } @@ -304,6 +306,12 @@ public class FMLClientHandler implements IFMLSidedHandler public void onRenderTickEnd(float partialTickTime) { + if (!guiLoaded) + { + FMLCommonHandler.instance().rescheduleTicks(); + FMLCommonHandler.instance().tickStart(EnumSet.of(TickType.GUILOAD), partialTickTime, client.field_6313_p); + guiLoaded = true; + } FMLCommonHandler.instance().tickEnd(EnumSet.of(TickType.RENDER,TickType.GUI), partialTickTime, client.field_6313_p); } /** diff --git a/client/net/minecraft/src/BaseMod.java b/client/net/minecraft/src/BaseMod.java index 1801236129..45646af2dc 100644 --- a/client/net/minecraft/src/BaseMod.java +++ b/client/net/minecraft/src/BaseMod.java @@ -53,7 +53,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod public final boolean doTickInGUI(TickType tick, boolean tickEnd, Object minecraftInstance, Object... data) { Minecraft mc = (Minecraft) minecraftInstance; - if (tickEnd && ( tick==TickType.RENDER || tick==TickType.GAME )) { + if (tickEnd && ( tick==TickType.RENDER || tick==TickType.GAME ) || tick == TickType.GUILOAD) { return onTickInGUI((Float) data[0], mc, mc.field_6313_p); } return true; diff --git a/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java b/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java index bb57909ceb..b9bfc5c231 100644 --- a/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java +++ b/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java @@ -43,8 +43,10 @@ public class ModLoaderHelper // If we're enabled but we want clock ticks, or we're server side we get game ticks if (enable && (useClock || FMLCommonHandler.instance().getSide().isServer())) { ticks.add(TickType.GAME); + ticks.add(TickType.WORLDLOAD); } else { ticks.remove(TickType.GAME); + ticks.remove(TickType.WORLDLOAD); } } @@ -55,14 +57,19 @@ public class ModLoaderHelper // If we're enabled and we don't want clock ticks we get render ticks if (enable && !useClock) { ticks.add(TickType.RENDER); + ticks.add(TickType.GUILOAD); } else { ticks.remove(TickType.RENDER); } // If we're enabled but we want clock ticks, or we're server side we get world ticks if (enable && useClock) { ticks.add(TickType.GAME); + ticks.add(TickType.GUILOAD); + ticks.add(TickType.WORLDLOAD); } else { ticks.remove(TickType.GAME); + ticks.remove(TickType.GUILOAD); + ticks.remove(TickType.WORLDLOAD); } }