public override void DidConnectAt(IWorldAccessor world, BlockPos pos, BlockFacing face)
        {
            if (IsDeadEnd())
            {
                BlockFacing nowFace = BlockFacing.FromFirstLetter(LastCodePart()[0]);
                if (nowFace.IsAdjacent(face))
                {
                    AssetLocation loc          = new AssetLocation(FirstCodePart() + "-" + LastCodePart() + face.Code[0]);
                    Block         toPlaceBlock = world.GetBlock(loc);

                    if (toPlaceBlock == null)
                    {
                        loc          = new AssetLocation(FirstCodePart() + "-" + face.Code[0] + LastCodePart());
                        toPlaceBlock = world.GetBlock(loc);
                    }


                    MechanicalNetwork nw = GetNetwork(world, pos);

                    world.BlockAccessor.SetBlock(toPlaceBlock.BlockId, pos);

                    BEMPBase be = (world.BlockAccessor.GetBlockEntity(pos) as BEMPBase);
                    be.JoinNetwork(nw);
                }
            }
        }
Пример #2
0
        public virtual void DidConnectTo(BlockPos pos, BlockFacing facing)
        {
            BEMPBase nbe = api.World.BlockAccessor.GetBlockEntity(pos) as BEMPBase;

            if (nbe != null)
            {
                NetworkId = nbe.NetworkId;
            }
        }
Пример #3
0
        public void WasPlaced(IWorldAccessor world, BlockPos ownPos, BlockFacing connectedOnFacing = null, IMechanicalPowerBlock connectedToBlock = null)
        {
            BEMPBase beMechBase = (world.BlockAccessor.GetBlockEntity(ownPos) as BEMPBase);

            MechanicalNetwork network;

            if (connectedOnFacing == null)
            {
                network = mechPower.CreateNetwork();
            }
            else
            {
                network = connectedToBlock.GetNetwork(world, ownPos.AddCopy(connectedOnFacing));

                IMechanicalPowerNode node = world.BlockAccessor.GetBlockEntity(ownPos.AddCopy(connectedOnFacing)) as IMechanicalPowerNode;

                beMechBase?.SetBaseTurnDirection(node.GetTurnDirection(connectedOnFacing.GetOpposite()), connectedOnFacing.GetOpposite());
            }

            beMechBase?.JoinNetwork(network);
        }
        public override void OnNeighourBlockChange(IWorldAccessor world, BlockPos pos, BlockPos neibpos)
        {
            string orients = LastCodePart();

            BlockFacing[] facings;
            facings = orients.Length == 1 ? new BlockFacing[] { BlockFacing.FromFirstLetter(orients[0]) } : new BlockFacing[] { BlockFacing.FromFirstLetter(orients[0]), BlockFacing.FromFirstLetter(orients[1]) };

            List <BlockFacing> lostFacings = new List <BlockFacing>();

            foreach (BlockFacing facing in facings)
            {
                BlockPos npos = pos.AddCopy(facing);
                IMechanicalPowerBlock nblock = world.BlockAccessor.GetBlock(npos) as IMechanicalPowerBlock;

                if (nblock == null || !nblock.HasConnectorAt(world, npos, facing.GetOpposite()))
                {
                    lostFacings.Add(facing);
                }
            }

            if (lostFacings.Count == orients.Length)
            {
                world.BlockAccessor.BreakBlock(pos, null);
                return;
            }

            if (lostFacings.Count > 0)
            {
                MechanicalNetwork nw = GetNetwork(world, pos);

                orients = orients.Replace("" + lostFacings[0].Code[0], "");
                Block toPlaceBlock = world.GetBlock(new AssetLocation(FirstCodePart() + "-" + orients));
                world.BlockAccessor.SetBlock(toPlaceBlock.BlockId, pos);

                BEMPBase be = (world.BlockAccessor.GetBlockEntity(pos) as BEMPBase);
                be.JoinNetwork(nw);
            }
        }