Esempio n. 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);
        }
Esempio n. 2
0
        /// <summary>
        /// Retrieves the contents of a placed bucket
        /// </summary>
        /// <param name="world"></param>
        /// <param name="pos"></param>
        /// <returns></returns>
        public ItemStack GetContent(IWorldAccessor world, BlockPos pos)
        {
            BlockEntityBucket bebucket = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityBucket;

            if (bebucket == null)
            {
                return(null);
            }
            return(bebucket.GetContent());
        }
Esempio n. 3
0
        /// <summary>
        /// Retrives the containable properties of the currently contained itemstack of a placed water bucket
        /// </summary>
        /// <param name="world"></param>
        /// <param name="pos"></param>
        /// <param name="bucketStack"></param>
        /// <returns></returns>
        public WaterTightContainableProps GetContentProps(IWorldAccessor world, BlockPos pos)
        {
            BlockEntityBucket bebucket = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityBucket;

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

            ItemStack stack = bebucket.GetContent();

            try
            {
                return(stack?.ItemAttributes?["waterTightContainerProps"].AsObject <WaterTightContainableProps>());
            }
            catch (Exception)
            {
                return(null);
            }
        }