コード例 #1
0
        public MechanicalNetworkOld getNetworkById(long id)
        {
            MechanicalNetworkOld network = null;

            networksById.TryGetValue(id, out network);
            return(network);
        }
コード例 #2
0
        private void OnPacket(MechNetworkPacket networkMessage)
        {
            bool isNew = networksById.ContainsKey(networkMessage.networkId);

            MechanicalNetworkOld network = getOrCreateNetwork(networkMessage.networkId);

            network.updateFromPacket(networkMessage, isNew);
        }
コード例 #3
0
        public MechanicalNetworkOld createAndRegisterNetwork(IMechanicalPowerNetworkNode originatorNode)
        {
            MechanicalNetworkOld network = createAndRegisterNetwork();

            network.register(originatorNode);
            network.firstPowerNode = originatorNode.getPosition();

            return(network);
        }
コード例 #4
0
        public MechanicalNetworkOld[] getNetworks()
        {
            MechanicalNetworkOld network = MechNetworkManagerRegistry.ManagersByWorld[api.World].getNetworkById(networkId);

            if (network == null)
            {
                return(new MechanicalNetworkOld[0]);
            }
            return(new MechanicalNetworkOld[] { network });
        }
コード例 #5
0
        public float getNetworkSpeed(BlockFacing facing)
        {
            MechanicalNetworkOld network = getNetwork(facing);

            if (network == null)
            {
                return(0);
            }
            return(network.getSpeed());
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        public float getAngle()
        {
            MechanicalNetworkOld network = getNetwork(null);

            if (network == null)
            {
                return(lastAngle);
            }

            if (directionFromFacing != orientation)
            {
                return(lastAngle = 360 - network.getAngle());
            }

            return(lastAngle = network.getAngle());
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
 public BlockFacing getFacing(MechanicalNetworkOld network)
 {
     return(orientation);
 }
コード例 #11
0
        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);
            }
        }
コード例 #12
0
 public void discardNetwork(MechanicalNetworkOld network)
 {
     networksById.Remove(network.networkId);
 }