Exemplo n.º 1
0
        public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos)
        {
            BlockEntityWateringCan becan = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityWateringCan;

            if (becan != null)
            {
                ItemStack stack = new ItemStack(this);
                SetRemainingWateringSeconds(stack, becan.SecondsWateringLeft);
                return(stack);
            }

            return(base.OnPickBlock(world, pos));
        }
Exemplo n.º 2
0
        public override bool DoPlaceBlock(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ItemStack byItemStack)
        {
            bool val = base.DoPlaceBlock(world, byPlayer, blockSel, byItemStack);

            if (val)
            {
                BlockEntityWateringCan bect = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityWateringCan;
                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);
        }