Converted Fulmination generator to scala
This commit is contained in:
parent
7e0d7eedb8
commit
888bd05345
4 changed files with 115 additions and 124 deletions
|
@ -1,82 +0,0 @@
|
|||
package resonantinduction.atomic.machine.fulmination;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.util.Vec3;
|
||||
import resonant.api.explosion.ExplosionEvent.DoExplosionEvent;
|
||||
import resonantinduction.atomic.AtomicContent;
|
||||
import universalelectricity.core.transform.vector.Vector3;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Atomic Science Event Handling.
|
||||
*/
|
||||
public class FulminationHandler
|
||||
{
|
||||
public static final FulminationHandler INSTANCE = new FulminationHandler();
|
||||
|
||||
public static final List<TileFulmination> list = new ArrayList<TileFulmination>();
|
||||
|
||||
public void register(TileFulmination tileEntity)
|
||||
{
|
||||
if (!list.contains(tileEntity))
|
||||
{
|
||||
list.add(tileEntity);
|
||||
}
|
||||
}
|
||||
|
||||
public void unregister(TileFulmination tileEntity)
|
||||
{
|
||||
list.remove(tileEntity);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void BaoZha(DoExplosionEvent evt)
|
||||
{
|
||||
if (evt.iExplosion != null)
|
||||
{
|
||||
if (evt.iExplosion.getRadius() > 0 && evt.iExplosion.getEnergy() > 0)
|
||||
{
|
||||
HashSet<TileFulmination> avaliableGenerators = new HashSet<TileFulmination>();
|
||||
|
||||
for (TileFulmination tileEntity : FulminationHandler.list)
|
||||
{
|
||||
if (tileEntity != null)
|
||||
{
|
||||
if (!tileEntity.isInvalid())
|
||||
{
|
||||
Vector3 tileDiDian = new Vector3(tileEntity);
|
||||
tileDiDian.add(0.5f);
|
||||
double juLi = tileDiDian.distance(new Vector3(evt.x, evt.y, evt.z));
|
||||
|
||||
if (juLi <= evt.iExplosion.getRadius() && juLi > 0)
|
||||
{
|
||||
float miDu = evt.world.getBlockDensity(Vec3.createVectorHelper(evt.x, evt.y, evt.z), AtomicContent.blockFulmination().getCollisionBoundingBoxFromPool(evt.world, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord));
|
||||
|
||||
if (miDu < 1)
|
||||
{
|
||||
avaliableGenerators.add(tileEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final float totalEnergy = evt.iExplosion.getEnergy();
|
||||
final float maxEnergyPerGenerator = totalEnergy / avaliableGenerators.size();
|
||||
|
||||
for (TileFulmination tileEntity : avaliableGenerators)
|
||||
{
|
||||
float density = evt.world.getBlockDensity(Vec3.createVectorHelper(evt.x, evt.y, evt.z), AtomicContent.blockFulmination().getCollisionBoundingBoxFromPool(evt.world, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord));
|
||||
double juLi = new Vector3(tileEntity).distance(new Vector3(evt.x, evt.y, evt.z));
|
||||
|
||||
long energy = (long) Math.min(maxEnergyPerGenerator, maxEnergyPerGenerator / (juLi / evt.iExplosion.getRadius()));
|
||||
energy = (long) Math.max((1 - density) * energy, 0);
|
||||
tileEntity.energy().receiveEnergy(energy, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package resonantinduction.atomic.machine.fulmination
|
||||
|
||||
import java.util.{ArrayList, HashSet, List}
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent
|
||||
import net.minecraft.util.Vec3
|
||||
import resonant.api.explosion.ExplosionEvent
|
||||
import resonantinduction.atomic.AtomicContent
|
||||
import universalelectricity.core.transform.vector.Vector3
|
||||
|
||||
/**
|
||||
* Atomic Science Event Handling.
|
||||
*/
|
||||
object FulminationHandler
|
||||
{
|
||||
final val INSTANCE: FulminationHandler = new FulminationHandler
|
||||
final val list: List[TileFulmination] = new ArrayList[TileFulmination]
|
||||
}
|
||||
|
||||
class FulminationHandler
|
||||
{
|
||||
def register(tileEntity: TileFulmination)
|
||||
{
|
||||
if (!FulminationHandler.list.contains(tileEntity))
|
||||
{
|
||||
FulminationHandler.list.add(tileEntity)
|
||||
}
|
||||
}
|
||||
|
||||
def unregister(tileEntity: TileFulmination)
|
||||
{
|
||||
FulminationHandler.list.remove(tileEntity)
|
||||
}
|
||||
|
||||
@SubscribeEvent def BaoZha(evt: ExplosionEvent.DoExplosionEvent)
|
||||
{
|
||||
if (evt.iExplosion != null)
|
||||
{
|
||||
if (evt.iExplosion.getRadius > 0 && evt.iExplosion.getEnergy > 0)
|
||||
{
|
||||
val avaliableGenerators: HashSet[TileFulmination] = new HashSet[TileFulmination]
|
||||
import scala.collection.JavaConversions._
|
||||
for (tileEntity <- FulminationHandler.list)
|
||||
{
|
||||
if (tileEntity != null)
|
||||
{
|
||||
if (!tileEntity.isInvalid)
|
||||
{
|
||||
val tileDiDian: Vector3 = new Vector3(tileEntity)
|
||||
tileDiDian.add(0.5f)
|
||||
val juLi: Double = tileDiDian.distance(new Vector3(evt.x, evt.y, evt.z))
|
||||
if (juLi <= evt.iExplosion.getRadius && juLi > 0)
|
||||
{
|
||||
val miDu: Float = evt.world.getBlockDensity(Vec3.createVectorHelper(evt.x, evt.y, evt.z), AtomicContent.blockFulmination.getCollisionBoundingBoxFromPool(evt.world, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord))
|
||||
if (miDu < 1)
|
||||
{
|
||||
avaliableGenerators.add(tileEntity)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
val totalEnergy: Float = evt.iExplosion.getEnergy
|
||||
val maxEnergyPerGenerator: Float = totalEnergy / avaliableGenerators.size
|
||||
import scala.collection.JavaConversions._
|
||||
for (tileEntity <- avaliableGenerators)
|
||||
{
|
||||
val density: Float = evt.world.getBlockDensity(Vec3.createVectorHelper(evt.x, evt.y, evt.z), AtomicContent.blockFulmination.getCollisionBoundingBoxFromPool(evt.world, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord))
|
||||
val juLi: Double = new Vector3(tileEntity).distance(new Vector3(evt.x, evt.y, evt.z))
|
||||
var energy: Long = Math.min(maxEnergyPerGenerator, maxEnergyPerGenerator / (juLi / evt.iExplosion.getRadius)).asInstanceOf[Long]
|
||||
energy = Math.max((1 - density) * energy, 0).asInstanceOf[Long]
|
||||
tileEntity.energy.receiveEnergy(energy, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package resonantinduction.atomic.machine.fulmination;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import resonant.lib.content.prefab.java.TileElectric;
|
||||
|
||||
/**
|
||||
* Fulmination TileEntity
|
||||
*/
|
||||
public class TileFulmination extends TileElectric
|
||||
{
|
||||
private static final long DIAN = 10000000000000L;
|
||||
|
||||
public TileFulmination()
|
||||
{
|
||||
super(Material.iron);
|
||||
energy().setCapacity(DIAN * 2);
|
||||
this.blockHardness(10);
|
||||
this.blockResistance(25000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start()
|
||||
{
|
||||
super.start();
|
||||
FulminationHandler.INSTANCE.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
super.update();
|
||||
// Slowly lose energy.
|
||||
energy().extractEnergy(10, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
FulminationHandler.INSTANCE.unregister(this);
|
||||
super.start();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package resonantinduction.atomic.machine.fulmination
|
||||
|
||||
import net.minecraft.block.material.Material
|
||||
import resonant.lib.content.prefab.java.TileElectric
|
||||
|
||||
/**
|
||||
* Fulmination TileEntity
|
||||
*/
|
||||
object TileFulmination
|
||||
{
|
||||
private final val DIAN: Long = 10000000000000L
|
||||
}
|
||||
|
||||
class TileFulmination extends TileElectric(Material.iron)
|
||||
{
|
||||
//Constructor
|
||||
energy.setCapacity(TileFulmination.DIAN * 2)
|
||||
this.blockHardness(10)
|
||||
this.blockResistance(25000)
|
||||
|
||||
override def start
|
||||
{
|
||||
super.start
|
||||
FulminationHandler.INSTANCE.register(this)
|
||||
}
|
||||
|
||||
override def update
|
||||
{
|
||||
super.update
|
||||
energy.extractEnergy(10, true)
|
||||
}
|
||||
|
||||
override def invalidate
|
||||
{
|
||||
FulminationHandler.INSTANCE.unregister(this)
|
||||
super.start
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue