1dfa5817bf
Moved DDTeleporter to the mod_pocketDim.core package. It seemed reasonable given that DDTeleporter is closely tied to how Dimensional Doors works. It controls the most critical feature for all items - teleportation - and handles routing requests to initialize link destinations.
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.core.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!
|
|
}
|
|
}
|