Interface IStructureDefinition<T>

  • Type Parameters:
    T - Type of the context object. Usually this will be the multiblock controller.
    All Known Implementing Classes:
    StructureDefinition

    public interface IStructureDefinition<T>
    This is the structure definition of your multi. You will have one of these for each multi.

    Cache the instances of this class

    You will construct this definition once per multi, either at class load or at first call to your variant of getStructureDefinition(). You can use a ClassValue<IStructureDefinition<?>> if you have a template for subclass. You can also use defer() or its overloads for simpler cases, but it is slightly less performant as it will allocate new objects on each structure check, whereas ClassValue will allocate once and cache it onwards.

    Constructing

    IStructureDefinition is constructed using builder()

    Builder has two main methods:

    • addShape() is a 2d string array describing the layout of structure. You can optionally use `StructureUtility#transpose()` to transpose the array to make the structure look nicer in source code.
    • addElement(). It takes a char identifier (mapped to a char in any of addShape() calls) and a IStructureElement.

    Position A, B and C

    Imagine you stand in front of the controller, with controller facing towards you not rotated or flipped.
    • The "A" position would be the number of blocks on the left side of the controller, not counting controller itself.
    • The "B" position would be the number of blocks on the top side of the controller, not counting controller itself.
    • The "C" position would be the number of blocks between you and controller, not counting controller itself.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods 
      Modifier and Type Method Description
      default boolean build​(T object, ItemStack trigger, java.lang.String piece, World world, ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB, int basePositionC)
      Build the multi in creative mode on a best-effort basis.
      static <T> StructureDefinition.Builder<T> builder()
      Create a new instance of builder.
      default boolean buildOrHints​(T object, ItemStack trigger, java.lang.String piece, World world, ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB, int basePositionC, boolean hintsOnly)
      default boolean check​(T object, java.lang.String piece, World world, ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB, int basePositionC, boolean forceCheckAllBlocks)
      Run a structure check.
      java.util.List<com.gtnewhorizon.structurelib.coords.Position<com.gtnewhorizon.structurelib.coords.StructureDefinitionCoords>> getAllSockets​(java.lang.String piece, char socket)
      Gets all sockets with a given character for a piece.
      com.gtnewhorizon.structurelib.coords.Position<com.gtnewhorizon.structurelib.coords.StructureDefinitionCoords> getControllerPosition​(java.lang.String piece)
      Gets the controller position for a piece.
      com.gtnewhorizon.structurelib.coords.StructureDefinitionCoords getCoordinateSystem​(java.lang.String piece)
      Gets the coordinate system for a piece.
      com.gtnewhorizon.structurelib.coords.Position<com.gtnewhorizon.structurelib.coords.StructureDefinitionCoords> getSocket​(java.lang.String piece, char socket)
      Gets a socket from a piece.
      IStructureElement<T>[] getStructureFor​(java.lang.String name)
      Used internally
      default boolean hints​(T object, ItemStack trigger, java.lang.String piece, World world, ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB, int basePositionC)
      Spawn hint particles.
      boolean isContainedInStructure​(java.lang.String name, int offsetA, int offsetB, int offsetC)  
      default void iterate​(java.lang.String piece, World world, ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB, int basePositionC, IStructureWalker<T> predicate)  
      static <T> boolean iterate​(T object, ItemStack trigger, IStructureElement<T>[] elements, World world, ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB, int basePositionC, boolean hintsOnly, java.lang.Boolean checkBlocksIfNotNullForceCheckAllIfTrue)
      Low level utility.
      default int survivalBuild​(T object, ItemStack trigger, java.lang.String piece, World world, ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB, int basePositionC, int elementBudget, IItemSource source, EntityPlayerMP actor, boolean check)
      Deprecated.
      default int survivalBuild​(T object, ItemStack trigger, java.lang.String piece, World world, ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB, int basePositionC, int elementBudget, ISurvivalBuildEnvironment env, boolean check)
      Cause a survival build.
    • Method Detail

      • getStructureFor

        IStructureElement<T>[] getStructureFor​(java.lang.String name)
        Used internally

        Might, but is not required, to throw NoSuchElementException if the given structure piece is not found.

        Parameters:
        name - same name as for other methods here
        Returns:
        the array of elements to process
        Throws:
        java.util.NoSuchElementException - if the given structure piece is not found and the moon phase perfectly matches
      • isContainedInStructure

        boolean isContainedInStructure​(java.lang.String name,
                                       int offsetA,
                                       int offsetB,
                                       int offsetC)
      • check

        default boolean check​(T object,
                              java.lang.String piece,
                              World world,
                              ExtendedFacing extendedFacing,
                              int basePositionX,
                              int basePositionY,
                              int basePositionZ,
                              int basePositionA,
                              int basePositionB,
                              int basePositionC,
                              boolean forceCheckAllBlocks)
        Run a structure check.
        Parameters:
        object - context object. usually multiblock controller.
        piece - the structure piece's string identifier.
        world - the world object this check takes place in.
        extendedFacing - the current structure's orientation.
        basePositionX - X location of the structure
        basePositionY - Y location of the structure
        basePositionZ - Z location of the structure
        basePositionA - see class javadoc
        basePositionB - see class javadoc
        basePositionC - see class javadoc
        forceCheckAllBlocks - check all location even if chunk not currently loaded.
        Returns:
        true if successful, false otherwise
      • hints

        default boolean hints​(T object,
                              ItemStack trigger,
                              java.lang.String piece,
                              World world,
                              ExtendedFacing extendedFacing,
                              int basePositionX,
                              int basePositionY,
                              int basePositionZ,
                              int basePositionA,
                              int basePositionB,
                              int basePositionC)
        Spawn hint particles. Should not be called on server side.
        Parameters:
        object - context object. usually multiblock controller.
        piece - the structure piece's string identifier.
        world - the world object this check takes place in.
        extendedFacing - the current structure's orientation.
        basePositionX - X location of the structure
        basePositionY - Y location of the structure
        basePositionZ - Z location of the structure
        basePositionA - see class javadoc
        basePositionB - see class javadoc
        basePositionC - see class javadoc
        Returns:
        true if successful, false otherwise
      • build

        default boolean build​(T object,
                              ItemStack trigger,
                              java.lang.String piece,
                              World world,
                              ExtendedFacing extendedFacing,
                              int basePositionX,
                              int basePositionY,
                              int basePositionZ,
                              int basePositionA,
                              int basePositionB,
                              int basePositionC)
        Build the multi in creative mode on a best-effort basis. Does not guarantee the structure is correct after a successful call.
        Parameters:
        object - context object. usually multiblock controller.
        trigger - The trigger item that contains channel data.
        piece - the structure piece's string identifier.
        world - the world object this check takes place in.
        extendedFacing - the current structure's orientation.
        basePositionX - X location of the structure
        basePositionY - Y location of the structure
        basePositionZ - Z location of the structure
        basePositionA - see class javadoc
        basePositionB - see class javadoc
        basePositionC - see class javadoc
        Returns:
        true if sucessful, false otherwise
      • survivalBuild

        @Deprecated
        default int survivalBuild​(T object,
                                  ItemStack trigger,
                                  java.lang.String piece,
                                  World world,
                                  ExtendedFacing extendedFacing,
                                  int basePositionX,
                                  int basePositionY,
                                  int basePositionZ,
                                  int basePositionA,
                                  int basePositionB,
                                  int basePositionC,
                                  int elementBudget,
                                  IItemSource source,
                                  EntityPlayerMP actor,
                                  boolean check)
        Deprecated.
        Cause a survival build.
        Parameters:
        object - context object. usually multiblock controller.
        trigger - The trigger item that contains channel data.
        piece - the structure piece's string identifier.
        world - the world object this check takes place in.
        extendedFacing - the current structure's orientation.
        basePositionX - X location of the structure
        basePositionY - Y location of the structure
        basePositionZ - Z location of the structure
        basePositionA - see class javadoc
        basePositionB - see class javadoc
        basePositionC - see class javadoc
        elementBudget - build up to this many elements
        source - from where to drain resource
        actor - source of action
        check - whether IStructureElement.check(Object, World, int, int, int) should be called if anything would be placed. use with caution. if in doubt, call check(Object, String, World, ExtendedFacing, int, int, int, int, int, int, boolean) after this call and set this parameter to false
        Returns:
        number of elements built, or -1 if structure done
        See Also:
        build(Object, ItemStack, String, World, ExtendedFacing, int, int, int, int, int, int)
      • survivalBuild

        default int survivalBuild​(T object,
                                  ItemStack trigger,
                                  java.lang.String piece,
                                  World world,
                                  ExtendedFacing extendedFacing,
                                  int basePositionX,
                                  int basePositionY,
                                  int basePositionZ,
                                  int basePositionA,
                                  int basePositionB,
                                  int basePositionC,
                                  int elementBudget,
                                  ISurvivalBuildEnvironment env,
                                  boolean check)
        Cause a survival build.
        Parameters:
        object - context object. usually multiblock controller.
        trigger - The trigger item that contains channel data.
        piece - the structure piece's string identifier.
        world - the world object this check takes place in.
        extendedFacing - the current structure's orientation.
        basePositionX - X location of the structure
        basePositionY - Y location of the structure
        basePositionZ - Z location of the structure
        basePositionA - see class javadoc
        basePositionB - see class javadoc
        basePositionC - see class javadoc
        elementBudget - build up to this many elements
        env - build environment.
        check - whether IStructureElement.check(Object, World, int, int, int) should be called if anything would be placed. use with caution. if in doubt, call check(Object, String, World, ExtendedFacing, int, int, int, int, int, int, boolean) after this call and set this parameter to false
        Returns:
        number of elements built, or -1 if structure done
        See Also:
        build(Object, ItemStack, String, World, ExtendedFacing, int, int, int, int, int, int)
      • iterate

        default void iterate​(java.lang.String piece,
                             World world,
                             ExtendedFacing extendedFacing,
                             int basePositionX,
                             int basePositionY,
                             int basePositionZ,
                             int basePositionA,
                             int basePositionB,
                             int basePositionC,
                             IStructureWalker<T> predicate)
      • getControllerPosition

        com.gtnewhorizon.structurelib.coords.Position<com.gtnewhorizon.structurelib.coords.StructureDefinitionCoords> getControllerPosition​(java.lang.String piece)
        Gets the controller position for a piece. Controller positions are denoted by a tilde.
        Parameters:
        piece - The piece name
        Returns:
        The controller position, or null if it doesn't exist for the given piece
      • getCoordinateSystem

        com.gtnewhorizon.structurelib.coords.StructureDefinitionCoords getCoordinateSystem​(java.lang.String piece)
        Gets the coordinate system for a piece. This is used to translate structure definition coordinates into structure relative coordinates.
        Parameters:
        piece - The piece
        Returns:
        The coordinate system
        Throws:
        java.lang.IllegalArgumentException - When the piece does not exist
      • getSocket

        com.gtnewhorizon.structurelib.coords.Position<com.gtnewhorizon.structurelib.coords.StructureDefinitionCoords> getSocket​(java.lang.String piece,
                                                                                                                                char socket)
        Gets a socket from a piece.
        Parameters:
        piece - The piece name
        socket - The socket character
        Returns:
        The socket's position
        Throws:
        java.lang.IllegalArgumentException - When the piece does not exist
        java.lang.IllegalArgumentException - When the socket does not exist
        java.lang.IllegalStateException - When more than one socket exists with this character
        See Also:
        StructureDefinition.Builder.addSocket(char, char)
      • getAllSockets

        @Nonnull
        java.util.List<com.gtnewhorizon.structurelib.coords.Position<com.gtnewhorizon.structurelib.coords.StructureDefinitionCoords>> getAllSockets​(java.lang.String piece,
                                                                                                                                                    char socket)
        Gets all sockets with a given character for a piece.
        Parameters:
        piece - The piece name
        socket - The socket character
        Returns:
        The list of socket positions, or an empty list if the socket is not present
        Throws:
        java.lang.IllegalArgumentException - When the piece does not exist
        See Also:
        StructureDefinition.Builder.addSocket(char, char)
      • iterate

        static <T> boolean iterate​(T object,
                                   ItemStack trigger,
                                   IStructureElement<T>[] elements,
                                   World world,
                                   ExtendedFacing extendedFacing,
                                   int basePositionX,
                                   int basePositionY,
                                   int basePositionZ,
                                   int basePositionA,
                                   int basePositionB,
                                   int basePositionC,
                                   boolean hintsOnly,
                                   java.lang.Boolean checkBlocksIfNotNullForceCheckAllIfTrue)
        Low level utility.
        Type Parameters:
        T - type of context object.
        Parameters:
        object - context object. usually multiblock controller.
        trigger - The trigger item that contains channel data.
        elements - the structure piece
        world - the world object this check takes place in.
        extendedFacing - the current structure's orientation.
        basePositionX - X location of the structure
        basePositionY - Y location of the structure
        basePositionZ - Z location of the structure
        basePositionA - see class javadoc
        basePositionB - see class javadoc
        basePositionC - see class javadoc
        hintsOnly - whether to spawn hints or do creative build. no effect if checkBlocksIfNotNullForceCheckAllIfTrue is not null.
        checkBlocksIfNotNullForceCheckAllIfTrue - creative build or spawn hints if null. Force check not loaded chunk if true. Check only loaded chunk is false.
        Returns:
        true if iteration completed successfully.
      • builder

        static <T> StructureDefinition.Builder<T> builder()
        Create a new instance of builder.
        Type Parameters:
        T - type of context object