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,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()) {

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()));
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();

View File

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

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

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

View File

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