687a75f4d5
Overhauled the way in which CommonTickHandler triggers tick-based actions such as Limbo decay, spawning Monoliths, and regenerating rifts. Now CommonTickHandler implements an interface called IRegularTickSender, which indicates that it will periodically call on classes that implement IRegulatTickReceiver to perform some task. I added classes for each regularly scheduled task we were performing: MonolithSpawner and RiftRegenerator, plus converted LimboDecay to a normal class instead of a static class. Modified several classes so that they have access to the MonolithSpawner instance to request MonolithSpawning when needed. This improves the structure of our code and gets us away from the way we did things before, which was accessing a public static list inside CommonTickHandler from other classes and adding arrays to specify chunk coordinates. We should not be exposing the internal state of classes like that! And we should be using clearly defined objects to pass information.
76 lines
1.8 KiB
Java
76 lines
1.8 KiB
Java
package StevenDimDoors.mod_pocketDim.ticking;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.EnumSet;
|
|
|
|
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
|
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 (mod_pocketDim.teleTimer > 0)
|
|
{
|
|
mod_pocketDim.teleTimer--;
|
|
}
|
|
}
|
|
|
|
@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!
|
|
}
|
|
}
|