Esempio n. 1
0
        public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref string failureCode)
        {
            if (!world.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak))
            {
                byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty();
                failureCode = "claimed";
                return(false);
            }

            if (IsSuitablePosition(world, blockSel.Position, ref failureCode))
            {
                BlockFacing[] horVer = SuggestedHVOrientation(byPlayer, blockSel);

                string face = (horVer[0] == BlockFacing.NORTH || horVer[0] == BlockFacing.SOUTH) ? "n" : "w";

                string        knobOrientation = GetSuggestedKnobOrientation(world.BlockAccessor, blockSel.Position, horVer[0]);
                AssetLocation newCode         = CodeWithParts(face, "closed", knobOrientation);

                world.BlockAccessor.SetBlock(world.BlockAccessor.GetBlock(newCode).BlockId, blockSel.Position);
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
    public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref EnumHandling handling, ref string failureCode)
    {
        handling = EnumHandling.PreventDefault;
        Vec3f         vec           = new Vec3d().Ahead(1f, byPlayer.Entity.Pos.Pitch, byPlayer.Entity.Pos.Yaw).ToVec3f();
        BlockFacing   face          = BlockFacing.FromNormal(vec).Opposite;
        AssetLocation blockCode     = block.CodeWithVariant("side", face.Code);
        Block         orientedBlock = world.BlockAccessor.GetBlock(blockCode);

        if (orientedBlock.CanPlaceBlock(world, byPlayer, blockSel, ref failureCode))
        {
            orientedBlock.DoPlaceBlock(world, byPlayer, blockSel, itemstack);
            return(true);
        }
        return(false);
    }
Esempio n. 3
0
        public override bool ApplyToolBuild(WorldEdit worldEdit, Block block /*, BlockPos pos*/, ushort oldBlockId, /* BlockFacing onBlockFace, Vec3f hitPos, bool didOffset*/ BlockSelection blockSel, BlockPos targetPos, ItemStack withItemStack)
        {
            if (heights == null)
            {
                return(false);
            }

            worldEdit.Good("Ok, placing blocks, this may take a while");

            int      width  = heights.GetLength(0);
            int      length = heights.GetLength(1);
            BlockPos tmpPos = new BlockPos();

            IBlockAccessor blockAccessorBulk = worldEdit.sapi.World.BulkBlockAccessor;

            for (int x = 0; x < width; x++)
            {
                for (int z = 0; z < length; z++)
                {
                    int height = heights[x, z];

                    tmpPos.Set(targetPos.X + x - width / 2, targetPos.Y, targetPos.Z + z - length / 2);

                    for (int y = 0; y < height; y++)
                    {
                        blockAccessorBulk.SetBlock(block.BlockId, tmpPos);
                        tmpPos.Up();
                    }
                }
            }

            blockAccessorBulk.Commit();

            return(false);
        }
Esempio n. 4
0
 public override void OnHeldInteractStop(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
 {
     soundplayed  = false;
     nextactionat = 0;
     base.OnHeldInteractStop(secondsUsed, slot, byEntity, blockSel, entitySel);
 }
 public override void OnBuild(WorldEdit worldEdit, int oldBlockId, BlockSelection blockSel, ItemStack withItemStack)
 {
     GrowShrink(worldEdit, oldBlockId, blockSel, withItemStack);
 }
Esempio n. 6
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            ItemStack itemstack = byPlayer.InventoryManager.ActiveHotbarSlot?.Itemstack;

            if (itemstack == null || !itemstack.Collectible.Attributes["isCandle"].AsBool() || CandleCount == 8)
            {
                return(false);
            }
            if (byPlayer != null && byPlayer.WorldData.CurrentGameMode == EnumGameMode.Survival)
            {
                byPlayer.InventoryManager.ActiveHotbarSlot.TakeOut(1);
            }

            Block block = world.GetBlock(CodeWithParts(GetNextCandleCount()));

            world.BlockAccessor.ExchangeBlock(block.BlockId, blockSel.Position);
            world.BlockAccessor.MarkBlockDirty(blockSel.Position);
            return(true);
        }
Esempio n. 7
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling)
        {
            //base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handling);
            nextactionat = 2;


            handling = EnumHandHandling.Handled;
        }
Esempio n. 8
0
        public override bool OnHeldInteractStep(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (blockSel == null)
            {
                return(false);
            }

            IPlayer byPlayer = (byEntity as EntityPlayer).Player;

            if (byEntity.World is IClientWorldAccessor)
            {
                ModelTransform tf = new ModelTransform();
                tf.EnsureDefaultValues();

                float rotateToTill = GameMath.Clamp(secondsUsed * 18, 0, 2f);
                float scrape       = GameMath.SmoothStep(1 / 0.4f * GameMath.Clamp(secondsUsed - 0.35f, 0, 1));
                float scrapeShake  = secondsUsed > 0.35f && secondsUsed < 0.75f ? (float)(GameMath.Sin(secondsUsed * 50) / 60f) : 0;

                float rotateWithReset = Math.Max(0, rotateToTill - GameMath.Clamp(24 * (secondsUsed - 0.75f), 0, 2));
                float scrapeWithReset = Math.Max(0, scrape - Math.Max(0, 20 * (secondsUsed - 0.75f)));

                tf.Origin.Set(0f, 0, 0.5f);
                tf.Rotation.Set(0, rotateWithReset * 45, 0);
                tf.Translation.Set(scrapeShake, 0, scrapeWithReset / 2);

                byEntity.Controls.UsingHeldItemTransformBefore = tf;
            }

            if (secondsUsed > 0.35f && secondsUsed < 0.87f)
            {
                Vec3d dir = new Vec3d().AheadCopy(1, 0, byEntity.LocalPos.Yaw - GameMath.PI);
                Vec3d pos = blockSel.Position.ToVec3d().Add(0.5 + dir.X, 1.03, 0.5 + dir.Z);

                pos.X -= dir.X * secondsUsed * 1 / 0.75f * 1.2f;
                pos.Z -= dir.Z * secondsUsed * 1 / 0.75f * 1.2f;

                byEntity.World.SpawnCubeParticles(blockSel.Position, pos, 0.25f, 3, 0.5f, byPlayer);
            }

            if (secondsUsed > 0.6f && byEntity.Attributes.GetInt("didtill") == 0 && byEntity.World.Side == EnumAppSide.Server)
            {
                byEntity.Attributes.SetInt("didtill", 1);
                DoTill(secondsUsed, slot, byEntity, blockSel, entitySel);
            }

            return(secondsUsed < 1);
        }
Esempio n. 9
0
 public override bool OnHeldInteractCancel(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, EnumItemUseCancelReason cancelReason)
 {
     return(false);
 }
Esempio n. 10
0
 public override WorldInteraction[] GetPlacedBlockInteractionHelp(IWorldAccessor world, BlockSelection selection, IPlayer forPlayer)
 {
     return((selection.SelectionBoxIndex == 0 ? interactionsLeft : interactionsRight).Append(base.GetPlacedBlockInteractionHelp(world, selection, forPlayer)));
 }
Esempio n. 11
0
        public override void OnHeldInteractStart(IItemSlot itemslot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handHandling)
        {
            if (blockSel == null)
            {
                return;
            }
            BlockPos pos   = blockSel.Position;
            Block    block = byEntity.World.BlockAccessor.GetBlock(pos);

            byEntity.Attributes.SetInt("didtill", 0);

            if (block.Code.Path.StartsWith("soil"))
            {
                handHandling = EnumHandHandling.PreventDefault;
            }
        }
Esempio n. 12
0
        public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref string failureCode)
        {
            if (!world.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak))
            {
                byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty();
                failureCode = "claimed";
                return(false);
            }

            if (!byPlayer.Entity.Controls.Sneak)
            {
                failureCode = "onlywhensneaking";
                return(false);
            }

            if (IsSuitablePosition(world, blockSel.Position, ref failureCode) && world.BlockAccessor.GetBlock(blockSel.Position.DownCopy()).SideSolid[BlockFacing.UP.Index])
            {
                DoPlaceBlock(world, blockSel.Position, blockSel.Face, itemstack);
                return(true);
            }

            return(false);
        }
Esempio n. 13
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            if (blockSel == null)
            {
                return(false);
            }

            BlockEntity be = world.BlockAccessor.GetBlockEntity(blockSel.Position);

            if (be is BlockEntityIngotMold)
            {
                BlockEntityIngotMold beim = (BlockEntityIngotMold)be;
                return(beim.OnPlayerInteract(byPlayer, blockSel.Face, blockSel.HitPosition));
            }

            return(false);
        }
Esempio n. 14
0
        public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling)
        {
            if (blockSel == null)
            {
                return;
            }

            BlockEntity be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position.AddCopy(blockSel.Face.GetOpposite()));

            IPlayer byPlayer = null;

            if (byEntity is EntityPlayer)
            {
                byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID);
            }

            if (byPlayer != null && be is BlockEntityIngotMold)
            {
                BlockEntityIngotMold beim = (BlockEntityIngotMold)be;
                if (beim.OnPlayerInteract(byPlayer, blockSel.Face, blockSel.HitPosition))
                {
                    handling = EnumHandHandling.PreventDefault;
                }
            }
        }
Esempio n. 15
0
 public override bool OnHeldInteractCancel(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, EnumItemUseCancelReason cancelReason)
 {
     byEntity.Attributes.SetInt("aiming", 0);
     byEntity.StopAnimation("aim");
     return(true);
 }
Esempio n. 16
0
        public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling)
        {
            IPlayer byPlayer = (byEntity as EntityPlayer)?.Player;

            if (blockSel == null || !byEntity.Controls.Sneak)
            {
                base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, ref handling);
                return;
            }

            if (!byEntity.World.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak))
            {
                return;
            }

            handling = EnumHandHandling.PreventDefault;

            Block block = byEntity.World.BlockAccessor.GetBlock(blockSel.Position);

            if (block is BlockLooseGears)
            {
                int q = 5;
                if (int.TryParse(block.LastCodePart(), out q) && q < 5)
                {
                    Block moregearsblock = byEntity.World.GetBlock(block.CodeWithPart((q + 1) + "", 1));
                    byEntity.World.BlockAccessor.SetBlock(moregearsblock.BlockId, blockSel.Position);
                    byEntity.World.PlaySoundAt(block.Sounds.Place, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, byPlayer);
                    slot.TakeOut(1);
                }


                return;
            }


            BlockPos placePos = blockSel.Position.AddCopy(blockSel.Face);

            if (!byEntity.World.TestPlayerAccessBlock((byEntity as EntityPlayer)?.Player, placePos, EnumBlockAccessFlags.BuildOrBreak))
            {
                return;
            }

            block = byEntity.World.BlockAccessor.GetBlock(placePos);
            Block gearBlock = byEntity.World.GetBlock(new AssetLocation("loosegears-1"));

            if (block.IsReplacableBy(gearBlock))
            {
                byEntity.World.BlockAccessor.SetBlock(gearBlock.BlockId, placePos);
                slot.TakeOut(1);
                byEntity.World.PlaySoundAt(block.Sounds.Place, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, byPlayer);
            }
        }
Esempio n. 17
0
        public override void OnHeldInteractStop(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (byEntity.Attributes.GetInt("aiming") == 0)
            {
                return;
            }

            byEntity.Attributes.SetInt("aiming", 0);
            byEntity.StopAnimation("aim");

            if (secondsUsed < 0.35f)
            {
                return;
            }

            float  damage   = 0.5f;
            string rockType = slot.Itemstack.Collectible.FirstCodePart(1);

            ItemStack stack = slot.TakeOut(1);

            slot.MarkDirty();

            IPlayer byPlayer = null;

            if (byEntity is IEntityPlayer)
            {
                byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID);
            }
            byEntity.World.PlaySoundAt(new AssetLocation("sounds/player/throw"), byEntity, byPlayer, false, 8);

            EntityProperties type   = byEntity.World.GetEntityType(new AssetLocation("thrownbeenade"));
            Entity           entity = byEntity.World.ClassRegistry.CreateEntity(type);

            ((EntityThrownBeenade)entity).FiredBy         = byEntity;
            ((EntityThrownBeenade)entity).Damage          = damage;
            ((EntityThrownBeenade)entity).ProjectileStack = stack;

            float  acc      = (1 - byEntity.Attributes.GetFloat("aimingAccuracy", 0));
            double rndpitch = byEntity.WatchedAttributes.GetDouble("aimingRandPitch", 1) * acc * 0.75;
            double rndyaw   = byEntity.WatchedAttributes.GetDouble("aimingRandYaw", 1) * acc * 0.75;

            Vec3d pos      = byEntity.ServerPos.XYZ.Add(0, byEntity.EyeHeight - 0.2, 0);
            Vec3d aheadPos = pos.AheadCopy(1, byEntity.ServerPos.Pitch + rndpitch, byEntity.ServerPos.Yaw + rndyaw);
            Vec3d velocity = (aheadPos - pos) * 0.5;

            entity.ServerPos.SetPos(byEntity.ServerPos.BehindCopy(0.21).XYZ.Add(0, byEntity.EyeHeight - 0.2, 0).Ahead(0.25, 0, byEntity.ServerPos.Yaw + GameMath.PIHALF));
            entity.ServerPos.Motion.Set(velocity);

            entity.Pos.SetFrom(entity.ServerPos);
            entity.World = byEntity.World;

            byEntity.World.SpawnEntity(entity);
            byEntity.StartAnimation("throw");
        }
        public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref EnumHandling handling, ref string failureCode)
        {
            handling = EnumHandling.PreventDefault;
            AssetLocation blockCode = null;
            Block         orientedBlock;

            EnumSlabPlaceMode mode = itemstack.Attributes == null ? EnumSlabPlaceMode.Auto : (EnumSlabPlaceMode)itemstack.Attributes.GetInt("slabPlaceMode", 0);

            if (mode == EnumSlabPlaceMode.Horizontal)
            {
                string side = blockSel.HitPosition.Y < 0.5 ? "down" : "up";
                if (blockSel.Face.IsVertical)
                {
                    side = blockSel.Face.Opposite.Code;
                }

                blockCode     = block.CodeWithVariant("rot", side);
                orientedBlock = world.BlockAccessor.GetBlock(blockCode);
                if (orientedBlock.CanPlaceBlock(world, byPlayer, blockSel, ref failureCode))
                {
                    world.BlockAccessor.SetBlock(orientedBlock.BlockId, blockSel.Position);
                    return(true);
                }
                return(false);
            }

            if (mode == EnumSlabPlaceMode.Vertical)
            {
                BlockFacing[] hv   = Block.SuggestedHVOrientation(byPlayer, blockSel);
                string        side = hv[0].Code;
                if (blockSel.Face.IsHorizontal)
                {
                    side = blockSel.Face.Opposite.Code;
                }

                blockCode = block.CodeWithVariant("rot", side);

                orientedBlock = world.BlockAccessor.GetBlock(blockCode);
                if (orientedBlock.CanPlaceBlock(world, byPlayer, blockSel, ref failureCode))
                {
                    world.BlockAccessor.SetBlock(orientedBlock.BlockId, blockSel.Position);
                    return(true);
                }
                return(false);
            }


            if (rotateSides)
            {
                // Simple 6 state rotator.

                if (facing == "block")
                {
                    var x = Math.Abs(blockSel.HitPosition.X - 0.5);
                    var y = Math.Abs(blockSel.HitPosition.Y - 0.5);
                    var z = Math.Abs(blockSel.HitPosition.Z - 0.5);
                    switch (blockSel.Face.Axis)
                    {
                    case EnumAxis.X:
                        if (z < 0.3 && y < 0.3)
                        {
                            blockCode = block.CodeWithVariant("rot", blockSel.Face.Opposite.Code);
                        }
                        else if (z > y)
                        {
                            blockCode = block.CodeWithVariant("rot", blockSel.HitPosition.Z < 0.5 ? "north" : "south");
                        }
                        else
                        {
                            blockCode = block.CodeWithVariant("rot", blockSel.HitPosition.Y < 0.5 ? "down" : "up");
                        }
                        break;

                    case EnumAxis.Y:
                        if (z < 0.3 && x < 0.3)
                        {
                            blockCode = block.CodeWithVariant("rot", blockSel.Face.Opposite.Code);
                        }
                        else if (z > x)
                        {
                            blockCode = block.CodeWithVariant("rot", blockSel.HitPosition.Z < 0.5 ? "north" : "south");
                        }
                        else
                        {
                            blockCode = block.CodeWithVariant("rot", blockSel.HitPosition.X < 0.5 ? "west" : "east");
                        }
                        break;

                    case EnumAxis.Z:
                        if (x < 0.3 && y < 0.3)
                        {
                            blockCode = block.CodeWithVariant("rot", blockSel.Face.Opposite.Code);
                        }
                        else if (x > y)
                        {
                            blockCode = block.CodeWithVariant("rot", blockSel.HitPosition.X < 0.5 ? "west" : "east");
                        }
                        else
                        {
                            blockCode = block.CodeWithVariant("rot", blockSel.HitPosition.Y < 0.5 ? "down" : "up");
                        }
                        break;
                    }
                }
                else
                {
                    if (blockSel.Face.IsVertical)
                    {
                        blockCode = block.CodeWithVariant("rot", blockSel.Face.Opposite.Code);
                    }
                    else
                    {
                        blockCode = block.CodeWithVariant("rot", BlockFacing.HorizontalFromAngle(byPlayer.Entity.Pos.Yaw).Code);
                    }
                }
            }
            else if (rotateH || rotateV)
            {
                // Complex 4/8/16 state rotator.
                string h = "north";
                string v = "up";
                if (blockSel.Face.IsVertical)
                {
                    v = blockSel.Face.Code;
                    h = BlockFacing.HorizontalFromAngle(byPlayer.Entity.Pos.Yaw).Code;
                }
                else if (rotateV4)
                {
                    if (facing == "block")
                    {
                        h = blockSel.Face.Opposite.Code;
                    }
                    else
                    {
                        // Default to player facing.
                        h = BlockFacing.HorizontalFromAngle(byPlayer.Entity.Pos.Yaw).Code;
                    }
                    switch (blockSel.Face.Axis)
                    {
                    case EnumAxis.X:
                        // Find the axis farther from the center.
                        if (Math.Abs(blockSel.HitPosition.Z - 0.5) > Math.Abs(blockSel.HitPosition.Y - 0.5))
                        {
                            v = blockSel.HitPosition.Z < 0.5 ? "left" : "right";
                        }
                        else
                        {
                            v = blockSel.HitPosition.Y < 0.5 ? "up" : "down";
                        }
                        break;

                    case EnumAxis.Z:
                        if (Math.Abs(blockSel.HitPosition.X - 0.5) > Math.Abs(blockSel.HitPosition.Y - 0.5))
                        {
                            v = blockSel.HitPosition.X < 0.5 ? "left" : "right";
                        }
                        else
                        {
                            v = blockSel.HitPosition.Y < 0.5 ? "up" : "down";
                        }
                        break;
                    }
                }
                else
                {
                    v = blockSel.HitPosition.Y < 0.5 ? "up" : "down";
                }

                if (rotateH && rotateV)
                {
                    blockCode = block.CodeWithVariants(new string[] { "v", "rot" }, new string[] { v, h });
                }
                else if (rotateH)
                {
                    blockCode = block.CodeWithVariant("rot", h);
                }
                else if (rotateV)
                {
                    blockCode = block.CodeWithVariant("rot", v);
                }
            }

            if (blockCode == null)
            {
                blockCode = this.block.Code;
            }

            orientedBlock = world.BlockAccessor.GetBlock(blockCode);
            if (orientedBlock.CanPlaceBlock(world, byPlayer, blockSel, ref failureCode))
            {
                world.BlockAccessor.SetBlock(orientedBlock.BlockId, blockSel.Position);
                return(true);
            }

            return(false);
        }
Esempio n. 19
0
 public override WorldInteraction[] GetPlacedBlockInteractionHelp(IWorldAccessor world, BlockSelection selection, IPlayer forPlayer)
 {
     if (CandleCount == 8)
     {
         return(null);
     }
     return(new WorldInteraction[1] {
         new WorldInteraction()
         {
             ActionLangCode = "blockhelp-chandelier-addcandle", MouseButton = EnumMouseButton.Right, Itemstacks = new ItemStack[] { new ItemStack(world.GetItem(new AssetLocation("candle-wax")), 1), new ItemStack(world.GetItem(new AssetLocation("candle-tallow")), 1) }
         }
     }.Append <WorldInteraction>(base.GetPlacedBlockInteractionHelp(world, selection, forPlayer)));
 }
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            ItemSlot slot = byPlayer.InventoryManager.ActiveHotbarSlot;

            if (slot.Itemstack != null)
            {
                if (IsSettingHammer(slot))
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 21
0
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            // - start particles
            // - first extension
            // - break top/bottom/side blocks (maybe add calculations to make it faster for less blocks
            // - second extension
            // - break back block
            // - reset
            if (blockSel == null)
            {
                return(false);
            }
            //if (!BlockFacing.HORIZONTALS.Contains(blockSel.Face)) { return false; } //not pointed at a block ahead, cancel
            if (secondsUsed > 0.25f && !soundplayed)
            {
                //api.World.PlaySoundAt(new AssetLocation("sounds/quarrytemp"), blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, null, false, 8, 1);
                soundplayed = true;
            }
            if (secondsUsed > nextactionat)
            {
                IPlayer  p = api.World.NearestPlayer(byEntity.Pos.X, byEntity.Pos.Y, byEntity.Pos.Z);
                Block    tb;
                BlockPos bp;
                BlockPos cp      = null;
                bool     altered = false;
                foreach (BlockFacing bf in BlockFacing.ALLFACES)
                {
                    bp = blockSel.Position.Copy().Offset(bf);
                    tb = api.World.BlockAccessor.GetBlock(bp);

                    if (tb == null)
                    {
                        continue;
                    }
                    if (tb.FirstCodePart() == "rock")
                    {
                        tb.OnBlockBroken(api.World, bp, p, 1);
                        altered = true;
                        cp      = bp.Copy();
                    }
                }
                if (altered)
                {
                    tb = api.World.BlockAccessor.GetBlock(blockSel.Position);
                    if (tb != null)
                    {
                        tb.OnNeighbourBlockChange(api.World, blockSel.Position, cp);
                        soundplayed   = false;
                        nextactionat += 2;
                    }
                }
            }
            return(true);
        }
        public override bool OnBlockInteractStep(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            ItemSlot slot = byPlayer.InventoryManager.ActiveHotbarSlot;

            if (slot.Itemstack != null)
            {
                if (IsSettingHammer(slot))
                {
                    return(HandAnimations.Hit(byPlayer.Entity, secondsUsed));
                }
            }
            return(false);
        }
Esempio n. 23
0
 public override void OnBreak(WorldEdit worldEdit, BlockSelection blockSel, ref EnumHandling handling)
 {
     handling = EnumHandling.PreventDefault;
     GrowShrink(worldEdit, -1, blockSel, null, true);
 }
        public override void OnBlockInteractStop(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            ItemSlot slot = byPlayer.InventoryManager.ActiveHotbarSlot;

            if (slot.Itemstack != null)
            {
                if (IsSettingHammer(slot))
                {
                    if (world.Side.IsServer())
                    {
                        uint  index = (world.BlockAccessor.GetBlockEntity(blockSel.Position) as BENeolithicRoads).index;
                        Block nextBlock;

                        if (byPlayer.Entity.Controls.Sneak)
                        {
                            nextBlock = new AssetLocation("neolithicmod:" + CodeWithoutParts(1) + "-" + types.Prev(ref index)).GetBlock(api);
                        }
                        else
                        {
                            nextBlock = new AssetLocation("neolithicmod:" + CodeWithoutParts(1) + "-" + types.Next(ref index)).GetBlock(api);
                        }

                        if (nextBlock == null)
                        {
                            return;
                        }
                        (world.BlockAccessor.GetBlockEntity(blockSel.Position) as BENeolithicRoads).index = index;

                        world.PlaySoundAtWithDelay(nextBlock.Sounds.Place, blockSel.Position, 100);
                        world.PlaySoundAtWithDelay(new AssetLocation("sounds/effect/anvilhit"), blockSel.Position, 150);
                        world.BlockAccessor.SetBlock(nextBlock.BlockId, blockSel.Position);
                    }
                    return;
                }
            }
        }
Esempio n. 25
0
        public bool GrowShrink(WorldEdit worldEdit, int oldBlockId, BlockSelection blockSel, ItemStack withItemStack, bool shrink = false)
        {
            if (BrushRadius == 0)
            {
                return(false);
            }

            Block blockToPlace = blockAccessRev.GetBlock(blockSel.Position);

            if (shrink)
            {
                blockToPlace = blockAccessRev.GetBlock(0);
            }

            int selectedBlockID = blockAccessRev.GetBlockId(blockSel.Position.AddCopy(blockSel.Face.Opposite));

            int   radInt = (int)Math.Ceiling(BrushRadius);
            float radSq  = BrushRadius * BrushRadius;

            HashSet <BlockPos> viablePositions = new HashSet <BlockPos>();
            BlockPos           dpos, ddpos;
            Block blockAtPos;

            for (int dx = -radInt; dx <= radInt; dx++)
            {
                for (int dy = -radInt; dy <= radInt; dy++)
                {
                    for (int dz = -radInt; dz <= radInt; dz++)
                    {
                        if (dx * dx + dy * dy + dz * dz > radSq)
                        {
                            continue;
                        }

                        dpos       = blockSel.Position.AddCopy(dx, dy, dz);
                        blockAtPos = blockAccessRev.GetBlock(dpos);
                        if (blockAtPos.Replaceable >= 6000)
                        {
                            continue;
                        }
                        if (GrowShrinkMode == EnumGrowShrinkMode.SelectedBlock && blockAtPos.BlockId != selectedBlockID)
                        {
                            continue;
                        }

                        for (int i = 0; i < BlockFacing.NumberOfFaces; i++)
                        {
                            ddpos = dpos.AddCopy(BlockFacing.ALLFACES[i]);
                            if (blockAccessRev.GetBlock(ddpos).Replaceable >= 6000)
                            {
                                // We found an air block beside a solid block -> let's remember that solid block for removal and we can stop here
                                if (shrink)
                                {
                                    viablePositions.Add(dpos);
                                    break;
                                }
                                else
                                // We found an air block beside a solid block -> let's remember that air block and keep looking
                                {
                                    viablePositions.Add(ddpos);
                                }
                            }
                        }
                    }
                }
            }

            foreach (BlockPos p in viablePositions)
            {
                blockAccessRev.SetBlock(blockToPlace.BlockId, p, withItemStack);
            }

            if (oldBlockId >= 0)
            {
                blockAccessRev.SetHistoryStateBlock(blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, oldBlockId, blockAccessRev.GetBlockId(blockSel.Position));
            }
            blockAccessRev.Commit();


            return(true);
        }
Esempio n. 26
0
        public override void OnHeldInteractStart(IItemSlot itemslot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling)
        {
            if (blockSel != null && byEntity.World.BlockAccessor.GetBlock(blockSel.Position).FirstCodePart() == "skep")
            {
                return;
            }

            // Not ideal to code the aiming controls this way. Needs an elegant solution - maybe an event bus?
            byEntity.Attributes.SetInt("aiming", 1);
            byEntity.StartAnimation("aim");

            handling = EnumHandHandling.PreventDefault;
        }
Esempio n. 27
0
        public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref string failureCode)
        {
            if (CanPlaceBlock(world, byPlayer, blockSel, ref failureCode))
            {
                BlockFacing[] horVer   = SuggestedHVOrientation(byPlayer, blockSel);
                BlockPos      blockPos = blockSel.Position;

                AssetLocation blockCode = CodeWithParts(horVer[0].Code);
                Block         block     = world.BlockAccessor.GetBlock(blockCode);
                world.BlockAccessor.SetBlock(block.BlockId, blockPos);

                // Stores what axis the waterwheel is facing inside its block entity
                if (world.BlockAccessor.GetBlockEntity(blockPos) is BEWaterWheel beWheel && blockSel.Face.IsAxisNS)
                {
                    beWheel.AxisNS = true;
                }

                //PlaceFakeBlocks(world, blockSel);

                foreach (BlockFacing face in BlockFacing.HORIZONTALS)
                {
                    BlockPos pos = blockPos.AddCopy(face);

                    if (world.BlockAccessor.GetBlock(pos) is IMechanicalPowerBlock mechblock)
                    {
                        if (mechblock.HasMechPowerConnectorAt(world, pos, face.Opposite))
                        {
                            mechblock.DidConnectAt(world, pos, face.Opposite);
                            WasPlaced(world, blockPos, face);

                            BEBehaviorMPBase beMechBase = world.BlockAccessor.GetBlockEntity(blockPos).GetBehavior <BEBehaviorMPBase>();
                            WasPlaced(world, blockPos, null);

                            if (beMechBase != null)
                            {
                                beMechBase.tryConnect(face);
                            }

                            return(true);
                        }
                    }
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 28
0
        public override bool OnHeldInteractStep(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (byEntity.World is IClientWorldAccessor)
            {
                ModelTransform tf = new ModelTransform();
                tf.EnsureDefaultValues();

                float offset = GameMath.Clamp(secondsUsed * 3, 0, 2f);

                tf.Translation.Set(offset, -offset / 4f, 0);

                byEntity.Controls.UsingHeldItemTransformBefore = tf;
            }

            return(true);
        }
Esempio n. 29
0
        public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref string failureCode)
        {
            if (!world.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak))
            {
                byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty();
                failureCode = "claimed";
                return(false);
            }

            string orientations = GetOrientations(world, blockSel.Position);
            Block  block        = world.BlockAccessor.GetBlock(CodeWithParts(orientations));

            if (block == null)
            {
                block = this;
            }

            if (block.IsSuitablePosition(world, blockSel.Position, ref failureCode))
            {
                world.BlockAccessor.SetBlock(block.BlockId, blockSel.Position);
                return(true);
            }

            return(false);
        }
Esempio n. 30
0
 public override WorldInteraction[] GetPlacedBlockInteractionHelp(IWorldAccessor world, BlockSelection selection, IPlayer forPlayer)
 {
     return(base.GetPlacedBlockInteractionHelp(world, selection, forPlayer));
 }