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.
This commit is contained in:
Christian 2012-07-03 22:39:35 -04:00
parent 275fd394c1
commit 3d8a5edc30
12 changed files with 163 additions and 79 deletions

View File

@ -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,17 +193,38 @@ public class FMLClientHandler implements IFMLSidedHandler
}
FMLCommonHandler.instance().getFMLLogger().info(String.format("Forge Mod Loader has detected optifine %s, enabling compatibility features",optifineContainer.getVersion()));
}
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
*
*/
public void onLoadComplete()
{
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()) {

View File

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

View File

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

View File

@ -27,4 +27,5 @@ public interface IFMLSidedHandler
List<String> getAdditionalBrandingInformation();
Side getSide();
ProxyInjector findSidedProxyOn(BaseMod mod);
void haltGame(String message, Throwable exception);
}

View File

@ -234,7 +234,15 @@ public class Loader
if (mod.wantsPreInit())
{
log.finer(String.format("Pre-initializing %s", mod.getSource()));
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();

View File

@ -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
*/

View File

@ -30,17 +30,20 @@ public class BaseModTicker implements ITickHandler
private BaseMod mod;
private EnumSet<TickType> 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<TickType> ticks)
BaseModTicker(EnumSet<TickType> ticks, boolean guiTicker)
{
this.ticks = ticks;
this.sendGuiTicks = guiTicker;
}
@Override
@ -57,15 +60,14 @@ public class BaseModTicker implements ITickHandler
private void tickBaseMod(EnumSet<TickType> 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;
}
}

View File

@ -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<TickType> 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<TickType> ticks = mlmc.getTickHandler().ticks();
EnumSet<TickType> 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);
}
}

View File

@ -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 <? extends BaseMod > 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<TickType> 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;
}
}

View File

@ -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_)

View File

@ -147,6 +147,12 @@ 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));

View File

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