Converted Accelerator to scala

This commit is contained in:
Robert S 2014-09-29 15:46:08 -04:00
parent 164e027319
commit dafe713123
10 changed files with 761 additions and 924 deletions

View file

@ -1,83 +0,0 @@
package resonantinduction.atomic.machine.accelerator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotFurnace;
import net.minecraft.item.ItemStack;
import resonant.lib.gui.ContainerBase;
import resonantinduction.atomic.AtomicContent;
/**
* Accelerator container
*/
public class ContainerAccelerator extends ContainerBase
{
private TileAccelerator tileEntity;
public ContainerAccelerator(EntityPlayer player, TileAccelerator tileEntity)
{
super(player, (IInventory) tileEntity);
this.tileEntity = tileEntity;
// Inputs
addSlotToContainer(new Slot((IInventory) tileEntity, 0, 132, 26));
addSlotToContainer(new Slot((IInventory) tileEntity, 1, 132, 51));
// Output
addSlotToContainer(new SlotFurnace(player, (IInventory) tileEntity, 2, 132, 75));
addSlotToContainer(new SlotFurnace(player, (IInventory) tileEntity, 3, 106, 75));
addPlayerInventory(player);
}
/**
* Called to transfer a stack from one inventory to the other eg. when shift clicking.
*/
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par1)
{
ItemStack var2 = null;
Slot var3 = (Slot) this.inventorySlots.get(par1);
if (var3 != null && var3.getHasStack())
{
ItemStack itemStack = var3.getStack();
var2 = itemStack.copy();
if (par1 > 2)
{
if (itemStack.getItem() == AtomicContent.itemCell())
{
if (!this.mergeItemStack(itemStack, 1, 2, false))
{
return null;
}
}
else if (!this.mergeItemStack(itemStack, 0, 1, false))
{
return null;
}
}
else if (!this.mergeItemStack(itemStack, 3, 36 + 3, false))
{
return null;
}
if (itemStack.stackSize == 0)
{
var3.putStack((ItemStack) null);
}
else
{
var3.onSlotChanged();
}
if (itemStack.stackSize == var2.stackSize)
{
return null;
}
var3.onPickupFromSlot(par1EntityPlayer, itemStack);
}
return var2;
}
}

View file

@ -0,0 +1,66 @@
package resonantinduction.atomic.machine.accelerator
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.inventory.{IInventory, Slot, SlotFurnace}
import net.minecraft.item.ItemStack
import resonant.lib.gui.ContainerBase
import resonantinduction.atomic.AtomicContent
/**
* Accelerator container
*/
class ContainerAccelerator(player: EntityPlayer, tileEntity: TileAccelerator) extends ContainerBase(player, tileEntity.asInstanceOf[IInventory])
{
//Constructor
addSlotToContainer(new Slot(tileEntity.asInstanceOf[IInventory], 0, 132, 26))
addSlotToContainer(new Slot(tileEntity.asInstanceOf[IInventory], 1, 132, 51))
addSlotToContainer(new SlotFurnace(player, tileEntity.asInstanceOf[IInventory], 2, 132, 75))
addSlotToContainer(new SlotFurnace(player, tileEntity.asInstanceOf[IInventory], 3, 106, 75))
addPlayerInventory(player)
/**
* Called to transfer a stack from one inventory to the other eg. when shift clicking.
*/
override def transferStackInSlot(par1EntityPlayer: EntityPlayer, par1: Int): ItemStack =
{
var var2: ItemStack = null
val var3: Slot = this.inventorySlots.get(par1).asInstanceOf[Slot]
if (var3 != null && var3.getHasStack)
{
val itemStack: ItemStack = var3.getStack
var2 = itemStack.copy
if (par1 > 2)
{
if (itemStack.getItem eq AtomicContent.itemCell)
{
if (!this.mergeItemStack(itemStack, 1, 2, false))
{
return null
}
}
else if (!this.mergeItemStack(itemStack, 0, 1, false))
{
return null
}
}
else if (!this.mergeItemStack(itemStack, 3, 36 + 3, false))
{
return null
}
if (itemStack.stackSize == 0)
{
var3.putStack(null.asInstanceOf[ItemStack])
}
else
{
var3.onSlotChanged
}
if (itemStack.stackSize == var2.stackSize)
{
return null
}
var3.onPickupFromSlot(par1EntityPlayer, itemStack)
}
return var2
}
}

View file

@ -1,329 +0,0 @@
package resonantinduction.atomic.machine.accelerator;
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeChunkManager;
import net.minecraftforge.common.ForgeChunkManager.Ticket;
import net.minecraftforge.common.ForgeChunkManager.Type;
import net.minecraftforge.common.util.ForgeDirection;
import resonant.api.IElectromagnet;
import resonant.lib.prefab.poison.PoisonRadiation;
import resonantinduction.atomic.Atomic;
import resonantinduction.core.Reference;
import universalelectricity.core.transform.vector.Vector3;
import java.util.List;
/**
* The particle entity used to determine the particle acceleration.
*/
public class EntityParticle extends Entity implements IEntityAdditionalSpawnData
{
private static final int MOVE_TICK_RATE = 20;
public Ticket updateTicket;
public boolean didParticleCollide = false;
private int lastTurn = 60;
private Vector3 movementVector = new Vector3();
private ForgeDirection movementDirection = ForgeDirection.NORTH;
public EntityParticle(World par1World)
{
super(par1World);
this.setSize(0.3f, 0.3f);
this.renderDistanceWeight = 4f;
this.ignoreFrustumCheck = true;
}
public EntityParticle(World world, Vector3 pos, Vector3 movementVec, ForgeDirection dir)
{
this(world);
this.setPosition(pos.x(), pos.y(), pos.z());
this.movementVector = movementVec;
this.movementDirection = dir;
}
public static boolean canSpawnParticle(World world, Vector3 pos)
{
Block block = pos.getBlock(world);
if (block != null && !block.isAir(world, pos.xi(), pos.yi(), pos.zi()))
{
return false;
}
for (int i = 0; i <= 1; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
if (!isElectromagnet(world, pos, dir))
{
return false;
}
}
return true;
}
public static boolean isElectromagnet(World world, Vector3 position, ForgeDirection dir)
{
Vector3 checkPos = position.clone().add(dir);
TileEntity tile = checkPos.getTileEntity(world);
if (tile instanceof IElectromagnet)
{
return ((IElectromagnet) tile).isRunning();
}
return false;
}
@Override
public void writeSpawnData(ByteBuf data)
{
data.writeInt(this.movementVector.xi());
data.writeInt(this.movementVector.yi());
data.writeInt(this.movementVector.zi());
data.writeInt(this.movementDirection.ordinal());
}
@Override
public void readSpawnData(ByteBuf data)
{
this.movementVector = new Vector3(data);
this.movementDirection = ForgeDirection.getOrientation(data.readInt());
}
@Override
protected void entityInit()
{
this.dataWatcher.addObject(MOVE_TICK_RATE, (byte) 3);
if (this.updateTicket == null)
{
this.updateTicket = ForgeChunkManager.requestTicket(Atomic.INSTANCE(), this.worldObj, Type.ENTITY);
this.updateTicket.getModData();
this.updateTicket.bindEntity(this);
}
}
@Override
public void onUpdate()
{
/** Play sound fxs. */
if (this.ticksExisted % 10 == 0)
{
this.worldObj.playSoundAtEntity(this, Reference.prefix() + "accelerator", 1f, (float) (0.6f + (0.4 * (this.getParticleVelocity() / TileAccelerator.clientParticleVelocity))));
}
/** Check if the accelerator tile entity exists. */
TileEntity t = this.worldObj.getTileEntity(this.movementVector.xi(), this.movementVector.yi(), this.movementVector.zi());
if (!(t instanceof TileAccelerator))
{
setDead();
return;
}
TileAccelerator tileEntity = (TileAccelerator) t;
if (tileEntity.entityParticle == null)
{
tileEntity.entityParticle = this;
}
for (int x = -1; x < 1; x++)
{
for (int z = -1; z < 1; z++)
{
ForgeChunkManager.forceChunk(this.updateTicket, new ChunkCoordIntPair(((int) this.posX >> 4) + x, ((int) this.posZ >> 4) + z));
}
}
try
{
if (!this.worldObj.isRemote)
{
this.dataWatcher.updateObject(MOVE_TICK_RATE, (byte) this.movementDirection.ordinal());
}
else
{
this.movementDirection = ForgeDirection.getOrientation(this.dataWatcher.getWatchableObjectByte(MOVE_TICK_RATE));
}
}
catch (Exception e)
{
e.printStackTrace();
}
double acceleration = 0.0006f;
if ((!isElectromagnet(worldObj, new Vector3(this), movementDirection.getRotation(ForgeDirection.UP)) || !isElectromagnet(worldObj, new Vector3(this), movementDirection.getRotation(ForgeDirection.DOWN))) && this.lastTurn <= 0)
{
acceleration = turn();
this.motionX = 0;
this.motionY = 0;
this.motionZ = 0;
this.lastTurn = 40;
}
this.lastTurn--;
/** Checks if the current block condition allows the particle to exist */
if (!canSpawnParticle(this.worldObj, new Vector3(this)) || this.isCollided)
{
explode();
return;
}
Vector3 dongLi = new Vector3();
dongLi.add(this.movementDirection);
dongLi.multiply(acceleration);
this.motionX = Math.min(dongLi.x() + this.motionX, TileAccelerator.clientParticleVelocity);
this.motionY = Math.min(dongLi.y() + this.motionY, TileAccelerator.clientParticleVelocity);
this.motionZ = Math.min(dongLi.z() + this.motionZ, TileAccelerator.clientParticleVelocity);
this.isAirBorne = true;
this.lastTickPosX = this.posX;
this.lastTickPosY = this.posY;
this.lastTickPosZ = this.posZ;
this.moveEntity(this.motionX, this.motionY, this.motionZ);
this.setPosition(this.posX, this.posY, this.posZ);
if (this.lastTickPosX == this.posX && this.lastTickPosY == this.posY && this.lastTickPosZ == this.posZ && this.getParticleVelocity() <= 0 && this.lastTurn <= 0)
{
this.setDead();
}
this.worldObj.spawnParticle("portal", this.posX, this.posY, this.posZ, 0, 0, 0);
this.worldObj.spawnParticle("largesmoke", this.posX, this.posY, this.posZ, 0, 0, 0);
float radius = 0.5f;
AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(this.posX - radius, this.posY - radius, this.posZ - radius, this.posX + radius, this.posY + radius, this.posZ + radius);
List<Entity> entitiesNearby = this.worldObj.getEntitiesWithinAABB(Entity.class, bounds);
if (entitiesNearby.size() > 1)
{
this.explode();
return;
}
}
/**
* Try to move the particle left or right depending on which side is empty.
*
* @return The new velocity.
*/
private double turn()
{
int[][] RELATIVE_MATRIX = { { 3, 2, 1, 0, 5, 4 }, { 4, 5, 0, 1, 2, 3 }, { 0, 1, 3, 2, 4, 5 }, { 0, 1, 2, 3, 5, 4 }, { 0, 1, 5, 4, 3, 2 }, { 0, 1, 4, 5, 2, 3 } };
ForgeDirection zuoFangXiang = ForgeDirection.getOrientation(RELATIVE_MATRIX[this.movementDirection.ordinal()][ForgeDirection.EAST.ordinal()]);
Vector3 zuoBian = new Vector3(this).floor();
zuoBian.add(zuoFangXiang);
ForgeDirection youFangXiang = ForgeDirection.getOrientation(RELATIVE_MATRIX[this.movementDirection.ordinal()][ForgeDirection.WEST.ordinal()]);
Vector3 youBian = new Vector3(this).floor();
youBian.add(youFangXiang);
if (zuoBian.getBlock(this.worldObj) == null)
{
this.movementDirection = zuoFangXiang;
}
else if (youBian.getBlock(this.worldObj) == null)
{
this.movementDirection = youFangXiang;
}
else
{
setDead();
return 0;
}
this.setPosition(Math.floor(this.posX) + 0.5, Math.floor(this.posY) + 0.5, Math.floor(this.posZ) + 0.5);
return this.getParticleVelocity() - (this.getParticleVelocity() / Math.min(Math.max(70 * this.getParticleVelocity(), 4), 30));
}
public void explode()
{
this.worldObj.playSoundAtEntity(this, Reference.prefix() + "antimatter", 1.5f, 1f - this.worldObj.rand.nextFloat() * 0.3f);
if (!this.worldObj.isRemote)
{
if (this.getParticleVelocity() > TileAccelerator.clientParticleVelocity / 2)
{
/* Check for nearby particles and if colliding with another one, drop strange matter. */
float radius = 1f;
AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(this.posX - radius, this.posY - radius, this.posZ - radius, this.posX + radius, this.posY + radius, this.posZ + radius);
List<EntityParticle> entitiesNearby = this.worldObj.getEntitiesWithinAABB(EntityParticle.class, bounds);
if (entitiesNearby.size() > 0)
{
didParticleCollide = true;
setDead();
return;
}
}
this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, (float) this.getParticleVelocity() * 2.5f, true);
}
float radius = 6;
AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(this.posX - radius, this.posY - radius, this.posZ - radius, this.posX + radius, this.posY + radius, this.posZ + radius);
List<EntityLiving> livingNearby = this.worldObj.getEntitiesWithinAABB(EntityLiving.class, bounds);
for (EntityLiving entity : livingNearby)
{
PoisonRadiation.INSTANCE.poisonEntity(new Vector3(entity), entity);
}
setDead();
}
public double getParticleVelocity()
{
return Math.abs(this.motionX) + Math.abs(this.motionY) + Math.abs(this.motionZ);
}
@Override
public void applyEntityCollision(Entity par1Entity)
{
this.explode();
}
@Override
public void setDead()
{
ForgeChunkManager.releaseTicket(this.updateTicket);
super.setDead();
}
@Override
protected void readEntityFromNBT(NBTTagCompound nbt)
{
this.movementVector = new Vector3(nbt.getCompoundTag("jiqi"));
ForgeDirection.getOrientation(nbt.getByte("fangXiang"));
}
@Override
protected void writeEntityToNBT(NBTTagCompound nbt)
{
nbt.setTag("jiqi", this.movementVector.writeNBT(new NBTTagCompound()));
nbt.setByte("fangXiang", (byte) this.movementDirection.ordinal());
}
}

View file

@ -0,0 +1,280 @@
package resonantinduction.atomic.machine.accelerator
import java.util.List
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData
import io.netty.buffer.ByteBuf
import net.minecraft.block.Block
import net.minecraft.entity.{Entity, EntityLiving}
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.tileentity.TileEntity
import net.minecraft.util.AxisAlignedBB
import net.minecraft.world.{ChunkCoordIntPair, World}
import net.minecraftforge.common.ForgeChunkManager
import net.minecraftforge.common.ForgeChunkManager.Type
import net.minecraftforge.common.util.ForgeDirection
import resonant.api.IElectromagnet
import resonant.lib.prefab.poison.PoisonRadiation
import resonantinduction.atomic.Atomic
import resonantinduction.core.Reference
import universalelectricity.core.transform.vector.Vector3
import scala.collection.JavaConversions._
/**
* The particle entity used to determine the particle acceleration.
*/
object EntityParticle
{
def canSpawnParticle(world: World, pos: Vector3): Boolean =
{
val block: Block = pos.getBlock(world)
if (block != null && !block.isAir(world, pos.xi, pos.yi, pos.zi))
{
return false
}
for (i <- 0 to 1)
{
val dir: ForgeDirection = ForgeDirection.getOrientation(i)
if (!isElectromagnet(world, pos, dir))
{
return false
}
}
return true
}
def isElectromagnet(world: World, position: Vector3, dir: ForgeDirection): Boolean =
{
val checkPos: Vector3 = position.clone.add(dir)
val tile: TileEntity = checkPos.getTileEntity(world)
if (tile.isInstanceOf[IElectromagnet])
{
return (tile.asInstanceOf[IElectromagnet]).isRunning
}
return false
}
private final val MOVE_TICK_RATE: Int = 20
}
class EntityParticle(par1World: World) extends Entity(par1World) with IEntityAdditionalSpawnData
{
//Default Constructor
this.setSize(0.3f, 0.3f)
this.renderDistanceWeight = 4f
this.ignoreFrustumCheck = true
def this(world: World, pos: Vector3, movementVec: Vector3, dir: ForgeDirection)
{
this(world)
this.setPosition(pos.x, pos.y, pos.z)
this.movementVector = movementVec
this.movementDirection = dir
}
def writeSpawnData(data: ByteBuf)
{
data.writeInt(this.movementVector.xi)
data.writeInt(this.movementVector.yi)
data.writeInt(this.movementVector.zi)
data.writeInt(this.movementDirection.ordinal)
}
def readSpawnData(data: ByteBuf)
{
this.movementVector = new Vector3(data)
this.movementDirection = ForgeDirection.getOrientation(data.readInt)
}
protected def entityInit
{
this.dataWatcher.addObject(EntityParticle.MOVE_TICK_RATE, 3.asInstanceOf[Byte])
if (this.updateTicket == null)
{
this.updateTicket = ForgeChunkManager.requestTicket(Atomic.INSTANCE, this.worldObj, Type.ENTITY)
this.updateTicket.getModData
this.updateTicket.bindEntity(this)
}
}
override def onUpdate
{
if (this.ticksExisted % 10 == 0)
{
this.worldObj.playSoundAtEntity(this, Reference.prefix + "accelerator", 1f, (0.6f + (0.4 * (this.getParticleVelocity / TileAccelerator.clientParticleVelocity))).asInstanceOf[Float])
}
val t: TileEntity = this.worldObj.getTileEntity(this.movementVector.xi, this.movementVector.yi, this.movementVector.zi)
if (!(t.isInstanceOf[TileAccelerator]))
{
setDead
return
}
val tileEntity: TileAccelerator = t.asInstanceOf[TileAccelerator]
if (tileEntity.entityParticle == null)
{
tileEntity.entityParticle = this
}
for (x <- -1 to 1)
{
for (z <- -1 to 1)
{
ForgeChunkManager.forceChunk(this.updateTicket, new ChunkCoordIntPair((this.posX.asInstanceOf[Int] >> 4) + x, (this.posZ.asInstanceOf[Int] >> 4) + z))
}
}
try
{
if (!this.worldObj.isRemote)
{
this.dataWatcher.updateObject(EntityParticle.MOVE_TICK_RATE, this.movementDirection.ordinal.asInstanceOf[Byte])
}
else
{
this.movementDirection = ForgeDirection.getOrientation(this.dataWatcher.getWatchableObjectByte(EntityParticle.MOVE_TICK_RATE))
}
}
catch
{
case e: Exception =>
{
e.printStackTrace
}
}
var acceleration: Double = 0.0006f
if ((!EntityParticle.isElectromagnet(worldObj, new Vector3(this), movementDirection.getRotation(ForgeDirection.UP)) || !EntityParticle.isElectromagnet(worldObj, new Vector3(this), movementDirection.getRotation(ForgeDirection.DOWN))) && this.lastTurn <= 0)
{
acceleration = turn
this.motionX = 0
this.motionY = 0
this.motionZ = 0
this.lastTurn = 40
}
this.lastTurn -= 1
if (!EntityParticle.canSpawnParticle(this.worldObj, new Vector3(this)) || this.isCollided)
{
explode
return
}
val dongLi: Vector3 = new Vector3
dongLi.add(this.movementDirection)
dongLi.multiply(acceleration)
this.motionX = Math.min(dongLi.x + this.motionX, TileAccelerator.clientParticleVelocity)
this.motionY = Math.min(dongLi.y + this.motionY, TileAccelerator.clientParticleVelocity)
this.motionZ = Math.min(dongLi.z + this.motionZ, TileAccelerator.clientParticleVelocity)
this.isAirBorne = true
this.lastTickPosX = this.posX
this.lastTickPosY = this.posY
this.lastTickPosZ = this.posZ
this.moveEntity(this.motionX, this.motionY, this.motionZ)
this.setPosition(this.posX, this.posY, this.posZ)
if (this.lastTickPosX == this.posX && this.lastTickPosY == this.posY && this.lastTickPosZ == this.posZ && this.getParticleVelocity <= 0 && this.lastTurn <= 0)
{
this.setDead
}
this.worldObj.spawnParticle("portal", this.posX, this.posY, this.posZ, 0, 0, 0)
this.worldObj.spawnParticle("largesmoke", this.posX, this.posY, this.posZ, 0, 0, 0)
val radius: Float = 0.5f
val bounds: AxisAlignedBB = AxisAlignedBB.getBoundingBox(this.posX - radius, this.posY - radius, this.posZ - radius, this.posX + radius, this.posY + radius, this.posZ + radius)
val entitiesNearby: List[_] = this.worldObj.getEntitiesWithinAABB(classOf[Entity], bounds)
if (entitiesNearby.size > 1)
{
this.explode
return
}
}
/**
* Try to move the particle left or right depending on which side is empty.
*
* @return The new velocity.
*/
private def turn: Double =
{
val RELATIVE_MATRIX: Array[Array[Int]] = Array(Array(3, 2, 1, 0, 5, 4), Array(4, 5, 0, 1, 2, 3), Array(0, 1, 3, 2, 4, 5), Array(0, 1, 2, 3, 5, 4), Array(0, 1, 5, 4, 3, 2), Array(0, 1, 4, 5, 2, 3))
val zuoFangXiang: ForgeDirection = ForgeDirection.getOrientation(RELATIVE_MATRIX(this.movementDirection.ordinal)(ForgeDirection.EAST.ordinal))
val zuoBian: Vector3 = new Vector3(this).floor
zuoBian.add(zuoFangXiang)
val youFangXiang: ForgeDirection = ForgeDirection.getOrientation(RELATIVE_MATRIX(this.movementDirection.ordinal)(ForgeDirection.WEST.ordinal))
val youBian: Vector3 = new Vector3(this).floor
youBian.add(youFangXiang)
if (zuoBian.getBlock(this.worldObj) == null)
{
this.movementDirection = zuoFangXiang
}
else if (youBian.getBlock(this.worldObj) == null)
{
this.movementDirection = youFangXiang
}
else
{
setDead
return 0
}
this.setPosition(Math.floor(this.posX) + 0.5, Math.floor(this.posY) + 0.5, Math.floor(this.posZ) + 0.5)
return this.getParticleVelocity - (this.getParticleVelocity / Math.min(Math.max(70 * this.getParticleVelocity, 4), 30))
}
def explode
{
this.worldObj.playSoundAtEntity(this, Reference.prefix + "antimatter", 1.5f, 1f - this.worldObj.rand.nextFloat * 0.3f)
if (!this.worldObj.isRemote)
{
if (this.getParticleVelocity > TileAccelerator.clientParticleVelocity / 2)
{
val radius: Float = 1f
val bounds: AxisAlignedBB = AxisAlignedBB.getBoundingBox(this.posX - radius, this.posY - radius, this.posZ - radius, this.posX + radius, this.posY + radius, this.posZ + radius)
val entitiesNearby: List[_] = this.worldObj.getEntitiesWithinAABB(classOf[EntityParticle], bounds)
if (entitiesNearby.size > 0)
{
didParticleCollide = true
setDead
return
}
}
this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, this.getParticleVelocity.asInstanceOf[Float] * 2.5f, true)
}
val radius: Float = 6
val bounds: AxisAlignedBB = AxisAlignedBB.getBoundingBox(this.posX - radius, this.posY - radius, this.posZ - radius, this.posX + radius, this.posY + radius, this.posZ + radius)
val livingNearby: List[_] = this.worldObj.getEntitiesWithinAABB(classOf[EntityLiving], bounds)
for (entity <- livingNearby)
{
PoisonRadiation.INSTANCE.poisonEntity(new Vector3(entity.asInstanceOf[Entity]), entity.asInstanceOf[EntityLiving])
}
setDead
}
def getParticleVelocity: Double =
{
return Math.abs(this.motionX) + Math.abs(this.motionY) + Math.abs(this.motionZ)
}
override def applyEntityCollision(par1Entity: Entity)
{
this.explode
}
override def setDead
{
ForgeChunkManager.releaseTicket(this.updateTicket)
super.setDead
}
protected def readEntityFromNBT(nbt: NBTTagCompound)
{
this.movementVector = new Vector3(nbt.getCompoundTag("jiqi"))
ForgeDirection.getOrientation(nbt.getByte("fangXiang"))
}
protected def writeEntityToNBT(nbt: NBTTagCompound)
{
nbt.setTag("jiqi", this.movementVector.writeNBT(new NBTTagCompound))
nbt.setByte("fangXiang", this.movementDirection.ordinal.asInstanceOf[Byte])
}
var updateTicket: ForgeChunkManager.Ticket = null
var didParticleCollide: Boolean = false
private var lastTurn: Int = 60
private var movementVector: Vector3 = new Vector3
private var movementDirection: ForgeDirection = ForgeDirection.NORTH
}

View file

@ -1,73 +0,0 @@
package resonantinduction.atomic.machine.accelerator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.util.ForgeDirection;
import resonant.lib.gui.GuiContainerBase;
import universalelectricity.api.UnitDisplay;
import universalelectricity.core.transform.vector.Vector3;
public class GuiAccelerator extends GuiContainerBase
{
private TileAccelerator tileEntity;
private int containerWidth;
private int containerHeight;
public GuiAccelerator(EntityPlayer player, TileAccelerator tileEntity)
{
super(new ContainerAccelerator(player, tileEntity));
this.tileEntity = tileEntity;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items)
*/
@Override
public void drawGuiContainerForegroundLayer(int x, int y)
{
this.fontRendererObj.drawString("Accelerator", 40, 10, 4210752);
String status = "";
Vector3 position = new Vector3(this.tileEntity);
position.add(this.tileEntity.getDirection().getOpposite());
if (!EntityParticle.canSpawnParticle(this.tileEntity.world(), position))
{
status = "\u00a74Fail to emit; try rotating.";
}
else if (this.tileEntity.entityParticle != null && this.tileEntity.velocity > 0)
{
status = "\u00a76Accelerating";
}
else
{
status = "\u00a72Idle";
}
this.fontRendererObj.drawString("Velocity: " + Math.round((this.tileEntity.velocity / TileAccelerator.clientParticleVelocity) * 100) + "%", 8, 27, 4210752);
this.fontRendererObj.drawString("Energy Used:", 8, 38, 4210752);
this.fontRendererObj.drawString(new UnitDisplay(UnitDisplay.Unit.JOULES, this.tileEntity.totalEnergyConsumed).toString(), 8, 49, 4210752);
this.fontRendererObj.drawString(new UnitDisplay(UnitDisplay.Unit.WATT, TileAccelerator.energyPerTick * 20).toString(), 8, 60, 4210752);
this.fontRendererObj.drawString("N?A", 8, 70, 4210752);
this.fontRendererObj.drawString("Antimatter: " + this.tileEntity.antimatter + " mg", 8, 80, 4210752);
this.fontRendererObj.drawString("Status:", 8, 90, 4210752);
this.fontRendererObj.drawString(status, 8, 100, 4210752);
this.fontRendererObj.drawString("Buffer: " + this.tileEntity.electricNode().getEnergy(ForgeDirection.UNKNOWN) + "/" + new UnitDisplay(UnitDisplay.Unit.JOULES, this.tileEntity.electricNode().getEnergyCapacity(ForgeDirection.UNKNOWN), true), 8, 110,
4210752);
this.fontRendererObj.drawString("Facing: " + this.tileEntity.getDirection().getOpposite(), 100, 123, 4210752);
}
/**
* Draw the background layer for the GuiContainer (everything behind the items)
*/
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int x, int y)
{
super.drawGuiContainerBackgroundLayer(par1, x, y);
this.drawSlot(131, 25);
this.drawSlot(131, 50);
this.drawSlot(131, 74);
this.drawSlot(105, 74);
}
}

View file

@ -0,0 +1,55 @@
package resonantinduction.atomic.machine.accelerator
import net.minecraft.entity.player.EntityPlayer
import resonant.lib.gui.GuiContainerBase
import universalelectricity.api.UnitDisplay
import universalelectricity.core.transform.vector.Vector3
class GuiAccelerator(player: EntityPlayer, tileEntity: TileAccelerator) extends GuiContainerBase(new ContainerAccelerator(player, tileEntity))
{
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items)
*/
override def drawGuiContainerForegroundLayer(x: Int, y: Int)
{
this.fontRendererObj.drawString("Accelerator", 40, 10, 4210752)
var status: String = ""
val position: Vector3 = new Vector3(this.tileEntity)
position.add(this.tileEntity.getDirection.getOpposite)
if (!EntityParticle.canSpawnParticle(this.tileEntity.world, position))
{
status = "\u00a74Fail to emit; try rotating."
}
else if (this.tileEntity.entityParticle != null && this.tileEntity.velocity > 0)
{
status = "\u00a76Accelerating"
}
else
{
status = "\u00a72Idle"
}
this.fontRendererObj.drawString("Velocity: " + Math.round((this.tileEntity.velocity / TileAccelerator.clientParticleVelocity) * 100) + "%", 8, 27, 4210752)
this.fontRendererObj.drawString("Energy Used:", 8, 38, 4210752)
this.fontRendererObj.drawString(new UnitDisplay(UnitDisplay.Unit.JOULES, this.tileEntity.totalEnergyConsumed).toString, 8, 49, 4210752)
this.fontRendererObj.drawString(new UnitDisplay(UnitDisplay.Unit.WATT, TileAccelerator.energyPerTick * 20).toString, 8, 60, 4210752)
this.fontRendererObj.drawString("N?A", 8, 70, 4210752)
this.fontRendererObj.drawString("Antimatter: " + this.tileEntity.antimatter + " mg", 8, 80, 4210752)
this.fontRendererObj.drawString("Status:", 8, 90, 4210752)
this.fontRendererObj.drawString(status, 8, 100, 4210752)
this.fontRendererObj.drawString("Buffer: " + this.tileEntity.energy.getEnergy + "/" + new UnitDisplay(UnitDisplay.Unit.JOULES, this.tileEntity.energy.getEnergyCapacity, true), 8, 110, 4210752)
this.fontRendererObj.drawString("Facing: " + this.tileEntity.getDirection.getOpposite, 100, 123, 4210752)
}
/**
* Draw the background layer for the GuiContainer (everything behind the items)
*/
protected override def drawGuiContainerBackgroundLayer(par1: Float, x: Int, y: Int)
{
super.drawGuiContainerBackgroundLayer(par1, x, y)
this.drawSlot(131, 25)
this.drawSlot(131, 50)
this.drawSlot(131, 74)
this.drawSlot(105, 74)
}
}

View file

@ -1,93 +0,0 @@
package resonantinduction.atomic.machine.accelerator;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import java.util.Random;
@SideOnly(Side.CLIENT)
public class RenderParticle extends Render
{
@Override
public void doRender(Entity entity, double x, double y, double z, float var8, float var9)
{
Tessellator tessellator = Tessellator.instance;
/** Enderdragon Light */
float par2 = (entity.ticksExisted);
while (par2 > 200)
{
par2 -= 100;
}
RenderHelper.disableStandardItemLighting();
float var41 = (5 + par2) / 200.0F;
float var51 = 0.0F;
if (var41 > 0.8F)
{
var51 = (var41 - 0.8F) / 0.2F;
}
Random rand = new Random(432L);
GL11.glPushMatrix();
GL11.glTranslatef((float) x, (float) y, (float) z);
GL11.glScalef(0.15f, 0.15f, 0.15f);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glDepthMask(false);
GL11.glPushMatrix();
GL11.glTranslatef(0.0F, -1.0F, -2.0F);
for (int i1 = 0; i1 < (var41 + var41 * var41) / 2.0F * 60.0F; ++i1)
{
GL11.glRotatef(rand.nextFloat() * 360.0F, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(rand.nextFloat() * 360.0F, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(rand.nextFloat() * 360.0F, 0.0F, 0.0F, 1.0F);
GL11.glRotatef(rand.nextFloat() * 360.0F, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(rand.nextFloat() * 360.0F, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(rand.nextFloat() * 360.0F + var41 * 90.0F, 0.0F, 0.0F, 1.0F);
tessellator.startDrawing(6);
float var81 = rand.nextFloat() * 20.0F + 5.0F + var51 * 10.0F;
float var91 = rand.nextFloat() * 2.0F + 1.0F + var51 * 2.0F;
tessellator.setColorRGBA_I(16777215, (int) (255.0F * (1.0F - var51)));
tessellator.addVertex(0.0D, 0.0D, 0.0D);
tessellator.setColorRGBA_I(0, 0);
tessellator.addVertex(-0.866D * var91, var81, -0.5F * var91);
tessellator.addVertex(0.866D * var91, var81, -0.5F * var91);
tessellator.addVertex(0.0D, var81, 1.0F * var91);
tessellator.addVertex(-0.866D * var91, var81, -0.5F * var91);
tessellator.draw();
}
GL11.glPopMatrix();
GL11.glDepthMask(true);
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glDisable(GL11.GL_BLEND);
GL11.glShadeModel(GL11.GL_FLAT);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_ALPHA_TEST);
RenderHelper.enableStandardItemLighting();
GL11.glPopMatrix();
}
@Override
protected ResourceLocation getEntityTexture(Entity entity)
{
return null;
}
}

View file

@ -0,0 +1,79 @@
package resonantinduction.atomic.machine.accelerator
import java.util.Random
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.minecraft.client.renderer.{RenderHelper, Tessellator}
import net.minecraft.client.renderer.entity.Render
import net.minecraft.entity.Entity
import net.minecraft.util.ResourceLocation
import org.lwjgl.opengl.GL11
@SideOnly(Side.CLIENT) class RenderParticle extends Render
{
def doRender(entity: Entity, x: Double, y: Double, z: Double, var8: Float, var9: Float)
{
val tessellator: Tessellator = Tessellator.instance
var par2: Float = (entity.ticksExisted)
while (par2 > 200)
{
par2 -= 100
}
RenderHelper.disableStandardItemLighting
val var41: Float = (5 + par2) / 200.0F
var var51: Float = 0.0F
if (var41 > 0.8F)
{
var51 = (var41 - 0.8F) / 0.2F
}
val rand: Random = new Random(432L)
GL11.glPushMatrix
GL11.glTranslatef(x.asInstanceOf[Float], y.asInstanceOf[Float], z.asInstanceOf[Float])
GL11.glScalef(0.15f, 0.15f, 0.15f)
GL11.glDisable(GL11.GL_TEXTURE_2D)
GL11.glShadeModel(GL11.GL_SMOOTH)
GL11.glEnable(GL11.GL_BLEND)
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE)
GL11.glDisable(GL11.GL_ALPHA_TEST)
GL11.glEnable(GL11.GL_CULL_FACE)
GL11.glDepthMask(false)
GL11.glPushMatrix
GL11.glTranslatef(0.0F, -1.0F, -2.0F)
for (i1 <- 0 to ((var41 + var41 * var41) / 2.0F * 60.0F).asInstanceOf[Int])
{
GL11.glRotatef(rand.nextFloat * 360.0F, 1.0F, 0.0F, 0.0F)
GL11.glRotatef(rand.nextFloat * 360.0F, 0.0F, 1.0F, 0.0F)
GL11.glRotatef(rand.nextFloat * 360.0F, 0.0F, 0.0F, 1.0F)
GL11.glRotatef(rand.nextFloat * 360.0F, 1.0F, 0.0F, 0.0F)
GL11.glRotatef(rand.nextFloat * 360.0F, 0.0F, 1.0F, 0.0F)
GL11.glRotatef(rand.nextFloat * 360.0F + var41 * 90.0F, 0.0F, 0.0F, 1.0F)
tessellator.startDrawing(6)
val var81: Float = rand.nextFloat * 20.0F + 5.0F + var51 * 10.0F
val var91: Float = rand.nextFloat * 2.0F + 1.0F + var51 * 2.0F
tessellator.setColorRGBA_I(16777215, (255.0F * (1.0F - var51)).asInstanceOf[Int])
tessellator.addVertex(0.0D, 0.0D, 0.0D)
tessellator.setColorRGBA_I(0, 0)
tessellator.addVertex(-0.866D * var91, var81, -0.5F * var91)
tessellator.addVertex(0.866D * var91, var81, -0.5F * var91)
tessellator.addVertex(0.0D, var81, 1.0F * var91)
tessellator.addVertex(-0.866D * var91, var81, -0.5F * var91)
tessellator.draw
}
GL11.glPopMatrix
GL11.glDepthMask(true)
GL11.glDisable(GL11.GL_CULL_FACE)
GL11.glDisable(GL11.GL_BLEND)
GL11.glShadeModel(GL11.GL_FLAT)
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F)
GL11.glEnable(GL11.GL_TEXTURE_2D)
GL11.glEnable(GL11.GL_ALPHA_TEST)
RenderHelper.enableStandardItemLighting
GL11.glPopMatrix
}
protected def getEntityTexture(entity: Entity): ResourceLocation =
{
return null
}
}

View file

@ -1,346 +0,0 @@
package resonantinduction.atomic.machine.accelerator;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.Packet;
import net.minecraftforge.common.util.ForgeDirection;
import resonant.api.IElectromagnet;
import resonant.api.IRotatable;
import resonant.engine.ResonantEngine;
import resonant.lib.content.prefab.java.TileElectricInventory;
import resonant.lib.network.Synced;
import resonant.lib.network.discriminator.PacketAnnotation;
import resonant.lib.utility.BlockUtility;
import resonantinduction.atomic.Atomic;
import resonantinduction.atomic.AtomicContent;
import resonantinduction.atomic.items.ItemAntimatter;
import resonantinduction.core.Reference;
import resonantinduction.core.Settings;
import universalelectricity.core.transform.vector.Vector3;
/**
* Accelerator TileEntity
*/
public class TileAccelerator extends TileElectricInventory implements IElectromagnet, IRotatable
{
/**
* Joules required per ticks.
*/
public static final int energyPerTick = 4800000;
/**
* User client side to determine the velocity of the particle.
*/
public static final float clientParticleVelocity = 0.9f;
private static final int DENSITY_MULTIPLYER_DEFAULT = 1;
/**
* Multiplier that is used to give extra anti-matter based on density (hardness) of a given ore.
*/
private int antiMatterDensityMultiplyer = DENSITY_MULTIPLYER_DEFAULT;
/**
* The total amount of energy consumed by this particle. In Joules.
*/
@Synced
public float totalEnergyConsumed = 0;
/**
* The amount of anti-matter stored within the accelerator. Measured in milligrams.
*/
@Synced
public int antimatter;
public EntityParticle entityParticle;
@Synced
public float velocity;
@Synced
private double clientEnergy = 0;
private int lastSpawnTick = 0;
public TileAccelerator()
{
super(Material.iron);
this.setSizeInventory(4);
antiMatterDensityMultiplyer = DENSITY_MULTIPLYER_DEFAULT;
}
@Override
public void update()
{
super.update();
if (!worldObj.isRemote)
{
clientEnergy = energy().getEnergy();
velocity = 0;
// Calculate accelerated particle velocity if it is spawned.
if (entityParticle != null)
{
velocity = (float) entityParticle.getParticleVelocity();
}
// Check if item inside of empty cell slot is indeed an empty slot.
if (Atomic.isItemStackEmptyCell(getStackInSlot(1)))
{
// Check if there are any empty cells we can store anti-matter in.
if (getStackInSlot(1).stackSize > 0)
{
// Craft anti-matter item if there is enough anti-matter to actually do so.
if (antimatter >= 125)
{
if (getStackInSlot(2) != null)
{
// Increase the existing amount of anti-matter if stack already exists.
if (getStackInSlot(2).getItem() == AtomicContent.itemAntimatter())
{
ItemStack newStack = getStackInSlot(2).copy();
if (newStack.stackSize < newStack.getMaxStackSize())
{
// Remove an empty cell which we will put the anti-matter into.
decrStackSize(1, 1);
// Remove anti-matter from internal reserve and increase stack count.
antimatter -= 125;
newStack.stackSize++;
setInventorySlotContents(2, newStack);
}
}
}
else
{
// Remove some of the internal reserves of anti-matter and use it to craft an individual item.
antimatter -= 125;
decrStackSize(1, 1);
setInventorySlotContents(2, new ItemStack(AtomicContent.itemAntimatter()));
}
}
}
}
// Check if redstone signal is currently being applied.
if (worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord))
{
if (energy().checkExtract())
{
if (entityParticle == null)
{
// Creates a accelerated particle if one needs to exist (on world load for example or player login).
if (getStackInSlot(0) != null && lastSpawnTick >= 40)
{
Vector3 spawn_vec = new Vector3(this);
spawn_vec.add(getDirection().getOpposite());
spawn_vec.add(0.5f);
// Only render the particle if container within the proper environment for it.
if (EntityParticle.canSpawnParticle(worldObj, spawn_vec))
{
// Spawn the particle.
totalEnergyConsumed = 0;
entityParticle = new EntityParticle(worldObj, spawn_vec, new Vector3(this), getDirection().getOpposite());
worldObj.spawnEntityInWorld(entityParticle);
// Grabs input block hardness if available, otherwise defaults are used.
CalculateParticleDensity();
// Decrease particle we want to collide.
decrStackSize(0, 1);
lastSpawnTick = 0;
}
}
}
else
{
if (entityParticle.isDead)
{
// On particle collision we roll the dice to see if dark-matter is generated.
if (entityParticle.didParticleCollide)
{
if (worldObj.rand.nextFloat() <= Settings.darkMatterSpawnChance())
{
incrStackSize(3, new ItemStack(AtomicContent.itemDarkMatter()));
}
}
entityParticle = null;
}
else if (velocity > clientParticleVelocity)
{
// Play sound of anti-matter being created.
worldObj.playSoundEffect(xCoord, yCoord, zCoord, Reference.prefix() + "antimatter", 2f, 1f - worldObj.rand.nextFloat() * 0.3f);
// Create anti-matter in the internal reserve.
int generatedAntimatter = 5 + worldObj.rand.nextInt(antiMatterDensityMultiplyer);
antimatter += generatedAntimatter;
// AtomicScience.LOGGER.info("[Particle Accelerator] Generated " + String.valueOf(generatedAntimatter) + " mg of anti-matter.");
// Reset energy consumption levels and destroy accelerated particle.
totalEnergyConsumed = 0;
entityParticle.setDead();
entityParticle = null;
}
// Plays sound of particle accelerating past the speed based on total velocity at the time of anti-matter creation.
if (entityParticle != null)
{
worldObj.playSoundEffect(xCoord, yCoord, zCoord, Reference.prefix() + "accelerator", 1.5f, (float) (0.6f + (0.4 * (entityParticle.getParticleVelocity()) / TileAccelerator.clientParticleVelocity)));
}
}
energy().extractEnergy();
}
else
{
if (entityParticle != null)
{
entityParticle.setDead();
}
entityParticle = null;
}
}
else
{
if (entityParticle != null)
{
entityParticle.setDead();
}
entityParticle = null;
}
if (ticks() % 5 == 0)
{
//for (EntityPlayer player : getPlayersUsing())
//{
// ResonantEngine.instance.packetHandler.sendtoPlayer(new PacketAnnotation(this), player);
//}
}
lastSpawnTick++;
}
}
@Override
public boolean use(EntityPlayer player, int side, Vector3 hit)
{
if (!world().isRemote)
{
player.openGui(Atomic.INSTANCE(), 0, world(), x(), y(), z());
}
return true;
}
private void CalculateParticleDensity()
{
ItemStack itemToAccelerate = this.getStackInSlot(0);
if (itemToAccelerate != null)
{
// Calculate block density multiplier if ore dictionary block.
antiMatterDensityMultiplyer = DENSITY_MULTIPLYER_DEFAULT;
try
{
Block potentialBlock = Block.getBlockFromItem(itemToAccelerate.getItem());
if (potentialBlock != null)
{
// Prevent negative numbers and disallow zero for density multiplier.
antiMatterDensityMultiplyer = (int) Math.abs(BlockUtility.getBlockHardness(potentialBlock));
if (antiMatterDensityMultiplyer <= 0)
{
antiMatterDensityMultiplyer = 1;
}
// AtomicScience.LOGGER.info("[Particle Accelerator] " + String.valueOf(potentialBlock.getUnlocalizedName()) + " Hardness: " + String.valueOf(antiMatterDensityMultiplyer));
}
}
catch (Exception err)
{
antiMatterDensityMultiplyer = DENSITY_MULTIPLYER_DEFAULT;
// AtomicScience.LOGGER.info("[Particle Accelerator] Attempted to query Minecraft block-list with value out of index.");
}
}
}
@Override
public Packet getDescriptionPacket()
{
return ResonantEngine.instance.packetHandler.toMCPacket(new PacketAnnotation(this));
}
/**
* Reads a tile entity from NBT.
*/
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound);
totalEnergyConsumed = par1NBTTagCompound.getFloat("totalEnergyConsumed");
antimatter = par1NBTTagCompound.getInteger("antimatter");
}
/**
* Writes a tile entity to NBT.
*/
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound);
par1NBTTagCompound.setFloat("totalEnergyConsumed", totalEnergyConsumed);
par1NBTTagCompound.setInteger("antimatter", antimatter);
}
@Override
public int[] getAccessibleSlotsFromSide(int side)
{
return new int[]
{ 0, 1, 2, 3 };
}
@Override
public boolean canInsertItem(int slotID, ItemStack itemStack, int j)
{
return isItemValidForSlot(slotID, itemStack) && slotID != 2 && slotID != 3;
}
@Override
public boolean canExtractItem(int slotID, ItemStack itemstack, int j)
{
return slotID == 2 || slotID == 3;
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemStack)
{
switch (i)
{
case 0:
return true;
case 1:
return Atomic.isItemStackEmptyCell(itemStack);
case 2:
return itemStack.getItem() instanceof ItemAntimatter;
case 3:
return itemStack.getItem() != null && itemStack.getItem().getUnlocalizedName().contains("DarkMatter");
}
return false;
}
@Override
public boolean isRunning()
{
return true;
}
@Override
public ForgeDirection getDirection()
{
return ForgeDirection.getOrientation(getBlockMetadata());
}
@Override
public void setDirection(ForgeDirection direction)
{
world().setBlockMetadataWithNotify(xCoord, yCoord, zCoord, direction.ordinal(), 3);
}
}

View file

@ -0,0 +1,281 @@
package resonantinduction.atomic.machine.accelerator
import net.minecraft.block.Block
import net.minecraft.block.material.Material
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.network.Packet
import net.minecraftforge.common.util.ForgeDirection
import resonant.api.{IElectromagnet, IRotatable}
import resonant.engine.ResonantEngine
import resonant.lib.content.prefab.java.TileElectricInventory
import resonant.lib.network.Synced
import resonant.lib.network.discriminator.PacketAnnotation
import resonant.lib.utility.BlockUtility
import resonantinduction.atomic.{Atomic, AtomicContent}
import resonantinduction.atomic.items.ItemAntimatter
import resonantinduction.core.{Reference, Settings}
import universalelectricity.core.transform.vector.Vector3
/**
* Accelerator TileEntity
*/
object TileAccelerator
{
/**
* Joules required per ticks.
*/
final val energyPerTick: Int = 4800000
/**
* User client side to determine the velocity of the particle.
*/
final val clientParticleVelocity: Float = 0.9f
private final val DENSITY_MULTIPLYER_DEFAULT: Int = 1
}
class TileAccelerator extends TileElectricInventory(Material.iron) with IElectromagnet with IRotatable
{
/**
* Multiplier that is used to give extra anti-matter based on density (hardness) of a given ore.
*/
private var antiMatterDensityMultiplyer: Int = TileAccelerator.DENSITY_MULTIPLYER_DEFAULT
/**
* The total amount of energy consumed by this particle. In Joules.
*/
@Synced var totalEnergyConsumed: Float = 0
/**
* The amount of anti-matter stored within the accelerator. Measured in milligrams.
*/
@Synced var antimatter: Int = 0
var entityParticle: EntityParticle = null
@Synced var velocity: Float = 0
@Synced private var clientEnergy: Double = 0
private var lastSpawnTick: Int = 0
//Constructor
this.setSizeInventory(4)
override def update
{
super.update
if (!worldObj.isRemote)
{
clientEnergy = energy.getEnergy
velocity = 0
if (entityParticle != null)
{
velocity = entityParticle.getParticleVelocity.asInstanceOf[Float]
}
if (Atomic.isItemStackEmptyCell(getStackInSlot(1)))
{
if (getStackInSlot(1).stackSize > 0)
{
if (antimatter >= 125)
{
if (getStackInSlot(2) != null)
{
if (getStackInSlot(2).getItem eq AtomicContent.itemAntimatter)
{
val newStack: ItemStack = getStackInSlot(2).copy
if (newStack.stackSize < newStack.getMaxStackSize)
{
decrStackSize(1, 1)
antimatter -= 125
newStack.stackSize += 1
setInventorySlotContents(2, newStack)
}
}
}
else
{
antimatter -= 125
decrStackSize(1, 1)
setInventorySlotContents(2, new ItemStack(AtomicContent.itemAntimatter))
}
}
}
}
if (worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord))
{
if (energy.checkExtract)
{
if (entityParticle == null)
{
if (getStackInSlot(0) != null && lastSpawnTick >= 40)
{
val spawn_vec: Vector3 = new Vector3(this)
spawn_vec.add(getDirection.getOpposite)
spawn_vec.add(0.5f)
if (EntityParticle.canSpawnParticle(worldObj, spawn_vec))
{
totalEnergyConsumed = 0
entityParticle = new EntityParticle(worldObj, spawn_vec, new Vector3(this), getDirection.getOpposite)
worldObj.spawnEntityInWorld(entityParticle)
CalculateParticleDensity
decrStackSize(0, 1)
lastSpawnTick = 0
}
}
}
else
{
if (entityParticle.isDead)
{
if (entityParticle.didParticleCollide)
{
if (worldObj.rand.nextFloat <= Settings.darkMatterSpawnChance)
{
incrStackSize(3, new ItemStack(AtomicContent.itemDarkMatter))
}
}
entityParticle = null
}
else if (velocity > TileAccelerator.clientParticleVelocity)
{
worldObj.playSoundEffect(xCoord, yCoord, zCoord, Reference.prefix + "antimatter", 2f, 1f - worldObj.rand.nextFloat * 0.3f)
val generatedAntimatter: Int = 5 + worldObj.rand.nextInt(antiMatterDensityMultiplyer)
antimatter += generatedAntimatter
totalEnergyConsumed = 0
entityParticle.setDead
entityParticle = null
}
if (entityParticle != null)
{
worldObj.playSoundEffect(xCoord, yCoord, zCoord, Reference.prefix + "accelerator", 1.5f, (0.6f + (0.4 * (entityParticle.getParticleVelocity) / TileAccelerator.clientParticleVelocity)).asInstanceOf[Float])
}
}
energy.extractEnergy
}
else
{
if (entityParticle != null)
{
entityParticle.setDead
}
entityParticle = null
}
}
else
{
if (entityParticle != null)
{
entityParticle.setDead
}
entityParticle = null
}
if (ticks % 5 == 0)
{
}
lastSpawnTick += 1
}
}
override def use(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
{
if (!world.isRemote)
{
player.openGui(Atomic.INSTANCE, 0, world, x, y, z)
}
return true
}
private def CalculateParticleDensity
{
val itemToAccelerate: ItemStack = this.getStackInSlot(0)
if (itemToAccelerate != null)
{
antiMatterDensityMultiplyer = TileAccelerator.DENSITY_MULTIPLYER_DEFAULT
try
{
val potentialBlock: Block = Block.getBlockFromItem(itemToAccelerate.getItem)
if (potentialBlock != null)
{
antiMatterDensityMultiplyer = Math.abs(BlockUtility.getBlockHardness(potentialBlock)).asInstanceOf[Int]
if (antiMatterDensityMultiplyer <= 0)
{
antiMatterDensityMultiplyer = 1
}
}
}
catch
{
case err: Exception =>
{
antiMatterDensityMultiplyer = TileAccelerator.DENSITY_MULTIPLYER_DEFAULT
}
}
}
}
override def getDescriptionPacket: Packet =
{
return ResonantEngine.instance.packetHandler.toMCPacket(new PacketAnnotation(this))
}
/**
* Reads a tile entity from NBT.
*/
override def readFromNBT(par1NBTTagCompound: NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound)
totalEnergyConsumed = par1NBTTagCompound.getFloat("totalEnergyConsumed")
antimatter = par1NBTTagCompound.getInteger("antimatter")
}
/**
* Writes a tile entity to NBT.
*/
override def writeToNBT(par1NBTTagCompound: NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound)
par1NBTTagCompound.setFloat("totalEnergyConsumed", totalEnergyConsumed)
par1NBTTagCompound.setInteger("antimatter", antimatter)
}
override def getAccessibleSlotsFromSide(side: Int): Array[Int] =
{
return Array[Int](0, 1, 2, 3)
}
override def canInsertItem(slotID: Int, itemStack: ItemStack, j: Int): Boolean =
{
return isItemValidForSlot(slotID, itemStack) && slotID != 2 && slotID != 3
}
override def canExtractItem(slotID: Int, itemstack: ItemStack, j: Int): Boolean =
{
return slotID == 2 || slotID == 3
}
override def isItemValidForSlot(i: Int, itemStack: ItemStack): Boolean =
{
i match
{
case 0 =>
return true
case 1 =>
return Atomic.isItemStackEmptyCell(itemStack)
case 2 =>
return itemStack.getItem.isInstanceOf[ItemAntimatter]
case 3 =>
return itemStack.getItem != null && itemStack.getItem.getUnlocalizedName.contains("DarkMatter")
}
return false
}
def isRunning: Boolean =
{
return true
}
override def getDirection: ForgeDirection =
{
return ForgeDirection.getOrientation(getBlockMetadata)
}
override def setDirection(direction: ForgeDirection)
{
world.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, direction.ordinal, 3)
}
}