Updated to new Multipart packet system
This commit is contained in:
parent
a5c8641710
commit
839d5f0abc
17 changed files with 251 additions and 298 deletions
|
@ -35,7 +35,6 @@ import resonantinduction.electrical.tesla.{RenderTesla, TileTesla}
|
|||
import resonantinduction.electrical.transformer.RenderTransformer
|
||||
import resonantinduction.mechanical.MechanicalContent
|
||||
import resonantinduction.mechanical.fluid.pipe.RenderPipe
|
||||
import resonantinduction.mechanical.fluid.transport.TilePump
|
||||
import resonantinduction.mechanical.mech.gear.RenderGear
|
||||
import resonantinduction.mechanical.mech.gearshaft.RenderGearShaft
|
||||
import resonantinduction.mechanical.mech.process.crusher.{RenderMechanicalPiston, TileMechanicalPiston}
|
||||
|
@ -65,7 +64,7 @@ import resonantinduction.mechanical.mech.turbine._
|
|||
ClientRegistry.bindTileEntitySpecialRenderer(classOf[TileElectricTurbine], new RenderElectricTurbine)
|
||||
|
||||
//Electrical content
|
||||
ItemRenderHandler.register(ElectricalContent.itemTransformer, RenderTransformer.INSTANCE)
|
||||
ItemRenderHandler.register(ElectricalContent.itemTransformer, RenderTransformer)
|
||||
ItemRenderHandler.register(ElectricalContent.itemMultimeter, RenderMultimeter)
|
||||
ItemRenderHandler.register(ElectricalContent.itemQuantumGlyph, RenderQuantumGlyph)
|
||||
|
||||
|
|
|
@ -36,13 +36,13 @@ abstract class PartFace extends PartAbstract with TCuboidPart with JNormalOcclus
|
|||
this.facing = (facing - 2).asInstanceOf[Byte]
|
||||
}
|
||||
|
||||
override def readDesc(packet: MCDataInput)
|
||||
override def read(packet: MCDataInput, id: Int)
|
||||
{
|
||||
placementSide = ForgeDirection.getOrientation(packet.readByte)
|
||||
facing = packet.readByte
|
||||
}
|
||||
|
||||
override def writeDesc(packet: MCDataOutput)
|
||||
override def write(packet: MCDataOutput, id: Int)
|
||||
{
|
||||
packet.writeByte(placementSide.ordinal)
|
||||
packet.writeByte(facing)
|
||||
|
|
|
@ -70,32 +70,26 @@ abstract class PartAbstract extends TMultiPart with TraitTicker
|
|||
write(getWriteStream, id)
|
||||
}
|
||||
|
||||
def write(packet: MCDataOutput, id: Int)
|
||||
{
|
||||
packet.writeByte(id)
|
||||
}
|
||||
|
||||
/**
|
||||
* Should NOT override!
|
||||
*/
|
||||
override def writeDesc(packet: MCDataOutput)
|
||||
override final def writeDesc(packet: MCDataOutput)
|
||||
{
|
||||
write(packet, 0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Should NOT override!
|
||||
*/
|
||||
override def readDesc(packet: MCDataInput)
|
||||
override final def readDesc(packet: MCDataInput)
|
||||
{
|
||||
read(packet)
|
||||
}
|
||||
|
||||
override def read(packet: MCDataInput)
|
||||
override final def read(packet: MCDataInput)
|
||||
{
|
||||
read(packet, packet.readUByte)
|
||||
}
|
||||
|
||||
def write(packet: MCDataOutput, id: Int)
|
||||
{
|
||||
packet.writeByte(id)
|
||||
}
|
||||
|
||||
def read(packet: MCDataInput, id: Int)
|
||||
{
|
||||
|
||||
|
|
|
@ -79,15 +79,9 @@ abstract class PartFramedNode extends PartAbstract with TPartNodeProvider with T
|
|||
tile.getWriteStream(this).writeByte(0).writeByte(node.connectedMask)
|
||||
}
|
||||
|
||||
override def readDesc(packet: MCDataInput)
|
||||
override def write(packet: MCDataOutput, id: Int)
|
||||
{
|
||||
super.readDesc(packet)
|
||||
clientRenderMask = packet.readByte
|
||||
}
|
||||
|
||||
override def writeDesc(packet: MCDataOutput)
|
||||
{
|
||||
super.writeDesc(packet)
|
||||
super.write(packet, id)
|
||||
packet.writeByte(node.connectedMask)
|
||||
}
|
||||
|
||||
|
|
|
@ -67,22 +67,22 @@ trait TColorable extends PartAbstract
|
|||
return false
|
||||
}
|
||||
|
||||
override def readDesc(packet: MCDataInput)
|
||||
override def write(packet: MCDataOutput, id: Int)
|
||||
{
|
||||
colorID = packet.readByte
|
||||
}
|
||||
super.write(packet, id)
|
||||
|
||||
override def writeDesc(packet: MCDataOutput)
|
||||
{
|
||||
packet.writeByte(colorID.toByte)
|
||||
if (id == 0 || id == 2)
|
||||
packet.writeByte(colorID.toByte)
|
||||
}
|
||||
|
||||
override def read(packet: MCDataInput, packetID: Int)
|
||||
{
|
||||
if (packetID == 2)
|
||||
packetID match
|
||||
{
|
||||
colorID = packet.readInt()
|
||||
tile.markRender()
|
||||
case 0 => colorID = packet.readByte
|
||||
case 2 =>
|
||||
colorID = packet.readInt()
|
||||
tile.markRender()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -96,19 +96,19 @@ trait TInsulatable extends PartAbstract
|
|||
drops += new ItemStack(insulationItem)
|
||||
}
|
||||
|
||||
override def writeDesc(packet: MCDataOutput)
|
||||
override def write(packet: MCDataOutput, id: Int)
|
||||
{
|
||||
packet.writeBoolean(insulated)
|
||||
}
|
||||
super.write(packet, id)
|
||||
|
||||
override def readDesc(packet: MCDataInput)
|
||||
{
|
||||
_insulated = packet.readBoolean
|
||||
if (id <= 1)
|
||||
packet.writeBoolean(insulated)
|
||||
}
|
||||
|
||||
override def read(packet: MCDataInput, packetID: Int)
|
||||
{
|
||||
if (packetID == 1)
|
||||
super.read(packet,packetID)
|
||||
|
||||
if (packetID <= 1)
|
||||
_insulated = packet.readBoolean
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
package resonantinduction.core.prefab.part.connector
|
||||
|
||||
import codechicken.lib.data.{MCDataInput, MCDataOutput}
|
||||
import codechicken.multipart.TMultiPart
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
/**
|
||||
* Trait applied to objects that can associates with a material.
|
||||
* @author Calclavia
|
||||
*/
|
||||
trait TMaterial[M] extends TMultiPart
|
||||
trait TMaterial[M] extends PartAbstract
|
||||
{
|
||||
var material: M = _
|
||||
|
||||
|
@ -16,14 +15,16 @@ trait TMaterial[M] extends TMultiPart
|
|||
|
||||
def getMaterialID: Int
|
||||
|
||||
override def readDesc(packet: MCDataInput)
|
||||
override def read(packet: MCDataInput, id: Int)
|
||||
{
|
||||
setMaterial(packet.readByte)
|
||||
if (id == 0)
|
||||
setMaterial(packet.readByte)
|
||||
}
|
||||
|
||||
override def writeDesc(packet: MCDataOutput)
|
||||
override def write(packet: MCDataOutput, id: Int)
|
||||
{
|
||||
packet.writeByte(getMaterialID.toByte)
|
||||
if (id == 0)
|
||||
packet.writeByte(getMaterialID.toByte)
|
||||
}
|
||||
|
||||
override def save(nbt: NBTTagCompound)
|
||||
|
|
|
@ -16,17 +16,17 @@ import net.minecraft.util.{ChatComponentText, MovingObjectPosition}
|
|||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import net.minecraftforge.fluids.{FluidTankInfo, IFluidHandler}
|
||||
import resonant.api.IRemovable
|
||||
import resonant.api.grid.INodeProvider
|
||||
import resonant.lib.grid.Compatibility
|
||||
import resonant.lib.network.discriminator.PacketType
|
||||
import resonant.lib.network.handle.IPacketReceiver
|
||||
import resonant.lib.transform.vector.Vector3
|
||||
import resonant.lib.utility.WrenchUtility
|
||||
import resonantinduction.core.ResonantInduction
|
||||
import resonantinduction.core.interfaces.TMechanicalNode
|
||||
import resonantinduction.core.prefab.part.ChickenBonesWrapper._
|
||||
import resonantinduction.core.prefab.part.PartFace
|
||||
import resonantinduction.electrical.ElectricalContent
|
||||
import resonant.api.grid.INodeProvider
|
||||
import resonant.lib.transform.vector.Vector3
|
||||
|
||||
import scala.collection.convert.wrapAll._
|
||||
|
||||
|
@ -68,7 +68,8 @@ class PartMultimeter extends PartFace with IRedstonePart with IPacketReceiver wi
|
|||
|
||||
override def preRemove
|
||||
{
|
||||
if (!world.isRemote) getNetwork.remove(this)
|
||||
if (!world.isRemote)
|
||||
getNetwork.remove(this)
|
||||
}
|
||||
|
||||
def updateDesc
|
||||
|
@ -76,9 +77,9 @@ class PartMultimeter extends PartFace with IRedstonePart with IPacketReceiver wi
|
|||
writeDesc(getWriteStream)
|
||||
}
|
||||
|
||||
def updateGraph
|
||||
def updateGraph()
|
||||
{
|
||||
writeGraph(getWriteStream)
|
||||
sendPacket(2)
|
||||
}
|
||||
|
||||
/** Gets the multimeter on the same plane. */
|
||||
|
@ -190,43 +191,32 @@ class PartMultimeter extends PartFace with IRedstonePart with IPacketReceiver wi
|
|||
getNetwork.energyCapacityGraph.queue(Compatibility.getMaxEnergy(tileEntity, receivingSide))
|
||||
}
|
||||
|
||||
override def readDesc(packet: MCDataInput)
|
||||
override def write(packet: MCDataOutput, id: Int)
|
||||
{
|
||||
packet.readByte
|
||||
placementSide = ForgeDirection.getOrientation(packet.readByte)
|
||||
facing = packet.readByte
|
||||
detectMode = DetectModes(packet.readByte).asInstanceOf[DetectModes.DetectMode]
|
||||
detectType = packet.readByte
|
||||
graphType = packet.readByte
|
||||
getNetwork.center = new Vector3(packet.readNBTTagCompound)
|
||||
getNetwork.size = new Vector3(packet.readNBTTagCompound)
|
||||
getNetwork.isEnabled = packet.readBoolean
|
||||
}
|
||||
super.write(packet, id)
|
||||
|
||||
override def writeDesc(packet: MCDataOutput)
|
||||
{
|
||||
packet.writeByte(0)
|
||||
packet.writeByte(placementSide.ordinal)
|
||||
packet.writeByte(facing)
|
||||
packet.writeByte(detectMode.id)
|
||||
packet.writeByte(detectType)
|
||||
packet.writeByte(graphType)
|
||||
packet.writeNBTTagCompound(getNetwork.center.writeNBT(new NBTTagCompound))
|
||||
packet.writeNBTTagCompound(getNetwork.size.writeNBT(new NBTTagCompound))
|
||||
packet.writeBoolean(getNetwork.isEnabled)
|
||||
}
|
||||
|
||||
def writeGraph(packet: MCDataOutput)
|
||||
{
|
||||
packet.writeByte(2)
|
||||
isPrimary = getNetwork.isPrimary(this)
|
||||
packet.writeBoolean(isPrimary)
|
||||
if (isPrimary) packet.writeNBTTagCompound(getNetwork.save)
|
||||
}
|
||||
|
||||
override def read(packet: MCDataInput)
|
||||
{
|
||||
read(packet, packet.readUByte)
|
||||
id match
|
||||
{
|
||||
case 0 =>
|
||||
{
|
||||
packet.writeByte(placementSide.ordinal)
|
||||
packet.writeByte(facing)
|
||||
packet.writeByte(detectMode.id)
|
||||
packet.writeByte(detectType)
|
||||
packet.writeByte(graphType)
|
||||
packet.writeNBTTagCompound(getNetwork.center.writeNBT(new NBTTagCompound))
|
||||
packet.writeNBTTagCompound(getNetwork.size.writeNBT(new NBTTagCompound))
|
||||
packet.writeBoolean(getNetwork.isEnabled)
|
||||
}
|
||||
case 2 =>
|
||||
{
|
||||
//Graph
|
||||
packet.writeByte(2)
|
||||
isPrimary = getNetwork.isPrimary(this)
|
||||
packet.writeBoolean(isPrimary)
|
||||
if (isPrimary) packet.writeNBTTagCompound(getNetwork.save)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override def read(packet: MCDataInput, packetID: Int)
|
||||
|
|
|
@ -38,34 +38,30 @@ class PartElectricTransformer extends PartFace with INodeProvider
|
|||
inputNode.otherNode = outputNode
|
||||
}
|
||||
|
||||
override def readDesc(packet: MCDataInput)
|
||||
override def read(packet: MCDataInput, id: Int)
|
||||
{
|
||||
super.readDesc(packet)
|
||||
super.read(packet, id)
|
||||
multiplier = packet.readByte
|
||||
}
|
||||
|
||||
override def writeDesc(packet: MCDataOutput)
|
||||
override def write(packet: MCDataOutput, id: Int)
|
||||
{
|
||||
super.writeDesc(packet)
|
||||
super.write(packet, id)
|
||||
packet.writeByte(multiplier)
|
||||
}
|
||||
|
||||
override def doesTick: Boolean =
|
||||
{
|
||||
return false
|
||||
}
|
||||
override def doesTick: Boolean = false
|
||||
|
||||
protected def getItem: ItemStack =
|
||||
{
|
||||
return new ItemStack(ElectricalContent.itemTransformer)
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT) override def renderDynamic(pos: Vector3, frame: Float, pass: Int)
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def renderDynamic(pos: Vector3, frame: Float, pass: Int)
|
||||
{
|
||||
if (pass == 0)
|
||||
{
|
||||
RenderTransformer.INSTANCE.render(this, pos.x, pos.y, pos.z)
|
||||
}
|
||||
RenderTransformer.render(this, pos.x, pos.y, pos.z)
|
||||
}
|
||||
|
||||
override def load(nbt: NBTTagCompound)
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package resonantinduction.electrical.transformer
|
||||
|
||||
import cpw.mods.fml.client.FMLClientHandler
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.util.ResourceLocation
|
||||
import net.minecraftforge.client.IItemRenderer
|
||||
|
@ -13,60 +12,57 @@ import resonant.content.prefab.scal.render.ISimpleItemRenderer
|
|||
import resonant.lib.render.RenderUtility
|
||||
import resonantinduction.core.Reference
|
||||
|
||||
@SideOnly(Side.CLIENT) object RenderTransformer
|
||||
@SideOnly(Side.CLIENT)
|
||||
object RenderTransformer extends ISimpleItemRenderer
|
||||
{
|
||||
final val INSTANCE: RenderTransformer = new RenderTransformer
|
||||
final val MODEL: WavefrontObject = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "transformer.obj")).asInstanceOf[WavefrontObject]
|
||||
final val TEXTURE_COIL: ResourceLocation = new ResourceLocation(Reference.domain, Reference.modelPath + "transformer_winding.png")
|
||||
final val TEXTURE_STONE: ResourceLocation = new ResourceLocation(Reference.blockTextureDirectory + "stone.png")
|
||||
final val TEXTURE_IRON: ResourceLocation = new ResourceLocation(Reference.blockTextureDirectory + "iron_block.png")
|
||||
}
|
||||
val model: WavefrontObject = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "transformer.obj")).asInstanceOf[WavefrontObject]
|
||||
val textureCoil: ResourceLocation = new ResourceLocation(Reference.domain, Reference.modelPath + "transformer_winding.png")
|
||||
val textureStone: ResourceLocation = new ResourceLocation(Reference.blockTextureDirectory + "stone.png")
|
||||
val textureIron: ResourceLocation = new ResourceLocation(Reference.blockTextureDirectory + "iron_block.png")
|
||||
|
||||
@SideOnly(Side.CLIENT) class RenderTransformer extends ISimpleItemRenderer
|
||||
{
|
||||
def renderInventoryItem(`type`: IItemRenderer.ItemRenderType, itemStack: ItemStack, data: AnyRef*)
|
||||
{
|
||||
GL11.glTranslated(0, -0.2f, 0)
|
||||
doRender
|
||||
}
|
||||
def renderInventoryItem(`type`: IItemRenderer.ItemRenderType, itemStack: ItemStack, data: AnyRef*)
|
||||
{
|
||||
GL11.glTranslated(0, -0.2f, 0)
|
||||
doRender
|
||||
}
|
||||
|
||||
def doRender
|
||||
{
|
||||
GL11.glScalef(0.5f, 0.5f, 0.5f)
|
||||
FMLClientHandler.instance.getClient.renderEngine.bindTexture(RenderTransformer.TEXTURE_COIL)
|
||||
RenderTransformer.MODEL.renderAllExcept("core", "base")
|
||||
FMLClientHandler.instance.getClient.renderEngine.bindTexture(RenderTransformer.TEXTURE_IRON)
|
||||
RenderTransformer.MODEL.renderOnly("core")
|
||||
FMLClientHandler.instance.getClient.renderEngine.bindTexture(RenderTransformer.TEXTURE_STONE)
|
||||
RenderTransformer.MODEL.renderOnly("base")
|
||||
}
|
||||
def doRender
|
||||
{
|
||||
GL11.glScalef(0.5f, 0.5f, 0.5f)
|
||||
FMLClientHandler.instance.getClient.renderEngine.bindTexture(RenderTransformer.textureCoil)
|
||||
RenderTransformer.model.renderAllExcept("core", "base")
|
||||
FMLClientHandler.instance.getClient.renderEngine.bindTexture(RenderTransformer.textureIron)
|
||||
RenderTransformer.model.renderOnly("core")
|
||||
FMLClientHandler.instance.getClient.renderEngine.bindTexture(RenderTransformer.textureStone)
|
||||
RenderTransformer.model.renderOnly("base")
|
||||
}
|
||||
|
||||
def render(part: PartElectricTransformer, x: Double, y: Double, z: Double)
|
||||
def render(part: PartElectricTransformer, x: Double, y: Double, z: Double)
|
||||
{
|
||||
GL11.glPushMatrix
|
||||
GL11.glTranslatef(x.asInstanceOf[Float] + 0.5F, y.asInstanceOf[Float] + 0.5F, z.asInstanceOf[Float] + 0.5F)
|
||||
RenderUtility.rotateFaceBlockToSide(part.placementSide)
|
||||
RenderUtility.rotateBlockBasedOnDirection(part.getFacing)
|
||||
GL11.glRotatef(90, 0, 1, 0)
|
||||
GL11.glScalef(0.5f, 0.5f, 0.5f)
|
||||
FMLClientHandler.instance.getClient.renderEngine.bindTexture(RenderTransformer.textureCoil)
|
||||
if (part.multiplier == 0)
|
||||
{
|
||||
GL11.glPushMatrix
|
||||
GL11.glTranslatef(x.asInstanceOf[Float] + 0.5F, y.asInstanceOf[Float] + 0.5F, z.asInstanceOf[Float] + 0.5F)
|
||||
RenderUtility.rotateFaceBlockToSide(part.placementSide)
|
||||
RenderUtility.rotateBlockBasedOnDirection(part.getFacing)
|
||||
GL11.glRotatef(90, 0, 1, 0)
|
||||
GL11.glScalef(0.5f, 0.5f, 0.5f)
|
||||
FMLClientHandler.instance.getClient.renderEngine.bindTexture(RenderTransformer.TEXTURE_COIL)
|
||||
if (part.multiplier == 0)
|
||||
{
|
||||
RenderTransformer.MODEL.renderOnly("InsulatorLayerLow", "OuterWindingLowBox", "InnerWindingLowBox")
|
||||
}
|
||||
else if (part.multiplier == 1)
|
||||
{
|
||||
RenderTransformer.MODEL.renderOnly("InsulatorLayerMed", "OuterWindingMedBox", "InnerWindingMedBox")
|
||||
}
|
||||
else if (part.multiplier == 2)
|
||||
{
|
||||
RenderTransformer.MODEL.renderOnly("InnerWindingHighBox", "InsulatorLayerHigh", "OuterWindingHighBox")
|
||||
}
|
||||
RenderTransformer.MODEL.renderOnly("OuterWindingConnector", "InnerWindingConnector")
|
||||
FMLClientHandler.instance.getClient.renderEngine.bindTexture(RenderTransformer.TEXTURE_IRON)
|
||||
RenderTransformer.MODEL.renderOnly("core")
|
||||
FMLClientHandler.instance.getClient.renderEngine.bindTexture(RenderTransformer.TEXTURE_STONE)
|
||||
RenderTransformer.MODEL.renderOnly("base")
|
||||
GL11.glPopMatrix
|
||||
RenderTransformer.model.renderOnly("InsulatorLayerLow", "OuterWindingLowBox", "InnerWindingLowBox")
|
||||
}
|
||||
else if (part.multiplier == 1)
|
||||
{
|
||||
RenderTransformer.model.renderOnly("InsulatorLayerMed", "OuterWindingMedBox", "InnerWindingMedBox")
|
||||
}
|
||||
else if (part.multiplier == 2)
|
||||
{
|
||||
RenderTransformer.model.renderOnly("InnerWindingHighBox", "InsulatorLayerHigh", "OuterWindingHighBox")
|
||||
}
|
||||
RenderTransformer.model.renderOnly("OuterWindingConnector", "InnerWindingConnector")
|
||||
FMLClientHandler.instance.getClient.renderEngine.bindTexture(RenderTransformer.textureIron)
|
||||
RenderTransformer.model.renderOnly("core")
|
||||
FMLClientHandler.instance.getClient.renderEngine.bindTexture(RenderTransformer.textureStone)
|
||||
RenderTransformer.model.renderOnly("base")
|
||||
GL11.glPopMatrix
|
||||
}
|
||||
}
|
|
@ -3,11 +3,8 @@ package resonantinduction.electrical.wire.base
|
|||
import codechicken.lib.data.{MCDataInput, MCDataOutput}
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import resonant.lib.grid.electric.DCNode
|
||||
import resonantinduction.core.prefab.part.connector._
|
||||
import resonantinduction.electrical.ElectricalContent
|
||||
import resonant.api.grid.INodeProvider
|
||||
|
||||
/**
|
||||
* Abstract class extended by both flat and framed wires to handle material, insulation, color and multipart node logic.
|
||||
|
@ -23,6 +20,7 @@ import resonant.api.grid.INodeProvider
|
|||
trait TWire extends PartAbstract with TPartNodeProvider with TMaterial[WireMaterial] with TInsulatable with TColorable
|
||||
{
|
||||
override protected val insulationItem: Item = ElectricalContent.itemInsulation
|
||||
|
||||
material = WireMaterial.COPPER
|
||||
|
||||
def preparePlacement(side: Int, meta: Int)
|
||||
|
@ -39,24 +37,18 @@ trait TWire extends PartAbstract with TPartNodeProvider with TMaterial[WireMater
|
|||
/**
|
||||
* Packet Methods
|
||||
*/
|
||||
override def writeDesc(packet: MCDataOutput)
|
||||
override def write(packet: MCDataOutput, id: Int)
|
||||
{
|
||||
super[TMaterial].writeDesc(packet)
|
||||
super[TInsulatable].writeDesc(packet)
|
||||
super[TColorable].writeDesc(packet)
|
||||
super[TMaterial].write(packet, id)
|
||||
super[TInsulatable].write(packet, id)
|
||||
super[TColorable].write(packet, id)
|
||||
}
|
||||
|
||||
override def readDesc(packet: MCDataInput)
|
||||
override def read(packet: MCDataInput, id: Int)
|
||||
{
|
||||
super[TMaterial].readDesc(packet)
|
||||
super[TInsulatable].readDesc(packet)
|
||||
super[TColorable].readDesc(packet)
|
||||
}
|
||||
|
||||
override def read(packet: MCDataInput, packetID: Int)
|
||||
{
|
||||
super[TInsulatable].read(packet, packetID)
|
||||
super[TColorable].read(packet, packetID)
|
||||
super[TMaterial].read(packet, id)
|
||||
super[TInsulatable].read(packet, id)
|
||||
super[TColorable].read(packet, id)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -163,34 +163,33 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
|||
tag.setInteger("connMap", connectionMask)
|
||||
}
|
||||
|
||||
override def writeDesc(packet: MCDataOutput)
|
||||
override def write(packet: MCDataOutput, id: Int)
|
||||
{
|
||||
super.writeDesc(packet)
|
||||
packet.writeByte(side)
|
||||
packet.writeInt(connectionMask)
|
||||
}
|
||||
super.write(packet, id)
|
||||
|
||||
override def readDesc(packet: MCDataInput)
|
||||
{
|
||||
super.readDesc(packet)
|
||||
side = packet.readByte
|
||||
connectionMask = packet.readInt
|
||||
}
|
||||
|
||||
override def read(packet: MCDataInput, packetID: Int)
|
||||
{
|
||||
super.read(packet, packetID)
|
||||
|
||||
if (packetID == 3)
|
||||
id match
|
||||
{
|
||||
connectionMask = packet.readInt
|
||||
tile.markRender()
|
||||
case 0 =>
|
||||
packet.writeByte(side)
|
||||
packet.writeInt(connectionMask)
|
||||
case 3 =>
|
||||
packet.writeInt(connectionMask)
|
||||
}
|
||||
}
|
||||
|
||||
def sendConnUpdate()
|
||||
override def read(packet: MCDataInput, id: Int)
|
||||
{
|
||||
tile.getWriteStream(this).writeByte(3).writeInt(connectionMask)
|
||||
super.read(packet, id)
|
||||
|
||||
id match
|
||||
{
|
||||
case 0 =>
|
||||
side = packet.readByte
|
||||
connectionMask = packet.readInt
|
||||
case 3 =>
|
||||
connectionMask = packet.readInt
|
||||
tile.markRender()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -234,7 +233,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
|||
super.onAdded()
|
||||
|
||||
if (!world.isRemote)
|
||||
sendConnUpdate()
|
||||
sendPacket(3)
|
||||
}
|
||||
|
||||
override def onPartChanged(part: TMultiPart)
|
||||
|
@ -242,7 +241,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
|||
super.onPartChanged(part)
|
||||
|
||||
if (!world.isRemote)
|
||||
sendConnUpdate()
|
||||
sendPacket(3)
|
||||
}
|
||||
|
||||
override def onNeighborChanged()
|
||||
|
@ -254,7 +253,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
|||
super.onNeighborChanged()
|
||||
|
||||
if (!world.isRemote)
|
||||
sendConnUpdate()
|
||||
sendPacket(3)
|
||||
}
|
||||
|
||||
def notifyCornerChange(r: Int)
|
||||
|
@ -799,7 +798,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
|||
}
|
||||
if (oldConn != PartFlatWire.this.connectionMask)
|
||||
{
|
||||
sendConnUpdate
|
||||
sendPacket(3)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -819,7 +818,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
|||
PartFlatWire.this.connectionMask |= 0x10 << r
|
||||
if (oldConn != PartFlatWire.this.connectionMask)
|
||||
{
|
||||
sendConnUpdate()
|
||||
sendPacket(3)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -839,7 +838,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
|
|||
PartFlatWire.this.connectionMask |= 0x100 << r
|
||||
if (oldConn != PartFlatWire.this.connectionMask)
|
||||
{
|
||||
sendConnUpdate()
|
||||
sendPacket(3)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -8,10 +8,11 @@ import net.minecraft.client.renderer.RenderBlocks
|
|||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import resonant.lib.grid.electric.DCNode
|
||||
import resonant.lib.wrapper.BitmaskWrapper._
|
||||
import resonantinduction.core.prefab.node.TMultipartNode
|
||||
import resonantinduction.core.prefab.part.connector.PartFramedNode
|
||||
import resonantinduction.electrical.wire.base.TWire
|
||||
import resonant.lib.wrapper.BitmaskWrapper._
|
||||
|
||||
/**
|
||||
* Fluid transport pipe
|
||||
*
|
||||
|
@ -48,20 +49,16 @@ class PartFramedWire extends PartFramedNode with TWire
|
|||
/**
|
||||
* Packet Methods
|
||||
*/
|
||||
override def writeDesc(packet: MCDataOutput)
|
||||
override def write(packet: MCDataOutput, id: Int)
|
||||
{
|
||||
super[PartFramedNode].writeDesc(packet)
|
||||
super[TWire].writeDesc(packet)
|
||||
}
|
||||
|
||||
override def readDesc(packet: MCDataInput)
|
||||
{
|
||||
super[PartFramedNode].readDesc(packet)
|
||||
super[TWire].readDesc(packet)
|
||||
super.write(packet, id)
|
||||
super[PartFramedNode].write(packet, id)
|
||||
super[TWire].write(packet, id)
|
||||
}
|
||||
|
||||
override def read(packet: MCDataInput, packetID: Int)
|
||||
{
|
||||
super.read(packet, packetID)
|
||||
super[PartFramedNode].read(packet, packetID)
|
||||
super[TWire].read(packet, packetID)
|
||||
}
|
||||
|
|
|
@ -54,49 +54,40 @@ class PartPipe extends PartFramedNode with TMaterial[PipeMaterial] with TColorab
|
|||
|
||||
if (!world.isRemote && markPacket)
|
||||
{
|
||||
sendFluidUpdate()
|
||||
sendPacket(3)
|
||||
markPacket = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends fluid level to the client to be used in the renderer
|
||||
*/
|
||||
def sendFluidUpdate()
|
||||
{
|
||||
val nbt = new NBTTagCompound
|
||||
var averageAmount: Int = 0
|
||||
if (averageTankData.size > 0)
|
||||
{
|
||||
for (i <- 0 until averageTankData.size)
|
||||
{
|
||||
{
|
||||
averageAmount += averageTankData.get(i)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
/**
|
||||
* Packet Methods
|
||||
*/
|
||||
override def writeDesc(packet: MCDataOutput)
|
||||
override def write(packet: MCDataOutput, id: Int)
|
||||
{
|
||||
super[TMaterial].writeDesc(packet)
|
||||
super[PartFramedNode].writeDesc(packet)
|
||||
super[TColorable].writeDesc(packet)
|
||||
}
|
||||
super[TMaterial].write(packet,id)
|
||||
super[PartFramedNode].write(packet,id)
|
||||
super[TColorable].write(packet,id)
|
||||
|
||||
override def readDesc(packet: MCDataInput)
|
||||
{
|
||||
super[TMaterial].readDesc(packet)
|
||||
super[PartFramedNode].readDesc(packet)
|
||||
super[TColorable].readDesc(packet)
|
||||
if(id == 3)
|
||||
{
|
||||
//Tank Packet
|
||||
val nbt = new NBTTagCompound
|
||||
var averageAmount: Int = 0
|
||||
if (averageTankData.size > 0)
|
||||
{
|
||||
for (i <- 0 until averageTankData.size)
|
||||
{
|
||||
{
|
||||
averageAmount += averageTankData.get(i)
|
||||
}
|
||||
}
|
||||
|
||||
averageAmount /= averageTankData.size
|
||||
}
|
||||
val tempTank = if (tank.getFluid != null) new FluidTank(tank.getFluid.getFluid, averageAmount, tank.getCapacity) else new FluidTank(tank.getCapacity)
|
||||
tempTank.writeToNBT(nbt)
|
||||
packet.writeInt(tank.getCapacity).writeNBTTagCompound(nbt)
|
||||
}
|
||||
}
|
||||
|
||||
override def read(packet: MCDataInput, packetID: Int)
|
||||
|
|
|
@ -71,11 +71,8 @@ abstract class PartMechanical extends PartAbstract with JNormalOcclusion with TF
|
|||
id match
|
||||
{
|
||||
case 0 =>
|
||||
{
|
||||
val nbt = new NBTTagCompound
|
||||
save(nbt)
|
||||
packet.writeNBTTagCompound(nbt)
|
||||
}
|
||||
packet.writeByte(placementSide.ordinal.toByte)
|
||||
packet.writeByte(tier.toByte)
|
||||
case 1 => packet.writeFloat(mechanicalNode.angularVelocity.toFloat)
|
||||
case 2 => packet.writeFloat(mechanicalNode.prevAngle.toFloat)
|
||||
}
|
||||
|
@ -87,7 +84,9 @@ abstract class PartMechanical extends PartAbstract with JNormalOcclusion with TF
|
|||
|
||||
id match
|
||||
{
|
||||
case 0 => load(packet.readNBTTagCompound)
|
||||
case 0 =>
|
||||
placementSide = ForgeDirection.getOrientation(packet.readByte())
|
||||
tier = packet.readByte()
|
||||
case 1 => mechanicalNode.angularVelocity = packet.readFloat()
|
||||
case 2 => mechanicalNode.prevAngle = packet.readFloat()
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
|
|||
markVelocityUpdate = true
|
||||
}
|
||||
|
||||
mechanicalNode.onGridReconstruct = () => if(!world.isRemote) sendPacket(2)
|
||||
mechanicalNode.onGridReconstruct = () => if (world != null && !world.isRemote) sendPacket(2)
|
||||
|
||||
//TODO: Can we not have update ticks here?
|
||||
override def update()
|
||||
|
@ -95,7 +95,7 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
|
|||
/** Is this gear block the one in the center-edge of the multiblock that can interact with other
|
||||
* gears?
|
||||
*
|
||||
* @return */
|
||||
* @return*/
|
||||
def isCenterMultiBlock: Boolean =
|
||||
{
|
||||
if (!getMultiBlock.isConstructed)
|
||||
|
|
|
@ -39,6 +39,8 @@ class MechanicalGrid extends GridNode[MechanicalNode](classOf[MechanicalNode]) w
|
|||
override protected def populateNode(node: MechanicalNode, prev: MechanicalNode)
|
||||
{
|
||||
super.populateNode(node, prev)
|
||||
|
||||
//TODO: Check if gears are LOCKED (when two nodes obtain undesirable spins)
|
||||
val dir = if (prev != null) (if (node.inverseRotation(prev)) !spinMap(prev) else spinMap(prev)) else false
|
||||
spinMap += (node -> dir)
|
||||
|
||||
|
@ -49,60 +51,63 @@ class MechanicalGrid extends GridNode[MechanicalNode](classOf[MechanicalNode]) w
|
|||
|
||||
override def update(deltaTime: Double)
|
||||
{
|
||||
//Find all nodes that are currently producing energy
|
||||
val inputs = getNodes.filter(n => n.bufferTorque != 0 && n.bufferAngle != 0)
|
||||
|
||||
//Calculate the total input equivalent torque and angular velocity
|
||||
val input = inputs
|
||||
.map(
|
||||
n =>
|
||||
{
|
||||
val inversion = if (spinMap(n)) 1 else -1
|
||||
(n.bufferTorque * n.ratio * inversion, n.bufferAngle / deltaTime / n.ratio * inversion)
|
||||
})
|
||||
.foldLeft((0D, 0D))((b, a) => (a._1 + b._1, a._2 + b._2))
|
||||
|
||||
var delta = (0D, 0D)
|
||||
|
||||
if (input._1 != 0 && input._2 != 0)
|
||||
getNodes synchronized
|
||||
{
|
||||
//Calculate the total resistance of all nodes
|
||||
//TODO: Cache this
|
||||
val resistance = getNodes.view
|
||||
.map(n => (n.getTorqueLoad, n.getAngularVelocityLoad))
|
||||
//Find all nodes that are currently producing energy
|
||||
val inputs = getNodes.filter(n => n.bufferTorque != 0 && n.bufferAngle != 0)
|
||||
|
||||
//Calculate the total input equivalent torque and angular velocity
|
||||
val input = inputs
|
||||
.map(
|
||||
n =>
|
||||
{
|
||||
val inversion = if (spinMap(n)) 1 else -1
|
||||
(n.bufferTorque * n.ratio * inversion, n.bufferAngle / deltaTime / n.ratio * inversion)
|
||||
})
|
||||
.foldLeft((0D, 0D))((b, a) => (a._1 + b._1, a._2 + b._2))
|
||||
|
||||
//Calculate the total change in torque and angular velocity
|
||||
delta = (input._1 - input._1 * resistance._1 / getNodes.size(), input._2 - input._2 * resistance._2 / getNodes.size())
|
||||
var delta = (0D, 0D)
|
||||
|
||||
if (input._1 != 0 && input._2 != 0)
|
||||
{
|
||||
//Calculate the total resistance of all nodes
|
||||
//TODO: Cache this
|
||||
val resistance = getNodes.view
|
||||
.map(n => (n.getTorqueLoad, n.getAngularVelocityLoad))
|
||||
.foldLeft((0D, 0D))((b, a) => (a._1 + b._1, a._2 + b._2))
|
||||
|
||||
//Calculate the total change in torque and angular velocity
|
||||
delta = (input._1 - input._1 * resistance._1 / getNodes.size(), input._2 - input._2 * resistance._2 / getNodes.size())
|
||||
}
|
||||
|
||||
//Calculate power
|
||||
_power = delta._1 * delta._2
|
||||
|
||||
//Set torque and angular velocity of all nodes
|
||||
getNodes.foreach(n =>
|
||||
{
|
||||
val prevTorque = n.torque
|
||||
val prevAngularVelocity = n.angularVelocity
|
||||
|
||||
val inversion = if (spinMap(n)) 1 else -1
|
||||
n.torque = delta._1 * n.ratio * inversion
|
||||
n.angularVelocity = delta._2 / n.ratio * inversion
|
||||
|
||||
if (Math.abs(prevTorque - n.torque) >= 0.1)
|
||||
n.onTorqueChanged()
|
||||
|
||||
if (Math.abs(prevAngularVelocity - n.angularVelocity) >= 0.1)
|
||||
n.onVelocityChanged()
|
||||
|
||||
})
|
||||
|
||||
//Clear buffers
|
||||
inputs.foreach(n =>
|
||||
{
|
||||
n.bufferTorque = 0
|
||||
n.bufferAngle = 0
|
||||
})
|
||||
}
|
||||
|
||||
//Calculate power
|
||||
_power = delta._1 * delta._2
|
||||
|
||||
//Set torque and angular velocity of all nodes
|
||||
getNodes.foreach(n =>
|
||||
{
|
||||
val prevTorque = n.torque
|
||||
val prevAngularVelocity = n.angularVelocity
|
||||
|
||||
val inversion = if (spinMap(n)) 1 else -1
|
||||
n.torque = delta._1 * n.ratio * inversion
|
||||
n.angularVelocity = delta._2 / n.ratio * inversion
|
||||
|
||||
if (Math.abs(prevTorque - n.torque) >= 0.1)
|
||||
n.onTorqueChanged()
|
||||
|
||||
if (Math.abs(prevAngularVelocity - n.angularVelocity) >= 0.1)
|
||||
n.onVelocityChanged()
|
||||
|
||||
})
|
||||
|
||||
//Clear buffers
|
||||
inputs.foreach(n =>
|
||||
{
|
||||
n.bufferTorque = 0
|
||||
n.bufferAngle = 0
|
||||
})
|
||||
}
|
||||
|
||||
override def continueUpdate = getNodes.size > 0
|
||||
|
|
Loading…
Reference in a new issue