Error: Updated UE and Node class changes

This commit is contained in:
Calclavia 2014-11-02 19:33:59 +08:00
parent 310638aa31
commit 9423b0d753
16 changed files with 710 additions and 685 deletions

View file

@ -1,7 +1,8 @@
package resonantinduction.archaic.firebox
import cpw.mods.fml.relauncher.Side
import cpw.mods.fml.relauncher.SideOnly
import java.util.List
import cpw.mods.fml.relauncher.{Side, SideOnly}
import io.netty.buffer.ByteBuf
import net.minecraft.block.Block
import net.minecraft.block.material.Material
@ -10,8 +11,7 @@ import net.minecraft.creativetab.CreativeTabs
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.init.Blocks
import net.minecraft.inventory.IInventory
import net.minecraft.item.Item
import net.minecraft.item.ItemStack
import net.minecraft.item.{Item, ItemStack}
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.tileentity.TileEntityFurnace
import net.minecraft.util.IIcon
@ -19,267 +19,266 @@ import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids._
import resonant.content.spatial.block.SpatialBlock
import resonant.engine.grid.thermal.BoilEvent
import resonant.engine.grid.thermal.ThermalPhysics
import resonant.engine.grid.thermal.{BoilEvent, ThermalPhysics}
import resonant.lib.content.prefab.TEnergyStorage
import resonant.lib.content.prefab.java.TileElectricInventory
import resonant.lib.network.Synced
import resonant.lib.network.discriminator.PacketAnnotation
import resonant.lib.network.discriminator.PacketType
import resonant.lib.network.discriminator.{PacketAnnotation, PacketType}
import resonant.lib.network.handle.IPacketReceiver
import resonant.lib.utility.FluidUtility
import resonantinduction.core.Reference
import resonant.lib.transform.vector.Vector3
import java.util.List
import resonant.lib.utility.FluidUtility
import resonant.lib.wrapper.WrapList._
import resonantinduction.core.Reference
/**
* Meant to replace the furnace class.
*
* @author Calclavia
*/
class TileFirebox extends TileElectricInventory(Material.rock) with IPacketReceiver with IFluidHandler
class TileFirebox extends TileElectricInventory(Material.rock) with IPacketReceiver with IFluidHandler with TEnergyStorage
{
/**
* 1KG of coal ~= 24MJ
* Approximately one coal = 4MJ, one coal lasts 80 seconds. Therefore, we are producing 50000
* watts.
* The power of the firebox in terms of thermal energy. The thermal energy can be transfered
* into fluids to increase their internal energy.
*/
private final val POWER: Long = 100000
protected var tank: FluidTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME)
@Synced private var burnTime: Int = 0
private var heatEnergy: Long = 0
private var boiledVolume: Int = 0
/**
* 1KG of coal ~= 24MJ
* Approximately one coal = 4MJ, one coal lasts 80 seconds. Therefore, we are producing 50000
* watts.
* The power of the firebox in terms of thermal energy. The thermal energy can be transfered
* into fluids to increase their internal energy.
*/
private final val POWER: Long = 100000
protected var tank: FluidTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME)
@Synced private var burnTime: Int = 0
private var heatEnergy: Long = 0
private var boiledVolume: Int = 0
//Constructor
setCapacity(POWER)
setMaxTransfer((POWER * 2) / 20)
setIO(ForgeDirection.UP, 0)
//Constructor
energy.setCapacity(POWER)
energy.setMaxTransfer((POWER * 2) / 20)
setIO(ForgeDirection.UP, 0)
override def update
override def update
{
if (!worldObj.isRemote)
{
if (!worldObj.isRemote)
val drainFluid: FluidStack = tank.drain(FluidContainerRegistry.BUCKET_VOLUME, false)
if (drainFluid != null && drainFluid.amount == FluidContainerRegistry.BUCKET_VOLUME && drainFluid.fluidID == FluidRegistry.LAVA.getID)
{
if (burnTime == 0)
{
val drainFluid: FluidStack = tank.drain(FluidContainerRegistry.BUCKET_VOLUME, false)
if (drainFluid != null && drainFluid.amount == FluidContainerRegistry.BUCKET_VOLUME && drainFluid.fluidID == FluidRegistry.LAVA.getID)
tank.drain(FluidContainerRegistry.BUCKET_VOLUME, true)
burnTime += 20000
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
}
}
else if (isElectrical && energy.checkExtract)
{
energy.extractEnergy
if (burnTime == 0)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
}
burnTime += 2
}
else if (canBurn(getStackInSlot(0)))
{
if (burnTime == 0)
{
burnTime += TileEntityFurnace.getItemBurnTime(this.getStackInSlot(0))
decrStackSize(0, 1)
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
}
}
val block: Block = worldObj.getBlock(xCoord, yCoord + 1, zCoord)
if (burnTime > 0)
{
if (block == null)
{
worldObj.setBlock(xCoord, yCoord + 1, zCoord, Blocks.fire)
}
heatEnergy += POWER / 20
var usedHeat: Boolean = false
if (block eq Blocks.water)
{
usedHeat = true
val volume: Int = 100
if (heatEnergy >= getRequiredBoilWaterEnergy(volume))
{
if (FluidRegistry.getFluid("steam") != null)
{
if (burnTime == 0)
{
tank.drain(FluidContainerRegistry.BUCKET_VOLUME, true)
burnTime += 20000
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
}
MinecraftForge.EVENT_BUS.post(new BoilEvent(worldObj, asVectorWorld.add(0, 1, 0), new FluidStack(FluidRegistry.WATER, volume), new FluidStack(FluidRegistry.getFluid("steam"), volume), 2, false))
boiledVolume += volume
}
else if (isElectrical && energy.checkExtract)
if (boiledVolume >= FluidContainerRegistry.BUCKET_VOLUME)
{
energy.extractEnergy
if (burnTime == 0)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
}
burnTime += 2
}
else if (canBurn(getStackInSlot(0)))
{
if (burnTime == 0)
{
burnTime += TileEntityFurnace.getItemBurnTime(this.getStackInSlot(0))
decrStackSize(0, 1)
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
}
}
val block: Block = worldObj.getBlock(xCoord, yCoord + 1, zCoord)
if (burnTime > 0)
{
if (block == null)
{
worldObj.setBlock(xCoord, yCoord + 1, zCoord, Blocks.fire)
}
heatEnergy += POWER / 20
var usedHeat: Boolean = false
if (block eq Blocks.water)
{
usedHeat = true
val volume: Int = 100
if (heatEnergy >= getRequiredBoilWaterEnergy(volume))
{
if (FluidRegistry.getFluid("steam") != null)
{
MinecraftForge.EVENT_BUS.post(new BoilEvent(worldObj, asVectorWorld.add(0, 1, 0), new FluidStack(FluidRegistry.WATER, volume), new FluidStack(FluidRegistry.getFluid("steam"), volume), 2, false))
boiledVolume += volume
}
if (boiledVolume >= FluidContainerRegistry.BUCKET_VOLUME)
{
boiledVolume = 0
worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord)
}
heatEnergy = 0
}
}
if (!usedHeat)
{
heatEnergy = 0
}
if (({
burnTime -= 1; burnTime
}) == 0)
{
if (block eq Blocks.fire)
{
worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord)
}
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
}
boiledVolume = 0
worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord)
}
heatEnergy = 0
}
}
}
/**
* Approximately 327600 + 2257000 = 2584600.
*
* @param volume
* @return
*/
def getRequiredBoilWaterEnergy(volume: Int): Long =
{
return ThermalPhysics.getRequiredBoilWaterEnergy(worldObj, xCoord, zCoord, volume).asInstanceOf[Long]
}
def getMeltIronEnergy(volume: Float): Long =
{
val temperatureChange: Float = 1811 - ThermalPhysics.getTemperatureForCoordinate(worldObj, xCoord, zCoord)
val mass: Float = ThermalPhysics.getMass(volume, 7.9f)
return (ThermalPhysics.getEnergyForTemperatureChange(mass, 450, temperatureChange) + ThermalPhysics.getEnergyForStateChange(mass, 272000)).asInstanceOf[Long]
}
def isElectrical: Boolean =
{
return this.getBlockMetadata == 1
}
def canBurn(stack: ItemStack): Boolean =
{
return TileEntityFurnace.getItemBurnTime(stack) > 0
}
def isBurning: Boolean =
{
return burnTime > 0
}
override def isItemValidForSlot(i: Int, itemStack: ItemStack): Boolean =
{
return i == 0 && canBurn(itemStack)
}
override def getDescPacket: PacketAnnotation =
{
return new PacketAnnotation(this)
}
def read(data: ByteBuf, player: EntityPlayer, `type`: PacketType)
{
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord)
}
override def readFromNBT(nbt: NBTTagCompound)
{
super.readFromNBT(nbt)
burnTime = nbt.getInteger("burnTime")
tank.readFromNBT(nbt)
}
override def writeToNBT(nbt: NBTTagCompound)
{
super.writeToNBT(nbt)
nbt.setInteger("burnTime", burnTime)
tank.writeToNBT(nbt)
}
def fill(from: ForgeDirection, resource: FluidStack, doFill: Boolean): Int =
{
return tank.fill(resource, doFill)
}
def drain(from: ForgeDirection, resource: FluidStack, doDrain: Boolean): FluidStack =
{
if (resource == null || resource.getFluid == FluidRegistry.LAVA)
if (!usedHeat)
{
return null
heatEnergy = 0
}
return tank.drain(resource.amount, doDrain)
}
def drain(from: ForgeDirection, maxDrain: Int, doDrain: Boolean): FluidStack =
{
return tank.drain(maxDrain, doDrain)
}
def canFill(from: ForgeDirection, fluid: Fluid): Boolean =
{
return fluid eq FluidRegistry.LAVA
}
def canDrain(from: ForgeDirection, fluid: Fluid): Boolean =
{
return false
}
def getTankInfo(from: ForgeDirection): Array[FluidTankInfo] =
{
return Array[FluidTankInfo](tank.getInfo)
}
@SideOnly(Side.CLIENT) override def registerIcons(iconReg: IIconRegister)
{
super.registerIcons(iconReg)
SpatialBlock.icon.put("firebox_side_on", iconReg.registerIcon(Reference.prefix + "firebox_side_on"))
SpatialBlock.icon.put("firebox_side_off", iconReg.registerIcon(Reference.prefix + "firebox_side_off"))
SpatialBlock.icon.put("firebox_top_on", iconReg.registerIcon(Reference.prefix + "firebox_top_on"))
SpatialBlock.icon.put("firebox_top_off", iconReg.registerIcon(Reference.prefix + "firebox_top_off"))
SpatialBlock.icon.put("firebox_electric_side_on", iconReg.registerIcon(Reference.prefix + "firebox_electric_side_on"))
SpatialBlock.icon.put("firebox_electric_side_off", iconReg.registerIcon(Reference.prefix + "firebox_electric_side_off"))
SpatialBlock.icon.put("firebox_electric_top_on", iconReg.registerIcon(Reference.prefix + "firebox_electric_top_on"))
SpatialBlock.icon.put("firebox_electric_top_off", iconReg.registerIcon(Reference.prefix + "firebox_electric_top_off"))
}
@SideOnly(Side.CLIENT) override def getIcon(side: Int, meta: Int): IIcon =
{
if (side == 0)
if (({
burnTime -= 1;
burnTime
}) == 0)
{
return SpatialBlock.icon.get("firebox")
if (block eq Blocks.fire)
{
worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord)
}
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
}
val isElectric: Boolean = meta == 1
val isBurning: Boolean = false
if (side == 1)
{
return if (isBurning) (if (isElectric) SpatialBlock.icon.get("firebox_electric_top_on") else SpatialBlock.icon.get("firebox_top_on")) else (if (isElectric) SpatialBlock.icon.get("firebox_electric_top_off") else SpatialBlock.icon.get("firebox_top_off"))
}
return if (isBurning) (if (isElectric) SpatialBlock.icon.get("firebox_electric_side_on") else SpatialBlock.icon.get("firebox_side_on")) else (if (isElectric) SpatialBlock.icon.get("firebox_electric_side_off") else SpatialBlock.icon.get("firebox_side_off"))
}
}
}
override def click(player: EntityPlayer)
{
if (server)
{
extractItem(this.asInstanceOf[IInventory], 0, player)
}
}
/**
* Approximately 327600 + 2257000 = 2584600.
*
* @param volume
* @return
*/
def getRequiredBoilWaterEnergy(volume: Int): Long =
{
return ThermalPhysics.getRequiredBoilWaterEnergy(worldObj, xCoord, zCoord, volume).asInstanceOf[Long]
}
override def use(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
{
if (FluidUtility.playerActivatedFluidItem(world, xi, yi, zi, player, side))
{
return true
}
return interactCurrentItem(this.asInstanceOf[IInventory], 0, player)
}
def getMeltIronEnergy(volume: Float): Long =
{
val temperatureChange: Float = 1811 - ThermalPhysics.getTemperatureForCoordinate(worldObj, xCoord, zCoord)
val mass: Float = ThermalPhysics.getMass(volume, 7.9f)
return (ThermalPhysics.getEnergyForTemperatureChange(mass, 450, temperatureChange) + ThermalPhysics.getEnergyForStateChange(mass, 272000)).asInstanceOf[Long]
}
override def getSubBlocks(par1: Item, par2CreativeTabs: CreativeTabs, par3List: List[_])
def isElectrical: Boolean =
{
return this.getBlockMetadata == 1
}
def canBurn(stack: ItemStack): Boolean =
{
return TileEntityFurnace.getItemBurnTime(stack) > 0
}
def isBurning: Boolean =
{
return burnTime > 0
}
override def isItemValidForSlot(i: Int, itemStack: ItemStack): Boolean =
{
return i == 0 && canBurn(itemStack)
}
override def getDescPacket: PacketAnnotation =
{
return new PacketAnnotation(this)
}
def read(data: ByteBuf, player: EntityPlayer, `type`: PacketType)
{
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord)
}
override def readFromNBT(nbt: NBTTagCompound)
{
super.readFromNBT(nbt)
burnTime = nbt.getInteger("burnTime")
tank.readFromNBT(nbt)
}
override def writeToNBT(nbt: NBTTagCompound)
{
super.writeToNBT(nbt)
nbt.setInteger("burnTime", burnTime)
tank.writeToNBT(nbt)
}
def fill(from: ForgeDirection, resource: FluidStack, doFill: Boolean): Int =
{
return tank.fill(resource, doFill)
}
def drain(from: ForgeDirection, resource: FluidStack, doDrain: Boolean): FluidStack =
{
if (resource == null || resource.getFluid == FluidRegistry.LAVA)
{
par3List.add(new ItemStack(par1, 1, 0))
par3List.add(new ItemStack(par1, 1, 1))
return null
}
return tank.drain(resource.amount, doDrain)
}
def drain(from: ForgeDirection, maxDrain: Int, doDrain: Boolean): FluidStack =
{
return tank.drain(maxDrain, doDrain)
}
def canFill(from: ForgeDirection, fluid: Fluid): Boolean =
{
return fluid eq FluidRegistry.LAVA
}
def canDrain(from: ForgeDirection, fluid: Fluid): Boolean =
{
return false
}
def getTankInfo(from: ForgeDirection): Array[FluidTankInfo] =
{
return Array[FluidTankInfo](tank.getInfo)
}
@SideOnly(Side.CLIENT) override def registerIcons(iconReg: IIconRegister)
{
super.registerIcons(iconReg)
SpatialBlock.icon.put("firebox_side_on", iconReg.registerIcon(Reference.prefix + "firebox_side_on"))
SpatialBlock.icon.put("firebox_side_off", iconReg.registerIcon(Reference.prefix + "firebox_side_off"))
SpatialBlock.icon.put("firebox_top_on", iconReg.registerIcon(Reference.prefix + "firebox_top_on"))
SpatialBlock.icon.put("firebox_top_off", iconReg.registerIcon(Reference.prefix + "firebox_top_off"))
SpatialBlock.icon.put("firebox_electric_side_on", iconReg.registerIcon(Reference.prefix + "firebox_electric_side_on"))
SpatialBlock.icon.put("firebox_electric_side_off", iconReg.registerIcon(Reference.prefix + "firebox_electric_side_off"))
SpatialBlock.icon.put("firebox_electric_top_on", iconReg.registerIcon(Reference.prefix + "firebox_electric_top_on"))
SpatialBlock.icon.put("firebox_electric_top_off", iconReg.registerIcon(Reference.prefix + "firebox_electric_top_off"))
}
@SideOnly(Side.CLIENT) override def getIcon(side: Int, meta: Int): IIcon =
{
if (side == 0)
{
return SpatialBlock.icon.get("firebox")
}
val isElectric: Boolean = meta == 1
val isBurning: Boolean = false
if (side == 1)
{
return if (isBurning) (if (isElectric) SpatialBlock.icon.get("firebox_electric_top_on") else SpatialBlock.icon.get("firebox_top_on")) else (if (isElectric) SpatialBlock.icon.get("firebox_electric_top_off") else SpatialBlock.icon.get("firebox_top_off"))
}
return if (isBurning) (if (isElectric) SpatialBlock.icon.get("firebox_electric_side_on") else SpatialBlock.icon.get("firebox_side_on")) else (if (isElectric) SpatialBlock.icon.get("firebox_electric_side_off") else SpatialBlock.icon.get("firebox_side_off"))
}
override def click(player: EntityPlayer)
{
if (server)
{
extractItem(this.asInstanceOf[IInventory], 0, player)
}
}
override def use(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
{
if (FluidUtility.playerActivatedFluidItem(world, xi, yi, zi, player, side))
{
return true
}
return interactCurrentItem(this.asInstanceOf[IInventory], 0, player)
}
override def getSubBlocks(par1: Item, par2CreativeTabs: CreativeTabs, par3List: List[_])
{
par3List.add(new ItemStack(par1, 1, 0))
par3List.add(new ItemStack(par1, 1, 1))
}
}

View file

@ -37,7 +37,7 @@ class GuiAccelerator(player: EntityPlayer, tileEntity: TileAccelerator) extends
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("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)
}

View file

@ -10,310 +10,311 @@ import net.minecraft.nbt.NBTTagCompound
import net.minecraft.util.IIcon
import net.minecraftforge.common.util.ForgeDirection
import resonant.api.{IElectromagnet, IRotatable}
import resonant.lib.content.prefab.TEnergyStorage
import resonant.lib.content.prefab.java.TileElectricInventory
import resonant.lib.network.discriminator.{PacketTile, PacketType}
import resonant.lib.network.handle.TPacketIDReceiver
import resonant.lib.transform.vector.Vector3
import resonant.lib.utility.BlockUtility
import resonantinduction.atomic.AtomicContent
import resonantinduction.atomic.items.ItemAntimatter
import resonantinduction.core.{Reference, ResonantInduction, Settings}
import resonant.lib.transform.vector.Vector3
import scala.collection.JavaConversions._
class TileAccelerator extends TileElectricInventory(Material.iron) with IElectromagnet with IRotatable with TPacketIDReceiver
class TileAccelerator extends TileElectricInventory(Material.iron) with IElectromagnet with IRotatable with TPacketIDReceiver with TEnergyStorage
{
final val DESC_PACKET_ID = 2;
/**
* Multiplier that is used to give extra anti-matter based on density (hardness) of a given ore.
*/
private var antiMatterDensityMultiplyer: Int = Settings.ACCELERATOR_ANITMATTER_DENSITY_MULTIPLIER
/**
* The total amount of energy consumed by this particle. In Joules.
*/
var totalEnergyConsumed: Double = 0
/**
* The amount of anti-matter stored within the accelerator. Measured in milligrams.
*/
var antimatter: Int = 0
var entityParticle: EntityParticle = null
var velocity: Float = 0
var clientEnergy: Double = 0
var lastSpawnTick: Int = 0
final val DESC_PACKET_ID = 2;
/**
* Multiplier that is used to give extra anti-matter based on density (hardness) of a given ore.
*/
private var antiMatterDensityMultiplyer: Int = Settings.ACCELERATOR_ANITMATTER_DENSITY_MULTIPLIER
/**
* The total amount of energy consumed by this particle. In Joules.
*/
var totalEnergyConsumed: Double = 0
/**
* The amount of anti-matter stored within the accelerator. Measured in milligrams.
*/
var antimatter: Int = 0
var entityParticle: EntityParticle = null
var velocity: Float = 0
var clientEnergy: Double = 0
var lastSpawnTick: Int = 0
//Constructor
this.setSizeInventory(4)
this.setCapacity(Settings.ACCELERATOR_ENERGY_COST_PER_TICK * 20)
this.setMaxTransfer(Settings.ACCELERATOR_ENERGY_COST_PER_TICK)
//Constructor
this.setSizeInventory(4)
energy.setCapacity(Settings.ACCELERATOR_ENERGY_COST_PER_TICK * 20)
energy.setMaxTransfer(Settings.ACCELERATOR_ENERGY_COST_PER_TICK)
override def update
override def update
{
super.update
if (!worldObj.isRemote)
{
super.update
if (!worldObj.isRemote)
clientEnergy = energy.getEnergy
velocity = getParticleVel()
outputAntimatter()
if (worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord))
{
if (energy.checkExtract)
{
clientEnergy = energy.getEnergy
velocity = getParticleVel()
outputAntimatter()
if (entityParticle == null)
{
//Create new particle if we have materials to spawn it with
if (getStackInSlot(0) != null && lastSpawnTick >= 40)
{
val spawn_vec: Vector3 = asVector3
spawn_vec.add(getDirection.getOpposite)
spawn_vec.add(0.5f)
if (EntityParticle.canSpawnParticle(worldObj, spawn_vec))
{
totalEnergyConsumed = 0
entityParticle = new EntityParticle(worldObj, spawn_vec, asVector3, getDirection.getOpposite)
worldObj.spawnEntityInWorld(entityParticle)
CalculateParticleDensity
decrStackSize(0, 1)
lastSpawnTick = 0
}
}
}
else
{
if (entityParticle.isDead)
{
//Handle strange matter creation
if (entityParticle.didParticleCollide)
{
if (worldObj.rand.nextFloat <= Settings.darkMatterSpawnChance)
{
incrStackSize(3, new ItemStack(AtomicContent.itemDarkMatter))
}
}
entityParticle = null
}
else if (velocity > EntityParticle.ANITMATTER_CREATION_SPEED)
{
//Create antimatter if we have hit max speed
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
if (worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord))
{
if (energy.checkExtract)
{
if (entityParticle == null)
{
//Create new particle if we have materials to spawn it with
if (getStackInSlot(0) != null && lastSpawnTick >= 40)
{
val spawn_vec: Vector3 = asVector3
spawn_vec.add(getDirection.getOpposite)
spawn_vec.add(0.5f)
if (EntityParticle.canSpawnParticle(worldObj, spawn_vec))
{
totalEnergyConsumed = 0
entityParticle = new EntityParticle(worldObj, spawn_vec, asVector3, getDirection.getOpposite)
worldObj.spawnEntityInWorld(entityParticle)
CalculateParticleDensity
decrStackSize(0, 1)
lastSpawnTick = 0
}
}
}
else
{
if (entityParticle.isDead)
{
//Handle strange matter creation
if (entityParticle.didParticleCollide)
{
if (worldObj.rand.nextFloat <= Settings.darkMatterSpawnChance)
{
incrStackSize(3, new ItemStack(AtomicContent.itemDarkMatter))
}
}
entityParticle = null
}
else if (velocity > EntityParticle.ANITMATTER_CREATION_SPEED)
{
//Create antimatter if we have hit max speed
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
//Cleanup
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) / EntityParticle.ANITMATTER_CREATION_SPEED)).asInstanceOf[Float])
}
}
energy.extractEnergy
}
else
{
if (entityParticle != null)
{
entityParticle.setDead
}
entityParticle = null
}
//Cleanup
totalEnergyConsumed = 0
entityParticle.setDead
entityParticle = null
}
else
if (entityParticle != null)
{
if (entityParticle != null)
{
entityParticle.setDead
}
entityParticle = null
worldObj.playSoundEffect(xCoord, yCoord, zCoord, Reference.prefix + "accelerator", 1.5f, (0.6f + (0.4 * (entityParticle.getParticleVelocity) / EntityParticle.ANITMATTER_CREATION_SPEED)).asInstanceOf[Float])
}
if (ticks % 5 == 0)
{
for (player <- getPlayersUsing)
{
sendPacketToPlayer(player, getDescPacket)
}
}
lastSpawnTick += 1
}
energy.extractEnergy
}
}
/**
* Converts antimatter storage into item if the condition are meet
*/
def outputAntimatter()
{
//Do we have an empty cell in slot one
if (AtomicContent.isItemStackEmptyCell(getStackInSlot(1)) && getStackInSlot(1).stackSize > 0)
{
// Each cell can only hold 125mg of antimatter TODO maybe a config for this?
if (antimatter >= 125)
{
if (getStackInSlot(2) != null)
{
// If the output slot is not empty we must increase stack size
if (getStackInSlot(2).getItem == 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
{
//Output to slot 2 and decrease volume of antimatter
antimatter -= 125
decrStackSize(1, 1)
setInventorySlotContents(2, new ItemStack(AtomicContent.itemAntimatter))
}
}
}
}
override def activate(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
{
player.openGui(ResonantInduction, 0, world, xi, yi, zi)
return true
}
private def CalculateParticleDensity
{
val itemToAccelerate: ItemStack = this.getStackInSlot(0)
if (itemToAccelerate != null)
{
antiMatterDensityMultiplyer = Settings.ACCELERATOR_ANITMATTER_DENSITY_MULTIPLIER
val potentialBlock: Block = Block.getBlockFromItem(itemToAccelerate.getItem)
if (potentialBlock != null)
{
antiMatterDensityMultiplyer = BlockUtility.getBlockHardness(potentialBlock).asInstanceOf[Int] * Settings.ACCELERATOR_ANITMATTER_DENSITY_MULTIPLIER
if (antiMatterDensityMultiplyer <= 0)
{
antiMatterDensityMultiplyer = Settings.ACCELERATOR_ANITMATTER_DENSITY_MULTIPLIER
}
if (antiMatterDensityMultiplyer > 1000)
{
antiMatterDensityMultiplyer = 1000 * Settings.ACCELERATOR_ANITMATTER_DENSITY_MULTIPLIER
}
}
}
}
/////////////////////////////////////////
/// Packet Handling ///
////////////////////////////////////////
override def read(buf: ByteBuf, id: Int, player: EntityPlayer, packet: PacketType): Boolean =
{
//Client only packets
if (world.isRemote)
{
if (id == DESC_PACKET_ID)
{
this.velocity = buf.readFloat()
this.totalEnergyConsumed = buf.readDouble();
this.antimatter = buf.readInt();
this.energy.setEnergy(buf.readDouble())
return true;
}
}
return super.read(buf, id, player, packet);
}
override def getDescPacket: PacketTile =
{
return new PacketTile(xi, yi, zi, Array[Any](DESC_PACKET_ID, velocity, totalEnergyConsumed, antimatter, energy.getEnergy))
}
/////////////////////////////////////////
/// Save handling ///
////////////////////////////////////////
override def readFromNBT(par1NBTTagCompound: NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound)
totalEnergyConsumed = par1NBTTagCompound.getDouble("energyUsed")
antimatter = par1NBTTagCompound.getInteger("antimatter")
}
override def writeToNBT(par1NBTTagCompound: NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound)
par1NBTTagCompound.setDouble("energyUsed", totalEnergyConsumed)
par1NBTTagCompound.setInteger("antimatter", antimatter)
}
/////////////////////////////////////////
/// Inventory Overrides ///
////////////////////////////////////////
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 AtomicContent.isItemStackEmptyCell(itemStack)
case 2 =>
return itemStack.getItem.isInstanceOf[ItemAntimatter]
case 3 =>
return itemStack.getItem != null && itemStack.getItem.getUnlocalizedName.contains("DarkMatter")
}
return false
}
/////////////////////////////////////////
/// Field Getters & Setters ///
////////////////////////////////////////
override 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)
}
/** get velocity for the particle and @return it as a float */
def getParticleVel(): Float =
{
if (entityParticle != null)
return entityParticle.getParticleVelocity.asInstanceOf[Float]
else
return 0
}
@SideOnly(Side.CLIENT)
override def getIcon(side: Int, meta: Int): IIcon =
{
if(side == getDirection.getOpposite.ordinal())
{
return AtomicContent.blockElectromagnet.getIcon(side, meta)
if (entityParticle != null)
{
entityParticle.setDead
}
entityParticle = null
}
return getIcon
}
else
{
if (entityParticle != null)
{
entityParticle.setDead
}
entityParticle = null
}
if (ticks % 5 == 0)
{
for (player <- getPlayersUsing)
{
sendPacketToPlayer(player, getDescPacket)
}
}
lastSpawnTick += 1
}
}
/**
* Converts antimatter storage into item if the condition are meet
*/
def outputAntimatter()
{
//Do we have an empty cell in slot one
if (AtomicContent.isItemStackEmptyCell(getStackInSlot(1)) && getStackInSlot(1).stackSize > 0)
{
// Each cell can only hold 125mg of antimatter TODO maybe a config for this?
if (antimatter >= 125)
{
if (getStackInSlot(2) != null)
{
// If the output slot is not empty we must increase stack size
if (getStackInSlot(2).getItem == 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
{
//Output to slot 2 and decrease volume of antimatter
antimatter -= 125
decrStackSize(1, 1)
setInventorySlotContents(2, new ItemStack(AtomicContent.itemAntimatter))
}
}
}
}
override def activate(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
{
player.openGui(ResonantInduction, 0, world, xi, yi, zi)
return true
}
private def CalculateParticleDensity
{
val itemToAccelerate: ItemStack = this.getStackInSlot(0)
if (itemToAccelerate != null)
{
antiMatterDensityMultiplyer = Settings.ACCELERATOR_ANITMATTER_DENSITY_MULTIPLIER
val potentialBlock: Block = Block.getBlockFromItem(itemToAccelerate.getItem)
if (potentialBlock != null)
{
antiMatterDensityMultiplyer = BlockUtility.getBlockHardness(potentialBlock).asInstanceOf[Int] * Settings.ACCELERATOR_ANITMATTER_DENSITY_MULTIPLIER
if (antiMatterDensityMultiplyer <= 0)
{
antiMatterDensityMultiplyer = Settings.ACCELERATOR_ANITMATTER_DENSITY_MULTIPLIER
}
if (antiMatterDensityMultiplyer > 1000)
{
antiMatterDensityMultiplyer = 1000 * Settings.ACCELERATOR_ANITMATTER_DENSITY_MULTIPLIER
}
}
}
}
/////////////////////////////////////////
/// Packet Handling ///
////////////////////////////////////////
override def read(buf: ByteBuf, id: Int, player: EntityPlayer, packet: PacketType): Boolean =
{
//Client only packets
if (world.isRemote)
{
if (id == DESC_PACKET_ID)
{
this.velocity = buf.readFloat()
this.totalEnergyConsumed = buf.readDouble();
this.antimatter = buf.readInt();
this.energy.setEnergy(buf.readDouble())
return true;
}
}
return super.read(buf, id, player, packet);
}
override def getDescPacket: PacketTile =
{
return new PacketTile(xi, yi, zi, Array[Any](DESC_PACKET_ID, velocity, totalEnergyConsumed, antimatter, energy.getEnergy))
}
/////////////////////////////////////////
/// Save handling ///
////////////////////////////////////////
override def readFromNBT(par1NBTTagCompound: NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound)
totalEnergyConsumed = par1NBTTagCompound.getDouble("energyUsed")
antimatter = par1NBTTagCompound.getInteger("antimatter")
}
override def writeToNBT(par1NBTTagCompound: NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound)
par1NBTTagCompound.setDouble("energyUsed", totalEnergyConsumed)
par1NBTTagCompound.setInteger("antimatter", antimatter)
}
/////////////////////////////////////////
/// Inventory Overrides ///
////////////////////////////////////////
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 AtomicContent.isItemStackEmptyCell(itemStack)
case 2 =>
return itemStack.getItem.isInstanceOf[ItemAntimatter]
case 3 =>
return itemStack.getItem != null && itemStack.getItem.getUnlocalizedName.contains("DarkMatter")
}
return false
}
/////////////////////////////////////////
/// Field Getters & Setters ///
////////////////////////////////////////
override 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)
}
/** get velocity for the particle and @return it as a float */
def getParticleVel(): Float =
{
if (entityParticle != null)
return entityParticle.getParticleVelocity.asInstanceOf[Float]
else
return 0
}
@SideOnly(Side.CLIENT)
override def getIcon(side: Int, meta: Int): IIcon =
{
if (side == getDirection.getOpposite.ordinal())
{
return AtomicContent.blockElectromagnet.getIcon(side, meta)
}
return getIcon
}
}

View file

@ -10,6 +10,7 @@ import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids._
import resonant.api.IRotatable
import resonant.engine.ResonantEngine
import resonant.lib.content.prefab.TEnergyStorage
import resonant.lib.content.prefab.java.TileElectricInventory
import resonant.lib.network.Synced
import resonant.lib.network.discriminator.{PacketTile, PacketType}
@ -26,7 +27,7 @@ object TileNuclearBoiler
final val DIAN: Long = 50000
}
class TileNuclearBoiler extends TileElectricInventory(Material.iron) with IPacketReceiver with IFluidHandler with IRotatable
class TileNuclearBoiler extends TileElectricInventory(Material.iron) with IPacketReceiver with IFluidHandler with IRotatable with TEnergyStorage
{
final val SHI_JIAN: Int = 20 * 15

View file

@ -9,6 +9,7 @@ import net.minecraft.nbt.NBTTagCompound
import net.minecraft.tileentity.TileEntity
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids._
import resonant.lib.content.prefab.TEnergyStorage
import resonant.lib.content.prefab.java.TileElectricInventory
import resonant.lib.grid.Compatibility
import resonant.lib.network.discriminator.{PacketTile, PacketType}
@ -26,7 +27,7 @@ object TileCentrifuge
final val DIAN: Long = 500000
}
class TileCentrifuge extends TileElectricInventory(Material.iron) with IPacketReceiver with IFluidHandler with IInventory
class TileCentrifuge extends TileElectricInventory(Material.iron) with IPacketReceiver with IFluidHandler with IInventory with TEnergyStorage
{
val gasTank: FluidTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 5)
var timer: Int = 0

View file

@ -8,6 +8,7 @@ import net.minecraft.network.Packet
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids._
import resonant.engine.ResonantEngine
import resonant.lib.content.prefab.TEnergyStorage
import resonant.lib.grid.Compatibility
import resonant.lib.network.Synced
import resonant.lib.network.discriminator.PacketAnnotation
@ -25,7 +26,7 @@ object TileChemicalExtractor
final val ENERGY: Long = 5000
}
class TileChemicalExtractor extends TileProcess(Material.iron) with IFluidHandler
class TileChemicalExtractor extends TileProcess(Material.iron) with IFluidHandler with TEnergyStorage
{
energy.setCapacity(TileChemicalExtractor.ENERGY * 2)
this.setSizeInventory(7)

View file

@ -1,6 +1,7 @@
package resonantinduction.atomic.machine.fulmination
import net.minecraft.block.material.Material
import resonant.lib.content.prefab.TEnergyStorage
import resonant.lib.content.prefab.java.TileElectric
/**
@ -8,31 +9,31 @@ import resonant.lib.content.prefab.java.TileElectric
*/
object TileFulmination
{
private final val DIAN: Long = 10000000000000L
private final val DIAN: Long = 10000000000000L
}
class TileFulmination extends TileElectric(Material.iron)
class TileFulmination extends TileElectric(Material.iron) with TEnergyStorage
{
//Constructor
energy.setCapacity(TileFulmination.DIAN * 2)
this.blockHardness(10)
this.blockResistance(25000)
//Constructor
energy.setCapacity(TileFulmination.DIAN * 2)
this.blockHardness(10)
this.blockResistance(25000)
override def start
{
super.start
FulminationHandler.INSTANCE.register(this)
}
override def start
{
super.start
FulminationHandler.INSTANCE.register(this)
}
override def update
{
super.update
energy.extractEnergy(10, true)
}
override def update
{
super.update
energy.extractEnergy(10, true)
}
override def invalidate
{
FulminationHandler.INSTANCE.unregister(this)
super.start
}
override def invalidate
{
FulminationHandler.INSTANCE.unregister(this)
super.start
}
}

View file

@ -2,39 +2,45 @@ package resonantinduction.core.prefab.node
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids.{FluidStack, IFluidHandler}
import resonant.api.grid.{IUpdate, INodeProvider}
import resonant.api.grid.{INodeProvider, IUpdate}
/**
* Created by robert on 8/15/2014.
*/
class NodePressure(parent : INodeProvider, buckets : Int) extends NodeTank(parent, buckets) with IUpdate {
import scala.collection.convert.wrapAll._
def this(parent: INodeProvider)
class NodePressure(parent: INodeProvider, buckets: Int = 1) extends NodeTank(parent, buckets) with IUpdate
{
private var pressure: Int = 0
def update(deltaTime: Double)
{
this(parent, 1)
}
if (!world.isRemote)
{
updatePressure()
def update(deltaTime: Double) {
if (!world.isRemote) {
updatePressure
if (getFluid != null) {
import scala.collection.JavaConversions._
for (entry <- connections.entrySet) {
if (entry.getKey.isInstanceOf[INodeProvider] && (entry.getKey.asInstanceOf[INodeProvider]).getNode(classOf[NodePressure], entry.getValue.getOpposite).isInstanceOf[NodePressure]) {
if (getFluid != null)
{
for (entry <- directionMap.entrySet)
{
if (entry.getKey.isInstanceOf[INodeProvider] && (entry.getKey.asInstanceOf[INodeProvider]).getNode(classOf[NodePressure], entry.getValue.getOpposite).isInstanceOf[NodePressure])
{
val node: NodePressure = (entry.getKey.asInstanceOf[INodeProvider]).getNode(classOf[NodePressure], entry.getValue.getOpposite).asInstanceOf[NodePressure]
if (node.getPressure(entry.getValue.getOpposite) <= getPressure(entry.getValue)) {
if (node.getPressure(entry.getValue.getOpposite) <= getPressure(entry.getValue))
{
}
}
else if (entry.getKey.isInstanceOf[INodeProvider] && (entry.getKey.asInstanceOf[INodeProvider]).getNode(classOf[NodeTank], entry.getValue.getOpposite).isInstanceOf[NodeTank]) {
else if (entry.getKey.isInstanceOf[INodeProvider] && (entry.getKey.asInstanceOf[INodeProvider]).getNode(classOf[NodeTank], entry.getValue.getOpposite).isInstanceOf[NodeTank])
{
val node: NodeTank = (entry.getKey.asInstanceOf[INodeProvider]).getNode(classOf[NodeTank], entry.getValue.getOpposite).asInstanceOf[NodeTank]
if (node.canFill(entry.getValue.getOpposite, getFluid.getFluid)) {
if (node.canFill(entry.getValue.getOpposite, getFluid.getFluid))
{
val stack: FluidStack = drain(Integer.MAX_VALUE, false)
val drained: Int = node.fill(stack, true)
drain(drained, true)
}
}
else if (entry.getKey.isInstanceOf[IFluidHandler]) {
if ((entry.getKey.asInstanceOf[IFluidHandler]).canFill(entry.getValue.getOpposite, getFluid.getFluid)) {
else if (entry.getKey.isInstanceOf[IFluidHandler])
{
if ((entry.getKey.asInstanceOf[IFluidHandler]).canFill(entry.getValue.getOpposite, getFluid.getFluid))
{
val stack: FluidStack = drain(Integer.MAX_VALUE, false)
val drained: Int = (entry.getKey.asInstanceOf[IFluidHandler]).fill(entry.getValue.getOpposite, stack, true)
drain(drained, true)
@ -45,22 +51,16 @@ class NodePressure(parent : INodeProvider, buckets : Int) extends NodeTank(paren
}
}
def canUpdate: Boolean = {
return true
}
def continueUpdate: Boolean = {
return true
}
protected def updatePressure {
protected def updatePressure()
{
var totalPressure: Int = 0
val connectionSize: Int = connections.size
var minPressure: Int = 0
var maxPressure: Int = 0
import scala.collection.JavaConversions._
for (entry <- connections.entrySet) {
if (entry.getKey.isInstanceOf[INodeProvider] && (entry.getKey.asInstanceOf[INodeProvider]).getNode(classOf[NodePressure], entry.getValue.getOpposite).isInstanceOf[NodePressure]) {
for (entry <- directionMap.entrySet)
{
if (entry.getKey.isInstanceOf[INodeProvider] && (entry.getKey.asInstanceOf[INodeProvider]).getNode(classOf[NodePressure], entry.getValue.getOpposite).isInstanceOf[NodePressure])
{
val node: NodePressure = (entry.getKey.asInstanceOf[INodeProvider]).getNode(classOf[NodePressure], entry.getValue.getOpposite).asInstanceOf[NodePressure]
val pressure: Int = node.getPressure(entry.getValue.getOpposite)
minPressure = Math.min(pressure, minPressure)
@ -68,27 +68,35 @@ class NodePressure(parent : INodeProvider, buckets : Int) extends NodeTank(paren
totalPressure += pressure
}
}
if (connectionSize == 0) {
if (connectionSize == 0)
{
setPressure(0)
}
else {
if (minPressure < 0) {
else
{
if (minPressure < 0)
{
minPressure += 1
}
if (maxPressure > 0) {
if (maxPressure > 0)
{
maxPressure -= 1
}
setPressure(Math.max(minPressure, Math.min(maxPressure, totalPressure / connectionSize + Integer.signum(totalPressure))))
}
}
def getPressure(direction: ForgeDirection): Int = {
def getPressure(direction: ForgeDirection): Int =
{
return pressure
}
def setPressure(pressure: Int) {
def setPressure(pressure: Int)
{
this.pressure = pressure
}
private var pressure: Int = 0
def canUpdate =true
def continueUpdate = true
}

View file

@ -4,18 +4,17 @@ import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids._
import resonant.api.ISave
import resonant.api.grid.{INode, INodeProvider}
import resonant.lib.prefab.fluid.{LimitedTank, NodeFluidHandler}
import resonant.lib.utility.WorldUtility
import resonant.api.grid.{INodeProvider, INode}
/**
* Simple tank node designed to be implemented by any machine that can connect to other fluid based machines.
*
* @author Darkguardsman
*/
class NodeTank(parent: INodeProvider, buckets: Int) extends NodeFluidHandler(parent, new LimitedTank(buckets * FluidContainerRegistry.BUCKET_VOLUME)) with ISave with INode {
class NodeTank(parent: INodeProvider, buckets: Int) extends NodeFluidHandler(parent, new LimitedTank(buckets * FluidContainerRegistry.BUCKET_VOLUME)) with ISave with INode
{
def load(nbt: NBTTagCompound)
{
getPrimaryTank.readFromNBT(nbt.getCompoundTag("tank"))
@ -26,25 +25,30 @@ class NodeTank(parent: INodeProvider, buckets: Int) extends NodeFluidHandler(pa
nbt.setTag("tank", getPrimaryTank.writeToNBT(new NBTTagCompound))
}
protected override def addConnection(obj: AnyRef, dir: ForgeDirection)
protected override def connect(obj: NodeFluidHandler, dir: ForgeDirection)
{
super.addConnection(obj, dir)
super.connect(obj, dir)
if (showConnectionsFor(obj, dir))
{
renderSides = WorldUtility.setEnableSide(getRenderSides, dir, true)
}
}
protected def showConnectionsFor(obj: AnyRef, dir: ForgeDirection): Boolean = {
if (obj != null) {
if (obj.getClass.isAssignableFrom(getParent.getClass)) {
protected def showConnectionsFor(obj: AnyRef, dir: ForgeDirection): Boolean =
{
if (obj != null)
{
if (obj.getClass.isAssignableFrom(getParent.getClass))
{
return true
}
}
return false
}
def getRenderSides: Int = {
def getRenderSides: Int =
{
return renderSides
}

View file

@ -1,85 +1,86 @@
package resonantinduction.electrical.battery
import java.util.Arrays
import java.util.LinkedHashSet
import java.util.Set
import java.util.{Arrays, LinkedHashSet, Set}
import resonant.lib.content.prefab.TEnergyStorage
import resonant.lib.grid.Grid
import resonant.lib.grid.node.NodeEnergy
import scala.collection.JavaConversions._
/** Basic grid designed to be used for creating a level look for batteries connected together
* @author robert(Darkguardsman)
*/
class GridBattery extends Grid[TileBattery](classOf[NodeEnergy])
class GridBattery extends Grid[TileBattery](classOf[NodeEnergy[_]]) with TEnergyStorage
{
var totalEnergy: Double = 0
var totalCapacity: Double = 0
var totalEnergy: Double = 0
var totalCapacity: Double = 0
/**
* Causes the energy shared by all batteries to be distributed out to all linked batteries
* @param exclusion - battery not to share with, used when batteries are removed from the network
*/
def redistribute(exclusion: TileBattery*)
/**
* Causes the energy shared by all batteries to be distributed out to all linked batteries
* @param exclusion - battery not to share with, used when batteries are removed from the network
*/
def redistribute(exclusion: TileBattery*)
{
var lowestY: Int = 255
var highestY: Int = 0
totalEnergy = 0
totalCapacity = 0
for (connector <- this.getNodes)
{
var lowestY: Int = 255
var highestY: Int = 0
totalEnergy = 0
totalCapacity = 0
for (connector <- this.getNodes)
{
totalEnergy += connector.energy.getEnergy
totalCapacity += connector.energy.getEnergyCapacity
lowestY = Math.min(connector.yCoord, lowestY)
highestY = Math.max(connector.yCoord, highestY)
connector.renderEnergyAmount = 0
}
var remainingRenderEnergy: Double = totalEnergy
var y: Int = 0
while (y >= 0 && y <= highestY && remainingRenderEnergy > 0)
{
val connectorsInlevel: Set[TileBattery] = new LinkedHashSet[TileBattery]
import scala.collection.JavaConversions._
for (connector <- this.getNodes)
{
if (connector.yCoord == y)
{
connectorsInlevel.add(connector)
}
}
val levelSize: Int = connectorsInlevel.size
var used: Double = 0
import scala.collection.JavaConversions._
for (connector <- connectorsInlevel)
{
val tryInject: Double = Math.min(remainingRenderEnergy / levelSize, connector.energy.getEnergyCapacity)
connector.renderEnergyAmount_$eq(tryInject)
used += tryInject
}
remainingRenderEnergy -= used
y += 1
}
val percentageLoss: Double = 0
val energyLoss: Double = percentageLoss * 100
totalEnergy -= energyLoss
val amountOfNodes: Int = this.getNodes.size - exclusion.length
if (totalEnergy > 0 && amountOfNodes > 0)
{
var remainingEnergy: Double = totalEnergy
val firstNode: TileBattery = this.getFirstNode
for (node <- this.getNodes)
{
if (node != firstNode && !Arrays.asList(exclusion).contains(node))
{
val percentage: Double = (node.energy.getEnergyCapacity / totalCapacity)
val energyForBattery: Double = Math.max(totalEnergy * percentage, 0)
node.energy.setEnergy(energyForBattery)
remainingEnergy -= energyForBattery
}
}
firstNode.energy.setEnergy(Math.max(remainingEnergy, 0))
}
totalEnergy += connector.energy.getEnergy
totalCapacity += connector.energy.getEnergyCapacity
lowestY = Math.min(connector.yCoord, lowestY)
highestY = Math.max(connector.yCoord, highestY)
connector.renderEnergyAmount = 0
}
var remainingRenderEnergy: Double = totalEnergy
var y: Int = 0
while (y >= 0 && y <= highestY && remainingRenderEnergy > 0)
{
val connectorsInlevel: Set[TileBattery] = new LinkedHashSet[TileBattery]
for (connector <- this.getNodes)
{
if (connector.yCoord == y)
{
connectorsInlevel.add(connector)
}
}
val levelSize: Int = connectorsInlevel.size
var used: Double = 0
for (connector <- connectorsInlevel)
{
val tryInject: Double = Math.min(remainingRenderEnergy / levelSize, connector.energy.getEnergyCapacity)
connector.renderEnergyAmount_$eq(tryInject)
used += tryInject
}
remainingRenderEnergy -= used
y += 1
}
val percentageLoss: Double = 0
val energyLoss: Double = percentageLoss * 100
totalEnergy -= energyLoss
val amountOfNodes: Int = this.getNodes.size - exclusion.length
if (totalEnergy > 0 && amountOfNodes > 0)
{
var remainingEnergy: Double = totalEnergy
val firstNode: TileBattery = this.getFirstNode
for (node <- this.getNodes)
{
if (node != firstNode && !Arrays.asList(exclusion).contains(node))
{
val percentage: Double = (node.energy.getEnergyCapacity / totalCapacity)
val energyForBattery: Double = Math.max(totalEnergy * percentage, 0)
node.energy.setEnergy(energyForBattery)
remainingEnergy -= energyForBattery
}
}
firstNode.energy.setEnergy(Math.max(remainingEnergy, 0))
}
}
}

View file

@ -98,7 +98,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
if (!world.isRemote)
{
println(node)
println(node.getConnections.size())
println(node.connections.size())
}
return true
@ -388,10 +388,12 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
if (tile.partMap(PartMap.edgeBetween(absDir, side)) == null)
{
val part = tile.partMap(absDir)
val to = ForgeDirection.getOrientation(absDir)
if (canConnectTo(part))
{
connections.put(part, ForgeDirection.getOrientation(absDir))
//TODO: Check dir
connect(part.asInstanceOf[INodeProvider].getNode(classOf[DCNode], to.getOpposite).asInstanceOf[DCNode], to)
skip = true
}
}
@ -438,13 +440,13 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
if (wire.canConnectTo(PartFlatWire.this, fromDir) && wire.maskOpen(otherR))
{
connections.put(dcNode, forgeDir)
connect(dcNode, forgeDir)
return true
}
}
else if (canConnectTo(part))
{
connections.put(dcNode, forgeDir)
connect(dcNode, forgeDir)
return true
}
}
@ -462,7 +464,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
if (canConnectTo(tileEntity, forgeDir))
{
connections.put(tileComponent, forgeDir)
connect(tileComponent, forgeDir)
return true
}
@ -488,8 +490,8 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
if (canConnectTo(part, absForgeDir))
{
//TODO: Connect to node, not part.
connections.put(part, absForgeDir)
//TODO: Check dir
connect(part.asInstanceOf[INodeProvider].getNode(classOf[DCNode], absForgeDir.getOpposite).asInstanceOf[DCNode], absForgeDir)
return true
}
}
@ -502,7 +504,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
if (!world.isRemote)
{
//TODO: Refine this. It's very hacky and may cause errors when the wire connects to a block both ways
val inverseCon = connections.map(_.swap)
val inverseCon = directionMap.map(_.swap)
val forgeDir = ForgeDirection.getOrientation(i)
if (inverseCon.contains(forgeDir))
@ -511,7 +513,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
if (connected != null)
{
connections -= connected
disconnect(connected)
}
}
}

View file

@ -35,7 +35,7 @@ class PartFramedWire extends PartFramedNode with TWire
override protected def addConnection(obj: AnyRef, dir: ForgeDirection)
{
super.addConnection(obj, dir)
super.connect(obj, dir)
connectionMask = connectionMask.openMask(dir)
}
}

View file

@ -90,9 +90,9 @@ public class DebugFrameMechanical extends FrameNodeDebug
@Override
public int getRowCount()
{
if (getNode() != null && getNode().getConnections() != null)
if (getNode() != null && getNode().connections() != null)
{
return getNode().getConnections().size();
return getNode().connections().size();
}
return 10;
}
@ -100,10 +100,10 @@ public class DebugFrameMechanical extends FrameNodeDebug
@Override
public Object getValueAt(int row, int col)
{
if (getNode() != null && getNode().getConnections() != null)
if (getNode() != null && getNode().connections() != null)
{
ForgeDirection dir = (ForgeDirection) getNode().getConnections().values().toArray()[row];
MechanicalNode node = (MechanicalNode) getNode().getConnections().keySet().toArray()[row];
ForgeDirection dir = (ForgeDirection) getNode().connections().values().toArray()[row];
MechanicalNode node = (MechanicalNode) getNode().connections().keySet().toArray()[row];
switch(col)
{
case 0: return dir;

View file

@ -20,7 +20,7 @@ import java.util.Map.Entry;
* @author Calclavia, Darkguardsman
*/
//Don't convert to scala as this will find its way into RE later - From Darkguardsman
public class MechanicalNode extends NodeConnector implements TMultipartNode, IMechanicalNode, ISaveObj, IVectorWorld, IUpdate
public class MechanicalNode extends NodeConnector<MechanicalNode> implements TMultipartNode, IMechanicalNode, ISaveObj, IVectorWorld, IUpdate
{
/**
* Marks that the rotation has changed and should be updated client side
@ -164,7 +164,7 @@ public class MechanicalNode extends NodeConnector implements TMultipartNode, IMe
if (sharePower)
{
// Power sharing calculations
Iterator<Entry<Object, ForgeDirection>> it = getConnections().entrySet().iterator();
Iterator<Entry<Object, ForgeDirection>> it = connections().entrySet().iterator();
while (it.hasNext())
{
@ -332,4 +332,10 @@ public class MechanicalNode extends NodeConnector implements TMultipartNode, IMe
{
return true;
}
@Override
public Class getConnectClass()
{
return getClass();
}
}

View file

@ -67,7 +67,7 @@ class GearNode(parent: PartGear) extends MechanicalNode(parent: PartGear)
val instance: MechanicalNode = (tileBehind.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], gear.placementSide.getOpposite).asInstanceOf[MechanicalNode]
if (instance != null && instance != this && !(instance.getParent.isInstanceOf[PartGearShaft]) && instance.canConnect(this,gear.placementSide.getOpposite))
{
addConnection(instance, gear.placementSide)
connect(instance, gear.placementSide)
}
}
for (i <- 0 until 6)
@ -83,7 +83,7 @@ class GearNode(parent: PartGear) extends MechanicalNode(parent: PartGear)
val instance: MechanicalNode = (tile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], if (checkDir eq gear.placementSide.getOpposite) ForgeDirection.UNKNOWN else checkDir).asInstanceOf[MechanicalNode]
if (!connections.containsValue(checkDir) && instance != this && checkDir != gear.placementSide && instance != null && instance.canConnect(this,checkDir.getOpposite))
{
addConnection(instance, checkDir)
connect(instance, checkDir)
}
}
}
@ -101,7 +101,7 @@ class GearNode(parent: PartGear) extends MechanicalNode(parent: PartGear)
val instance: MechanicalNode = (checkTile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], gear.placementSide).asInstanceOf[MechanicalNode]
if (instance != null && instance != this && instance.canConnect(this,checkDir.getOpposite) && !(instance.getParent.isInstanceOf[PartGearShaft]))
{
addConnection(instance, checkDir)
connect(instance, checkDir)
}
}
}

View file

@ -9,7 +9,6 @@ import resonant.lib.transform.vector.Vector3
class GearShaftNode(parent: INodeProvider) extends MechanicalNode(parent)
{
override def getTorqueLoad: Double =
{
shaft.tier match
@ -40,9 +39,10 @@ class GearShaftNode(parent: INodeProvider) extends MechanicalNode(parent)
if (shaft.tile.isInstanceOf[INodeProvider])
{
val instance: MechanicalNode = (shaft.tile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], checkDir).asInstanceOf[MechanicalNode]
if (instance != null && instance != this && instance.canConnect(this, checkDir.getOpposite))
{
addConnection(instance, checkDir)
connect(instance, checkDir)
}
}
else
@ -53,7 +53,7 @@ class GearShaftNode(parent: INodeProvider) extends MechanicalNode(parent)
val instance: MechanicalNode = (checkTile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], checkDir.getOpposite).asInstanceOf[MechanicalNode]
if (instance != null && instance != this && instance.getParent.isInstanceOf[PartGearShaft] && instance.canConnect(this, checkDir.getOpposite))
{
addConnection(instance, checkDir)
connect(instance, checkDir)
}
}
}