예제 #1
0
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates)
        {
            base.UseItem(world, player, blockCoordinates);
            PlayerInteractEventArgs interactEvent = new PlayerInteractEventArgs((EPlayer)player, player.Inventory.GetItemInHand(), blockCoordinates, (BlockFace)0);

            if (interactEvent.OnCallEvent())
            {
                base.UseItem(world, player, blockCoordinates);
            }
        }
예제 #2
0
        private void OnPlayerInteract(object sender, PlayerInteractEventArgs args)
        {
            Player player = args.Player;

            if (player.Inventory.MainHandItem.Item.ID != ItemIDs.WOODEN_AXE)
            {
                return;
            }

            args.IsCancel = true;

            Block        block = args.Target;
            Vector3      pos   = block.ToVector3();
            PositionData data  = WorldEdit.Instance.PositionManager.getPositionData(player.Name);

            data.FirstPosition = pos;

            player.SendMessage($"§b1つ目の位置 | x {pos.FloorX} | y {pos.FloorY} | z {pos.FloorZ} | 範囲 {data.GetRange()}");
            player.SendMessage($"§bブロック名 {block.Name} | ブロックID {block.ID}:{block.Damage}");
        }
예제 #3
0
        public void UseItem(Vector3 pos, Item item, BlockFace blockFace, Vector3 clickPos, Player player)
        {
            Block clicked = this.GetBlock(pos);
            Block replace = clicked.GetSideBlock(blockFace);

            if (clicked.Y > 255 || clicked.Y < 0 || clicked.ID == BlockFactory.AIR)
            {
                return;
            }

            PlayerInteractEventArgs playerInteractEvent = new PlayerInteractEventArgs(player, item, clicked, blockFace);

            if (player.IsAdventure)
            {
                playerInteractEvent.IsCancel = true;
            }

            if (Server.ServerConfig.SpawnProtection > 0 || player.Op)
            {
                //TODO
            }

            PlayerEvents.OnPlayerInteract(playerInteractEvent);
            if (playerInteractEvent.IsCancel)
            {
                return;
            }

            clicked.Update(World.BLOCK_UPDATE_TOUCH);
            if (!player.Sneaking && clicked.CanBeActivated && clicked.Activate(player, item))
            {
                return;
            }

            if (!player.Sneaking && item.CanBeActivate && item.Activate(player, this, clicked, blockFace, clickPos))
            {
                if (item.Count <= 0)
                {
                    return;
                }
            }

            if (!item.CanBePlace)
            {
                return;
            }
            Block hand = item.Block;

            hand.Position = replace.Position;

            if (clicked.CanBeReplaced)
            {
                replace       = clicked;
                hand.Position = replace.Position;
            }

            //TODO : near by entity check

            //TODO : check can place on

            BlockPlaceEventArgs blockPlaceEvent = new BlockPlaceEventArgs(player, hand, replace, clicked, item);

            //TODO : check spawn protection

            BlockEvents.OnBlockPlace(blockPlaceEvent);
            if (blockPlaceEvent.IsCancel)
            {
                return;
            }
            hand.Place(clicked, replace, blockFace, clickPos, player, item);

            LevelSoundEventPacket pk = new LevelSoundEventPacket();

            pk.Position  = (Vector3)hand.Position;
            pk.Sound     = LevelSoundEventPacket.SOUND_PLACE;
            pk.ExtraData = hand.RuntimeId;
            pk.Pitch     = 1;
            player.SendPacket(pk); //TODO : near players
        }
예제 #4
0
    private async Task OnPlayerInteract(PlayerInteractEventArgs e)
    {
        var item = e.Item;

        var block  = e.Block;
        var server = e.Server as Server;
        var player = e.Player as Player;

        if (e.Cancel)
        {
            return;
        }

        if (block.HasValue)
        {
            if (e.BlockLocation is not Vector blockPosition)
            {
                return;
            }
            var interactedBlock = block.Value;

            player.LastClickedBlock = interactedBlock;

            var type = interactedBlock.Material;

            BaseContainer?container = type switch
            {
                Material.Anvil or Material.SmithingTable => new AnvilContainer(type.ToString().ToSnakeCase())
                {
                    Title = type == Material.Anvil ? "Anvil" : "Smithing Table"
                },
                Material.EnchantingTable => new EnchantmentTable
                {
                    BlockPosition = blockPosition
                },
                Material.Dropper or Material.Dispenser => new Container(9)
                {
                    Owner         = player.Uuid,
                    Title         = type.ToString(),
                    BlockPosition = blockPosition,
                    Id            = type is Material.Dropper ? "dropper" : "dispenser"
                },
                Material.BrewingStand => new BrewingStand
                {
                    BlockPosition = blockPosition
                },
                Material.Hopper => new Container(5)
                {
                    BlockPosition = blockPosition
                },
                Material.CraftingTable => new CraftingTable(),
                Material.Loom => new Loom(),
                Material.CartographyTable => new CartographyTable(),
                Material.Stonecutter => new Stonecutter(),
                Material.Grindstone => new Grindstone(),

                _ => null
            };
            //TODO check if container is cached if so get that container
            if (type == Material.Chest) // TODO check if chest its next to another single chest
            {
                container = new Container
                {
                    Owner         = player.Uuid,
                    Title         = "Chest",
                    BlockPosition = blockPosition,
                    Id            = "chest"
                };

                await player.OpenInventoryAsync(container);

                await player.client.QueuePacketAsync(new BlockAction
                {
                    Position    = blockPosition,
                    ActionId    = 1,
                    ActionParam = 1,
                    BlockType   = interactedBlock.Id
                });

                await player.SendSoundAsync(Sounds.BlockChestOpen, blockPosition.SoundPosition, SoundCategory.Blocks);
            }
            else if (type == Material.EnderChest)
            {
                container = new Container
                {
                    Owner = player.Uuid,
                    Title = "Ender Chest",
                    Id    = type.ToString().ToSnakeCase()
                };

                await player.OpenInventoryAsync(container);

                await player.client.QueuePacketAsync(new BlockAction
                {
                    Position    = blockPosition,
                    ActionId    = 1,
                    ActionParam = 1,
                    BlockType   = interactedBlock.Id
                });

                await player.SendSoundAsync(Sounds.BlockEnderChestOpen, blockPosition.SoundPosition, SoundCategory.Blocks);
            }
            else if (type == Material.Furnace || type == Material.BlastFurnace || type == Material.Smoker)
            {
                InventoryType actualType = type switch
                {
                    Material.Furnace => InventoryType.Furnace,
                    Material.BlastFurnace => InventoryType.BlastFurnace,
                    Material.Smoker => InventoryType.Smoker,
                    _ => InventoryType.Furnace
                };

                container = new SmeltingContainer(actualType, actualType.ToString().ToSnakeCase())
                {
                    BlockPosition = blockPosition,
                    Title         = actualType.ToString()
                };
            }
            else if (type >= Material.ShulkerBox && type <= Material.BlackShulkerBox)
            {
                container = new Container // TODO shulker box functionality
                {
                    Owner         = player.Uuid,
                    Title         = "Shulker Box",
                    BlockPosition = blockPosition,
                    Id            = "shulker_box"
                };

                await player.client.QueuePacketAsync(new BlockAction
                {
                    Position    = blockPosition,
                    ActionId    = 1,
                    ActionParam = 1,
                    BlockType   = interactedBlock.Id
                });

                await player.SendSoundAsync(Sounds.BlockShulkerBoxOpen, blockPosition.SoundPosition, SoundCategory.Blocks);
            }
            else if (type == Material.Barrel)
            {
                container = new Container
                {
                    //Owner = player.Uuid,
                    Title         = "Barrel",
                    BlockPosition = blockPosition,
                    Id            = "Barrel"
                };
                await player.SendSoundAsync(Sounds.BlockBarrelOpen, blockPosition.SoundPosition, SoundCategory.Blocks);
            }
            else if (type == Material.Lectern)
            {
                //TODO open lectern??
            }

            if (container is IBlockEntity)
            {
                var tileEntity = await player.World.GetBlockEntityAsync(blockPosition);

                if (tileEntity == null)
                {
                    tileEntity = new NbtCompound()
                    {
                        new NbtTag <string>("id", (container as IBlockEntity).Id),

                        new NbtTag <int>("x", blockPosition.X),
                        new NbtTag <int>("y", blockPosition.Y),
                        new NbtTag <int>("z", blockPosition.Z),

                        new NbtTag <string>("CustomName", container.Title.ToJson())
                    };

                    player.World.SetBlockEntity(blockPosition, tileEntity);
                }
                else if (tileEntity is NbtCompound dataCompound)
                {
                    if (dataCompound.TryGetTag("Items", out var tag))
                    {
                        var items = tag as NbtList;

                        foreach (NbtCompound i in items)
                        {
                            var inventoryItem = i.ItemFromNbt();

                            container.SetItem(inventoryItem.Slot, inventoryItem);
                        }
                    }
                }
            }

            await player.OpenInventoryAsync(container);
        }
        else
        {
            //TODO check for other
        }
    }
 public static void OnPlayerInteract(PlayerInteractEventArgs args)
 {
     PlayerInteract?.Invoke(args);
 }
예제 #6
0
    internal async ValueTask <PlayerInteractEventArgs> InvokePlayerInteractAsync(PlayerInteractEventArgs eventArgs)
    {
        await PlayerInteract.InvokeAsync(eventArgs);

        return(eventArgs);
    }
예제 #7
0
 public void PlayerInteract(object sender, PlayerInteractEventArgs e)
 {
 }
예제 #8
0
        public void UseItem(Vector3 pos, Item item, BlockFace blockFace, Vector3 clickPos, Player player)
        {
            Block clicked = this.GetBlock(pos);
            Block replace = clicked.GetSideBlock(blockFace);

            if (clicked.Y > 255 || clicked.Y < 0 || clicked.ID == BlockIDs.AIR)
            {
                return;
            }

            PlayerInteractEventArgs args = new PlayerInteractEventArgs(player, item, clicked, blockFace);

            if (player.IsAdventure)
            {
                args.IsCancel = true;
            }

            /*if (Server.ServerConfig.SpawnProtection > 0 || player.Op)
             * {
             *  //TODO
             * }*/

            Server.Instance.Event.Player.OnPlayerInteract(this, args);
            if (args.IsCancel)
            {
                return;
            }

            clicked.OnTouchUpdate();
            if (!player.Sneaking && clicked.CanBeActivated && clicked.Activate(player, item))
            {
                return;
            }

            if (!player.Sneaking && item.Activate(player, this, clicked, blockFace, clickPos))
            {
                if (item.Count <= 0)
                {
                    return;
                }
            }

            Block hand = item.Block;

            if (hand.ID == BlockIDs.AIR)
            {
                return;
            }

            hand.Damage = item.Damage;
            hand.SetPosition(replace.GetPosition());

            if (clicked.CanBeReplaced)
            {
                replace = clicked;
                hand.SetPosition(replace.GetPosition());
            }

            //TODO : near by entity check

            //TODO : check can place on

            BlockPlaceEventArgs args1 = new BlockPlaceEventArgs(player, hand, replace, clicked, item);

            //TODO : check spawn protection

            Server.Instance.Event.Block.OnBlockPlace(this, args1);
            if (args1.IsCancel)
            {
                this.SendBlocks(Server.Instance.GetOnlinePlayers(), new Vector3[] { hand.ToVector3() });
                return;
            }

            hand.Place(clicked, replace, blockFace, clickPos, player, item);

            LevelSoundEventPacket pk = new LevelSoundEventPacket
            {
                Position  = hand.ToVector3(),
                Sound     = LevelSoundEventPacket.SOUND_PLACE,
                ExtraData = hand.RuntimeId
            };

            Server.Instance.BroadcastSendPacket(pk); //TODO : near players
        }