Class CoordinateComponent

  • All Implemented Interfaces:

    
    public final class CoordinateComponent
    
                        

    A coordinate in Crafting slots.

    You can convert this for index(int) with the following expression. (x + y*9)

    Zero origin

    Since:

    5.0.0

    • Constructor Detail

      • CoordinateComponent

        CoordinateComponent(Integer x, Integer y)
        Parameters:
        x - X coordinate
        y - Y coordinate
    • Method Detail

      • toIndex

         final Integer toIndex()

        returns a calculated index from a coordinate.

        Returns:

        Int calculated index

      • squareFill

        @JvmOverloads() final static Set<CoordinateComponent> squareFill(Integer size, Integer dx, Integer dy, Boolean safeTrim)

        returns specified size square coordinates set.

        the origin is (0, 0).

        for example

        val three = CoordinateComponent.square(3)
        // xxx
        // xxx
        // xxx
        // 'x' means a coordinate what is contained a result.
        Parameters:
        size - size of square (0 or greater; 0 returns an empty set)
        dx - initial x coordinate used to calculate.
        dy - initial y coordinate used to calculate.
        safeTrim - trims coordinates what are out of the CustomCrafter's gui range.
        Returns:

        Set set of filled coordinates.

        Since:

        5.0.7

      • squareFill

        @JvmOverloads() final static Set<CoordinateComponent> squareFill(Integer size, Integer dx, Integer dy)

        returns specified size square coordinates set.

        the origin is (0, 0).

        for example

        val three = CoordinateComponent.square(3)
        // xxx
        // xxx
        // xxx
        // 'x' means a coordinate what is contained a result.
        Parameters:
        size - size of square (0 or greater; 0 returns an empty set)
        dx - initial x coordinate used to calculate.
        dy - initial y coordinate used to calculate.
        Returns:

        Set set of filled coordinates.

        Since:

        5.0.7

      • squareFill

        @JvmOverloads() final static Set<CoordinateComponent> squareFill(Integer size, Integer dx)

        returns specified size square coordinates set.

        the origin is (0, 0).

        for example

        val three = CoordinateComponent.square(3)
        // xxx
        // xxx
        // xxx
        // 'x' means a coordinate what is contained a result.
        Parameters:
        size - size of square (0 or greater; 0 returns an empty set)
        dx - initial x coordinate used to calculate.
        Returns:

        Set set of filled coordinates.

        Since:

        5.0.7

      • squareFill

        @JvmOverloads() final static Set<CoordinateComponent> squareFill(Integer size)

        returns specified size square coordinates set.

        the origin is (0, 0).

        for example

        val three = CoordinateComponent.square(3)
        // xxx
        // xxx
        // xxx
        // 'x' means a coordinate what is contained a result.
        Parameters:
        size - size of square (0 or greater; 0 returns an empty set)
        Returns:

        Set set of filled coordinates.

        Since:

        5.0.7

      • square

        @JvmOverloads() final static Set<CoordinateComponent> square(Integer size, Integer dx, Integer dy)

        returns specified size square frame coordinates set.

        the origin is (0, 0).

        for example

        val three = CoordinateComponent.square(3)
        // xxx
        // x_x
        // xxx
        // 'x' means a coordinate what is contained a result.
        Parameters:
        size - size of square frame (0 or greater; 0 returns an empty set)
        dx - initial x coordinate used to calculate.
        dy - initial y coordinate used to calculate.
        Returns:

        Set<CoordinateComponent> set of frame coordinates.

      • square

        @JvmOverloads() final static Set<CoordinateComponent> square(Integer size, Integer dx)

        returns specified size square frame coordinates set.

        the origin is (0, 0).

        for example

        val three = CoordinateComponent.square(3)
        // xxx
        // x_x
        // xxx
        // 'x' means a coordinate what is contained a result.
        Parameters:
        size - size of square frame (0 or greater; 0 returns an empty set)
        dx - initial x coordinate used to calculate.
        Returns:

        Set<CoordinateComponent> set of frame coordinates.

      • square

        @JvmOverloads() final static Set<CoordinateComponent> square(Integer size)

        returns specified size square frame coordinates set.

        the origin is (0, 0).

        for example

        val three = CoordinateComponent.square(3)
        // xxx
        // x_x
        // xxx
        // 'x' means a coordinate what is contained a result.
        Parameters:
        size - size of square frame (0 or greater; 0 returns an empty set)
        Returns:

        Set<CoordinateComponent> set of frame coordinates.

      • recipeMapFromStringList

         final static Map<CoordinateComponent, CMatter> recipeMapFromStringList(List<String> lines, Map<String, CMatter> map)

        Builds a Map<CoordinateComponent, CMatter> from a list of comma-separated rows and a token-to-matter mapping.

        Each element of lines represents one row (y-axis) of the crafting grid. Within a row, tokens are separated by commas and represent individual slots (x-axis). Each token is looked up in map; tokens not present in map are silently skipped, which can be used to represent empty slots.

        Constraints:

        • lines size must be in range 1 to 6 (each row maps to y = 0–5).

        • Each row's token count must be in range 1 to 6 (each token maps to x = 0–5).

        • If lines or map is empty, returns an empty map without throwing.

        // Example — 3×3 shaped recipe
        val lines = listOf(
            "g,g,g",
            "g,a,g",
            "g,g,g"
        )
        val map = mapOf(
            "a" to CMatterImpl.of(Material.APPLE),
            "g" to CMatterImpl.of(Material.GOLD_BLOCK)
        )
        val recipeMap = CoordinateComponent.recipeMapFromStringList(lines, map)
        // CoordinateComponent(0,0)→GOLD_BLOCK  CoordinateComponent(1,0)→GOLD_BLOCK  CoordinateComponent(2,0)→GOLD_BLOCK
        // CoordinateComponent(0,1)→GOLD_BLOCK  CoordinateComponent(1,1)→APPLE        CoordinateComponent(2,1)→GOLD_BLOCK
        // CoordinateComponent(0,2)→GOLD_BLOCK  CoordinateComponent(1,2)→GOLD_BLOCK  CoordinateComponent(2,2)→GOLD_BLOCK
        // Example 2 — token not in map is skipped (acts as an empty slot)
        val lines = listOf(
            "a,a",
            "_,a"   // "_" is not a key in map, so (0,1) is skipped
        )
        val map = mapOf("a" to CMatterImpl.of(Material.APPLE))
        val recipeMap = CoordinateComponent.recipeMapFromStringList(lines, map)
        // CoordinateComponent(0,0)→APPLE  CoordinateComponent(1,0)→APPLE
        //                                  CoordinateComponent(1,1)→APPLE
        Parameters:
        lines - Comma-separated row strings.
        map - Mapping of token strings to CMatter instances.
        Returns:

        Map Mapping of coordinates to matters. Empty if lines or map is empty.

        Since:

        5.0.17-p1

      • mapToRecipeMap

         final static Map<CoordinateComponent, CMatter> mapToRecipeMap(Map<CMatter, Set<CoordinateComponent>> source)

        Builds a Map<CoordinateComponent, CMatter> from an inverted mapping of matter to coordinates.

        This is the inverse of the layout used in recipeMapFromStringList: instead of specifying where each slot goes, you declare which coordinates each CMatter occupies. All coordinates must be within the valid crafting grid range (x: 0–5, y: 0–5). Returns an empty map if source is empty.

        // Example — 3×3 shaped recipe (ring pattern)
        val source = mapOf(
            CMatterImpl.of(Material.GOLD_BLOCK) to setOf(
                CoordinateComponent(0, 0), CoordinateComponent(1, 0), CoordinateComponent(2, 0),
                CoordinateComponent(0, 1),                            CoordinateComponent(2, 1),
                CoordinateComponent(0, 2), CoordinateComponent(1, 2), CoordinateComponent(2, 2),
            ),
            CMatterImpl.of(Material.APPLE) to setOf(CoordinateComponent(1, 1))
        )
        val recipeMap = CoordinateComponent.mapToRecipeMap(source)
        // G: GOLD_BLOCK, A: APPLE
        // G,G,G
        // G,A,G
        // G,G,G
        Parameters:
        source - Mapping of CMatter to the set of grid coordinates it occupies.
        Returns:

        Map Mapping of coordinates to matters. Empty if source is empty.

        Since:

        5.0.17-p1

      • getComponentsShapeString

        @JvmOverloads() final static String getComponentsShapeString(Collection<CoordinateComponent> list, Character existsSlotChar, Character notExistsSlotChar)

        ※ This is a high cost function.

        val list = CoordinateComponent.squareFill(3)
        println(Converter.getComponentsShapeString(list))
        // -> OUTPUT
        // ###
        // ###
        // ###
        val list = CoordinateComponent.square(3)
        println(Converter.getComponentsShapeString(list))
        // -> OUTPUT
        // ###
        // #_#
        // ###
        Parameters:
        list - List of coordinates
        existsSlotChar - This is a char what is used on coordinate exists.
        notExistsSlotChar - This is a char what is used on coordinate NOT exists.
        Returns:

        String Shape

        Since:

        5.0.16

      • getComponentsShapeString

        @JvmOverloads() final static String getComponentsShapeString(Collection<CoordinateComponent> list, Character existsSlotChar)

        ※ This is a high cost function.

        val list = CoordinateComponent.squareFill(3)
        println(Converter.getComponentsShapeString(list))
        // -> OUTPUT
        // ###
        // ###
        // ###
        val list = CoordinateComponent.square(3)
        println(Converter.getComponentsShapeString(list))
        // -> OUTPUT
        // ###
        // #_#
        // ###
        Parameters:
        list - List of coordinates
        existsSlotChar - This is a char what is used on coordinate exists.
        Returns:

        String Shape

        Since:

        5.0.16

      • getComponentsShapeString

        @JvmOverloads() final static String getComponentsShapeString(Collection<CoordinateComponent> list)

        ※ This is a high cost function.

        val list = CoordinateComponent.squareFill(3)
        println(Converter.getComponentsShapeString(list))
        // -> OUTPUT
        // ###
        // ###
        // ###
        val list = CoordinateComponent.square(3)
        println(Converter.getComponentsShapeString(list))
        // -> OUTPUT
        // ###
        // #_#
        // ###
        Parameters:
        list - List of coordinates
        Returns:

        String Shape

        Since:

        5.0.16