Added Tesla grid
This commit is contained in:
parent
6770d6d02b
commit
9b3ca1e547
3 changed files with 102 additions and 2 deletions
13
src/resonantinduction/ITesla.java
Normal file
13
src/resonantinduction/ITesla.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package resonantinduction;
|
||||
|
||||
/**
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public interface ITesla
|
||||
{
|
||||
|
||||
}
|
62
src/resonantinduction/TeslaGrid.java
Normal file
62
src/resonantinduction/TeslaGrid.java
Normal 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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue