DimDoors/StevenDimDoors/mod_pocketDim/ticking/CommonTickHandler.java
SenseiKiwi 4086e75ead More Progress on Rewrite
Fixed the code in DDTeleporter and made minor changes to other classes
that depended on those fixes. Ensured that PocketManager's load, save,
and unload methods are called appropriately and rewrote some of their
code. Made various changes in other classes (e.g. EventHookContainer,
PlayerRespawnTracker) to pass them references to DDProperties through
their constructors instead of having them rely on
DDProperties.instance() - this is a better programming practice in the
long run.

Renamed initialization methods in mod_pocketDim to make it clear that
they're called on events. Commented out command registration in
mod_pocketDim so that we can test DD as soon as PacketHandler is fixed,
without worrying about fixing the command classes.
2013-09-01 09:21:27 -04:00

76 lines
1.8 KiB
Java

package StevenDimDoors.mod_pocketDim.ticking;
import java.util.ArrayList;
import java.util.EnumSet;
import StevenDimDoors.mod_pocketDim.DDTeleporter;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;
public class CommonTickHandler implements ITickHandler, IRegularTickSender
{
private static final String PROFILING_LABEL = "Dimensional Doors: Common Tick";
private int tickCount = 0;
private ArrayList<RegularTickReceiverInfo> receivers;
public CommonTickHandler()
{
this.receivers = new ArrayList<RegularTickReceiverInfo>();
}
@Override
public void registerForTicking(IRegularTickReceiver receiver, int interval, boolean onTickStart)
{
RegularTickReceiverInfo info = new RegularTickReceiverInfo(receiver, interval, onTickStart);
receivers.add(info);
}
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
if (type.equals(EnumSet.of(TickType.SERVER)))
{
for (RegularTickReceiverInfo info : receivers)
{
if (info.OnTickStart && tickCount % info.Interval == 0)
{
info.RegularTickReceiver.notifyTick();
}
}
}
//TODO: Stuck this in here because it's already rather hackish.
//We should standardize this as an IRegularTickReceiver in the future. ~SenseiKiwi
if (DDTeleporter.cooldown > 0)
{
DDTeleporter.cooldown--;
}
}
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
for (RegularTickReceiverInfo info : receivers)
{
if (!info.OnTickStart && tickCount % info.Interval == 0)
{
info.RegularTickReceiver.notifyTick();
}
}
tickCount++; //There is no need to reset the counter. Let it overflow.
}
@Override
public EnumSet<TickType> ticks()
{
return EnumSet.of(TickType.SERVER);
}
@Override
public String getLabel()
{
return PROFILING_LABEL; //Used for profiling!
}
}