Added Tesla grid

This commit is contained in:
Calclavia 2013-08-01 21:24:33 -04:00
parent 6770d6d02b
commit 9b3ca1e547
3 changed files with 102 additions and 2 deletions

View file

@ -0,0 +1,13 @@
/**
*
*/
package resonantinduction;
/**
* @author Calclavia
*
*/
public interface ITesla
{
}

View file

@ -0,0 +1,62 @@
/**
*
*/
package resonantinduction;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import net.minecraft.tileentity.TileEntity;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
/**
* @author Calclavia
*
*/
public class TeslaGrid
{
private static final TeslaGrid INSTANCE_CLIENT = new TeslaGrid();
private static final TeslaGrid INSTANCE_SERVER = new TeslaGrid();
private final Set<ITesla> tileEntities = new HashSet<ITesla>();
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);
}
public static TeslaGrid getInstance()
{
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
{
return INSTANCE_SERVER;
}
return INSTANCE_CLIENT;
}
}

View file

@ -3,13 +3,38 @@
*/
package resonantinduction.tesla;
import net.minecraft.tileentity.TileEntity;
import resonantinduction.ITesla;
import resonantinduction.TeslaGrid;
import resonantinduction.base.TileEntityBase;
/**
* @author Calclavia
*
*/
public class TileEntityTesla extends TileEntity
public class TileEntityTesla extends TileEntityBase implements ITesla
{
@Override
public void initiate()
{
TeslaGrid.getInstance().register(this);
}
@Override
public void updateEntity()
{
super.updateEntity();
}
public int getRange()
{
return 5;
}
@Override
public void invalidate()
{
TeslaGrid.getInstance().unregister(this);
super.invalidate();
}
}