Пример #1
0
        private bool UpdateState(IBlockAccess world,
                                 BlockState state,
                                 BlockCoordinates position,
                                 BlockCoordinates updatedBlock,
                                 out BlockState result, bool checkCorners)
        {
            result = state;
            var block = world.GetBlockState(updatedBlock).Block;

            if (!(block is Stairs))
            {
                return(false);
            }

            var myHalf = GetHalf(state);

            var blockState = block.BlockState;

            if (myHalf != GetHalf(blockState))
            {
                return(false);
            }

            var facing         = GetFacing(state);
            var neighborFacing = GetFacing(blockState);

            if (checkCorners)
            {
                BlockCoordinates offset1 = facing.GetVector3();

                if (neighborFacing != facing && neighborFacing != facing.Opposite() &&
                    updatedBlock == position + offset1)
                {
                    if (neighborFacing == BlockModel.RotateDirection(
                            facing, 1, BlockModel.FACE_ROTATION, BlockModel.INVALID_FACE_ROTATION))
                    {
                        if (facing == BlockFace.North || facing == BlockFace.South)
                        {
                            result = state.WithProperty("shape", "outer_right");
                        }
                        else
                        {
                            result = state.WithProperty("shape", "outer_right");
                        }

                        return(true);
                    }

                    if (facing == BlockFace.North || facing == BlockFace.South)
                    {
                        result = state.WithProperty("shape", "outer_left");
                    }
                    else
                    {
                        result = state.WithProperty("shape", "outer_left");
                    }

                    return(true);
                }

                BlockCoordinates offset2 = facing.Opposite().GetVector3();

                if (neighborFacing != facing && neighborFacing != facing.Opposite() &&
                    updatedBlock == position + offset2)
                {
                    if (neighborFacing == BlockModel.RotateDirection(
                            facing, 1, BlockModel.FACE_ROTATION, BlockModel.INVALID_FACE_ROTATION))
                    {
                        if (facing == BlockFace.North || facing == BlockFace.South)
                        {
                            result = state.WithProperty("shape", "inner_right");
                        }
                        else
                        {
                            result = state.WithProperty("shape", "inner_right");
                        }

                        return(true);
                    }

                    if (facing == BlockFace.North || facing == BlockFace.South)
                    {
                        result = state.WithProperty("shape", "inner_left");
                    }
                    else
                    {
                        result = state.WithProperty("shape", "inner_left");
                    }

                    return(true);
                }
            }
            else
            {
                if (facing == neighborFacing)
                {
                    result = state.WithProperty("shape", "straight");

                    return(true);
                }
            }


            return(false);
        }
Пример #2
0
        private bool UpdateState(IBlockAccess world, BlockState state, BlockCoordinates position, BlockCoordinates updatedBlock, out BlockState result)
        {
            result = state;
            var block = world.GetBlockState(updatedBlock).Block;

            if (!(block is Stairs))
            {
                return(false);
            }

            var myHalf = GetHalf(state);

            var blockState = block.BlockState;

            if (myHalf != GetHalf(blockState))
            {
                return(false);
            }

            var facing   = GetFacing(state);
            var neighbor = GetFacing(blockState);

            var myShape       = GetShape(state);
            var neighborShape = GetShape(blockState);

            // int offset = (myHalf == "top") ? -1 : 1;

            //  var innerRight = ""
            if (myHalf == "top")
            {
            }

            //if ()
            {
                // if (neighbor == BlockModel.RotateDirection(facing, 1, BlockModel.FACE_ROTATION,
                //         BlockModel.INVALID_FACE_ROTATION) && neighbor != facing && GetHalf(state) == GetHalf(blockState))
                //if (facing == BlockFace.East && updatedBlock == (position + facing.Opposite().GetBlockCoordinates()))

                BlockCoordinates offset1 = facing.GetVector3();

                if (neighbor != facing && neighbor != facing.Opposite() && updatedBlock == position + offset1)
                {
                    if (neighbor == BlockModel.RotateDirection(facing, 1, BlockModel.FACE_ROTATION,
                                                               BlockModel.INVALID_FACE_ROTATION))
                    {
                        if (facing == BlockFace.North || facing == BlockFace.South)
                        {
                            result = state.WithProperty("shape", "inner_right");
                        }
                        else
                        {
                            result = state.WithProperty("shape", "outer_right");
                        }
                        return(true);
                    }

                    if (facing == BlockFace.North || facing == BlockFace.South)
                    {
                        result = state.WithProperty("shape", "inner_left");
                    }
                    else
                    {
                        result = state.WithProperty("shape", "outer_left");
                    }

                    return(true);
                }

                BlockCoordinates offset2 = facing.Opposite().GetVector3();

                if (neighbor != facing && neighbor != facing.Opposite() && updatedBlock == position + offset2)
                {
                    if (neighbor == BlockModel.RotateDirection(facing, 1, BlockModel.FACE_ROTATION,
                                                               BlockModel.INVALID_FACE_ROTATION))
                    {
                        if (facing == BlockFace.North || facing == BlockFace.South)
                        {
                            result = state.WithProperty("shape", "outer_right");
                        }
                        else
                        {
                            result = state.WithProperty("shape", "inner_right");
                        }
                        return(true);
                    }

                    if (facing == BlockFace.North || facing == BlockFace.South)
                    {
                        result = state.WithProperty("shape", "outer_left");
                    }
                    else
                    {
                        result = state.WithProperty("shape", "inner_left");
                    }
                    return(true);
                }

                /* if (updatedBlock == (position + facing.Opposite().GetBlockCoordinates()))
                 * {
                 *  return state.WithProperty("shape", "outer_left");
                 * }*/
            }

            return(false);
        }