Esempio n. 1
0
        /// <summary>
        ///   Attempts to get this player to place down its
        ///   <see cref="CarriedBlock"/> (if any) at the specified
        ///   selection, returning whether it was successful.
        /// </summary>
        /// <example cref="ArgumentNullException"> Thrown if player or selection is null. </exception>
        public static bool PlaceCarried(this IPlayer player, BlockSelection selection, CarrySlot slot)
        {
            if (player == null)
            {
                throw new ArgumentNullException(nameof(player));
            }
            if (selection == null)
            {
                throw new ArgumentNullException(nameof(selection));
            }

            if (!player.Entity.World.Claims.TryAccess(
                    player, selection.Position, EnumBlockAccessFlags.BuildOrBreak))
            {
                return(false);
            }
            var carried = CarriedBlock.Get(player.Entity, slot);

            if (carried == null)
            {
                return(false);
            }

            return(carried.PlaceDown(player.Entity.World, selection, player.Entity));
        }
Esempio n. 2
0
        /// <summary>
        ///   Attempts to swap the <see cref="CarriedBlock"/>s currently carried in the
        ///   entity's <paramref name="first"/> and <paramref name="second"/> slots.
        /// </summary>
        /// <example cref="ArgumentNullException"> Thrown if entity is null. </exception>
        public static bool Swap(this Entity entity, CarrySlot first, CarrySlot second)
        {
            if (first == second)
            {
                throw new ArgumentException("Slots can't be the same");
            }

            var carriedFirst  = CarriedBlock.Get(entity, first);
            var carriedSecond = CarriedBlock.Get(entity, second);

            if ((carriedFirst == null) && (carriedSecond == null))
            {
                return(false);
            }

            CarriedBlock.Remove(entity, first);
            CarriedBlock.Remove(entity, second);

            if (carriedFirst != null)
            {
                carriedFirst.Set(entity, second);
            }
            if (carriedSecond != null)
            {
                carriedSecond.Set(entity, first);
            }

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        ///   Attempts to get this entity to pick up the block the
        ///   specified position as a <see cref="CarriedBlock"/>,
        ///   returning whether it was successful.
        /// </summary>
        /// <example cref="ArgumentNullException"> Thrown if entity or pos is null. </exception>
        public static bool Carry(this Entity entity, BlockPos pos,
                                 CarrySlot slot, bool checkIsCarryable = true)
        {
            if (CarriedBlock.Get(entity, slot) != null)
            {
                return(false);
            }
            var carried = CarriedBlock.PickUp(entity.World, pos, slot, checkIsCarryable);

            if (carried == null)
            {
                return(false);
            }

            carried.Set(entity, slot);
            carried.PlaySound(pos, entity.World, (entity as EntityPlayer));
            return(true);
        }
Esempio n. 4
0
        /// <summary>
        ///   Attempts to get this player to place down its
        ///   <see cref="CarriedBlock"/> (if any) at the specified
        ///   selection, returning whether it was successful.
        /// </summary>
        /// <example cref="ArgumentNullException"> Thrown if player or selection is null. </exception>
        public static bool PlaceCarried(this IPlayer player, BlockSelection selection, CarrySlot slot)
        {
            if (player == null)
            {
                throw new ArgumentNullException(nameof(player));
            }
            if (selection == null)
            {
                throw new ArgumentNullException(nameof(selection));
            }

            var carried = CarriedBlock.Get(player.Entity, slot);

            if (carried == null)
            {
                return(false);
            }

            return(carried.PlaceDown(player.Entity.World, selection, player.Entity));
        }
Esempio n. 5
0
        /// <summary>
        ///   Attempts to make this entity drop its <see cref="CarriedBlock"/>
        ///   (if any) at the specified position, returning whether it was successful.
        /// </summary>
        /// <example cref="ArgumentNullException"> Thrown if entity or pos is null. </exception>
        public static bool DropCarried(this IEntity entity, BlockPos pos)
        {
            if (pos == null)
            {
                throw new ArgumentNullException(nameof(pos));
            }

            var carried = CarriedBlock.Get(entity);

            if (carried == null)
            {
                return(false);
            }

            var selection = new BlockSelection {
                Position    = pos,
                Face        = BlockFacing.UP,
                HitPosition = new Vec3d(0.5, 0.5, 0.5),
            };

            return(carried.PlaceDown(entity.World, selection, entity));
        }
Esempio n. 6
0
 /// <summary> Returns the <see cref="CarriedBlock"/> this entity
 ///           is carrying in the specified slot, or null of none. </summary>
 /// <example cref="ArgumentNullException"> Thrown if entity or pos is null. </exception>
 public static CarriedBlock GetCarried(this Entity entity, CarrySlot slot)
 => CarriedBlock.Get(entity, slot);
Esempio n. 7
0
 /// <summary> Returns the <see cref="CarriedBlock"/>
 ///           this entity is carrying, or null of none. </summary>
 /// <example cref="ArgumentNullException"> Thrown if entity or pos is null. </exception>
 public static CarriedBlock GetCarried(this IEntity entity)
 => CarriedBlock.Get(entity);