Some wire trait reorganization

This commit is contained in:
Calclavia 2014-09-12 19:07:04 +08:00
parent b1d8527bea
commit 48864b2701
6 changed files with 30 additions and 352 deletions

View file

@ -24,7 +24,7 @@ object PartColorableMaterial
abstract class PartColorableMaterial[M](materialItem: Item) extends TMultiPart with TraitPart
{
var color: Int = PartColorableMaterial.defaultColor
var color = PartColorableMaterial.defaultColor
var material: M = _
var isInsulated = false
var requiresInsulation = true

View file

@ -139,31 +139,23 @@ abstract class PartFramedNode[M](material: Item) extends PartColorableMaterial[M
return PartFramedNode.connectionMapContainsSide(getAllCurrentConnections, side)
}
override def onWorldJoin
override def onWorldJoin()
{
node.reconstruct()
}
override def onNeighborChanged
override def onNeighborChanged()
{
node.reconstruct()
}
override def onWorldSeparate
override def onWorldSeparate()
{
node.deconstruct()
}
def copyFrom(other: PartFramedNode[M])
{
this.isInsulated = other.isInsulated
this.color = other.color
this.connections = other.connections
this.material = other.material
}
/** Packet Methods */
def sendConnectionUpdate
def sendConnectionUpdate()
{
tile.getWriteStream(this).writeByte(0).writeByte(currentConnections)
}

View file

@ -0,0 +1,22 @@
package resonantinduction.electrical.wire.base
import net.minecraft.item.ItemStack
import resonantinduction.core.prefab.part.PartColorableMaterial
import resonantinduction.electrical.ElectricalContent
import resonantinduction.electrical.wire.WireMaterial
/**
* @author Calclavia
*/
trait TWire extends PartColorableMaterial[WireMaterial]
{
override def setMaterial(i: Int)
{
material = WireMaterial.values()(i)
}
override def getMaterialID = material.ordinal()
override protected def getItem = new ItemStack(ElectricalContent.itemInsulation, getMaterialID)
}

View file

@ -1,24 +1,16 @@
package resonantinduction.electrical.wire.framed
import net.minecraft.item.ItemStack
import resonantinduction.core.prefab.part.PartFramedNode
import resonantinduction.core.prefab.part.{PartColorableMaterial, PartFramedNode}
import resonantinduction.electrical.ElectricalContent
import resonantinduction.electrical.wire.WireMaterial
import resonantinduction.electrical.wire.base.TWire
/**
* A framed version of the electrical wire
* @author Calclavia
*/
class PartFramedWire extends PartFramedNode[WireMaterial](ElectricalContent.itemInsulation)
class PartFramedWire extends PartColorableMaterial[WireMaterial](ElectricalContent.itemInsulation) with TWire
{
override def setMaterial(i: Int)
{
material = WireMaterial.values()(i)
}
override def getMaterialID = material.ordinal()
override protected def getItem = new ItemStack(ElectricalContent.itemInsulation, getMaterialID)
override def getType = "FramedWire"
}

View file

@ -1,193 +0,0 @@
package resonantinduction.electrical.wire.trait;
import java.util.HashSet;
import java.util.Set;
import net.minecraftforge.common.util.ForgeDirection;
import resonantinduction.electrical.wire.PartConductor;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
import cofh.api.energy.IEnergyHandler;
public class TraitEnergyHandler extends TileMultipart implements IEnergyHandler
{
public Set<PartConductor> teConductorInterfaces = new HashSet<PartConductor>();
public Set<IEnergyHandler> teInterfaces = new HashSet<IEnergyHandler>();
@Override
public void copyFrom(TileMultipart that)
{
super.copyFrom(that);
if (that instanceof TraitEnergyHandler)
{
this.teConductorInterfaces = ((TraitEnergyHandler) that).teConductorInterfaces;
this.teInterfaces = ((TraitEnergyHandler) that).teInterfaces;
}
}
@Override
public void bindPart(TMultiPart part)
{
super.bindPart(part);
if (part instanceof IEnergyHandler)
{
if (part instanceof PartConductor)
{
this.teConductorInterfaces.add((PartConductor) part);
}
else
{
this.teInterfaces.add((IEnergyHandler) part);
}
}
}
@Override
public void partRemoved(TMultiPart part, int p)
{
super.partRemoved(part, p);
if (part instanceof IEnergyHandler)
{
if (part instanceof PartConductor)
{
this.teConductorInterfaces.remove(part);
}
else
{
this.teInterfaces.remove(part);
}
}
}
@Override
public void clearParts()
{
super.clearParts();
this.teInterfaces.clear();
this.teConductorInterfaces.clear();
}
@Override
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
{
/**
* Try out different sides to try to inject energy into.
*/
if (this.partMap(from.ordinal()) == null)
{
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
if (dir != from.getOpposite())
{
TMultiPart part = this.partMap(dir.ordinal());
if (this.teConductorInterfaces.contains(part))
{
return ((IEnergyHandler) part).receiveEnergy(from, maxReceive, simulate);
}
}
}
}
/**
* Failed, try pure TE interfaces.
*/
for (IEnergyHandler handler : this.teInterfaces)
{
return handler.receiveEnergy(from, maxReceive, simulate);
}
return 0;
}
@Override
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate)
{
return 0;
}
@Override
public boolean canConnectEnergy(ForgeDirection from)
{
if (this.partMap(from.ordinal()) == null)
{
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
if (dir != from.getOpposite())
{
TMultiPart part = this.partMap(dir.ordinal());
if (this.teConductorInterfaces.contains(part))
{
return ((IEnergyHandler) part).canConnectEnergy(from);
}
}
}
}
for (IEnergyHandler handler : this.teInterfaces)
{
return handler.canConnectEnergy(from);
}
return false;
}
@Override
public int getEnergyStored(ForgeDirection from)
{
if (this.partMap(from.ordinal()) == null)
{
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
if (dir != from.getOpposite())
{
TMultiPart part = this.partMap(dir.ordinal());
if (this.teConductorInterfaces.contains(part))
{
return ((IEnergyHandler) part).getEnergyStored(from);
}
}
}
}
for (IEnergyHandler handler : this.teInterfaces)
{
return handler.getEnergyStored(from);
}
return 0;
}
@Override
public int getMaxEnergyStored(ForgeDirection from)
{
if (this.partMap(from.ordinal()) == null)
{
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
if (dir != from.getOpposite())
{
TMultiPart part = this.partMap(dir.ordinal());
if (this.teConductorInterfaces.contains(part))
{
return ((IEnergyHandler) part).getMaxEnergyStored(from);
}
}
}
}
for (IEnergyHandler handler : this.teInterfaces)
{
return handler.getMaxEnergyStored(from);
}
return 0;
}
}

View file

@ -1,135 +0,0 @@
package resonantinduction.electrical.wire.trait;
import ic2.api.energy.tile.IEnergySink;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import codechicken.multipart.PartMap;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
public class TraitEnergySink extends TileMultipart implements IEnergySink
{
public Set<IEnergySink> icInterfaces = new HashSet<IEnergySink>();
@Override
public void copyFrom(TileMultipart that)
{
super.copyFrom(that);
if (that instanceof TraitEnergySink)
{
this.icInterfaces = ((TraitEnergySink) that).icInterfaces;
}
}
@Override
public void bindPart(TMultiPart part)
{
super.bindPart(part);
if (part instanceof IEnergySink)
{
this.icInterfaces.add((IEnergySink) part);
}
}
@Override
public void partRemoved(TMultiPart part, int p)
{
super.partRemoved(part, p);
if (part instanceof IEnergySink)
{
this.icInterfaces.remove(part);
}
}
@Override
public void clearParts()
{
super.clearParts();
this.icInterfaces.clear();
}
@Override
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection from)
{
if (this.partMap(from.ordinal()) == null)
{
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
if (dir != from.getOpposite())
{
TMultiPart part = this.partMap(dir.ordinal());
if (this.icInterfaces.contains(part))
{
return ((IEnergySink) part).acceptsEnergyFrom(emitter, from);
}
}
}
}
return false;
}
@Override
public double demandedEnergyUnits()
{
double demanded = 0;
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
TMultiPart part = this.partMap(dir.ordinal());
if (part instanceof IEnergySink)
{
demanded += ((IEnergySink) part).demandedEnergyUnits();
}
}
return demanded;
}
@Override
public double injectEnergyUnits(ForgeDirection from, double amount)
{
/**
* Try out different sides to try to inject energy into.
*/
if (partMap(from.ordinal()) instanceof IEnergySink)
{
return ((IEnergySink) partMap(from.ordinal())).injectEnergyUnits(from, amount);
}
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
if (dir != from.getOpposite())
{
TMultiPart part = this.partMap(dir.ordinal());
if (part instanceof IEnergySink)
{
return ((IEnergySink) part).injectEnergyUnits(from, amount);
}
}
}
if (partMap(PartMap.CENTER.ordinal()) instanceof IEnergySink)
{
return ((IEnergySink) partMap(PartMap.CENTER.ordinal())).injectEnergyUnits(from, amount);
}
return amount;
}
@Override
public int getMaxSafeInput()
{
return Integer.MAX_VALUE;
}
}