Some work on PipePart
This commit is contained in:
parent
d5159e94b2
commit
20b118158b
4 changed files with 183 additions and 19 deletions
|
@ -41,7 +41,7 @@ object PartFramedNode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class PartFramedNode extends TMultiPart with TInsulatable with INodeProvider with TSlottedPart with TNormalOcclusion with TIconHitEffects
|
abstract class PartFramedNode extends TMultiPart with INodeProvider with TSlottedPart with TNormalOcclusion with TIconHitEffects
|
||||||
{
|
{
|
||||||
/** Bitmask connections */
|
/** Bitmask connections */
|
||||||
var connectionMask: Byte = 0x00
|
var connectionMask: Byte = 0x00
|
||||||
|
@ -89,16 +89,17 @@ abstract class PartFramedNode extends TMultiPart with TInsulatable with INodePro
|
||||||
{
|
{
|
||||||
val collisionBoxes: Set[Cuboid6] = new HashSet[Cuboid6]
|
val collisionBoxes: Set[Cuboid6] = new HashSet[Cuboid6]
|
||||||
collisionBoxes.addAll(getSubParts.asInstanceOf[Collection[_ <: Cuboid6]])
|
collisionBoxes.addAll(getSubParts.asInstanceOf[Collection[_ <: Cuboid6]])
|
||||||
return collisionBoxes;
|
return collisionBoxes
|
||||||
}
|
}
|
||||||
|
|
||||||
override def getSubParts: java.lang.Iterable[IndexedCuboid6] =
|
override def getSubParts: java.lang.Iterable[IndexedCuboid6] =
|
||||||
{
|
{
|
||||||
super.getSubParts
|
super.getSubParts
|
||||||
|
|
||||||
val currentSides: Array[IndexedCuboid6] = if (insulated) PartFramedNode.insulatedSides.clone() else PartFramedNode.sides.clone()
|
val currentSides: Array[IndexedCuboid6] = if (this.isInstanceOf[TInsulatable] && this.asInstanceOf[TInsulatable].insulated) PartFramedNode.insulatedSides.clone() else PartFramedNode.sides.clone()
|
||||||
|
|
||||||
|
val list = new util.LinkedList[IndexedCuboid6]
|
||||||
|
|
||||||
val list: util.LinkedList[IndexedCuboid6] = new util.LinkedList[IndexedCuboid6]
|
|
||||||
if (tile != null)
|
if (tile != null)
|
||||||
{
|
{
|
||||||
for (side <- ForgeDirection.VALID_DIRECTIONS)
|
for (side <- ForgeDirection.VALID_DIRECTIONS)
|
||||||
|
@ -121,7 +122,7 @@ abstract class PartFramedNode extends TMultiPart with TInsulatable with INodePro
|
||||||
|
|
||||||
def getHollowSize: Int =
|
def getHollowSize: Int =
|
||||||
{
|
{
|
||||||
return if (insulated) 8 else 6
|
return if (this.isInstanceOf[TInsulatable] && this.asInstanceOf[TInsulatable].insulated) 8 else 6
|
||||||
}
|
}
|
||||||
|
|
||||||
def isBlockedOnSide(side: ForgeDirection): Boolean =
|
def isBlockedOnSide(side: ForgeDirection): Boolean =
|
||||||
|
@ -183,20 +184,15 @@ abstract class PartFramedNode extends TMultiPart with TInsulatable with INodePro
|
||||||
read(packet, packet.readUByte)
|
read(packet, packet.readUByte)
|
||||||
}
|
}
|
||||||
|
|
||||||
override def read(packet: MCDataInput, packetID: Int)
|
def read(packet: MCDataInput, packetID: Int)
|
||||||
{
|
{
|
||||||
if (packetID == 0)
|
if (packetID == 0)
|
||||||
{
|
{
|
||||||
connectionMask = packet.readByte
|
connectionMask = packet.readByte
|
||||||
tile.markRender
|
tile.markRender
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
super.read(packet, packetID)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings(Array("hiding"))
|
|
||||||
def getNode(nodeType: Class[_ <: INode], from: ForgeDirection): INode =
|
def getNode(nodeType: Class[_ <: INode], from: ForgeDirection): INode =
|
||||||
{
|
{
|
||||||
if (node != null && nodeType != null)
|
if (node != null && nodeType != null)
|
||||||
|
@ -209,6 +205,7 @@ abstract class PartFramedNode extends TMultiPart with TInsulatable with INodePro
|
||||||
override def save(nbt: NBTTagCompound)
|
override def save(nbt: NBTTagCompound)
|
||||||
{
|
{
|
||||||
super.save(nbt)
|
super.save(nbt)
|
||||||
|
|
||||||
if (node.isInstanceOf[ISave])
|
if (node.isInstanceOf[ISave])
|
||||||
node.asInstanceOf[ISave].save(nbt)
|
node.asInstanceOf[ISave].save(nbt)
|
||||||
}
|
}
|
||||||
|
@ -216,15 +213,11 @@ abstract class PartFramedNode extends TMultiPart with TInsulatable with INodePro
|
||||||
override def load(nbt: NBTTagCompound)
|
override def load(nbt: NBTTagCompound)
|
||||||
{
|
{
|
||||||
super.load(nbt)
|
super.load(nbt)
|
||||||
|
|
||||||
if (node.isInstanceOf[ISave])
|
if (node.isInstanceOf[ISave])
|
||||||
node.asInstanceOf[ISave].load(nbt)
|
node.asInstanceOf[ISave].load(nbt)
|
||||||
}
|
}
|
||||||
|
|
||||||
override def toString: String =
|
|
||||||
{
|
|
||||||
return this.getClass.getSimpleName + this.hashCode
|
|
||||||
}
|
|
||||||
|
|
||||||
def getNode: INode = node
|
def getNode: INode = node
|
||||||
|
|
||||||
def setNode(n: INode)
|
def setNode(n: INode)
|
||||||
|
|
|
@ -58,4 +58,6 @@ trait TPart extends TMultiPart with TraitTicker
|
||||||
}
|
}
|
||||||
|
|
||||||
override def toString: String = "[" + getClass.getSimpleName + "]" + x + "x " + y + "y " + z + "z"
|
override def toString: String = "[" + getClass.getSimpleName + "]" + x + "x " + y + "y " + z + "z"
|
||||||
|
|
||||||
|
override def getType: String = "ResonantInduction:" + getClass.getSimpleName
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@ import codechicken.lib.data.MCDataInput;
|
||||||
import codechicken.lib.render.CCRenderState;
|
import codechicken.lib.render.CCRenderState;
|
||||||
import codechicken.lib.vec.Cuboid6;
|
import codechicken.lib.vec.Cuboid6;
|
||||||
import codechicken.multipart.JNormalOcclusion;
|
import codechicken.multipart.JNormalOcclusion;
|
||||||
|
import codechicken.multipart.TNormalOcclusion;
|
||||||
import codechicken.multipart.TSlottedPart;
|
import codechicken.multipart.TSlottedPart;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
@ -24,7 +25,7 @@ import java.util.Set;
|
||||||
*
|
*
|
||||||
* @author Calclavia, Darkguardsman
|
* @author Calclavia, Darkguardsman
|
||||||
*/
|
*/
|
||||||
public class PartPipe extends PartFramedNode<EnumPipeMaterial> implements TSlottedPart, JNormalOcclusion, IFluidHandler
|
public class PartPipe extends PartFramedNode<EnumPipeMaterial> implements TSlottedPart, TNormalOcclusion, IFluidHandler
|
||||||
{
|
{
|
||||||
protected final FluidTank tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
|
protected final FluidTank tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,168 @@
|
||||||
|
package resonantinduction.mechanical.fluid.pipe
|
||||||
|
|
||||||
|
import codechicken.multipart.{TNormalOcclusion, TSlottedPart}
|
||||||
|
import net.minecraftforge.fluids._
|
||||||
|
import resonantinduction.core.prefab.part.{PartFramedNode, TColorable, TMaterial}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fluid transport pipe
|
||||||
|
*
|
||||||
|
* @author Calclavia,
|
||||||
|
*/
|
||||||
|
class PartPipe extends PartFramedNode with TMaterial[EnumPipeMaterial] with TColorable with TSlottedPart with TNormalOcclusion with IFluidHandler
|
||||||
|
{
|
||||||
|
setNode(new PipePressureNode(this))
|
||||||
|
|
||||||
|
def setMaterial(i: Int)
|
||||||
|
{
|
||||||
|
material = EnumPipeMaterial.values(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
def getMaterialID: Int = material.ordinal
|
||||||
|
|
||||||
|
|
||||||
|
override def update
|
||||||
|
{
|
||||||
|
super.update
|
||||||
|
averageTankData.add(tank.getFluidAmount)
|
||||||
|
if (!world.isRemote && markPacket)
|
||||||
|
{
|
||||||
|
sendFluidUpdate
|
||||||
|
markPacket = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends fluid level to the client to be used in the renderer
|
||||||
|
*/
|
||||||
|
def sendFluidUpdate
|
||||||
|
{
|
||||||
|
val nbt: NBTTagCompound = new NBTTagCompound
|
||||||
|
var averageAmount: Int = 0
|
||||||
|
if (averageTankData.size > 0)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
var i: Int = 0
|
||||||
|
while (i < averageTankData.size)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
averageAmount += averageTankData.get(i)
|
||||||
|
}
|
||||||
|
(
|
||||||
|
{
|
||||||
|
i += 1;
|
||||||
|
i - 1
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
averageAmount /= averageTankData.size
|
||||||
|
}
|
||||||
|
val tempTank: FluidTank = if (tank.getFluid != null) new FluidTank(tank.getFluid.getFluid, averageAmount, tank.getCapacity) else new FluidTank(tank.getCapacity)
|
||||||
|
tempTank.writeToNBT(nbt)
|
||||||
|
tile.getWriteStream(this).writeByte(3).writeInt(tank.getCapacity).writeNBTTagCompound(nbt)
|
||||||
|
}
|
||||||
|
|
||||||
|
override def read(packet: MCDataInput, packetID: Int)
|
||||||
|
{
|
||||||
|
if (packetID == 3)
|
||||||
|
{
|
||||||
|
tank.setCapacity(packet.readInt)
|
||||||
|
tank.readFromNBT(packet.readNBTTagCompound)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
super.read(packet, packetID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT) override def renderDynamic(pos: Vector3, frame: Float, pass: Int)
|
||||||
|
{
|
||||||
|
RenderPipe.INSTANCE.render(this, pos.x, pos.y, pos.z, frame)
|
||||||
|
}
|
||||||
|
|
||||||
|
def getItem: ItemStack =
|
||||||
|
{
|
||||||
|
return new ItemStack(Mechanical.itemPipe, 1, getMaterialID)
|
||||||
|
}
|
||||||
|
|
||||||
|
def fill(from: ForgeDirection, resource: FluidStack, doFill: Boolean): Int =
|
||||||
|
{
|
||||||
|
if (!world.isRemote)
|
||||||
|
{
|
||||||
|
if (doFill)
|
||||||
|
{
|
||||||
|
markPacket = true
|
||||||
|
}
|
||||||
|
return tank.fill(resource, doFill)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
def drain(from: ForgeDirection, resource: FluidStack, doDrain: Boolean): FluidStack =
|
||||||
|
{
|
||||||
|
return drain(from, resource.amount, doDrain)
|
||||||
|
}
|
||||||
|
|
||||||
|
def drain(from: ForgeDirection, maxDrain: Int, doDrain: Boolean): FluidStack =
|
||||||
|
{
|
||||||
|
if (!world.isRemote)
|
||||||
|
{
|
||||||
|
if (doDrain)
|
||||||
|
{
|
||||||
|
markPacket = true
|
||||||
|
}
|
||||||
|
return tank.drain(maxDrain, doDrain)
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
def canFill(from: ForgeDirection, fluid: Fluid): Boolean =
|
||||||
|
{
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
def canDrain(from: ForgeDirection, fluid: Fluid): Boolean =
|
||||||
|
{
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
def getTankInfo(from: ForgeDirection): Array[FluidTankInfo] =
|
||||||
|
{
|
||||||
|
return Array[FluidTankInfo](tank.getInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
override def drawBreaking(renderBlocks: RenderBlocks)
|
||||||
|
{
|
||||||
|
CCRenderState.reset
|
||||||
|
}
|
||||||
|
|
||||||
|
override def save(nbt: NBTTagCompound)
|
||||||
|
{
|
||||||
|
super.save(nbt)
|
||||||
|
tank.writeToNBT(nbt)
|
||||||
|
}
|
||||||
|
|
||||||
|
override def load(nbt: NBTTagCompound)
|
||||||
|
{
|
||||||
|
super.load(nbt)
|
||||||
|
tank.readFromNBT(nbt)
|
||||||
|
}
|
||||||
|
|
||||||
|
override def getOcclusionBoxes: Set[Cuboid6] =
|
||||||
|
{
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
override def getSlotMask: Int =
|
||||||
|
{
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final val tank: FluidTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes the average fluid for client to render.
|
||||||
|
*/
|
||||||
|
private var averageTankData: EvictingList[Integer] = new EvictingList[Integer](20)
|
||||||
|
private var markPacket: Boolean = true
|
||||||
|
}
|
Loading…
Reference in a new issue