コード例 #1
0
        public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref EnumHandling handling, ref string failureCode)
        {
            handling = EnumHandling.PreventDefault;

            // Prefer selected block face
            if (blockSel.Face.IsHorizontal)
            {
                if (TryAttachTo(world, byPlayer, blockSel, itemstack, ref failureCode))
                {
                    return(true);
                }
            }

            // Otherwise attach to any possible face
            BlockFacing[] faces = BlockFacing.HORIZONTALS;
            blockSel = blockSel.Clone();
            for (int i = 0; i < faces.Length; i++)
            {
                blockSel.Face = faces[i];
                if (TryAttachTo(world, byPlayer, blockSel, itemstack, ref failureCode))
                {
                    return(true);
                }
            }

            failureCode = "requirehorizontalattachable";

            return(false);
        }
コード例 #2
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));
        }
コード例 #3
0
        public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel)
        {
            if (CanPlantStay(world.BlockAccessor, blockSel.Position.UpCopy()))
            {
                blockSel          = blockSel.Clone();
                blockSel.Position = blockSel.Position.Up();
                return(base.TryPlaceBlock(world, byPlayer, itemstack, blockSel));
            }

            return(false);
        }
コード例 #4
0
        protected bool putOrGetItemStacking(IPlayer byPlayer, BlockSelection bs)
        {
            BlockPos    abovePos = Pos.UpCopy();
            BlockEntity be       = Api.World.BlockAccessor.GetBlockEntity(abovePos);

            if (be is BlockEntityGroundStorage beg)
            {
                return(beg.OnPlayerInteractStart(byPlayer, bs));
            }

            bool sneaking = byPlayer.Entity.Controls.Sneak;


            ItemSlot hotbarSlot = byPlayer.InventoryManager.ActiveHotbarSlot;

            if (sneaking && TotalStackSize >= Capacity)
            {
                Block pileblock  = Api.World.BlockAccessor.GetBlock(Pos);
                Block aboveblock = Api.World.BlockAccessor.GetBlock(abovePos);

                if (aboveblock.IsReplacableBy(pileblock))
                {
                    BlockGroundStorage bgs = pileblock as BlockGroundStorage;
                    var bsc = bs.Clone();
                    bsc.Position.Up();
                    bsc.Face = null;
                    return(bgs.CreateStorage(Api.World, bsc, byPlayer));
                }

                return(false);
            }


            bool equalStack = inventory[0].Empty || hotbarSlot.Itemstack != null && hotbarSlot.Itemstack.Equals(Api.World, inventory[0].Itemstack, GlobalConstants.IgnoredStackAttributes);

            if (sneaking && !equalStack)
            {
                return(false);
            }

            lock (inventoryLock)
            {
                if (sneaking)
                {
                    return(TryPutItem(byPlayer));
                }
                else
                {
                    return(TryTakeItem(byPlayer));
                }
            }
        }
コード例 #5
0
        public bool DoesBehaviorAllow(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            bool preventDefault = false;

            foreach (BlockBehavior behavior in BlockBehaviors)
            {
                EnumHandling handled        = EnumHandling.PassThrough;
                bool         behaviorResult = behavior.OnBlockInteractStart(world, byPlayer, blockSel, ref handled);
                if (handled != EnumHandling.PassThrough)
                {
                    preventDefault = true;
                }

                if (handled == EnumHandling.PreventSubsequent)
                {
                    return(false);
                }
            }
            if (preventDefault)
            {
                return(false);
            }


            if (this is BlockDoor)
            {
                blockSel          = blockSel.Clone();
                blockSel.Position = (this as BlockDoor).IsUpperHalf() ? blockSel.Position.DownCopy() : blockSel.Position.UpCopy();

                foreach (BlockBehavior behavior in BlockBehaviors)
                {
                    EnumHandling handled        = EnumHandling.PassThrough;
                    bool         behaviorResult = behavior.OnBlockInteractStart(world, byPlayer, blockSel, ref handled);
                    if (handled != EnumHandling.PassThrough)
                    {
                        preventDefault = true;
                    }

                    if (handled == EnumHandling.PreventSubsequent)
                    {
                        return(false);
                    }
                }

                if (preventDefault)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #6
0
        public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref string failureCode)
        {
            if (CanPlantStay(world.BlockAccessor, blockSel.Position.UpCopy()))
            {
                blockSel          = blockSel.Clone();
                blockSel.Position = blockSel.Position.Up();
                return(base.TryPlaceBlock(world, byPlayer, itemstack, blockSel, ref failureCode));
            }

            failureCode = "requirefullwater";

            return(false);
        }
コード例 #7
0
        public override WorldInteraction[] GetPlacedBlockInteractionHelp(IWorldAccessor world, BlockSelection blockSel, IPlayer forPlayer)
        {
            var blockSelOffsetInved = blockSel.Clone();

            blockSelOffsetInved.Position.Add(OffsetInv);
            var block = world.BlockAccessor.GetBlock(blockSelOffsetInved.Position);

            if (block is IMultiBlockModular mbMono)
            {
                return(mbMono.GetPlacedBlockInteractionHelp(world, blockSel, forPlayer, OffsetInv));
            }

            return(block.GetPlacedBlockInteractionHelp(world, blockSelOffsetInved, forPlayer));
        }
コード例 #8
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling)
        {
            if (byEntity.Controls.Sneak && blockSel != null)
            {
                IPlayer byPlayer = null;
                if (byEntity is EntityPlayer)
                {
                    byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID);
                }
                if (byPlayer == null)
                {
                    return;
                }

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


                Block    placeblock  = api.World.GetBlock(new AssetLocation("cheese"));
                BlockPos targetPos   = blockSel.Position.AddCopy(blockSel.Face);
                string   failureCode = "";

                BlockSelection placeSel = blockSel.Clone();
                placeSel.Position.Add(blockSel.Face);

                if (placeblock.TryPlaceBlock(api.World, byPlayer, slot.Itemstack, placeSel, ref failureCode))
                {
                    BECheese bec = api.World.BlockAccessor.GetBlockEntity(targetPos) as BECheese;
                    if (bec != null)
                    {
                        slot.TakeOut(1);
                        slot.MarkDirty();
                    }

                    api.World.PlaySoundAt(placeblock.Sounds.Place, targetPos.X + 0.5, targetPos.Y, targetPos.Z + 0.5, byPlayer);

                    handling = EnumHandHandling.PreventDefault;
                }
                else
                {
                    (api as ICoreClientAPI)?.TriggerIngameError(this, failureCode, Lang.Get("placefailure-" + failureCode));
                }

                return;
            }

            base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handling);
        }
コード例 #9
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            var blockSelOffsetInved = blockSel.Clone();

            blockSelOffsetInved.Position.Add(OffsetInv);
            var block = world.BlockAccessor.GetBlock(blockSelOffsetInved.Position);

            if (block is IMultiBlockModular mbMono)
            {
                return(mbMono.MBOnBlockInteractStart(world, byPlayer, blockSel, OffsetInv));
            }

            return(block.OnBlockInteractStart(world, byPlayer, blockSelOffsetInved));
        }
コード例 #10
0
        public override bool OnBlockInteractCancel(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, EnumItemUseCancelReason cancelReason)
        {
            var blockSelOffsetInved = blockSel.Clone();

            blockSelOffsetInved.Position.Add(OffsetInv);
            var block = world.BlockAccessor.GetBlock(blockSelOffsetInved.Position);

            if (block is IMultiBlockModular mbMono)
            {
                return(mbMono.MBOnBlockInteractCancel(secondsUsed, world, byPlayer, blockSel, cancelReason, OffsetInv));
            }

            return(block.OnBlockInteractCancel(secondsUsed, world, byPlayer, blockSelOffsetInved, cancelReason));
        }
コード例 #11
0
        public override WorldInteraction[] GetPlacedBlockInteractionHelp(IWorldAccessor world, BlockSelection selection, IPlayer forPlayer)
        {
            BlockPos npos;

            if ((npos = GetControllerBlockPositionOrNull(selection.Position)) != null)
            {
                BlockSelection nsele = selection.Clone();
                nsele.Position = npos;

                return(api.World.BlockAccessor.GetBlock(npos).GetPlacedBlockInteractionHelp(world, nsele, forPlayer));
            }

            return(base.GetPlacedBlockInteractionHelp(world, selection, forPlayer));
        }
コード例 #12
0
        public override void OnBlockInteractStop(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            var blockSelOffsetInved = blockSel.Clone();

            blockSelOffsetInved.Position.Add(OffsetInv);
            var block = world.BlockAccessor.GetBlock(blockSelOffsetInved.Position);

            if (block is IMultiBlockModular mbMono)
            {
                mbMono.MBOnBlockInteractStop(secondsUsed, world, byPlayer, blockSel, OffsetInv);
                return;
            }

            block.OnBlockInteractStop(secondsUsed, world, byPlayer, blockSelOffsetInved);
        }
コード例 #13
0
        public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (blockSel == null || byEntity?.World == null || !byEntity.Controls.Sneak)
            {
                base.OnHeldInteractStart(itemslot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);
                return;
            }

            bool  waterBlock = byEntity.World.BlockAccessor.GetBlock(blockSel.Position.AddCopy(blockSel.Face)).LiquidCode == "water";
            Block block;

            if (this.Code.Path.Contains("papyrus"))
            {
                block = byEntity.World.GetBlock(new AssetLocation(waterBlock ? "tallplant-papyrus-water-harvested-free" : "tallplant-papyrus-land-harvested-free"));
            }
            else
            {
                block = byEntity.World.GetBlock(new AssetLocation(waterBlock ? "tallplant-coopersreed-water-harvested-free" : "tallplant-coopersreed-land-harvested-free"));
            }

            if (block == null)
            {
                base.OnHeldInteractStart(itemslot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);
                return;
            }

            IPlayer byPlayer = null;

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

            blockSel = blockSel.Clone();
            blockSel.Position.Add(blockSel.Face);

            string useless = "";

            bool ok = block.TryPlaceBlock(byEntity.World, byPlayer, itemslot.Itemstack, blockSel, ref useless);

            if (ok)
            {
                byEntity.World.PlaySoundAt(block.Sounds.GetBreakSound(byPlayer), blockSel.Position.X + 0.5, blockSel.Position.Y + 0.5, blockSel.Position.Z + 0.5, byPlayer);
                itemslot.TakeOut(1);
                itemslot.MarkDirty();
                handHandling = EnumHandHandling.PreventDefaultAction;
            }
        }
コード例 #14
0
        public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (blockSel == null || !byEntity.Controls.Sneak)
            {
                base.OnHeldInteractStart(itemslot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);
                return;
            }

            string treetype = Variant["type"];

            Block saplBlock = byEntity.World.GetBlock(AssetLocation.Create("sapling-" + treetype + "-free", Code.Domain));

            if (saplBlock != null)
            {
                IPlayer byPlayer = null;
                if (byEntity is EntityPlayer)
                {
                    byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID);
                }

                blockSel = blockSel.Clone();
                blockSel.Position.Up();

                string failureCode = "";
                if (!saplBlock.TryPlaceBlock(api.World, byPlayer, itemslot.Itemstack, blockSel, ref failureCode))
                {
                    if (api is ICoreClientAPI capi && failureCode != null && failureCode != "__ignore__")
                    {
                        capi.TriggerIngameError(this, failureCode, Lang.Get("placefailure-" + failureCode));
                    }
                }
                else
                {
                    byEntity.World.PlaySoundAt(new AssetLocation("sounds/block/dirt1"), blockSel.Position.X + 0.5f, blockSel.Position.Y, blockSel.Position.Z + 0.5f, byPlayer);

                    ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);

                    if (byPlayer?.WorldData?.CurrentGameMode != EnumGameMode.Creative)
                    {
                        itemslot.TakeOut(1);
                        itemslot.MarkDirty();
                    }
                }

                handHandling = EnumHandHandling.PreventDefault;
            }
        }
コード例 #15
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;
            }

            BEWaterWheelSegment beSegment = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BEWaterWheelSegment;
            BlockPos            centerPos = beSegment.WaterWheelHubPos;

            Block          centerBlock = world.BlockAccessor.GetBlock(centerPos);
            BlockSelection bs          = blockSel.Clone();

            bs.Position = centerPos;

            return(centerBlock.OnGettingBroken(player, bs, itemslot, remainingResistance, dt, counter));
        }
コード例 #16
0
        public void OnAttackStart(IServerPlayer byPlayer, BlockSelection blockSel)
        {
            this.fromPlayer = byPlayer;
            if (!CanUseWorldEdit(byPlayer))
            {
                return;
            }

            workspace = GetOrCreateWorkSpace(byPlayer);
            if (!workspace.ToolsEnabled)
            {
                return;
            }
            if (workspace.ToolInstance == null)
            {
                return;
            }

            workspace.ToolInstance.OnAttackStart(this, blockSel?.Clone());
        }
コード例 #17
0
        private void OnDidBuildBlock(IServerPlayer byPlayer, int oldblockId, BlockSelection blockSel, ItemStack withItemStack)
        {
            this.fromPlayer = byPlayer;
            if (!CanUseWorldEdit(byPlayer))
            {
                return;
            }

            workspace = GetOrCreateWorkSpace(byPlayer);
            if (!workspace.ToolsEnabled)
            {
                return;
            }
            if (workspace.ToolInstance == null)
            {
                return;
            }

            workspace.ToolInstance.OnBuild(this, oldblockId, blockSel.Clone(), withItemStack);
        }
コード例 #18
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.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));
        }
コード例 #19
0
        public override bool CanPlaceBlock(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref string failureCode)
        {
            if (!base.CanPlaceBlock(world, byPlayer, blockSel, ref failureCode))
            {
                return(false);
            }

            BlockSelection bs = blockSel.Clone();

            bs.Position = blockSel.Position.UpCopy();
            if (!base.CanPlaceBlock(world, byPlayer, bs, ref failureCode))
            {
                return(false);
            }
            bs.Position = blockSel.Position.UpCopy(2);
            if (!base.CanPlaceBlock(world, byPlayer, bs, ref failureCode))
            {
                return(false);
            }

            return(true);
        }
コード例 #20
0
        public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (blockSel == null || byEntity.World == null || byEntity.Controls.Sneak)
            {
                base.OnHeldInteractStart(itemslot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);
                return;
            }

            bool waterBlock = byEntity.World.BlockAccessor.GetBlock(blockSel.Position.AddCopy(blockSel.Face)).LiquidCode == "water";

            Block block = byEntity.World.GetBlock(new AssetLocation(waterBlock ? "giantreed-arundo-water-harvested" : "giantreed-arundo-free-harvested"));

            if (block == null)
            {
                base.OnHeldInteractStart(itemslot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);
                return;
            }

            IPlayer byPlayer = null;

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

            blockSel = blockSel.Clone();
            blockSel.Position.Add(blockSel.Face);
            string f = "";

            bool ok = block.TryPlaceBlock(byEntity.World, byPlayer, itemslot.Itemstack, blockSel, ref f);

            if (ok)
            {
                itemslot.TakeOut(1);
                itemslot.MarkDirty();
                handHandling = EnumHandHandling.PreventDefaultAction;
            }
        }
コード例 #21
0
        public override bool CanPlaceBlock(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref string failureCode)
        {
            if (!base.CanPlaceBlock(world, byPlayer, blockSel, ref failureCode))
            {
                return(false);
            }

            BlockPos pos = blockSel.Position;

            // All surrounding paddle blocks must be placeable in order for the whole wheel to be placed
            foreach (BlockPos paddlePos in Watermills.GetPaddlePositions(pos, blockSel.Face.IsAxisNS))
            {
                BlockSelection paddleSelection = blockSel.Clone();
                paddleSelection.Position = paddlePos;

                if (!base.CanPlaceBlock(world, byPlayer, paddleSelection, ref failureCode))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #22
0
ファイル: Waterwheel.cs プロジェクト: Niker323/VS-mods
    private bool CanPlaceThisBlock(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref string failureCode)
    {
        if (!base.CanPlaceBlock(world, byPlayer, blockSel, ref failureCode))
        {
            return(false);
        }
        BlockPos pos = blockSel.Position;

        BlockPos       tmpPos = new BlockPos();
        BlockSelection bs     = blockSel.Clone();

        for (int d1 = -1; d1 <= 1; d1++)
        {
            for (int d2 = -1; d2 <= 1; d2++)
            {
                if (d1 == 0 && d2 == 0)
                {
                    continue;
                }
                if (powerOutFacing == BlockFacing.EAST || powerOutFacing == BlockFacing.WEST)
                {
                    tmpPos.Set(pos.X, pos.Y + d1, pos.Z + d2);
                }
                else
                {
                    tmpPos.Set(pos.X + d2, pos.Y + d1, pos.Z);
                }
                bs.Position = tmpPos;
                if (!base.CanPlaceBlock(world, byPlayer, bs, ref failureCode))
                {
                    return(false);
                }
            }
        }

        return(true);
    }
コード例 #23
0
        public override void OnHeldInteractStart(IItemSlot itemslot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handHandling)
        {
            if (blockSel == null || byEntity?.World == null || !byEntity.Controls.Sneak)
            {
                base.OnHeldInteractStart(itemslot, byEntity, blockSel, entitySel, ref handHandling);
                return;
            }

            bool waterBlock = byEntity.World.BlockAccessor.GetBlock(blockSel.Position.AddCopy(blockSel.Face)).IsWater();

            Block block = byEntity.World.GetBlock(new AssetLocation(waterBlock ? "tallplant-coopersreed-water-harvested" : "tallplant-coopersreed-free-harvested"));

            if (block == null)
            {
                base.OnHeldInteractStart(itemslot, byEntity, blockSel, entitySel, ref handHandling);
                return;
            }

            IPlayer byPlayer = null;

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

            blockSel = blockSel.Clone();
            blockSel.Position.Add(blockSel.Face);

            bool ok = block.TryPlaceBlock(byEntity.World, byPlayer, itemslot.Itemstack, blockSel);

            if (ok)
            {
                itemslot.TakeOut(1);
                itemslot.MarkDirty();
                handHandling = EnumHandHandling.PreventDefaultAction;
            }
        }
コード例 #24
0
        public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling)
        {
            IPlayer byPlayer = null;

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


            if (byEntity.Controls.Sneak && blockSel != null)
            {
                IWorldAccessor world         = byEntity.World;
                Block          knappingBlock = world.GetBlock(new AssetLocation("knappingsurface"));
                if (knappingBlock == null)
                {
                    return;
                }

                Block block = world.BlockAccessor.GetBlock(blockSel.Position);
                if (!block.CanAttachBlockAt(byEntity.World.BlockAccessor, knappingBlock, blockSel.Position, BlockFacing.UP))
                {
                    return;
                }

                BlockPos pos = blockSel.Position.AddCopy(blockSel.Face);
                if (!world.BlockAccessor.GetBlock(pos).IsReplacableBy(knappingBlock))
                {
                    return;
                }

                BlockSelection placeSel = blockSel.Clone();
                placeSel.Position  = pos;
                placeSel.DidOffset = true;
                if (!knappingBlock.TryPlaceBlock(world, byPlayer, slot.Itemstack, placeSel))
                {
                    return;
                }

                if (knappingBlock.Sounds != null)
                {
                    world.PlaySoundAt(knappingBlock.Sounds.Place, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z);
                }

                BlockEntityKnappingSurface bec = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityKnappingSurface;
                if (bec != null)
                {
                    bec.BaseMaterial           = slot.Itemstack.Clone();
                    bec.BaseMaterial.StackSize = 1;

                    if (byEntity.World is IClientWorldAccessor)
                    {
                        bec.OpenDialog(world as IClientWorldAccessor, pos, slot.Itemstack);
                    }
                }

                slot.TakeOut(1);

                handling = EnumHandHandling.PreventDefaultAction;
                return;
            }

            base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, ref handling);
        }
コード例 #25
0
        public override void OnBlockInteractStop(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handled)
        {
            handled = EnumHandling.PreventDefault;
            base.OnBlockInteractStop(secondsUsed, world, byPlayer, blockSel, ref handled);
            if (createBlocks == null)
            {
                world.Logger.Notification("CreateBlocks error in " + block.Code.ToString());
                return;
            }
            var      active = byPlayer?.InventoryManager;
            BlockPos Pos    = blockSel?.Position;

            if (active?.ActiveHotbarSlot?.Itemstack?.Collectible?.Code != null && Pos != null)
            {
                foreach (var val in createBlocks)
                {
                    //if (Api.Side.IsClient()) Api.ModLoader.GetModSystem<ShaderTest>().progressBar = 0;

                    if (secondsUsed > val.MakeTime && active.ActiveHotbarSlot.Itemstack.Collectible.WildCardMatch(val.Takes.Code) && active.ActiveHotbarSlot.StackSize >= val.Takes.StackSize)
                    {
                        if (world.Side.IsServer())
                        {
                            world.PlaySoundAt(block.Sounds.Place, Pos.X, Pos.Y, Pos.Z);
                            if (active?.ActiveHotbarSlot?.Itemstack?.Item?.Tool != null)
                            {
                                active.ActiveHotbarSlot.Itemstack.Collectible.DamageItem(world, byPlayer.Entity, active.ActiveHotbarSlot);
                            }
                        }

                        if (val.IntoInv)
                        {
                            if (!active.TryGiveItemstack(val.Makes))
                            {
                                world.SpawnItemEntity(val.Makes, Pos.MidPoint(), new Vec3d(0.0, 0.1, 0.0));
                            }
                        }
                        else
                        {
                            world.SpawnItemEntity(val.Makes, Pos.MidPoint(), new Vec3d(0.0, 0.1, 0.0));
                        }
                        active.ActiveHotbarSlot.TakeOut(val.Takes.StackSize);

                        try
                        {
                            if (world.Side.IsClient())
                            {
                                world.SpawnCubeParticles(Pos.MidPoint(), active.ActiveHotbarSlot.Itemstack, 2, 16);
                            }
                        }
                        catch (Exception)
                        {
                            world.Logger.Error("Could not create particles, missing itemstack?");
                        }

                        active.ActiveHotbarSlot.MarkDirty();

                        if (val.RemoveOnFinish)
                        {
                            world.BlockAccessor.SetBlock(0, Pos);
                        }
                        handled = EnumHandling.PreventDefault;
                        return;
                    }
                }
            }

            ItemStack stack = byPlayer?.InventoryManager?.ActiveHotbarSlot?.Itemstack;

            if (stack != null && allowPlaceOn)
            {
                string         r      = "";
                BlockSelection newsel = blockSel.Clone();
                newsel.Position = blockSel.Position.Offset(blockSel.Face);
                Block block = stack.Block;

                if (block != null && block.TryPlaceBlock(world, byPlayer, stack, newsel, ref r))
                {
                    world.PlaySoundAt(stack.Block?.Sounds.Place, newsel.Position);
                }
            }
        }
コード例 #26
0
ファイル: ItemStone.cs プロジェクト: curquhart/vssurvivalmod
        public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling)
        {
            if (blockSel != null && byEntity.World.BlockAccessor.GetBlock(blockSel.Position) is BlockDisplayCase)
            {
                handling = EnumHandHandling.NotHandled;
                return;
            }

            bool knappable          = itemslot.Itemstack.Collectible.Attributes != null && itemslot.Itemstack.Collectible.Attributes["knappable"].AsBool(false);
            bool haveKnappableStone = false;

            IPlayer byPlayer = (byEntity as EntityPlayer)?.Player;

            if (byEntity.Controls.Sneak && blockSel != null)
            {
                Block block = byEntity.World.BlockAccessor.GetBlock(blockSel.Position);
                haveKnappableStone =
                    block.Code.Path.StartsWith("loosestones") &&
                    block.FirstCodePart(1).Equals(itemslot.Itemstack.Collectible.FirstCodePart(1))
                ;
            }

            if (haveKnappableStone)
            {
                if (!knappable)
                {
                    if (byEntity.World.Side == EnumAppSide.Client)
                    {
                        (this.api as ICoreClientAPI).TriggerIngameError(this, "toosoft", Lang.Get("This type of stone is too soft to be used for knapping."));
                    }
                    return;
                }

                if (!byEntity.World.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.Use))
                {
                    itemslot.MarkDirty();
                    return;
                }

                IWorldAccessor world         = byEntity.World;
                Block          knappingBlock = world.GetBlock(new AssetLocation("knappingsurface"));
                if (knappingBlock == null)
                {
                    return;
                }

                string failCode = "";

                BlockPos pos = blockSel.Position;
                knappingBlock.CanPlaceBlock(world, byPlayer, blockSel, ref failCode);

                if (failCode == "entityintersecting")
                {
                    bool selfBlocked   = false;
                    bool entityBlocked = world.GetIntersectingEntities(pos, knappingBlock.GetCollisionBoxes(world.BlockAccessor, pos), e => { selfBlocked = e == byEntity; return(!(e is EntityItem)); }).Length != 0;

                    string err =
                        entityBlocked ?
                        (selfBlocked ? Lang.Get("Cannot place a knapping surface here, too close to you") : Lang.Get("Cannot place a knapping surface here, to close to another player or creature.")) :
                        Lang.Get("Cannot place a knapping surface here")
                    ;

                    (api as ICoreClientAPI).TriggerIngameError(this, "cantplace", err);

                    return;
                }

                world.BlockAccessor.SetBlock(knappingBlock.BlockId, pos);
                world.BlockAccessor.TriggerNeighbourBlockUpdate(blockSel.Position);

                if (knappingBlock.Sounds != null)
                {
                    world.PlaySoundAt(knappingBlock.Sounds.Place, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z);
                }

                BlockEntityKnappingSurface bec = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityKnappingSurface;
                if (bec != null)
                {
                    bec.BaseMaterial           = itemslot.Itemstack.Clone();
                    bec.BaseMaterial.StackSize = 1;

                    if (byEntity.World is IClientWorldAccessor)
                    {
                        bec.OpenDialog(world as IClientWorldAccessor, pos, itemslot.Itemstack);
                    }
                }
                //itemslot.Take(1);

                handling = EnumHandHandling.PreventDefault;
                byEntity.Attributes.SetInt("aimingCancel", 1);
                return;
            }

            if (blockSel != null && byEntity?.World != null && byEntity.Controls.Sneak)
            {
                IWorldAccessor world = byEntity.World;
                Block          block = world.GetBlock(CodeWithPath("loosestones-" + LastCodePart() + "-free"));
                if (block == null)
                {
                    block = world.GetBlock(CodeWithPath("loosestones-" + LastCodePart(1) + "-" + LastCodePart(0) + "-free"));
                }
                if (block == null)
                {
                    return;
                }

                if (!world.BlockAccessor.GetBlock(blockSel.Position).SideSolid[BlockFacing.UP.Index])
                {
                    return;
                }

                BlockPos       targetpos = blockSel.Position.AddCopy(blockSel.Face);
                BlockSelection placeSel  = blockSel.Clone();
                placeSel.Position  = targetpos;
                placeSel.DidOffset = true;
                string error = "";

                if (!block.TryPlaceBlock(world, byPlayer, itemslot.Itemstack, placeSel, ref error))
                {
                    if (api.Side == EnumAppSide.Client)
                    {
                        (api as ICoreClientAPI).TriggerIngameError(this, "cantplace", Lang.Get("placefailure-" + error));
                    }
                    return;
                }

                world.BlockAccessor.TriggerNeighbourBlockUpdate(blockSel.Position);

                if (block.Sounds != null)
                {
                    world.PlaySoundAt(block.Sounds.Place, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z);
                }

                itemslot.Itemstack.StackSize--;

                handling = EnumHandHandling.PreventDefault;
                byEntity.Attributes.SetInt("aimingCancel", 1);
                return;
            }

            if (byEntity.Controls.Sneak)
            {
                return;
            }


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

            handling = EnumHandHandling.PreventDefault;
        }
コード例 #27
0
        public override void OnBlockInteractStop(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling)
        {
            BlockPos pos = blockSel?.Position;

            if (pos == null)
            {
                return;
            }

            ModSystemBlockReinforcement bR = api.ModLoader.GetModSystem <ModSystemBlockReinforcement>();

            if (disabled || bR.IsReinforced(pos) || bR.IsLocked(pos, byPlayer))
            {
                return;
            }

            SwapSystem swapSystem = api.ModLoader.GetModSystem <SwapSystem>();

            handling = EnumHandling.PreventDefault;
            ItemSlot slot = byPlayer.InventoryManager.ActiveHotbarSlot;


            if (!(requireSneak && !byPlayer.Entity.Controls.Sneak) && slot.Itemstack != null)
            {
                string key = GetKey(slot.Itemstack.Collectible.Code.ToString());

                if (swapSystem.SwapPairs.TryGetValue(key, out SwapBlocks swap))
                {
                    if (world.Side.IsClient())
                    {
                        api.ModLoader.GetModSystem <ShaderTest>().progressBar = 0;
                    }

                    if (swap.Takes != null && swap.Takes != block.Code.ToString() || secondsUsed < swap.MakeTime)
                    {
                        return;
                    }

                    AssetLocation asset = slot.Itemstack.Collectible.Code;
                    if (asset.ToString() == swap.Tool)
                    {
                        AssetLocation toAsset = new AssetLocation(swap.Makes.WithDomain());
                        Block         toBlock = toAsset.GetBlock(world.Api);

                        int count = swap.Count;

                        if (count != 0)
                        {
                            if (count < 0)
                            {
                                ItemStack withCount = slot.Itemstack.Clone();
                                withCount.StackSize = Math.Abs(count);
                                if (!byPlayer.InventoryManager.TryGiveItemstack(withCount))
                                {
                                    world.SpawnItemEntity(withCount, pos.ToVec3d().Add(0.5, 0.5, 0.5));
                                }
                            }
                            else if (slot.Itemstack.StackSize >= count)
                            {
                                if (byPlayer.WorldData.CurrentGameMode.IsSurvival())
                                {
                                    slot.TakeOut(count);
                                }
                            }
                            else
                            {
                                return;
                            }
                        }

                        if ((block.EntityClass != null && toBlock.EntityClass != null) && (toBlock.EntityClass == block.EntityClass))
                        {
                            world.BlockAccessor.ExchangeBlock(toBlock.BlockId, pos);
                        }
                        else
                        {
                            world.BlockAccessor.SetBlock(toBlock.BlockId, pos);
                        }
                        slot.MarkDirty();
                        PlaySoundDispenseParticles(world, pos, slot);
                        return;
                    }
                }
            }

            ItemStack stack = byPlayer?.InventoryManager?.ActiveHotbarSlot?.Itemstack;

            if (stack != null && allowPlaceOn)
            {
                string         r      = "";
                BlockSelection newsel = blockSel.Clone();
                newsel.Position = newsel.Position.Offset(blockSel.Face);
                Block block = stack.Block;

                if (block != null && block.TryPlaceBlock(world, byPlayer, stack, newsel, ref r))
                {
                    world.PlaySoundAt(stack.Block?.Sounds.Place, newsel.Position);
                }
            }
        }
コード例 #28
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling)
        {
            IPlayer byPlayer = null;

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


            if (byEntity.Controls.Sneak && blockSel != null)
            {
                IWorldAccessor world         = byEntity.World;
                Block          knappingBlock = world.GetBlock(new AssetLocation("knappingsurface"));
                if (knappingBlock == null)
                {
                    return;
                }

                Block block = world.BlockAccessor.GetBlock(blockSel.Position);
                if (!block.CanAttachBlockAt(byEntity.World.BlockAccessor, knappingBlock, blockSel.Position, BlockFacing.UP))
                {
                    if (api.Side == EnumAppSide.Client)
                    {
                        (api as ICoreClientAPI).TriggerIngameError(this, "cantplace", Lang.Get("Cannot place a knapping surface here"));
                    }
                    return;
                }

                BlockPos pos = blockSel.Position.AddCopy(blockSel.Face);
                if (!world.BlockAccessor.GetBlock(pos).IsReplacableBy(knappingBlock))
                {
                    return;
                }

                BlockSelection placeSel = blockSel.Clone();
                placeSel.Position  = pos;
                placeSel.DidOffset = true;
                string useless = "";

                if (!knappingBlock.TryPlaceBlock(world, byPlayer, slot.Itemstack, placeSel, ref useless))
                {
                    if (api.Side == EnumAppSide.Client)
                    {
                        bool selfBlocked   = false;
                        bool entityBlocked = world.GetIntersectingEntities(pos, knappingBlock.GetCollisionBoxes(world.BlockAccessor, pos), e => { selfBlocked = e == byEntity; return(!(e is EntityItem)); }).Length != 0;

                        string err =
                            entityBlocked ?
                            (selfBlocked ? Lang.Get("Cannot place a knapping surface here, too close to you") : Lang.Get("Cannot place a knapping surface here, to close to another player or creature.")) :
                            Lang.Get("Cannot place a knapping surface here")
                        ;

                        (api as ICoreClientAPI).TriggerIngameError(this, "cantplace", err);
                    }

                    return;
                }

                world.BlockAccessor.TriggerNeighbourBlockUpdate(pos);

                if (knappingBlock.Sounds != null)
                {
                    world.PlaySoundAt(knappingBlock.Sounds.Place, pos.X, pos.Y, pos.Z);
                }

                BlockEntityKnappingSurface bec = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityKnappingSurface;
                if (bec != null)
                {
                    bec.BaseMaterial           = slot.Itemstack.Clone();
                    bec.BaseMaterial.StackSize = 1;

                    if (byEntity.World is IClientWorldAccessor)
                    {
                        bec.OpenDialog(world as IClientWorldAccessor, pos, slot.Itemstack);
                    }
                }

                slot.TakeOut(1);

                handling = EnumHandHandling.PreventDefaultAction;
                return;
            }

            base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handling);
        }
コード例 #29
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling)
        {
            IPlayer byPlayer = null;

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


            if (byEntity.Controls.Sneak && blockSel != null)
            {
                IWorldAccessor world         = byEntity.World;
                Block          knappingBlock = world.GetBlock(new AssetLocation("knappingsurface"));
                if (knappingBlock == null)
                {
                    return;
                }

                //world.Logger.Debug("Flint interact start: Test attach");

                Block block = world.BlockAccessor.GetBlock(blockSel.Position);
                if (!block.CanAttachBlockAt(byEntity.World.BlockAccessor, knappingBlock, blockSel.Position, BlockFacing.UP))
                {
                    if (api.Side == EnumAppSide.Client)
                    {
                        (api as ICoreClientAPI).TriggerIngameError(this, "cantplace", Lang.Get("Cannot place a knapping surface here"));
                    }
                    return;
                }

                //world.Logger.Debug("Flint interact start: Can place");

                BlockPos pos = blockSel.Position.AddCopy(blockSel.Face);
                if (!world.BlockAccessor.GetBlock(pos).IsReplacableBy(knappingBlock))
                {
                    return;
                }

                BlockSelection placeSel = blockSel.Clone();
                placeSel.Position  = pos;
                placeSel.DidOffset = true;
                string error = "";

                //world.Logger.Debug("Flint interact start: Try place");

                if (!knappingBlock.TryPlaceBlock(world, byPlayer, slot.Itemstack, placeSel, ref error))
                {
                    (api as ICoreClientAPI)?.TriggerIngameError(this, "cantplace", error);
                    return;
                }

                world.BlockAccessor.TriggerNeighbourBlockUpdate(pos);

                if (knappingBlock.Sounds != null)
                {
                    world.PlaySoundAt(knappingBlock.Sounds.Place, pos.X, pos.Y, pos.Z);
                }

                //world.Logger.Debug("Flint interact start: Could place");

                BlockEntityKnappingSurface bec = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityKnappingSurface;
                if (bec != null)
                {
                    bec.BaseMaterial           = slot.Itemstack.Clone();
                    bec.BaseMaterial.StackSize = 1;

                    if (byEntity.World is IClientWorldAccessor)
                    {
                        bec.OpenDialog(world as IClientWorldAccessor, pos, slot.Itemstack);
                    }
                }

                //world.Logger.Debug("Flint interact start: Dlg opened");

                slot.TakeOut(1);

                handling = EnumHandHandling.PreventDefaultAction;
                return;
            }

            base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handling);
        }
コード例 #30
0
        public override void OnHeldInteractStart(IItemSlot itemslot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling)
        {
            bool knappable          = itemslot.Itemstack.Collectible.Attributes != null && itemslot.Itemstack.Collectible.Attributes["knappable"].AsBool(false);
            bool haveKnappableStone = false;

            IPlayer byPlayer = (byEntity as EntityPlayer)?.Player;

            if (knappable && byEntity.Controls.Sneak && blockSel != null)
            {
                Block block = byEntity.World.BlockAccessor.GetBlock(blockSel.Position);
                haveKnappableStone =
                    block.Code.Path.StartsWith("loosestones") &&
                    block.FirstCodePart(1).Equals(itemslot.Itemstack.Collectible.FirstCodePart(1))
                ;
            }

            if (haveKnappableStone)
            {
                if (!byEntity.World.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.Use))
                {
                    itemslot.MarkDirty();
                    return;
                }

                IWorldAccessor world         = byEntity.World;
                Block          knappingBlock = world.GetBlock(new AssetLocation("knappingsurface"));
                if (knappingBlock == null)
                {
                    return;
                }

                BlockPos pos = blockSel.Position;
                if (!knappingBlock.IsSuitablePosition(world, pos))
                {
                    return;
                }

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

                if (knappingBlock.Sounds != null)
                {
                    world.PlaySoundAt(knappingBlock.Sounds.Place, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z);
                }

                BlockEntityKnappingSurface bec = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityKnappingSurface;
                if (bec != null)
                {
                    bec.BaseMaterial           = itemslot.Itemstack.Clone();
                    bec.BaseMaterial.StackSize = 1;

                    if (byEntity.World is IClientWorldAccessor)
                    {
                        bec.OpenDialog(world as IClientWorldAccessor, pos, itemslot.Itemstack);
                    }
                }
                //itemslot.Take(1);

                handling = EnumHandHandling.PreventDefault;
                byEntity.Attributes.SetInt("aimingCancel", 1);
                return;
            }

            if (blockSel != null && byEntity?.World != null && byEntity.Controls.Sneak)
            {
                IWorldAccessor world = byEntity.World;
                Block          block = world.GetBlock(CodeWithPath("loosestones-" + LastCodePart()));
                if (block == null)
                {
                    return;
                }
                if (!world.BlockAccessor.GetBlock(blockSel.Position).SideSolid[BlockFacing.UP.Index])
                {
                    return;
                }

                BlockPos       targetpos = blockSel.Position.AddCopy(blockSel.Face);
                BlockSelection placeSel  = blockSel.Clone();
                placeSel.Position  = targetpos;
                placeSel.DidOffset = true;
                if (!block.TryPlaceBlock(world, byPlayer, itemslot.Itemstack, placeSel))
                {
                    return;
                }

                if (block.Sounds != null)
                {
                    world.PlaySoundAt(block.Sounds.Place, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z);
                }

                itemslot.Itemstack.StackSize--;

                handling = EnumHandHandling.PreventDefault;
                byEntity.Attributes.SetInt("aimingCancel", 1);
                return;
            }

            if (byEntity.Controls.Sneak)
            {
                return;
            }


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

            handling = EnumHandHandling.PreventDefault;
        }