Converted NodeTank to scala but removed packet code for it in the process
This commit is contained in:
parent
b8e788f8f6
commit
9288caca58
4 changed files with 55 additions and 102 deletions
|
@ -18,7 +18,7 @@ public class NodePressure extends NodeTank implements IUpdate
|
||||||
|
|
||||||
public NodePressure(INodeProvider parent)
|
public NodePressure(INodeProvider parent)
|
||||||
{
|
{
|
||||||
super(parent);
|
super(parent, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NodePressure(INodeProvider parent, int buckets)
|
public NodePressure(INodeProvider parent, int buckets)
|
||||||
|
|
|
@ -1,99 +0,0 @@
|
||||||
package resonantinduction.core.prefab.node;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import net.minecraftforge.fluids.*;
|
|
||||||
import resonant.engine.ResonantEngine;
|
|
||||||
import resonant.lib.network.discriminator.PacketTile;
|
|
||||||
import resonant.lib.network.discriminator.PacketType;
|
|
||||||
import resonant.lib.network.handle.IPacketIDReceiver;
|
|
||||||
import resonant.lib.prefab.fluid.LimitedTank;
|
|
||||||
import resonant.lib.prefab.fluid.NodeFluidHandler;
|
|
||||||
import resonant.lib.utility.WorldUtility;
|
|
||||||
import universalelectricity.api.core.grid.INode;
|
|
||||||
import universalelectricity.api.core.grid.INodeProvider;
|
|
||||||
import universalelectricity.api.core.grid.ISave;
|
|
||||||
import universalelectricity.core.grid.node.NodeConnector;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Simple tank node designed to be implemented by any machine that can connect to other fluid based machines.
|
|
||||||
*
|
|
||||||
* @author Darkguardsman
|
|
||||||
*/
|
|
||||||
public class NodeTank extends NodeFluidHandler implements ISave, IPacketIDReceiver, INode
|
|
||||||
{
|
|
||||||
static final int PACKET_DESCRIPTION = 100, PACKET_TANK = 101;
|
|
||||||
int renderSides = 0;
|
|
||||||
|
|
||||||
public NodeTank(INodeProvider parent)
|
|
||||||
{
|
|
||||||
this(parent, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public NodeTank(INodeProvider parent, int buckets)
|
|
||||||
{
|
|
||||||
super(parent, new LimitedTank(buckets * FluidContainerRegistry.BUCKET_VOLUME));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void load(NBTTagCompound nbt)
|
|
||||||
{
|
|
||||||
getPrimaryTank().readFromNBT(nbt.getCompoundTag("tank"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save(NBTTagCompound nbt)
|
|
||||||
{
|
|
||||||
nbt.setTag("tank", getPrimaryTank().writeToNBT(new NBTTagCompound()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean read(ByteBuf buf, int id, EntityPlayer player, PacketType type)
|
|
||||||
{
|
|
||||||
switch (id)
|
|
||||||
{
|
|
||||||
case PACKET_DESCRIPTION:
|
|
||||||
this.load(ByteBufUtils.readTag(buf));
|
|
||||||
break;
|
|
||||||
case PACKET_TANK:
|
|
||||||
getPrimaryTank().readFromNBT(ByteBufUtils.readTag(buf));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendTank()
|
|
||||||
{
|
|
||||||
//ResonantEngine.instance.packetHandler.sendToAllAround(new PacketTile((int) x(), (int) y(), (int) z(), PACKET_TANK, getPrimaryTank().writeToNBT(new NBTTagCompound())), 64);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void addConnection(Object obj, ForgeDirection dir)
|
|
||||||
{
|
|
||||||
super.addConnection(obj, dir);
|
|
||||||
if (showConnectionsFor(obj, dir))
|
|
||||||
{
|
|
||||||
renderSides = WorldUtility.setEnableSide(getRenderSides(), dir, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean showConnectionsFor(Object obj, ForgeDirection dir)
|
|
||||||
{
|
|
||||||
if (obj != null)
|
|
||||||
{
|
|
||||||
if (obj.getClass().isAssignableFrom(getParent().getClass()))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRenderSides()
|
|
||||||
{
|
|
||||||
return renderSides;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package resonantinduction.core.prefab.node
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
|
import net.minecraftforge.common.util.ForgeDirection
|
||||||
|
import net.minecraftforge.fluids._
|
||||||
|
import resonant.lib.prefab.fluid.{LimitedTank, NodeFluidHandler}
|
||||||
|
import resonant.lib.utility.WorldUtility
|
||||||
|
import universalelectricity.api.core.grid.{INode, INodeProvider, ISave}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 {
|
||||||
|
|
||||||
|
|
||||||
|
def load(nbt: NBTTagCompound)
|
||||||
|
{
|
||||||
|
getPrimaryTank.readFromNBT(nbt.getCompoundTag("tank"))
|
||||||
|
}
|
||||||
|
|
||||||
|
def save(nbt: NBTTagCompound)
|
||||||
|
{
|
||||||
|
nbt.setTag("tank", getPrimaryTank.writeToNBT(new NBTTagCompound))
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override def addConnection(obj: AnyRef, dir: ForgeDirection)
|
||||||
|
{
|
||||||
|
super.addConnection(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)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
def getRenderSides: Int = {
|
||||||
|
return renderSides
|
||||||
|
}
|
||||||
|
|
||||||
|
private[node] var renderSides: Int = 0
|
||||||
|
}
|
|
@ -22,7 +22,7 @@ class TileTankNode(material: Material) extends TileAdvanced(material) with INode
|
||||||
val PACKET_DESCRIPTION = 0
|
val PACKET_DESCRIPTION = 0
|
||||||
val PACKET_RENDER = 1
|
val PACKET_RENDER = 1
|
||||||
var renderSides: Byte = 0
|
var renderSides: Byte = 0
|
||||||
var tankNode: NodeTank = new NodeTank(this)
|
var tankNode: NodeTank = new NodeTank(this, 16)
|
||||||
protected var colorID: Int = 0
|
protected var colorID: Int = 0
|
||||||
|
|
||||||
def getFluid(): FluidStack = getTank().getFluid
|
def getFluid(): FluidStack = getTank().getFluid
|
||||||
|
@ -72,6 +72,7 @@ class TileTankNode(material: Material) extends TileAdvanced(material) with INode
|
||||||
|
|
||||||
override def read(buf: ByteBuf, id: Int, player: EntityPlayer, t: PacketType): Boolean =
|
override def read(buf: ByteBuf, id: Int, player: EntityPlayer, t: PacketType): Boolean =
|
||||||
{
|
{
|
||||||
|
//TODO handle fluid node's packet code
|
||||||
if (id == PACKET_DESCRIPTION)
|
if (id == PACKET_DESCRIPTION)
|
||||||
{
|
{
|
||||||
colorID = buf.readInt()
|
colorID = buf.readInt()
|
||||||
|
@ -83,7 +84,7 @@ class TileTankNode(material: Material) extends TileAdvanced(material) with INode
|
||||||
colorID = buf.readInt()
|
colorID = buf.readInt()
|
||||||
renderSides = buf.readByte()
|
renderSides = buf.readByte()
|
||||||
}
|
}
|
||||||
return tankNode.read(buf, id, player, t);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
override def getNode(nodeType: Class[_ <: INode], from: ForgeDirection): INode = if (nodeType.isInstanceOf[NodeTank]) return tankNode else null
|
override def getNode(nodeType: Class[_ <: INode], from: ForgeDirection): INode = if (nodeType.isInstanceOf[NodeTank]) return tankNode else null
|
||||||
|
|
Loading…
Reference in a new issue