2013-07-26 08:09:14 +02:00
|
|
|
package StevenDimDoors.mod_pocketDim.ticking;
|
2013-06-14 01:01:54 +02:00
|
|
|
|
2013-07-12 05:58:59 +02:00
|
|
|
import java.util.ArrayList;
|
2013-02-18 03:46:16 +01:00
|
|
|
import java.util.EnumSet;
|
|
|
|
|
2013-09-01 15:21:27 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.DDTeleporter;
|
2013-02-18 03:46:16 +01:00
|
|
|
import cpw.mods.fml.common.ITickHandler;
|
|
|
|
import cpw.mods.fml.common.TickType;
|
2013-06-14 01:01:54 +02:00
|
|
|
|
2013-07-26 11:15:44 +02:00
|
|
|
public class CommonTickHandler implements ITickHandler, IRegularTickSender
|
2013-02-18 03:46:16 +01:00
|
|
|
{
|
2013-07-26 11:15:44 +02:00
|
|
|
private static final String PROFILING_LABEL = "Dimensional Doors: Common Tick";
|
|
|
|
|
2013-07-25 07:38:58 +02:00
|
|
|
private int tickCount = 0;
|
2013-07-26 11:15:44 +02:00
|
|
|
private ArrayList<RegularTickReceiverInfo> receivers;
|
2013-07-25 07:38:58 +02:00
|
|
|
|
2013-07-12 05:58:59 +02:00
|
|
|
|
2013-06-14 01:01:54 +02:00
|
|
|
public CommonTickHandler()
|
|
|
|
{
|
2013-07-26 11:15:44 +02:00
|
|
|
this.receivers = new ArrayList<RegularTickReceiverInfo>();
|
2013-06-14 01:01:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-07-26 11:15:44 +02:00
|
|
|
public void registerForTicking(IRegularTickReceiver receiver, int interval, boolean onTickStart)
|
2013-06-14 01:01:54 +02:00
|
|
|
{
|
2013-07-26 11:15:44 +02:00
|
|
|
RegularTickReceiverInfo info = new RegularTickReceiverInfo(receiver, interval, onTickStart);
|
|
|
|
receivers.add(info);
|
2013-06-14 01:01:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-07-26 11:15:44 +02:00
|
|
|
public void tickStart(EnumSet<TickType> type, Object... tickData)
|
2013-06-14 01:01:54 +02:00
|
|
|
{
|
|
|
|
if (type.equals(EnumSet.of(TickType.SERVER)))
|
|
|
|
{
|
2013-07-26 11:15:44 +02:00
|
|
|
for (RegularTickReceiverInfo info : receivers)
|
2013-07-12 05:58:59 +02:00
|
|
|
{
|
2013-07-26 11:15:44 +02:00
|
|
|
if (info.OnTickStart && tickCount % info.Interval == 0)
|
2013-07-12 05:58:59 +02:00
|
|
|
{
|
2013-07-26 11:15:44 +02:00
|
|
|
info.RegularTickReceiver.notifyTick();
|
2013-07-12 05:58:59 +02:00
|
|
|
}
|
|
|
|
}
|
2013-06-14 01:01:54 +02:00
|
|
|
}
|
2013-07-26 11:15:44 +02:00
|
|
|
|
|
|
|
//TODO: Stuck this in here because it's already rather hackish.
|
|
|
|
//We should standardize this as an IRegularTickReceiver in the future. ~SenseiKiwi
|
2013-09-01 15:21:27 +02:00
|
|
|
if (DDTeleporter.cooldown > 0)
|
2013-07-12 05:58:59 +02:00
|
|
|
{
|
2013-09-01 15:21:27 +02:00
|
|
|
DDTeleporter.cooldown--;
|
2013-07-12 05:58:59 +02:00
|
|
|
}
|
|
|
|
}
|
2013-07-25 07:38:58 +02:00
|
|
|
|
2013-07-26 11:15:44 +02:00
|
|
|
@Override
|
|
|
|
public void tickEnd(EnumSet<TickType> type, Object... tickData)
|
2013-07-12 05:58:59 +02:00
|
|
|
{
|
2013-07-26 11:15:44 +02:00
|
|
|
for (RegularTickReceiverInfo info : receivers)
|
2013-07-12 05:58:59 +02:00
|
|
|
{
|
2013-07-26 11:15:44 +02:00
|
|
|
if (!info.OnTickStart && tickCount % info.Interval == 0)
|
2013-07-12 05:58:59 +02:00
|
|
|
{
|
2013-07-26 11:15:44 +02:00
|
|
|
info.RegularTickReceiver.notifyTick();
|
2013-07-12 05:58:59 +02:00
|
|
|
}
|
|
|
|
}
|
2013-07-26 11:15:44 +02:00
|
|
|
tickCount++; //There is no need to reset the counter. Let it overflow.
|
2013-07-26 07:09:46 +02:00
|
|
|
}
|
2013-07-25 06:12:13 +02:00
|
|
|
|
2013-07-26 11:15:44 +02:00
|
|
|
@Override
|
|
|
|
public EnumSet<TickType> ticks()
|
2013-07-25 07:38:58 +02:00
|
|
|
{
|
2013-07-26 11:15:44 +02:00
|
|
|
return EnumSet.of(TickType.SERVER);
|
2013-07-25 07:38:58 +02:00
|
|
|
}
|
|
|
|
|
2013-07-26 11:15:44 +02:00
|
|
|
@Override
|
|
|
|
public String getLabel()
|
2013-06-14 01:01:54 +02:00
|
|
|
{
|
2013-07-26 11:15:44 +02:00
|
|
|
return PROFILING_LABEL; //Used for profiling!
|
2013-06-14 01:01:54 +02:00
|
|
|
}
|
2013-06-30 21:53:02 +02:00
|
|
|
}
|