Exemple #1
0
        protected override void DoInteraction(IClient client, IItemInventory item)
        {
            base.DoInteraction(client, item);

            if (client != null && item != null && !ItemHelper.IsVoid(item))
            {
                if (item.Type == (short)BlockData.Items.Shears && !Data.Sheared)
                {
                    // Drop Red mushroom when sheared
                    sbyte count = 5;

                    var drop = ItemHelper.GetInstance(BlockData.Blocks.Red_Mushroom);
                    drop.Count = count;
                    Server.DropItem(World, UniversalCoords.FromAbsWorld(Position.X, Position.Y, Position.Z), drop);

                    Data.Sheared = true;

                    SendMetadataUpdate();
                }
                else if (item.Type == (short)BlockData.Items.Bowl)
                {
                    short slot = (short)item.Slot;
                    client.GetOwner().GetInventory().RemoveItem(slot);
                    client.GetOwner().GetInventory().AddItem((short)BlockData.Items.Mushroom_Soup, 1, 0);
                }
                else if (item.Type == (short)BlockData.Items.Bucket)
                {
                    short slot = (short)item.Slot;
                    client.GetOwner().GetInventory().RemoveItem(slot);
                    client.GetOwner().GetInventory().AddItem((short)BlockData.Items.Milk_Bucket, 1, 0);
                }
            }
        }
Exemple #2
0
        protected override void DoInteraction(IClient iClient, IItemInventory item)
        {
            base.DoInteraction(iClient, item);

            Client client = iClient as Client;

            if (client == null)
            {
                return;
            }

            if (item != null && !ItemHelper.IsVoid(item))
            {
                if (item.Type == (short)BlockData.Items.Raw_Fish && !Data.IsTamed)
                {
                    FishUntilTamed--;
                    client.Owner.Inventory.RemoveItem(item.Slot); // consume the item

                    if (FishUntilTamed <= 0)
                    {
                        Data.IsTamed = true;
                        Data.TamedBy = client.Username;
                        Health       = MaxHealth;
                        // TODO: begin following this.Data.TamedBy
                        SendMetadataUpdate();
                    }
                }
            }
        }
Exemple #3
0
        protected override void DoInteraction(IClient client, IItemInventory item)
        {
            base.DoInteraction(client, item);

            if (client != null && item != null && !ItemHelper.IsVoid(item))
            {
                if (item.Type == (short)BlockData.Items.Shears && !Data.Sheared)
                {
                    // Drop wool when sheared
                    sbyte count = (sbyte)Server.Rand.Next(2, 4);

                    if (count > 0)
                    {
                        var drop = ItemHelper.GetInstance(BlockData.Blocks.Wool);
                        drop.Count      = count;
                        drop.Durability = (short)Data.WoolColor;
                        Server.DropItem(World, UniversalCoords.FromAbsWorld(Position.X, Position.Y, Position.Z), drop);
                    }
                    Data.Sheared = true;

                    SendMetadataUpdate();
                }
                else if (item.Type == (short)BlockData.Items.Ink_Sack)
                {
                    // Set the wool colour of this Sheep based on the item.Durability
                    // Safety check. Values of 16 and higher (color do not exist) may crash the client v1.8.1 and below
                    if (item.Durability >= 0 && item.Durability <= 15)
                    {
                        //this.Data.WoolColor = (WoolColor)Enum.ToObject(typeof(WoolColor), (15 - item.Durability));
                        Data.WoolColor = DyeColorToWoolColor((MetaData.Dyes)Enum.ToObject(typeof(MetaData.Dyes), item.Durability));
                        SendMetadataUpdate();
                    }
                }
            }
        }
Exemple #4
0
        protected override void DoInteraction(IClient iClient, IItemInventory item)
        {
            base.DoInteraction(iClient, item);

            Client client = iClient as Client;
            if (client == null)
                return;

            if (item != null && !ItemHelper.IsVoid(item))
            {
                if (item.Type == (short)BlockData.Items.Raw_Fish && !Data.IsTamed)
                {
                    FishUntilTamed--;
                    client.Owner.Inventory.RemoveItem(item.Slot); // consume the item

                    if (FishUntilTamed <= 0)
                    {
                        Data.IsTamed = true;
                        Data.TamedBy = client.Username;
                        Health = MaxHealth;
                        // TODO: begin following this.Data.TamedBy
                        SendMetadataUpdate();
                    }
                }
            }
        }
Exemple #5
0
        protected override void DoInteraction(IClient client, IItemInventory item)
        {
            base.DoInteraction(client, item);

            if (client != null && item != null && !ItemHelper.IsVoid(item))
            {
                if (item.Type == (short)BlockData.Items.Shears && !Data.Sheared)
                {
                    // Drop Red mushroom when sheared
                    sbyte count = 5;

                    var drop = ItemHelper.GetInstance(BlockData.Blocks.Red_Mushroom);
                    drop.Count = count;
                    Server.DropItem(World, UniversalCoords.FromAbsWorld(Position.X, Position.Y, Position.Z), drop);

                    Data.Sheared = true;

                    SendMetadataUpdate();
                }
                else if (item.Type == (short)BlockData.Items.Bowl)
                {
                    short slot = (short)item.Slot;
                    client.GetOwner().GetInventory().RemoveItem(slot);
                    client.GetOwner().GetInventory().AddItem((short)BlockData.Items.Mushroom_Soup, 1, 0);
                }
                else if (item.Type == (short)BlockData.Items.Bucket)
                {
                    short slot = (short)item.Slot;
                    client.GetOwner().GetInventory().RemoveItem(slot);
                    client.GetOwner().GetInventory().AddItem((short)BlockData.Items.Milk_Bucket, 1, 0);
                }
            }
        }
Exemple #6
0
 public bool AddItem(IItemInventory item)
 {
     for (int i = 0; i < cells.Length; i++)
     {
         if (cells[i].isFree)
         {
             cells[i] = CreateOccupiedCell(item);
             return(true);
         }
     }
     return(false);
 }
Exemple #7
0
        protected override void DoInteraction(IClient iClient, IItemInventory item)
        {
            base.DoInteraction(iClient, item);

            Client client = iClient as Client;

            if (client == null)
            {
                return;
            }

            if (item != null && !ItemHelper.IsVoid(item))
            {
                if (item is ItemRawPorkchop || item is ItemCookedPorkchop)
                {
                    client.Owner.Inventory.RemoveItem(item.Slot); // consume the item

                    if (Data.IsTamed)
                    {
                        // Feed a tame wolf pork chop
                        if (Health < MaxHealth)
                        {
                            if (Health < MaxHealth)
                            {
                                Health += 3; // Health is clamped, no need to check if exceeds MaxHealth
                                SendMetadataUpdate();
                            }
                        }
                    }
                }
                else if (!Data.IsTamed && item.Type == (short)BlockData.Items.Bone)
                {
                    // Give a bone
                    BonesUntilTamed--;
                    client.Owner.Inventory.RemoveItem(item.Slot); // consume the item

                    if (BonesUntilTamed <= 0)
                    {
                        Data.IsTamed = true;
                        Data.TamedBy = client.Username;
                        Health       = MaxHealth;
                        // TODO: begin following this.Data.TamedBy
                        SendMetadataUpdate();
                    }
                }
            }
        }
Exemple #8
0
 public void SetItem(short slot, IItemInventory newItem)
 {
     this[slot] = newItem as ItemInventory;
 }
Exemple #9
0
 public static bool IsVoid(IItemInventory item)
 {
     return(item == null | (item as ItemInventory).Type == -1 || (item as ItemInventory).Count < 1);
 }
Exemple #10
0
        protected override void DoInteraction(IClient client, IItemInventory item)
        {
            base.DoInteraction(client, item);

            if (client != null && item != null && !ItemHelper.IsVoid(item))
            {
                if (item.Type == (short)BlockData.Items.Shears && !Data.Sheared)
                {
                    // Drop wool when sheared
                    sbyte count = (sbyte)Server.Rand.Next(2, 4);

                    if (count > 0)
                    {
                        var drop = ItemHelper.GetInstance(BlockData.Blocks.Wool);
                        drop.Count = count;
                        drop.Durability = (short)Data.WoolColor;
                        Server.DropItem(World, UniversalCoords.FromAbsWorld(Position.X, Position.Y, Position.Z), drop);
                    }
                    Data.Sheared = true;

                    SendMetadataUpdate();
                }
                else if (item.Type == (short)BlockData.Items.Ink_Sack)
                {
                    // Set the wool colour of this Sheep based on the item.Durability
                    // Safety check. Values of 16 and higher (color do not exist) may crash the client v1.8.1 and below
                    if (item.Durability >= 0 && item.Durability <= 15)
                    {
                        //this.Data.WoolColor = (WoolColor)Enum.ToObject(typeof(WoolColor), (15 - item.Durability));
                        Data.WoolColor = DyeColorToWoolColor((MetaData.Dyes)Enum.ToObject(typeof(MetaData.Dyes), item.Durability));
                        SendMetadataUpdate();
                    }
                }
            }
        }
Exemple #11
0
        /// <summary>
        /// When a player interacts with a mob (right-click) with an item / hand
        /// </summary>
        /// <param name="client">The client that is interacting</param>
        /// <param name="item">The item being used (could be Void e.g. Hand)</param>
        public void InteractWith(IClient client, IItemInventory item)
        {
            // TODO: create a plugin event for this action

            DoInteraction(client, item);
        }
Exemple #12
0
 public Cell(IItemInventory item)
 {
     this.item = item;
 }
Exemple #13
0
 public OccupiedСell(IItemInventory item)
     : base(item)
 {
 }
Exemple #14
0
 protected override void DoInteraction(IClient iClient, IItemInventory item)
 {
     //TODO: Add trading with villagers
 }
Exemple #15
0
        /// <summary>
        /// When a player interacts with a mob (right-click) with an item / hand
        /// </summary>
        /// <param name="client">The client that is interacting</param>
        /// <param name="item">The item being used (could be Void e.g. Hand)</param>
        public void InteractWith(IClient client, IItemInventory item)
        {
            // TODO: create a plugin event for this action

            DoInteraction(client, item);
        }
Exemple #16
0
 protected virtual void DoInteraction(IClient client, IItemInventory item)
 {
 }
Exemple #17
0
 protected override Cell CreateOccupiedCell(IItemInventory item)
 {
     return(new Cells.OccupiedСell(item));
 }
Exemple #18
0
 public static bool IsVoid(IItemInventory item)
 {
     return (item == null | (item as ItemInventory).Type == -1 || (item as ItemInventory).Count < 1);
 }
Exemple #19
0
 /// <summary>
 /// Drops an item based on the given player's position and rotation.
 /// </summary>
 /// <param name="player">The player to be used for position calculations.</param>
 /// <param name="stack">The stack to be dropped.</param>
 /// <returns>The entity ID of the item drop.</returns>
 public int DropItem(IPlayer player, IItemInventory stack)
 {
     //todo - proper drop
     return DropItem(player.GetWorld(), UniversalCoords.FromAbsWorld(player.Position.X + 4, player.Position.Y, player.Position.Z), stack);
 }
Exemple #20
0
 protected abstract Cell CreateOccupiedCell(IItemInventory item);
Exemple #21
0
        protected override void DoInteraction(IClient iClient, IItemInventory item)
        {
            base.DoInteraction(iClient, item);

            Client client = iClient as Client;
            if (client == null)
                return;

            if (item != null && !ItemHelper.IsVoid(item))
            {
                if (item is ItemRawPorkchop || item is ItemCookedPorkchop)
                {
                    client.Owner.Inventory.RemoveItem(item.Slot); // consume the item
                    
                    if (Data.IsTamed)
                    {
                        // Feed a tame wolf pork chop
                        if (Health < MaxHealth)
                        {
                            if (Health < MaxHealth)
                            {
                                Health += 3; // Health is clamped, no need to check if exceeds MaxHealth
                                SendMetadataUpdate();
                            }
                        }
                    }
                }
                else if (!Data.IsTamed && item.Type == (short)BlockData.Items.Bone)
                {
                    // Give a bone
                    BonesUntilTamed--;
                    client.Owner.Inventory.RemoveItem(item.Slot); // consume the item

                    if (BonesUntilTamed <= 0)
                    {
                        Data.IsTamed = true;
                        Data.TamedBy = client.Username;
                        Health = MaxHealth;
                        // TODO: begin following this.Data.TamedBy
                        SendMetadataUpdate();
                    }
                }
            }
        }
Exemple #22
0
 public void SetItem(short slot, IItemInventory newItem)
 {
     this[slot] = newItem as ItemInventory;
 }
Exemple #23
0
 protected override void DoInteraction(IClient iClient, IItemInventory item)
 {
     //TODO: Add trading with villagers
 }
Exemple #24
0
        /// <summary>
        /// Drops an item at the given location.
        /// </summary>
        /// <param name="world">The world in which the coordinates reside.</param>
        /// <param name="coords">The target coordinate</param>
        /// <param name="stack">The stack to be dropped</param>
        /// <param name="velocity">An optional velocity (the velocity will be clamped to -0.4 and 0.4 on each axis)</param>
        /// <returns>The entity ID of the item drop.</returns>
        public int DropItem(IWorldManager world, UniversalCoords coords, IItemInventory stack, Vector3 velocity = new Vector3())
        {
            if (ItemHelper.IsVoid(stack))
                return -1;

            int entityId = AllocateEntity();

            bool sendVelocity = false;
            if (velocity != Vector3.Origin)
            {
                velocity = new Vector3(velocity.X.Clamp(-0.4, 0.4), velocity.Y.Clamp(-0.4, 0.4), velocity.Z.Clamp(-0.4, 0.4));
                sendVelocity = true;
            }

            AddEntity(new ItemEntity(this, entityId)
            {
                World = world as WorldManager,
                Position = new AbsWorldCoords(new Vector3(coords.WorldX + 0.5, coords.WorldY, coords.WorldZ + 0.5)), // Put in the middle of the block (ignoring Y)
                ItemId = stack.Type,
                Count = stack.Count,
                Velocity = velocity,
                Durability = stack.Durability
            });

            if (sendVelocity)
                SendPacketToNearbyPlayers(world as WorldManager, coords, new EntityVelocityPacket { EntityId = entityId, VelocityX = (short)(velocity.X * 8000), VelocityY = (short)(velocity.Y * 8000), VelocityZ = (short)(velocity.Z * 8000) });

            return entityId;
        }
Exemple #25
0
 protected virtual void DoInteraction(IClient client, IItemInventory item)
 {
 }