//Used for other power devices to offer this device some energy returns how much power was used //API public virtual int ReceivePacketOffer(IElectricity from, int inVolt, int inAmp) //eg 2 { if (usedconnections == null) { usedconnections = new List <IElectricity>(); } if (!isOn) { return(0); } //Not even on if (inVolt != maxVolts) { DoOverload(); return(0); } //Incompatible power - bad! if (inAmp <= 0) { return(0); } if (Capacitor >= Capacitance) { return(0); } //already full inAmp = Math.Min(inAmp, MaxAmps); //can only move a certain amount of amps - eg 2 int useamps = Math.Min(inAmp, Capacitance - Capacitor); //2 useamps = Math.Max(useamps, 0); ChangeCapacitor(useamps); usedconnections.Add(from); if (useamps != 0) { MarkDirty(); } //not zero should be dirty return(useamps); //return 2 }
//API public virtual bool TryOutputConnection(IElectricity connectto) { if (outputConnections == null) { outputConnections = new List <IElectricity>(); } Vec3d vector = connectto.EBlock.Pos.ToVec3d() - Pos.ToVec3d(); BlockFacing bf = BlockFacing.FromVector(vector.X, vector.Y, vector.Z); if (distributionFaces == null) { return(false); } if (!distributionFaces.Contains(bf)) { return(false); } if (!outputConnections.Contains(connectto)) { outputConnections.Add(connectto); MarkDirty(); } return(true); }
//Tell a connection to remove itself //API public virtual void RemoveConnection(IElectricity disconnect) { inputConnections.Remove(disconnect); outputConnections.Remove(disconnect); }
//generators don't receive power public override int ReceivePacketOffer(IElectricity from, int volt, int amp) { return(0); }
//Reject any connections requesting power public bool TryOutputConnection(IElectricity connectto) { return(true); }
//Do nothing, we don't track our power connections, we don't even care! public void RemoveConnection(IElectricity disconnect) { }
//Take any amps offered and report them taken public int ReceivePacketOffer(IElectricity from, int inVolt, int inAmp) { stolenpowercounter += inAmp; //keeping score return(inAmp); }