Пример #1
0
        /// <summary>
        /// Tries to take out as much items/liquid as possible from a placed bucket and returns it
        /// </summary>
        /// <param name="world"></param>
        /// <param name="pos"></param>
        /// <param name="quantity"></param>
        public ItemStack TryTakeContent(IWorldAccessor world, BlockPos pos, int quantity)
        {
            BlockEntityBucket bebucket = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityBucket;

            if (bebucket == null)
            {
                return(null);
            }

            ItemStack stack = bebucket.GetContent();

            if (stack == null)
            {
                return(null);
            }

            ItemStack takenStack = stack.Clone();

            takenStack.StackSize = quantity;

            stack.StackSize -= quantity;
            if (stack.StackSize <= 0)
            {
                bebucket.SetContent(null);
            }
            else
            {
                bebucket.SetContent(stack);
            }

            return(takenStack);
        }
Пример #2
0
        /// <summary>
        /// Sets the buckets contents to placed bucked block
        /// </summary>
        /// <param name="bucketStack"></param>
        /// <param name="content"></param>
        public void SetContent(IWorldAccessor world, BlockPos pos, ItemStack content)
        {
            BlockEntityBucket bebucket = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityBucket;

            if (bebucket == null)
            {
                return;
            }
            bebucket.SetContent(content);
        }