mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-22 13:09:59 +00:00
Reorganize basemod ticking to use ITickHandler. Introduce "GAME" tick vs "WORLD" tick for
mods that want to tick per world and "globally"
This commit is contained in:
1 parent
11652d597f
commit
9fd6f89fc3
13 files changed
+197
-147
No files matched your search
@@ -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<TickType> ticks;
|
||||
|
||||
|
||||
BaseModTicker(BaseMod mod)
|
||||
{
|
||||
this.mod = mod;
|
||||
this.ticks = EnumSet.noneOf(TickType.class);
|
||||
}
|
||||
|
||||
BaseModTicker(EnumSet<TickType> ticks)
|
||||
{
|
||||
this.ticks = ticks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tickStart(EnumSet<TickType> types, Object... tickData)
|
||||
{
|
||||
tickBaseMod(types, false, tickData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tickEnd(EnumSet<TickType> types, Object... tickData)
|
||||
{
|
||||
tickBaseMod(ticks, true, tickData);
|
||||
}
|
||||
|
||||
private void tickBaseMod(EnumSet<TickType> 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<TickType> ticks()
|
||||
{
|
||||
return ticks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel()
|
||||
{
|
||||
return mod.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mod2
|
||||
*/
|
||||
public void setMod(BaseMod mod)
|
||||
{
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user