From 888bd053455c5ba0f850c3a16e3f2e9b93e2b72f Mon Sep 17 00:00:00 2001 From: Robert S Date: Mon, 29 Sep 2014 15:10:58 -0400 Subject: [PATCH] Converted Fulmination generator to scala --- .../fulmination/FulminationHandler.java | 82 ------------------- .../fulmination/FulminationHandler.scala | 77 +++++++++++++++++ .../machine/fulmination/TileFulmination.java | 42 ---------- .../machine/fulmination/TileFulmination.scala | 38 +++++++++ 4 files changed, 115 insertions(+), 124 deletions(-) delete mode 100644 src/main/scala/resonantinduction/atomic/machine/fulmination/FulminationHandler.java create mode 100644 src/main/scala/resonantinduction/atomic/machine/fulmination/FulminationHandler.scala delete mode 100644 src/main/scala/resonantinduction/atomic/machine/fulmination/TileFulmination.java create mode 100644 src/main/scala/resonantinduction/atomic/machine/fulmination/TileFulmination.scala diff --git a/src/main/scala/resonantinduction/atomic/machine/fulmination/FulminationHandler.java b/src/main/scala/resonantinduction/atomic/machine/fulmination/FulminationHandler.java deleted file mode 100644 index 32f924780..000000000 --- a/src/main/scala/resonantinduction/atomic/machine/fulmination/FulminationHandler.java +++ /dev/null @@ -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 list = new ArrayList(); - - 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 avaliableGenerators = new HashSet(); - - 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); - } - } - } - } -} diff --git a/src/main/scala/resonantinduction/atomic/machine/fulmination/FulminationHandler.scala b/src/main/scala/resonantinduction/atomic/machine/fulmination/FulminationHandler.scala new file mode 100644 index 000000000..8d2026ca3 --- /dev/null +++ b/src/main/scala/resonantinduction/atomic/machine/fulmination/FulminationHandler.scala @@ -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) + } + } + } + } +} \ No newline at end of file diff --git a/src/main/scala/resonantinduction/atomic/machine/fulmination/TileFulmination.java b/src/main/scala/resonantinduction/atomic/machine/fulmination/TileFulmination.java deleted file mode 100644 index 41049b897..000000000 --- a/src/main/scala/resonantinduction/atomic/machine/fulmination/TileFulmination.java +++ /dev/null @@ -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(); - } -} diff --git a/src/main/scala/resonantinduction/atomic/machine/fulmination/TileFulmination.scala b/src/main/scala/resonantinduction/atomic/machine/fulmination/TileFulmination.scala new file mode 100644 index 000000000..c0b957f6a --- /dev/null +++ b/src/main/scala/resonantinduction/atomic/machine/fulmination/TileFulmination.scala @@ -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 + } +} \ No newline at end of file