示例#1
0
        public bool tryConnect(BlockFacing toFacing)
        {
            MechanicalNetwork newNetwork;

            BlockPos pos = Position.AddCopy(toFacing);
            IMechanicalPowerBlock connectedToBlock = Api.World.BlockAccessor.GetBlock(pos) as IMechanicalPowerBlock;

            if (DEBUG)
            {
                Api.Logger.Notification("tryConnect at " + this.Position + " towards " + toFacing + " " + pos);
            }

            if (connectedToBlock == null || !connectedToBlock.HasMechPowerConnectorAt(Api.World, pos, toFacing.Opposite))
            {
                return(false);
            }
            newNetwork = connectedToBlock.GetNetwork(Api.World, pos);
            if (newNetwork != null)
            {
                IMechanicalPowerDevice node = Api.World.BlockAccessor.GetBlockEntity(pos).GetBehavior <BEBehaviorMPBase>() as IMechanicalPowerDevice;

                connectedToBlock.DidConnectAt(Api.World, pos, toFacing.Opposite);  //do this first to set the new Angled Gear block correctly prior to getting propagation direction
                BlockFacing   newTurnDir = node.GetPropagationDirectionInput();
                MechPowerPath curPath    = new MechPowerPath(toFacing, node.GetGearedRatio(toFacing), pos, !node.IsPropagationDirection(Position, toFacing));
                SetPropagationDirection(curPath);
                MechPowerPath[] paths = GetMechPowerExits(curPath);
                JoinNetwork(newNetwork);

                for (int i = 0; i < paths.Length; i++)
                {
                    //if (paths[i].OutFacing == toFacing) continue;
                    if (DEBUG)
                    {
                        Api.Logger.Notification("== spreading path " + (paths[i].invert ? "-" : "") + paths[i].OutFacing + "  " + paths[i].gearingRatio);
                    }
                    BlockPos exitPos = Position.AddCopy(paths[i].OutFacing);

                    bool chunkLoaded = spreadTo(Api, newNetwork, exitPos, paths[i], out _);
                    if (!chunkLoaded)
                    {
                        LeaveNetwork();
                        return(true);
                    }
                }

                return(true);
            }
            else if (this.network != null)
            {
                BEBehaviorMPBase node = Api.World.BlockAccessor.GetBlockEntity(pos)?.GetBehavior <BEBehaviorMPBase>();
                if (node != null)
                {
                    return(node.tryConnect(toFacing.Opposite));
                }
            }

            return(false);
        }
示例#2
0
        public virtual void WasPlaced(IWorldAccessor world, BlockPos ownPos, BlockFacing connectedOnFacing)
        {
            if (connectedOnFacing == null)
            {
                return;
            }
            BEBehaviorMPBase beMechBase = world.BlockAccessor.GetBlockEntity(ownPos)?.GetBehavior <BEBehaviorMPBase>();

            beMechBase?.tryConnect(connectedOnFacing);
        }