Esempio n. 1
0
        public override float OnGettingBroken(IPlayer player, BlockSelection blockSel, ItemSlot itemslot, float remainingResistance, float dt, int counter)
        {
            IWorldAccessor world = player?.Entity?.World;

            if (world == null)
            {
                world = api.World;
            }
            BEMPMultiblock be = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BEMPMultiblock;

            if (be == null || be.Centre == null)
            {
                return(1f);                                  //never break
            }
            Block centreBlock = world.BlockAccessor.GetBlock(be.Centre);

            if (api.Side == EnumAppSide.Client)
            {
                //Vintagestory.Client.SystemMouseInWorldInteractions mouse;
                //mouse.loadOrCreateBlockDamage(bs, centreBlock);
                //mouse.curBlockDmg.LastBreakEllapsedMs = game.ElapsedMilliseconds;
            }
            BlockSelection bs = blockSel.Clone();

            bs.Position = be.Centre;
            return(centreBlock.OnGettingBroken(player, bs, itemslot, remainingResistance, dt, counter));
        }
Esempio n. 2
0
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1f)
        {
            BEMPMultiblock be = world.BlockAccessor.GetBlockEntity(pos) as BEMPMultiblock;

            if (be == null || be.Centre == null)
            {
                // being broken by other game code (including on breaking the pulverizer base block): standard block breaking treatment
                base.OnBlockBroken(world, pos, byPlayer, dropQuantityMultiplier);
                return;
            }
            // being broken by player: break the centre block instead
            BlockPos centrePos   = be.Centre;
            Block    centreBlock = world.BlockAccessor.GetBlock(centrePos);

            centreBlock.OnBlockBroken(world, centrePos, byPlayer, dropQuantityMultiplier);

            // Need to trigger neighbourchange on client side only (because it's normally in the player block breaking code)
            if (api.Side == EnumAppSide.Client)
            {
                foreach (BlockFacing facing in BlockFacing.HORIZONTALS)
                {
                    BlockPos npos = centrePos.AddCopy(facing);
                    world.BlockAccessor.GetBlock(npos).OnNeighbourBlockChange(world, npos, centrePos);
                }
            }

            base.OnBlockBroken(world, pos, byPlayer, dropQuantityMultiplier);
        }
        public bool IsReplacableByGear(IWorldAccessor world, BlockPos pos)
        {
            BEMPMultiblock be = world.BlockAccessor.GetBlockEntity(pos) as BEMPMultiblock;

            if (be == null || be.Centre == null)
            {
                return(true);
            }
            IGearAcceptor beg = world.BlockAccessor.GetBlockEntity(be.Centre) as IGearAcceptor;

            return(beg == null ? true : beg.CanAcceptGear(pos));
        }
Esempio n. 4
0
        //Need to override because this fake block has no texture of its own (no texture gives black breaking particles)
        public override int GetRandomColor(ICoreClientAPI capi, BlockPos pos, BlockFacing facing)
        {
            IBlockAccessor blockAccess = capi.World.BlockAccessor;
            BEMPMultiblock be          = blockAccess.GetBlockEntity(pos) as BEMPMultiblock;

            if (be == null || be.Centre == null)
            {
                return(0);
            }
            Block centreBlock = blockAccess.GetBlock(be.Centre);

            return(centreBlock.GetRandomColor(capi, be.Centre, facing));
        }
Esempio n. 5
0
        public override Cuboidf GetParticleBreakBox(IBlockAccessor blockAccess, BlockPos pos, BlockFacing facing)
        {
            BEMPMultiblock be = blockAccess.GetBlockEntity(pos) as BEMPMultiblock;

            if (be == null || be.Centre == null)
            {
                return(base.GetParticleBreakBox(blockAccess, pos, facing));
            }
            // being broken by player: break the centre block instead
            Block centreBlock = blockAccess.GetBlock(be.Centre);

            return(centreBlock.GetParticleBreakBox(blockAccess, be.Centre, facing));
        }
        // Need to override because this fake block has no texture of its own (no texture gives black breaking particles)
        public override int GetRandomColor(ICoreClientAPI capi, BlockPos pos, BlockFacing facing, int rndIndex = -1)
        {
            IBlockAccessor blockAccess = capi.World.BlockAccessor;
            BEMPMultiblock be          = blockAccess.GetBlockEntity(pos) as BEMPMultiblock;

            if (be == null || be.Principal == null)
            {
                return(0);
            }
            Block centerBlock = blockAccess.GetBlock(be.Principal);

            return(centerBlock.GetRandomColor(capi, be.Principal, facing, rndIndex));
        }
        public override Cuboidf GetParticleBreakBox(IBlockAccessor blockAccess, BlockPos pos, BlockFacing facing)
        {
            BEMPMultiblock be = blockAccess.GetBlockEntity(pos) as BEMPMultiblock;

            if (be == null || be.Principal == null)
            {
                return(base.GetParticleBreakBox(blockAccess, pos, facing));
            }
            // being broken by player: break the main block instead
            Block principalBlock = blockAccess.GetBlock(be.Principal);

            return(principalBlock.GetParticleBreakBox(blockAccess, be.Principal, facing));
        }
Esempio n. 8
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            BEMPMultiblock bem = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BEMPMultiblock;

            if (bem != null)
            {
                BlockEntity be = world.BlockAccessor.GetBlockEntity(bem.Centre);
                if (be is BEPulverizer bep)
                {
                    return(bep.OnInteract(byPlayer, blockSel));
                }
            }
            return(base.OnBlockInteractStart(world, byPlayer, blockSel));
        }
        public BlockEntity GearPlaced(IWorldAccessor world, BlockPos pos)
        {
            BEMPMultiblock be = world.BlockAccessor.GetBlockEntity(pos) as BEMPMultiblock;

            if (be == null || be.Centre == null)
            {
                return(null);
            }

            IGearAcceptor beg = world.BlockAccessor.GetBlockEntity(be.Centre) as IGearAcceptor;

            if (beg == null)
            {
                world.Logger.Notification("no gear acceptor");
            }
            beg?.AddGear(pos);
            return(beg as BlockEntity);
        }
        public override float OnGettingBroken(IPlayer player, BlockSelection blockSel, ItemSlot itemslot, float remainingResistance, float dt, int counter)
        {
            IWorldAccessor world = player?.Entity?.World;

            if (world == null)
            {
                world = api.World;
            }
            BEMPMultiblock be = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BEMPMultiblock;

            if (be == null || be.Principal == null)
            {
                return(1f);                                     //never break
            }
            Block centerBlock = world.BlockAccessor.GetBlock(be.Principal);

            BlockSelection bs = blockSel.Clone();

            bs.Position = be.Principal;
            return(centerBlock.OnGettingBroken(player, bs, itemslot, remainingResistance, dt, counter));
        }
Esempio n. 11
0
        public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref string failureCode)
        {
            Block blockExisting = world.BlockAccessor.GetBlock(blockSel.Position);

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

            BlockFacing           firstFace     = null;
            BlockFacing           secondFace    = null;
            BlockMPMultiblockGear largeGearEdge = blockExisting as BlockMPMultiblockGear;
            bool validLargeGear = false;

            if (largeGearEdge != null)
            {
                BEMPMultiblock be = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BEMPMultiblock;
                if (be != null)
                {
                    validLargeGear = be.Centre != null;
                }
            }

            foreach (BlockFacing face in BlockFacing.ALLFACES)
            {
                if (validLargeGear && (face == BlockFacing.UP || face == BlockFacing.DOWN))
                {
                    continue;
                }
                BlockPos pos = blockSel.Position.AddCopy(face);
                IMechanicalPowerBlock block = world.BlockAccessor.GetBlock(pos) as IMechanicalPowerBlock;
                if (block != null && block.HasMechPowerConnectorAt(world, pos, face.Opposite))
                {
                    if (firstFace == null)
                    {
                        firstFace = face;
                    }
                    else
                    {
                        if (face.IsAdjacent(firstFace))
                        {
                            secondFace = face;
                            break;
                        }
                    }
                }
            }

            if (firstFace != null)
            {
                BlockPos              firstPos  = blockSel.Position.AddCopy(firstFace);
                BlockEntity           be        = world.BlockAccessor.GetBlockEntity(firstPos);
                IMechanicalPowerBlock neighbour = be?.Block as IMechanicalPowerBlock;

                BEBehaviorMPAxle bempaxle = be?.GetBehavior <BEBehaviorMPAxle>();
                if (bempaxle != null && !BEBehaviorMPAxle.IsAttachedToBlock(world.BlockAccessor, neighbour as Block, firstPos))
                {
                    failureCode = "axlemusthavesupport";
                    return(false);
                }

                BlockEntity largeGearBE = validLargeGear ? largeGearEdge.GearPlaced(world, blockSel.Position) : null;

                Block toPlaceBlock = getGearBlock(world, validLargeGear, firstFace, secondFace);
                //world.BlockAccessor.RemoveBlockEntity(blockSel.Position);  //## needed in 1.12, but not with new chunk BlockEntity Dictionary in 1.13
                world.BlockAccessor.SetBlock(toPlaceBlock.BlockId, blockSel.Position);

                if (secondFace != null)
                {
                    BlockPos secondPos = blockSel.Position.AddCopy(secondFace);
                    IMechanicalPowerBlock neighbour2 = world.BlockAccessor.GetBlock(secondPos) as IMechanicalPowerBlock;
                    neighbour2?.DidConnectAt(world, secondPos, secondFace.Opposite);
                }

                BEBehaviorMPAngledGears beAngledGear = world.BlockAccessor.GetBlockEntity(blockSel.Position)?.GetBehavior <BEBehaviorMPAngledGears>();
                if (largeGearBE?.GetBehavior <BEBehaviorMPBase>() is BEBehaviorMPLargeGear3m largeGear)
                {
                    beAngledGear.AddToLargeGearNetwork(largeGear, firstFace);
                }

                //do this last even for the first face so that both neighbours are correctly set
                neighbour?.DidConnectAt(world, firstPos, firstFace.Opposite);
                beAngledGear.newlyPlaced = true;
                if (!beAngledGear.tryConnect(firstFace) && secondFace != null)
                {
                    beAngledGear.tryConnect(secondFace);
                }
                beAngledGear.newlyPlaced = false;

                return(true);
            }

            failureCode = "requiresaxle";

            return(false);
        }