public MechanicalNetworkOld getNetworkById(long id) { MechanicalNetworkOld network = null; networksById.TryGetValue(id, out network); return(network); }
private void OnPacket(MechNetworkPacket networkMessage) { bool isNew = networksById.ContainsKey(networkMessage.networkId); MechanicalNetworkOld network = getOrCreateNetwork(networkMessage.networkId); network.updateFromPacket(networkMessage, isNew); }
public MechanicalNetworkOld createAndRegisterNetwork(IMechanicalPowerNetworkNode originatorNode) { MechanicalNetworkOld network = createAndRegisterNetwork(); network.register(originatorNode); network.firstPowerNode = originatorNode.getPosition(); return(network); }
public MechanicalNetworkOld[] getNetworks() { MechanicalNetworkOld network = MechNetworkManagerRegistry.ManagersByWorld[api.World].getNetworkById(networkId); if (network == null) { return(new MechanicalNetworkOld[0]); } return(new MechanicalNetworkOld[] { network }); }
public float getNetworkSpeed(BlockFacing facing) { MechanicalNetworkOld network = getNetwork(facing); if (network == null) { return(0); } return(network.getSpeed()); }
public MechanicalNetworkOld createAndRegisterNetwork() { long networkId = findUniqueId(); //System.out.println(world.isRemote + " from create instantiated new network with id " + networkId); MechanicalNetworkOld network = new MechanicalNetworkOld(this, networkId); networksById[networkId] = network; return(network); }
public MechanicalNetworkOld getOrCreateNetwork(long networkid) { MechanicalNetworkOld network = getNetworkById(networkid); if (network == null) { //System.out.println("from get instantiated new network with id " + networkid); network = new MechanicalNetworkOld(this, networkid); networksById[networkid] = network; } return(network); }
public float getAngle() { MechanicalNetworkOld network = getNetwork(null); if (network == null) { return(lastAngle); } if (directionFromFacing != orientation) { return(lastAngle = 360 - network.getAngle()); } return(lastAngle = network.getAngle()); }
public void loadNetworks(ITreeAttribute networks) { //System.out.println("load networks for dimension " + world.provider.getDimensionId() + ", list: " + networks); networksById.Clear(); if (networks == null) { return; } foreach (var val in networks) { ITreeAttribute attr = (ITreeAttribute)val.Value; MechanicalNetworkOld network = new MechanicalNetworkOld(this, attr.GetInt("networkId")); networksById[network.networkId] = network; network.readFromTreeAttribute(attr); network.rediscoverNetwork(api.World); } }
public BlockFacing getFacing(MechanicalNetworkOld network) { return(orientation); }
public void handleMechanicalRelayPlacement() { Dictionary <BlockFacing, MechanicalNetworkOld> networks = new Dictionary <BlockFacing, MechanicalNetworkOld>(); List <BlockFacing> nullnetworks = new List <BlockFacing>(); foreach (BlockFacing facing in BlockFacing.ALLFACES) { IMechanicalPowerDeviceOld neib = getNeighbourDevice(facing, true); if (neib == null) { continue; } MechanicalNetworkOld network = neib.getNetwork(facing.GetOpposite()); if (network != null && !networks.ContainsValue(network)) { networks[facing] = network; } if (network == null) { nullnetworks.Add(facing); } } //System.out.println(worldObj.isRemote + " found " + networks.size() + " networks "); if (networks.Count == 1) { BlockFacing facing = networks.Keys.ToArray()[0]; trySetNetwork(networks[facing].networkId, facing); foreach (BlockFacing nullnetworkfacing in nullnetworks) { getNeighbourDevice(nullnetworkfacing, true).propagateNetworkToNeighbours( MechNetworkManagerRegistry.ManagersByWorld[api.World].getUniquePropagationId(), networkId, nullnetworkfacing ); } } if (networks.Count > 1 && api.World is IClientWorldAccessor) { float maxSpeedDifference = 0; MechanicalNetworkOld dominantNetwork = null; foreach (MechanicalNetworkOld network in networks.Values) { if (dominantNetwork == null) { dominantNetwork = network; continue; } maxSpeedDifference = Math.Max(maxSpeedDifference, Math.Abs(network.getSpeed() - dominantNetwork.getSpeed())); if (Math.Abs(network.getSpeed()) > Math.Abs(dominantNetwork.getSpeed())) { dominantNetwork = network; } } // Here we could disallow connecting of networks if // maxSpeedDifference is larger than 1 // e.g. immediately break the placed block again because it cannot handle // the large torque difference. But implementation will be somewhat complicated foreach (MechanicalNetworkOld network in networks.Values) { if (network != dominantNetwork) { network.isDead = true; MechNetworkManagerRegistry.ManagersByWorld[api.World].discardNetwork(network); } } dominantNetwork.rebuildNetwork(); api.World.BlockAccessor.MarkBlockEntityDirty(pos); } }
public void discardNetwork(MechanicalNetworkOld network) { networksById.Remove(network.networkId); }