Esempio n. 1
0
        private bool RequiresStand(BlockPos pos, Vec3i vector)
        {
            BlockMPBase block = Api.World.BlockAccessor.GetBlock(pos.X + vector.X, pos.Y + vector.Y, pos.Z + vector.Z) as BlockMPBase;

            if (block == null)
            {
                return(true);
            }
            BlockPos         sidePos = new BlockPos(pos.X + vector.X, pos.Y + vector.Y, pos.Z + vector.Z);
            BEBehaviorMPBase bemp    = Api.World.BlockAccessor.GetBlockEntity(sidePos)?.GetBehavior <BEBehaviorMPBase>();

            if (bemp == null)
            {
                return(true);
            }
            BEBehaviorMPAxle bempaxle = bemp as BEBehaviorMPAxle;

            if (bempaxle == null)
            {
                if (bemp is BEBehaviorMPBrake || bemp is BEBehaviorMPCreativeRotor)
                {
                    BlockFacing side = BlockFacing.FromNormal(vector);
                    if (side != null && block.HasMechPowerConnectorAt(Api.World, sidePos, side.Opposite))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            if (IsAttachedToBlock(Api.World.BlockAccessor, block, sidePos))
            {
                return(false);
            }
            return(bempaxle.RequiresStand(sidePos, vector));
        }
Esempio n. 2
0
        private bool RequiresStand(BlockPos pos, Vec3i vector)
        {
            try
            {
                BlockMPBase block = Api.World.BlockAccessor.GetBlock(pos.X + vector.X, pos.Y + vector.Y, pos.Z + vector.Z) as BlockMPBase;
                if (block == null)
                {
                    return(true);
                }

                BlockPos         sidePos = new BlockPos(pos.X + vector.X, pos.Y + vector.Y, pos.Z + vector.Z);
                BEBehaviorMPBase bemp    = Api.World.BlockAccessor.GetBlockEntity(sidePos)?.GetBehavior <BEBehaviorMPBase>();
                if (bemp == null)
                {
                    return(true);
                }

                BEBehaviorMPAxle bempaxle = bemp as BEBehaviorMPAxle;
                if (bempaxle == null)
                {
                    if (bemp is BEBehaviorMPBrake || bemp is BEBehaviorMPCreativeRotor)
                    {
                        BlockFacing side = BlockFacing.FromNormal(vector);
                        if (side != null && block.HasMechPowerConnectorAt(Api.World, sidePos, side.Opposite))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }

                if (IsAttachedToBlock(Api.World.BlockAccessor, block, sidePos))
                {
                    return(false);
                }
                return(bempaxle.RequiresStand(sidePos, vector));
            }
            catch (Exception e)
            {
#if DEBUG
                throw (e);
#else
                Api.Logger.Error("Exception thrown in RequiresStand, will log exception but silently ignore it");
                Api.Logger.Error("{0}", e);
                return(false);
#endif
            }
        }
        public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref string failureCode)
        {
            List <BlockPos> smallGears = new List <BlockPos>();

            if (!CanPlaceBlock(world, byPlayer, blockSel, ref failureCode, smallGears))
            {
                return(false);
            }

            bool ok = base.DoPlaceBlock(world, byPlayer, blockSel, itemstack);

            if (ok)
            {
                int                dx, dz;
                BlockEntity        beOwn       = world.BlockAccessor.GetBlockEntity(blockSel.Position);
                List <BlockFacing> connections = new List <BlockFacing>();

                foreach (var smallGear in smallGears)
                {
                    dx = smallGear.X - blockSel.Position.X;
                    dz = smallGear.Z - blockSel.Position.Z;
                    char orient = 'n';
                    if (dx == 1)
                    {
                        orient = 'e';
                    }
                    else if (dx == -1)
                    {
                        orient = 'w';
                    }
                    else if (dz == 1)
                    {
                        orient = 's';
                    }
                    BlockMPBase toPlaceBlock = world.GetBlock(new AssetLocation("angledgears-" + orient + orient)) as BlockMPBase;
                    BlockFacing bf           = BlockFacing.FromFirstLetter(orient);
                    toPlaceBlock.ExchangeBlockAt(world, smallGear);
                    toPlaceBlock.DidConnectAt(world, smallGear, bf.Opposite);
                    connections.Add(bf);
                    //IGearAcceptor beg = beOwn as IGearAcceptor;
                    //if (beg == null) world.Logger.Error("large gear wrong block entity type - not a gear acceptor");
                    //beg?.AddGear(smallGear);
                }
                PlaceFakeBlocks(world, blockSel.Position, smallGears);

                BEBehaviorMPBase beMechBase = beOwn?.GetBehavior <BEBehaviorMPBase>();
                BlockPos         pos        = blockSel.Position.DownCopy();
                if (world.BlockAccessor.GetBlock(pos) is IMechanicalPowerBlock block && block.HasMechPowerConnectorAt(world, pos, BlockFacing.UP))
                {
                    block.DidConnectAt(world, pos, BlockFacing.UP);
                    connections.Add(BlockFacing.DOWN);
                }
                else
                {
                    pos   = blockSel.Position.UpCopy();
                    block = world.BlockAccessor.GetBlock(pos) as IMechanicalPowerBlock;
                    if (block != null && block.HasMechPowerConnectorAt(world, pos, BlockFacing.DOWN))
                    {
                        block.DidConnectAt(world, pos, BlockFacing.DOWN);
                        connections.Add(BlockFacing.UP);
                    }
                }

                foreach (BlockFacing face in connections)
                {
                    beMechBase?.WasPlaced(face);
                }
            }