2013-08-02 03:24:33 +02:00
|
|
|
/**
|
2014-09-07 05:50:03 +02:00
|
|
|
*
|
2013-08-02 03:24:33 +02:00
|
|
|
*/
|
2015-01-14 12:06:03 +01:00
|
|
|
package edx.electrical.tesla;
|
|
|
|
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2015-01-26 12:40:32 +01:00
|
|
|
import resonantengine.api.mffs.fortron.IServerThread;
|
2013-08-02 03:24:33 +02:00
|
|
|
|
2014-03-13 13:53:36 +01:00
|
|
|
import java.util.Collections;
|
2013-08-02 03:24:33 +02:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Set;
|
2014-03-13 13:53:36 +01:00
|
|
|
import java.util.WeakHashMap;
|
2013-08-02 03:24:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Calclavia
|
|
|
|
*/
|
2014-09-27 16:57:52 +02:00
|
|
|
@Deprecated // TODO "Should be replaced with a shared frequency grid" - from Darkguardsman
|
2013-08-02 03:24:33 +02:00
|
|
|
public class TeslaGrid
|
|
|
|
{
|
|
|
|
private static final TeslaGrid INSTANCE_CLIENT = new TeslaGrid();
|
|
|
|
private static final TeslaGrid INSTANCE_SERVER = new TeslaGrid();
|
|
|
|
|
2014-03-13 13:53:36 +01:00
|
|
|
private final Set<ITesla> tileEntities = Collections.newSetFromMap(new WeakHashMap<ITesla, Boolean>());
|
2013-08-02 03:24:33 +02:00
|
|
|
|
2015-01-14 12:06:03 +01:00
|
|
|
public static TeslaGrid instance()
|
|
|
|
{
|
|
|
|
Thread thr = Thread.currentThread();
|
|
|
|
|
|
|
|
if (thr instanceof IServerThread)
|
|
|
|
{
|
|
|
|
return INSTANCE_SERVER;
|
|
|
|
}
|
|
|
|
|
|
|
|
return INSTANCE_CLIENT;
|
|
|
|
}
|
|
|
|
|
2013-08-02 03:24:33 +02:00
|
|
|
public void register(ITesla iTesla)
|
|
|
|
{
|
|
|
|
Iterator<ITesla> it = this.tileEntities.iterator();
|
|
|
|
|
|
|
|
while (it.hasNext())
|
|
|
|
{
|
|
|
|
ITesla tesla = it.next();
|
|
|
|
|
|
|
|
if (tesla instanceof TileEntity)
|
|
|
|
{
|
|
|
|
if (!((TileEntity) tesla).isInvalid())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
it.remove();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.tileEntities.add(iTesla);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void unregister(ITesla iTesla)
|
|
|
|
{
|
|
|
|
this.tileEntities.remove(iTesla);
|
|
|
|
}
|
|
|
|
|
2013-08-02 03:52:12 +02:00
|
|
|
public Set<ITesla> get()
|
|
|
|
{
|
|
|
|
return this.tileEntities;
|
|
|
|
}
|
2013-08-02 03:24:33 +02:00
|
|
|
}
|