Wind turbine now has persistent cache

This commit is contained in:
Calclavia 2014-11-23 11:03:11 +08:00
parent 074f8fd57d
commit b70ddf1e04
3 changed files with 53 additions and 34 deletions

View file

@ -37,15 +37,6 @@ class NodeTurbine(parent: TileTurbine) extends NodeMechanical(parent)
override def canConnect[B <: NodeMechanical](other: B, from: ForgeDirection): Boolean = override def canConnect[B <: NodeMechanical](other: B, from: ForgeDirection): Boolean =
{ {
if (!other.isInstanceOf[NodeTurbine])
println(other.getClass + " vs " + turbine.getDirection)
return turbine.getMultiBlock.isPrimary && other.isInstanceOf[NodeMechanical] && !other.isInstanceOf[NodeTurbine] && from == turbine.getDirection return turbine.getMultiBlock.isPrimary && other.isInstanceOf[NodeMechanical] && !other.isInstanceOf[NodeTurbine] && from == turbine.getDirection
} }
/**
override def inverseRotation(dir: ForgeDirection): Boolean =
{
return dir == turbine.getDirection.getOpposite
} */
} }

View file

@ -64,24 +64,6 @@ class TileTurbine extends TileMechanical(Material.wood) with IMultiBlockStructur
{ {
} }
/** Reads a tile entity from NBT. */
override def readFromNBT(nbt: NBTTagCompound)
{
super.readFromNBT(nbt)
multiBlockRadius = nbt.getInteger("multiBlockRadius")
tier = nbt.getInteger("tier")
getMultiBlock.load(nbt)
}
/** Writes a tile entity to NBT. */
override def writeToNBT(nbt: NBTTagCompound)
{
super.writeToNBT(nbt)
nbt.setInteger("multiBlockRadius", multiBlockRadius)
nbt.setInteger("tier", tier)
getMultiBlock.save(nbt)
}
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
override def getRenderBoundingBox: AxisAlignedBB = override def getRenderBoundingBox: AxisAlignedBB =
{ {
@ -127,12 +109,22 @@ class TileTurbine extends TileMechanical(Material.wood) with IMultiBlockStructur
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord) worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
} }
override def write(buf: ByteBuf, id: Int) /** Reads a tile entity from NBT. */
override def readFromNBT(nbt: NBTTagCompound)
{ {
super.write(buf, id) super.readFromNBT(nbt)
multiBlockRadius = nbt.getInteger("multiBlockRadius")
tier = nbt.getInteger("tier")
getMultiBlock.load(nbt)
}
if (id == 0) /** Writes a tile entity to NBT. */
buf <<<< writeToNBT override def writeToNBT(nbt: NBTTagCompound)
{
super.writeToNBT(nbt)
nbt.setInteger("multiBlockRadius", multiBlockRadius)
nbt.setInteger("tier", tier)
getMultiBlock.save(nbt)
} }
override def read(buf: ByteBuf, id: Int, packetType: PacketType) override def read(buf: ByteBuf, id: Int, packetType: PacketType)
@ -140,7 +132,23 @@ class TileTurbine extends TileMechanical(Material.wood) with IMultiBlockStructur
super.read(buf, id, packetType) super.read(buf, id, packetType)
if (id == 0) if (id == 0)
buf >>>> readFromNBT {
multiBlockRadius = buf.readInt()
tier = buf.readInt()
buf >>>> getMultiBlock.load
}
}
override def write(buf: ByteBuf, id: Int)
{
super.write(buf, id)
if (id == 0)
{
buf <<< multiBlockRadius
buf <<< tier
buf <<<< getMultiBlock.save
}
} }
def getWorld: World = def getWorld: World =

View file

@ -6,6 +6,7 @@ import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.minecraft.creativetab.CreativeTabs import net.minecraft.creativetab.CreativeTabs
import net.minecraft.init.{Blocks, Items} import net.minecraft.init.{Blocks, Items}
import net.minecraft.item.{Item, ItemStack} import net.minecraft.item.{Item, ItemStack}
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.util.ResourceLocation import net.minecraft.util.ResourceLocation
import net.minecraft.world.biome.{BiomeGenBase, BiomeGenOcean, BiomeGenPlains} import net.minecraft.world.biome.{BiomeGenBase, BiomeGenOcean, BiomeGenPlains}
import net.minecraftforge.client.model.AdvancedModelLoader import net.minecraftforge.client.model.AdvancedModelLoader
@ -18,6 +19,7 @@ import resonant.lib.render.RenderUtility
import resonant.lib.transform.vector.Vector3 import resonant.lib.transform.vector.Vector3
import resonant.lib.utility.MathUtility import resonant.lib.utility.MathUtility
import resonant.lib.utility.inventory.InventoryUtility import resonant.lib.utility.inventory.InventoryUtility
import resonant.lib.wrapper.NBTWrapper._
import resonant.lib.wrapper.WrapList._ import resonant.lib.wrapper.WrapList._
import resonantinduction.core.{Reference, Settings} import resonantinduction.core.{Reference, Settings}
@ -39,7 +41,7 @@ class TileWindTurbine extends TileTurbine with IBoilHandler
/** /**
* Wind simulations * Wind simulations
*/ */
private final val openBlockCache = new Array[Byte](224) private var openBlockCache = new Array[Byte](224)
private var checkCount = 0 private var checkCount = 0
private var efficiency = 0f private var efficiency = 0f
private var windPower = 0d private var windPower = 0d
@ -122,7 +124,7 @@ class TileWindTurbine extends TileTurbine with IBoilHandler
efficiency = efficiency - openBlockCache(checkCount) + openAirBlocks efficiency = efficiency - openBlockCache(checkCount) + openAirBlocks
openBlockCache(checkCount) = openAirBlocks.toByte openBlockCache(checkCount) = openAirBlocks.toByte
checkCount = (checkCount + 1) % (openBlockCache.length - 1) checkCount = (checkCount + 1) % (openBlockCache.length - 1)
val multiblockMultiplier = multiBlockRadius + 0.5f val multiblockMultiplier = (multiBlockRadius / 2) * (multiBlockRadius / 2)
val materialMultiplier = tier match val materialMultiplier = tier match
{ {
@ -158,6 +160,24 @@ class TileWindTurbine extends TileTurbine with IBoilHandler
override def getTankInfo(from: ForgeDirection): Array[FluidTankInfo] = Array(gasTank.getInfo) override def getTankInfo(from: ForgeDirection): Array[FluidTankInfo] = Array(gasTank.getInfo)
/** Reads a tile entity from NBT. */
override def readFromNBT(nbt: NBTTagCompound)
{
super.readFromNBT(nbt)
checkCount = nbt.getInteger("checkCount")
efficiency = nbt.getFloat("efficiency")
openBlockCache = nbt.getArray[Byte]("openBlockCache")
}
/** Writes a tile entity to NBT. */
override def writeToNBT(nbt: NBTTagCompound)
{
super.writeToNBT(nbt)
nbt.setInteger("checkCount", checkCount)
nbt.setFloat("efficiency", efficiency)
nbt.setArray("openBlockCache", openBlockCache)
}
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
override def renderDynamic(pos: Vector3, frame: Float, pass: Int): Unit = override def renderDynamic(pos: Vector3, frame: Float, pass: Int): Unit =
{ {