blob: d6033dcc809eee8e041a03adda51bf0a321cbcb2 [file] [log] [blame] [raw]
package li.cil.oc.common.asm;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import li.cil.oc.api.Network;
import net.minecraft.tileentity.TileEntity;
import java.util.ArrayList;
// This class is used for adding simple components to the component network.
// It is triggered from a validate call, and executed in the next update tick.
public final class SimpleComponentTickHandler {
public static final ArrayList<Runnable> pending = new java.util.ArrayList<Runnable>();
public static final SimpleComponentTickHandler Instance = new SimpleComponentTickHandler();
private SimpleComponentTickHandler() {
}
public static void schedule(final TileEntity tileEntity) {
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
synchronized (pending) {
pending.add(new Runnable() {
@Override
public void run() {
Network.joinOrCreateNetwork(tileEntity);
}
});
}
}
}
@SubscribeEvent
public void onTick(TickEvent.ServerTickEvent e) {
final Runnable[] adds;
synchronized (pending) {
adds = pending.toArray(new Runnable[pending.size()]);
pending.clear();
}
for (Runnable runnable : adds) {
runnable.run();
}
}
}