コード例 #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);
        }
コード例 #3
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());
        }
コード例 #4
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);
            }
        }
コード例 #5
0
        public override bool DoPlaceBlock(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ItemStack byItemStack)
        {
            bool val = base.DoPlaceBlock(world, byPlayer, blockSel, byItemStack);

            if (val)
            {
                BlockEntityBucket bect = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityBucket;
                if (bect != null)
                {
                    BlockPos targetPos = blockSel.DidOffset ? blockSel.Position.AddCopy(blockSel.Face.Opposite) : blockSel.Position;
                    double   dx        = byPlayer.Entity.Pos.X - (targetPos.X + blockSel.HitPosition.X);
                    double   dz        = byPlayer.Entity.Pos.Z - (targetPos.Z + blockSel.HitPosition.Z);
                    float    angleHor  = (float)Math.Atan2(dx, dz);

                    float deg22dot5rad = GameMath.PIHALF / 4;
                    float roundRad     = ((int)Math.Round(angleHor / deg22dot5rad)) * deg22dot5rad;
                    bect.MeshAngle = roundRad;
                }
            }

            return(val);
        }