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 Details

    • getStructureFor

      IStructureElement<T>[] getStructureFor(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:
      NoSuchElementException - if the given structure piece is not found and the moon phase perfectly matches
    • isContainedInStructure

      boolean isContainedInStructure(String name, int offsetA, int offsetB, int offsetC)
    • check

      default boolean check(T object, 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, 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, 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
    • buildOrHints

      default boolean buildOrHints(T object, ItemStack trigger, String piece, World world, ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB, int basePositionC, boolean hintsOnly)
      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
      hintsOnly - whether to spawn hints or do creative build.
      Returns:
      true if sucessful, false otherwise
      See Also:
    • survivalBuild

      @Deprecated default int survivalBuild(T object, ItemStack trigger, 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:
    • survivalBuild

      default int survivalBuild(T object, ItemStack trigger, 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:
    • 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, 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