mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 03:49:14 +00:00
Expose a "clean" ticking interface and fix server tick loop for world ticks
This commit is contained in:
1 parent
f943cd9b4b
commit
11652d597f
14 files changed
+179
-56
No files matched your search
@@ -84,11 +84,11 @@ import cpw.mods.fml.common.IFMLSidedHandler;
|
||||
import cpw.mods.fml.common.IKeyHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.ModContainer.TickType;
|
||||
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.ModLoaderHelper;
|
||||
import cpw.mods.fml.common.modloader.ModLoaderModContainer;
|
||||
import cpw.mods.fml.common.modloader.ModProperty;
|
||||
@@ -266,7 +266,7 @@ public class FMLClientHandler implements IFMLSidedHandler
|
||||
public void onPreWorldTick()
|
||||
{
|
||||
if (client.field_6324_e != null) {
|
||||
FMLCommonHandler.instance().worldTickStart();
|
||||
FMLCommonHandler.instance().worldTickStart(client.field_6324_e);
|
||||
FMLCommonHandler.instance().tickStart(TickType.WORLDGUI, 0.0f, client.field_6313_p);
|
||||
}
|
||||
}
|
||||
@@ -277,7 +277,7 @@ public class FMLClientHandler implements IFMLSidedHandler
|
||||
public void onPostWorldTick()
|
||||
{
|
||||
if (client.field_6324_e != null) {
|
||||
FMLCommonHandler.instance().worldTickEnd();
|
||||
FMLCommonHandler.instance().worldTickEnd(client.field_6324_e);
|
||||
FMLCommonHandler.instance().tickEnd(TickType.WORLDGUI, 0.0f, client.field_6313_p);
|
||||
}
|
||||
for (IKeyHandler entry : keyHandlers)
|
||||
|
||||
@@ -24,7 +24,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;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
|
||||
public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod
|
||||
{
|
||||
|
||||
@@ -26,7 +26,6 @@ import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.client.SpriteHelper;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer.TickType;
|
||||
import cpw.mods.fml.common.ReflectionHelper;
|
||||
import cpw.mods.fml.common.modloader.ModLoaderHelper;
|
||||
import cpw.mods.fml.common.modloader.ModLoaderModContainer;
|
||||
|
||||
@@ -35,7 +35,6 @@ import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import cpw.mods.fml.common.ModContainer.SourceType;
|
||||
import cpw.mods.fml.common.ModContainer.TickType;
|
||||
|
||||
/**
|
||||
* The main class for non-obfuscated hook handling code
|
||||
@@ -79,6 +78,8 @@ public class FMLCommonHandler
|
||||
private List<ModContainer> auxilliaryContainers = new ArrayList<ModContainer>();
|
||||
|
||||
private Map<String,Properties> modLanguageData=new HashMap<String,Properties>();
|
||||
|
||||
private Set<ITickHandler>tickHandlers = new HashSet<ITickHandler>();
|
||||
/**
|
||||
* We register our delegate here
|
||||
* @param handler
|
||||
@@ -91,17 +92,17 @@ public class FMLCommonHandler
|
||||
/**
|
||||
* Pre-tick the mods
|
||||
*/
|
||||
public void worldTickStart()
|
||||
public void worldTickStart(Object world)
|
||||
{
|
||||
tickStart(ModContainer.TickType.WORLD,0.0f);
|
||||
tickStart(TickType.WORLD,0.0f, world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post-tick the mods
|
||||
*/
|
||||
public void worldTickEnd()
|
||||
public void worldTickEnd(Object world)
|
||||
{
|
||||
tickEnd(ModContainer.TickType.WORLD,0.0f);
|
||||
tickEnd(TickType.WORLD,0.0f);
|
||||
}
|
||||
|
||||
public void tickStart(TickType type, Object ... data)
|
||||
@@ -120,6 +121,15 @@ public class FMLCommonHandler
|
||||
mod.tickStart(type, data);
|
||||
sidedDelegate.profileEnd();
|
||||
}
|
||||
for (ITickHandler ticker : tickHandlers)
|
||||
{
|
||||
if (ticker.ticks().contains(type))
|
||||
{
|
||||
sidedDelegate.profileStart(ticker.getClass().getSimpleName());
|
||||
ticker.tickStart(type, data);
|
||||
sidedDelegate.profileEnd();
|
||||
}
|
||||
}
|
||||
sidedDelegate.profileEnd();
|
||||
sidedDelegate.profileEnd();
|
||||
}
|
||||
@@ -140,6 +150,15 @@ public class FMLCommonHandler
|
||||
mod.tickEnd(type, data);
|
||||
sidedDelegate.profileEnd();
|
||||
}
|
||||
for (ITickHandler ticker : tickHandlers)
|
||||
{
|
||||
if (ticker.ticks().contains(type))
|
||||
{
|
||||
sidedDelegate.profileStart(ticker.getClass().getSimpleName());
|
||||
ticker.tickEnd(type, data);
|
||||
sidedDelegate.profileEnd();
|
||||
}
|
||||
}
|
||||
sidedDelegate.profileEnd();
|
||||
sidedDelegate.profileEnd();
|
||||
}
|
||||
@@ -515,4 +534,8 @@ public class FMLCommonHandler
|
||||
}
|
||||
}
|
||||
|
||||
public void registerTickHandler(ITickHandler handler)
|
||||
{
|
||||
tickHandlers.add(handler);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Tick handler for mods to implement and register through the TickRegistry
|
||||
*
|
||||
* The data available to each tick is documented in the TickType
|
||||
*
|
||||
* @author cpw
|
||||
*
|
||||
*/
|
||||
public interface ITickHandler
|
||||
{
|
||||
|
||||
/**
|
||||
* Called at the "start" phase of a tick
|
||||
* @param type
|
||||
* @param tickData
|
||||
*/
|
||||
public void tickStart(TickType type, Object... tickData);
|
||||
|
||||
/**
|
||||
* Called at the "end" phase of a tick
|
||||
* @param type
|
||||
* @param tickData
|
||||
*/
|
||||
public void tickEnd(TickType type, Object... tickData);
|
||||
|
||||
/**
|
||||
* Returns the list of ticks this tick handler is interested in receiving at the minute
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public EnumSet<TickType> ticks();
|
||||
}
|
||||
@@ -14,7 +14,6 @@
|
||||
package cpw.mods.fml.common;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -203,24 +202,6 @@ public interface ModContainer
|
||||
|
||||
IPlayerTracker getPlayerTracker();
|
||||
|
||||
public enum TickType {
|
||||
WORLD, RENDER, GUI, WORLDGUI,WORLDLOADTICK, GUILOADTICK;
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public EnumSet<TickType> 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);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
List<IKeyHandler> getKeys();
|
||||
|
||||
SourceType getSourceType();
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
public enum TickType {
|
||||
/**
|
||||
* Fired during the world evaluation loop
|
||||
* server and client side
|
||||
*
|
||||
* arg 0 : a float zero (the "render time")
|
||||
* arg 1 : The world that is ticking
|
||||
*/
|
||||
WORLD,
|
||||
/**
|
||||
* client side
|
||||
* Fired during the render processing phase
|
||||
* arg 0 : float "partial render time"
|
||||
*/
|
||||
RENDER,
|
||||
/**
|
||||
* client side
|
||||
* Fired during the render processing phase if a GUI is open
|
||||
* arg 0 : float "partial render time"
|
||||
* arg 1 : the open gui
|
||||
*/
|
||||
GUI,
|
||||
/**
|
||||
* client side
|
||||
* Fired during the world evaluation loop if a gui is open
|
||||
* arg 0 : The open gui
|
||||
*/
|
||||
WORLDGUI,
|
||||
/**
|
||||
* client side
|
||||
* Fired once as the world loads from disk
|
||||
*/
|
||||
WORLDLOADTICK,
|
||||
/**
|
||||
* client side
|
||||
* Fired once as the world loads from disk
|
||||
* arg 0 : the open gui
|
||||
*/
|
||||
GUILOADTICK;
|
||||
|
||||
/**
|
||||
* Partner ticks that are also cancelled by returning false from onTickInGame
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public EnumSet<TickType> 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);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -23,7 +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;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.ModContainer.TickType;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
|
||||
/**
|
||||
* @author cpw
|
||||
|
||||
@@ -45,9 +45,9 @@ import cpw.mods.fml.common.LoaderException;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.ModContainer.ModState;
|
||||
import cpw.mods.fml.common.ModContainer.SourceType;
|
||||
import cpw.mods.fml.common.ModContainer.TickType;
|
||||
import cpw.mods.fml.common.ModMetadata;
|
||||
import cpw.mods.fml.common.ProxyInjector;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
|
||||
public class ModLoaderModContainer implements ModContainer
|
||||
{
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
--- ../src-base/minecraft_server/net/minecraft/server/MinecraftServer.java 0000-00-00 00:00:00.000000000 -0000
|
||||
+++ ../src-work/minecraft_server/net/minecraft/server/MinecraftServer.java 0000-00-00 00:00:00.000000000 -0000
|
||||
@@ -13,6 +13,8 @@
|
||||
@@ -13,6 +13,9 @@
|
||||
import java.util.Random;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
+
|
||||
+import cpw.mods.fml.common.FMLCommonHandler;
|
||||
+import cpw.mods.fml.server.FMLServerHandler;
|
||||
import net.minecraft.src.AnvilSaveConverter;
|
||||
import net.minecraft.src.AnvilSaveHandler;
|
||||
import net.minecraft.src.AxisAlignedBB;
|
||||
@@ -100,6 +102,7 @@
|
||||
@@ -100,6 +103,7 @@
|
||||
var1.start();
|
||||
ConsoleLogManager.func_641_a();
|
||||
field_6038_a.info("Starting minecraft server version 1.2.5");
|
||||
@@ -17,7 +18,7 @@
|
||||
|
||||
if (Runtime.getRuntime().maxMemory() / 1024L / 1024L < 512L)
|
||||
{
|
||||
@@ -146,6 +149,7 @@
|
||||
@@ -146,6 +150,7 @@
|
||||
field_6038_a.warning("To change this, set \"online-mode\" to \"true\" in the server.settings file.");
|
||||
}
|
||||
|
||||
@@ -25,19 +26,13 @@
|
||||
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);
|
||||
@@ -370,6 +374,7 @@
|
||||
var7 = 0L;
|
||||
}
|
||||
|
||||
+ FMLServerHandler.instance().onPreTick();
|
||||
var3 += var7;
|
||||
var1 = var5;
|
||||
|
||||
@@ -386,6 +391,7 @@
|
||||
this.func_6018_h();
|
||||
}
|
||||
}
|
||||
+ FMLServerHandler.instance().onPostTick();
|
||||
@@ -487,7 +492,9 @@
|
||||
this.field_6033_f.func_28169_a(new Packet4UpdateTime(var7.func_22080_k()), var7.field_4272_q.field_6165_g);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
+ FMLServerHandler.instance().onPreWorldTick(var7);
|
||||
var7.func_22077_g();
|
||||
+ FMLServerHandler.instance().onPostWorldTick(var7);
|
||||
|
||||
while (true)
|
||||
{
|
||||
@@ -148,17 +148,17 @@ public class FMLServerHandler implements IFMLSidedHandler
|
||||
/**
|
||||
* Every tick just before world and other ticks occur
|
||||
*/
|
||||
public void onPreTick()
|
||||
public void onPreWorldTick(World world)
|
||||
{
|
||||
FMLCommonHandler.instance().worldTickStart();
|
||||
FMLCommonHandler.instance().worldTickStart(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Every tick just after world and other ticks occur
|
||||
*/
|
||||
public void onPostTick()
|
||||
public void onPostWorldTick(World world)
|
||||
{
|
||||
FMLCommonHandler.instance().worldTickEnd();
|
||||
FMLCommonHandler.instance().worldTickEnd(world);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,7 +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;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
|
||||
public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod
|
||||
{
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.logging.Logger;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer.TickType;
|
||||
import cpw.mods.fml.common.ReflectionHelper;
|
||||
import cpw.mods.fml.common.modloader.ModLoaderHelper;
|
||||
import cpw.mods.fml.common.modloader.ModLoaderModContainer;
|
||||
|
||||
Reference in new issue
Block a user