Class StructureUtility

java.lang.Object
com.gtnewhorizon.structurelib.structure.StructureUtility

public class StructureUtility extends Object
A brief index of everything contained

Control blocks

A lot of these might seem to make more sense as a default function on IStructureElement. However, in that case javac generic will often fail to infer the type for you, so we have to define them as static methods

If block

Provide if block, allowing downstream call only if user specified conditions are meet (i.e. predicate returns true)

Switch block

Provide switch block, allowing to select a downstream element by using a key or index computed from trigger item and/or context object.

Or Chain

Provide a short-circuiting OR chain.

Side effect

Provide callbacks on various occasion

Other Primitives

Error statement

Unconditionally return false.

Context Object Change

Switch the context object.

Channel Change

Change the channel. See Channels section on overview for more information.

Spawn hint particle

Just spawn a hint. Do nothing otherwise. Useful when you want to override the hint provided by another structure element, or as a fallback to a structure element that is check only.

Actual Element

These elements are elements that can actually do structure check, spawn hint and do auto place. Elements listed in above 2 sections are not going to be helpful without elements like these. They also serve as a reference implementation for your own custom IStructureElement implementations.

Simple Block Element

These accept one or more different block types in one location.

Complex Block Element

In case your logic on determining which block is accepted is complex, use these.

Helper Methods

These don't construct a IStructureElement, but is helpful to the instantiation or implementation of these.
  • Method Details

    • survivalPlaceBlock

      public static IStructureElement.PlaceResult survivalPlaceBlock(Block block, int meta, World world, int x, int y, int z, IItemSource s, EntityPlayerMP actor)
      This is a helper method for implementing IStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)

      This method will try to look up an ItemBlock for given block and meta from s and place it at given location. This method assume block at given coord is NOT acceptable, but may or may not be trivially replaceable This method might yield error messages to the player only if there is likely a programming error or exploit.

      Parameters:
      s - drain resources from this place
      actor - source of action. cannot be null.
    • survivalPlaceBlock

      public static IStructureElement.PlaceResult survivalPlaceBlock(Block block, int meta, World world, int x, int y, int z, IItemSource s, EntityPlayer actor)
      This is a helper method for implementing IStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)

      This method will try to look up an ItemBlock for given block and meta from s and place it at given location. This method assume block at given coord is NOT acceptable, but may or may not be trivially replaceable This method might yield error messages to the player only if there is likely a programming error or exploit.

      Parameters:
      s - drain resources from this place
      actor - source of action. cannot be null.
    • survivalPlaceBlock

      public static IStructureElement.PlaceResult survivalPlaceBlock(Block block, int meta, World world, int x, int y, int z, IItemSource s, EntityPlayerMP actor, Consumer<IChatComponent> chatter)
      This is a helper method for implementing IStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)

      This method will try to look up an ItemBlock for given block and meta from s and place it at given location. This method assume block at given coord is NOT acceptable, but may or may not be trivially replaceable This method might yield error messages to the player only if there is likely a programming error or exploit. This method might yield error messages to the chatter.

      Parameters:
      s - drain resources from this place
      actor - source of action. cannot be null.
      chatter - normal error destination. can be null to suppress them.
    • survivalPlaceBlock

      public static IStructureElement.PlaceResult survivalPlaceBlock(Block block, int meta, World world, int x, int y, int z, IItemSource s, EntityPlayer actor, Consumer<IChatComponent> chatter)
      This is a helper method for implementing IStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)

      This method will try to look up an ItemBlock for given block and meta from s and place it at given location. This method assume block at given coord is NOT acceptable, but may or may not be trivially replaceable This method might yield error messages to the player only if there is likely a programming error or exploit. This method might yield error messages to the chatter.

      Parameters:
      s - drain resources from this place
      actor - source of action. cannot be null.
      chatter - normal error destination. can be null to suppress them.
    • survivalPlaceBlock

      public static IStructureElement.PlaceResult survivalPlaceBlock(ItemStack stack, ItemStackPredicate.NBTMode nbtMode, NBTTagCompound tag, boolean assumeStackPresent, World world, int x, int y, int z, IItemSource s, EntityPlayerMP actor)
      This is a helper method for implementing IStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)

      This method will try to look up an ItemBlock for given block and meta from s and place it at given location. This method assume block at given coord is NOT acceptable, but may or may not be trivially replaceable This method might yield error messages to the player only if there is likely a programming error or exploit.

      Parameters:
      stack - a valid stack with stack size of exactly 1. Must be of an ItemBlock!
      s - drain resources from this place
      actor - source of action. cannot be null.
    • survivalPlaceBlock

      public static IStructureElement.PlaceResult survivalPlaceBlock(ItemStack stack, ItemStackPredicate.NBTMode nbtMode, NBTTagCompound tag, boolean assumeStackPresent, World world, int x, int y, int z, IItemSource s, EntityPlayer actor)
      This is a helper method for implementing IStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)

      This method will try to look up an ItemBlock for given block and meta from s and place it at given location. This method assume block at given coord is NOT acceptable, but may or may not be trivially replaceable This method might yield error messages to the player only if there is likely a programming error or exploit.

      Parameters:
      stack - a valid stack with stack size of exactly 1. Must be of an ItemBlock!
      s - drain resources from this place
      actor - source of action. cannot be null.
    • survivalPlaceBlock

      public static IStructureElement.PlaceResult survivalPlaceBlock(ItemStack stack, ItemStackPredicate.NBTMode nbtMode, NBTTagCompound tag, boolean assumeStackPresent, World world, int x, int y, int z, IItemSource s, EntityPlayerMP actor, @Nullable Consumer<IChatComponent> chatter)
      This is a helper method for implementing IStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)

      This method will try to look up an ItemBlock for given block and meta from s and place it at given location. This method assume block at given coord is NOT acceptable, but may or may not be trivially replaceable This method might yield error messages to the player only if there is likely a programming error or exploit. This method might yield error messages to the chatter.

      Parameters:
      stack - a valid stack with stack size of exactly 1. Must be of an ItemBlock!
      s - drain resources from this place
      actor - source of action. cannot be null.
      chatter - normal error destination. can be null to suppress them.
    • survivalPlaceBlock

      public static IStructureElement.PlaceResult survivalPlaceBlock(ItemStack stack, ItemStackPredicate.NBTMode nbtMode, NBTTagCompound tag, boolean assumeStackPresent, World world, int x, int y, int z, IItemSource s, EntityPlayer actor, @Nullable Consumer<IChatComponent> chatter)
      This is a helper method for implementing IStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)

      This method will try to look up an ItemBlock for given block and meta from s and place it at given location. This method assume block at given coord is NOT acceptable, but may or may not be trivially replaceable This method might yield error messages to the player only if there is likely a programming error or exploit. This method might yield error messages to the chatter.

      Parameters:
      stack - a valid stack with stack size of exactly 1. Must be of an ItemBlock!
      s - drain resources from this place
      actor - source of action. cannot be null.
      chatter - normal error destination. can be null to suppress them.
    • isAir

      public static <T> IStructureElement<T> isAir()
      Return a structure element that only allow air (or air equivalents, like Railcraft hidden blocks). You usually don't need to call this yourselves. Use - in shape to automatically use this. Provided nontheless in case you want this as a fallback to something else.
    • notAir

      public static <T> IStructureElement<T> notAir()
      Return a structure element that allow anything but air (or air equivalents, like Railcraft hidden blocks). You usually don't need to call this yourselves. Use + in shape to automatically use this. Provided nontheless in case you want this as a fallback to something else.
    • error

      public static <T> IStructureElement<T> error()
      Check returns false. Placement is always handled by this and does nothing. Makes little to no use it in fallback chain.
    • ofHint

      public static <T> IStructureElementNoPlacement<T> ofHint(int dots)
      Spawn a hint with given amount of dots. Check always returns: true. Only useful as a fallback, e.g. ofBlockUnlocalizedName(String, String, int, IStructureElement)
    • ofHintDeferred

      public static <T> IStructureElementNoPlacement<T> ofHintDeferred(Supplier<IIcon[]> icons)
      Spawn a hint with given textures. Check always returns: true. Only useful as a fallback, e.g. ofBlockUnlocalizedName(String, String, int, IStructureElement)
    • ofHintDeferred

      public static <T> IStructureElementNoPlacement<T> ofHintDeferred(Supplier<IIcon[]> icons, short[] RGBa)
      Spawn a hint with given amount of textures and tint. Check always returns: true. Only useful as a fallback, e.g. ofBlockUnlocalizedName(String, String, int, IStructureElement)
    • ofBlocksTiered

      public static <T,TIER> IStructureElementCheckOnly<T> ofBlocksTiered(ITierConverter<TIER> tierExtractor, @Nullable TIER notSet, BiConsumer<T,TIER> setter, Function<T,TIER> getter)
      A more primitive variant of ofBlocksTiered(ITierConverter, List, Object, BiConsumer, Function) Main difference is this one is check only.

      Note that if tierExtractor returns a null, this block will be rejected immediately. This makes null a potent candidate for notSet.

      See documentation on the other overload for more information.

      See Also:
    • ofBlocksTiered

      public static <T,TIER> IStructureElement<T> ofBlocksTiered(ITierConverter<TIER> tierExtractor, @Nullable List<org.apache.commons.lang3.tuple.Pair<Block,Integer>> allKnownTiers, @Nullable TIER notSet, BiConsumer<T,TIER> setter, Function<T,TIER> getter)
      Element representing a component with different tiers. Your multi will accept any of them (as long as player does not mix tier (*)), but would like to know which is used. Player can use more blueprint to get hints denoting more advanced components.

      Above all else, you need to decide what type of tier you are going to use. For simpler cases, Integer is a good choice. You can also use an existing Enum. It can also be a String or a ResourceLocation, or basically anything. It doesn't even have to implement Comparable.

      If your tier extractor function returns null on any (Block, meta) pair, then it means this block is rejected. This also implies null can never be a valid tier.

      This structure element require you will reset the backing storage of getter in your own code, such that in every round of structure checking, the first call to getter would always return notSet. You can also make getter to return other value on that occasion to forcefully select a certain tier, but then you'd probably be better off using block adders or ofBlock(Block, int, Block, int) and its overloads

      There is yet no TileEntity counterpart of this utility. Feel free to submit a PR to add it.

      (*): Implementation wise, this structure element will only accept a block if its tier is the same as existing tier or if existing tier is unset (i.e. value of third argument). If there are multiple (block, tier) tuple for a given tier, then player will be allowed to use multiple kinds of blocks, but their tier is guaranteed to be the same.

      WARNING

      You SHOULD NOT return notSet from your tierExtractor. If you do so, we will have this chain of events:
      • at check start, tier is reset to notSet
      • the tier extractor returns notSet for first block, so since ofBlocksTiered finds your current tier is notSet, and the new block's tier is the same as that, so it's accepted
      • at 2nd, 3rd..., same thing in 2 happens
      • at last occurrence, player placed a valid block with a tier not notSet. ofBlocksTiered now sets your current tier to this tier, and accept the block
      • check got notified structure is sound, and tier is not notSet. it marks the structure as complete and start doing its business
      • Player enjoy a (probably) hilariously shaped multi and (probably) reduced build cost.

      Example Implementation

      Assume you have 16 tier, each map to one particular block's 16 different meta. You will usually want something like this

      public class Tile extends TileEntity {
          private static final Block B = getTargetBlock();
          private static final IStructureDefinition<Tile> S = IStructureDefinition.<Tile>builder()
                 // ... addShape, and other elements
                 .addElement('c', ofBlocksTiered((b, m) -> b == B ? m : null,
                                                 IntStream.range(0, 16).mapToObj(i -> Pair.of(B, i)).collect(Collectors.toList()),
                                                 -1,
                                                 (t, m) -> t.tier = m,
                                                 t -> t.tier))
                 .build();
          private int tier;
      
          public boolean check() {
              tier = -1;
              if (!S.check(...))
                  return false;
              return isTierAcceptable(tier);
          }
      }
      
      Important bits of this example implementation:

      As a friendly reminder, the above characteristics are only for this simply demo, not as a general restriction imposed by ofBlocksTiered.

      Parameters:
      tierExtractor - a function to extract tier info from a block. This function can return null and will never be passed a null block or an invalid block meta. If this function returns null, then the block would be considered invalid.
      allKnownTiers - A list of all known tiers as of calling. Can be empty or null. No hint will be spawned if empty or null. Cannot have null elements. First element denotes the most primitive tier. Last element denotes the most advanced tier. If not all tiers are available at definition construction time, use lazy(Supplier) or its overloads to delay a bit. This list is only for hint particle spawning and survival build. The hint/autoplace code will choose 1st pair to spawn/place if trigger item has master channel data of 1, 2nd pair if 2, and so on.
      notSet - The value returned from getter when there were no tier info found in T yet. Cannot be null.
      setter - a function to set the current tier into context object
      getter - a function to retrieve the current tier from context object
    • ofBlocksTiered

      public static <T,TIER> IStructureElement<T> ofBlocksTiered(ITierConverter<TIER> tierExtractor, @Nullable List<org.apache.commons.lang3.tuple.Pair<Block,Integer>> allKnownTiers, @Nullable TIER notSet, BiConsumer<T,TIER> setter, Function<T,TIER> getter, @Nullable List<String> description)
      Parameters:
      description - the description lang keys to attach to this element, or null for no description
      See Also:
    • ofBlockUnlocalizedName

      public static <T> IStructureElement<T> ofBlockUnlocalizedName(String modid, String unlocalizedName, int meta)
      Denote a block using unlocalized names. This can be useful to get around mod loading order issues.

      DUE TO HISTORICAL REASONS, THIS WAS CALLED ofBlockUnlocalizedName, BUT IT ACTUALLY USES REGISTRY NAME INSTEAD.

      While no immediate error will be thrown, client code should ensure said mod is loaded and said mod is present, otherwise bad things will happen later!

    • ofBlockUnlocalizedName

      public static <T> IStructureElement<T> ofBlockUnlocalizedName(String modid, String registryName, int meta, boolean wildcard)
      Denote a block using unlocalized names. This can be useful to get around mod loading order issues.

      DUE TO HISTORICAL REASONS, THIS WAS CALLED ofBlockUnlocalizedName, BUT IT ACTUALLY USES REGISTRY NAME INSTEAD.

      While no immediate error will be thrown, client code should ensure said mod is loaded and said mod is present, otherwise the element will effectively become an error().

      Will place block or hint using the given meta if wildcard is true.

    • ofBlockUnlocalizedName

      public static <T> IStructureElement<T> ofBlockUnlocalizedName(String modid, String unlocalizedName, int meta, IStructureElement<T> fallback)
      Similiar to the other overload, but allows client code to specify a fallback in case said block was not found later when the element got called.

      DUE TO HISTORICAL REASONS, THIS WAS CALLED ofBlockUnlocalizedName, BUT IT ACTUALLY USES REGISTRY NAME INSTEAD.

      This is slightly different to using the other overload and another element in a ofChain(IStructureElement[]). Here fallback will only ever be used if this fails, where ofChain would form an OR relationship even if the mod is loaded and the block exists in registry.

    • ofBlocksFlatHint

      public static <T> IStructureElementNoPlacement<T> ofBlocksFlatHint(Map<Block,Integer> blocsMap, Block hintBlock, int hintMeta)
      Accept a set of blocks. Less cumbersome to use than ofBlocksMapHint(Map, Block, int) when for any accepted block type we accept only one meta for each.

      Does not have autoplace.

      Parameters:
      blocsMap - Accepted (block, meta) pairs.
      hintBlock - hint block to use
      hintMeta - hint meta to use
      See Also:
    • ofBlocksMapHint

      public static <T> IStructureElementNoPlacement<T> ofBlocksMapHint(Map<Block, Collection<Integer>> blocsMap, Block hintBlock, int hintMeta)
      Accept a set of blocks.

      Does not have autoplace.

      Parameters:
      blocsMap - Accepted (block, meta) pairs.
      hintBlock - hint block to use
      hintMeta - hint meta to use
      See Also:
    • ofBlockHint

      public static <T> IStructureElementNoPlacement<T> ofBlockHint(Block block, int meta, Block hintBlock, int hintMeta)
      Accept one (block, meta). Spawn hint particles using an alternative block and meta. Not very useful...
    • ofBlockHint

      public static <T> IStructureElementNoPlacement<T> ofBlockHint(Block block, int meta)
      Accept one (block, meta). Same as ofBlock(Block, int), except it explicitly turns off creative/survival build.
    • ofBlockAdderHint

      public static <T> IStructureElementNoPlacement<T> ofBlockAdderHint(IBlockAdder<T> iBlockAdder, Block hintBlock, int hintMeta)
      Add a block using block adder. Spawn hints using given hint block and meta.

      Useful when your logic is very complex. Does not support autoplace.

    • ofBlocksFlat

      public static <T> IStructureElement<T> ofBlocksFlat(Map<Block,Integer> blocsMap, Block defaultBlock, int defaultMeta)
      Accept a set of blocks. Less cumbersome to use than ofBlocksMap(Map, Block, int) when for any accepted block type we accept only one meta for each.
      Parameters:
      blocsMap - Accepted (block, meta) pairs.
      defaultBlock - default block to place/spawn hint
      defaultMeta - default meta to place/spawn hint
      See Also:
    • ofBlocksMap

      public static <T> IStructureElement<T> ofBlocksMap(Map<Block, Collection<Integer>> blocsMap, Block defaultBlock, int defaultMeta)
      Accept a set of blocks.
      Parameters:
      blocsMap - Accepted (block, meta) pairs.
      defaultBlock - default block to place/spawn hint
      defaultMeta - default meta to place/spawn hint
      See Also:
    • ofBlock

      public static <T> IStructureElement<T> ofBlock(Block block, int meta, Block defaultBlock, int defaultMeta)
      Accept a block. Spawn hint/autoplace using another.
      Parameters:
      block - accepted block
      meta - accepted meta
      defaultBlock - hint block
      defaultMeta - hint meta
    • ofBlockAnyMeta

      public static <T> IStructureElement<T> ofBlockAnyMeta(Block block, Block defaultBlock, int defaultMeta)
      Same as ofBlock(Block, int, Block, int) but ignores target meta id
    • ofBlock

      public static <T> IStructureElement<T> ofBlock(Block block, int meta)
      Accept a single block with a fixed meta. Most primitive form of structure.
    • ofBlockAnyMeta

      public static <T> IStructureElement<T> ofBlockAnyMeta(Block block)
      Accept a single block, but accept any meta.
    • ofBlockAnyMeta

      public static <T> IStructureElement<T> ofBlockAnyMeta(Block block, int defaultMeta)
      Accept a single block, but accept any meta. Spawn hint/autoplace using given meta.
    • ofBlockAdder

      public static <T> IStructureElement<T> ofBlockAdder(IBlockAdder<T> iBlockAdder, Block defaultBlock, int defaultMeta)
      Add a block using block adder. Spawn hints/autoplace using given hint block and meta.

      Useful when your logic is very complex.

    • ofBlockAdder

      public static <T> IStructureElement<T> ofBlockAdder(IBlockAdder<T> iBlockAdder, int dots)
    • ofTileAdder

      public static <T> IStructureElementNoPlacement<T> ofTileAdder(ITileAdder<T> iTileAdder, Block hintBlock, int hintMeta)
      Try to add a structure element with a tile entity. Note that tile adder will be called with a null argument at locations without tile entity.
    • ofSpecificTileAdder

      public static <T,E> IStructureElementNoPlacement<T> ofSpecificTileAdder(BiPredicate<T,E> iTileAdder, Class<E> tileClass, Block hintBlock, int hintMeta)
      Try to add a structure element with a particular type of tile entity. Note that tile adder will not be called at locations without a tile entity.
    • onElementPass

      public static <B extends IStructureElement<T>, T> IStructureElement<T> onElementPass(Consumer<T> onCheckPass, B element)
      Call a callback if downstream element returned true in check.
      Parameters:
      onCheckPass - side effect
      element - downstream
    • withDescription

      public static <B extends IStructureElement<T>, T> IStructureElement<T> withDescription(@Nullable List<String> description, B element)
      Wraps an element and overrides its description. Useful for providing human-readable names to elements whose underlying implementation doesn't provide a description (e.g. tiered block elements).
      Parameters:
      description - the description to use, or null to clear any existing description
      element - the element to wrap
    • onElementFail

      public static <B extends IStructureElement<T>, T> IStructureElement<T> onElementFail(Consumer<T> onFail, B element)
      Call a callback if downstream element returned false in check.
      Parameters:
      onFail - side effect
      element - downstream
    • onlyIf

      public static <T> IStructureElement<T> onlyIf(Predicate<? super T> predicate, IStructureElement<? super T> downstream)
      Enable this structure element only if given predicate returns true.

      Return SKIP when survival auto place if given predicate returns false.

    • onlyIf

      public static <T> IStructureElement<T> onlyIf(Predicate<? super T> predicate, IStructureElement<? super T> downstream, IStructureElement.PlaceResult placeResultWhenDisabled)
      Enable this structure element only if given predicate returns true.
      Parameters:
      placeResultWhenDisabled - value to return for survival auto place when predicate returns false
    • ofChain

      @SafeVarargs public static <T> IStructureElementChain<T> ofChain(IStructureElement<T>... elementChain)
      This allows you to compose different IStructureElement to form a OR chain. As with any other OR operator, this one exhibits short-circuiting behavior, i.e. it will not call next structure element if previous one succeeded. (*)

      This allows you e.g. accept both a glass block using ofBlock(Block, int, Block, int) and a piece of air using isAir(). It will not attempt to capture any errors though, so next one will not be tried if previous one would crash.

      (*): For survival auto place, it will * REJECT, if all structure element REJECT * SKIP, if 1 or more structure element SKIP and the rest structure element (0 or more) REJECT * any other result, **immediately** upon any structure element returns these other results. This behavior is not 100% fixed and might change later on, but we will send the notice on a best effort basis.

      Take care while chaining, as it will try to call every structure element until it returns true. If none does it will finally return false.

    • ofChain

      public static <T> IStructureElementChain<T> ofChain(List<IStructureElement<T>> elementChain)
      This allows you to compose different IStructureElement to form a OR chain.

      Practically no difference with the other overload.

      See Also:
    • withContext

      public static <CTX, T extends IWithExtendedContext<CTX>> IStructureElement<T> withContext(IStructureElement<CTX> elem)
      Switch to the extended context object in the downstream element
      Type Parameters:
      CTX - extended context type
      T - existing context object type
      Parameters:
      elem - downstream element
    • lazy

      public static <T> IStructureElementDeferred<T> lazy(Supplier<IStructureElement<T>> to)
      Similar to defer, but caches the first returned element returned and won't call it again. Initialization is not thread safe. These both allow the structure element **constructor** to access properties only present on the context object (e.g. GT5 multiblock controller), e.g. hatch texture index to use. Use `lazy` if the data you access will remain constant across different context object.
    • lazy

      public static <T> IStructureElementDeferred<T> lazy(Function<T, IStructureElement<T>> to)
      This will defer the actual instantiation of structure element until the first time structure code is actually called.

      Similar to defer, but caches the first returned element returned and won't call it again. Initialization is not thread safe. This will allow the structure element constructor to access properties only present on the context object (e.g. GT5 multiblock controller), e.g. hatch texture index to use. Use this if the data you access will remain constant.

      Parameters:
      to - create structure element from the first context object passed in
    • defer

      public static <T> IStructureElementDeferred<T> defer(Supplier<IStructureElement<T>> to)
      This will defer the actual instantiation of structure element until the structure code is actually called. This will allow the structure element constructor to access properties only present on the context object (e.g. GT5 multiblock controller), e.g. hatch texture index to use. Use this if it might change for the same structure definition, e.g. if your structure might switch mode and change some parameter, while basically remain the same shape. Using this while lazy(Supplier) is enough will not break anything, but would incur unnecessary performance overhead.
      Parameters:
      to - downstream element supplier
    • defer

      public static <T> IStructureElementDeferred<T> defer(Function<T, IStructureElement<T>> to)
      This will defer the actual instantiation of structure element until the structure code is actually called. This will allow the structure element constructor to access properties only present on the context object (e.g. GT5 multiblock controller), e.g. hatch texture index to use. Use this if it might change for the same structure definition, e.g. if your structure might switch mode and change some parameter, while basically remain the same shape. Using this while lazy(Supplier) is enough will not break anything, but would incur unnecessary performance overhead.
      Parameters:
      to - downstream element supplier
    • defer

      @Deprecated public static <T,K> IStructureElementDeferred<T> defer(Function<T,K> keyExtractor, Map<K, IStructureElement<T>> map)
      Deprecated.
      renamed to partitionBy
      This is the switch block for structure code.

      This allows you to extract or compute a key from context object, and lookup a map for actual structure element to use.

      Parameters:
      keyExtractor - extract a key from the context object
      map - all possible structure element
    • partitionBy

      public static <T,K> IStructureElementDeferred<T> partitionBy(Function<T,K> keyExtractor, Map<K, IStructureElement<T>> map)
      This is the switch block for structure code.

      This allows you to extract or compute a key from context object, and lookup a map for actual structure element to use. This will usually, but not guaranteed, to throw an exception at runtime if keyExtractor returns a key not found in map.

      Do pay attention to what properties your map has though. You need to pay attention to how they consider equality and how they consider null key/values. Guava ImmutableMap is usually a good enough choice.

      Parameters:
      keyExtractor - extract a key from the context object
      map - all possible structure element
    • defer

      @Deprecated public static <T,K> IStructureElementDeferred<T> defer(Function<T,K> keyExtractor, Map<K, IStructureElement<T>> map, IStructureElement<T> defaultElem)
      Deprecated.
      renamed to partitionBy
      This is the switch block for structure code, with default case support.

      This allows you to extract or compute a key from context object, and lookup a map for actual structure element to use. The fallback will only be used when keyExtractor returns a value not found in given map. This will play nicely in combination with error()

      Do pay attention to what properties your map has though. You need to pay attention to how they consider equality and how they consider null key/values. Guava ImmutableMap is usually a good enough choice.

      Parameters:
      keyExtractor - extract a key from the context object
      map - all possible structure element
      defaultElem - element to use when keyExtractor returns a value not found in given map
    • partitionBy

      public static <T,K> IStructureElementDeferred<T> partitionBy(Function<T,K> keyExtractor, Map<K, IStructureElement<T>> map, IStructureElement<T> defaultElem)
      This is the switch block for structure code, with default case support.

      This allows you to extract or compute a key from context object, and lookup a map for actual structure element to use. The fallback will only be used when keyExtractor returns a value not found in given map. This will play nicely in combination with error()

      Do pay attention to what properties your map has though. You need to pay attention to how they consider equality and how they consider null key/values. Guava ImmutableMap is usually a good enough choice.

      Parameters:
      keyExtractor - extract a key from the context object
      map - all possible structure element
      defaultElem - element to use when keyExtractor returns a value not found in given map
    • defer

      @SafeVarargs @Deprecated public static <T> IStructureElementDeferred<T> defer(Function<T,Integer> keyExtractor, IStructureElement<T>... array)
      Deprecated.
      renamed to partitionBy
      This is the switch block for structure code.

      This allows you to extract or compute an index from context object, and lookup an array for actual structure element to use. This will usually, but not guaranteed, to throw an exception at runtime if keyExtractor returns an index not within the array bound

      Do pay place null values in the array.

      Parameters:
      keyExtractor - extract an index from the context object
      array - all possible structure element
    • partitionBy

      @SafeVarargs public static <T> IStructureElementDeferred<T> partitionBy(Function<T,Integer> keyExtractor, IStructureElement<T>... array)
      This is the switch block for structure code.

      This allows you to extract or compute an index from context object, and lookup an array for actual structure element to use. This will usually, but not guaranteed, to throw an exception at runtime if keyExtractor returns an index not within the array bound

      Do pay place null values in the array.

      Parameters:
      keyExtractor - extract an index from the context object
      array - all possible structure element
    • defer

      @Deprecated public static <T> IStructureElementDeferred<T> defer(Function<T,Integer> keyExtractor, List<IStructureElement<T>> array)
      Deprecated.
      renamed to partitionBy
      This is the switch block for structure code.

      This allows you to extract or compute an index from context object, and lookup an array for actual structure element to use. This will usually, but not guaranteed, to throw an exception at runtime if keyExtractor returns an index not within the array bound

      Do pay place null values in the array.

      Parameters:
      keyExtractor - extract an index from the context object
      array - all possible structure element
    • partitionBy

      public static <T> IStructureElementDeferred<T> partitionBy(Function<T,Integer> keyExtractor, List<IStructureElement<T>> array)
      This is the switch block for structure code.

      This allows you to extract or compute an index from context object, and lookup an array for actual structure element to use. This will usually, but not guaranteed, to throw an exception at runtime if keyExtractor returns an index not within the array bound

      Do pay place null values in the array.

      Parameters:
      keyExtractor - extract an index from the context object
      array - all possible structure element
    • defer

      public static <T> IStructureElementDeferred<T> defer(BiFunction<T, ItemStack, IStructureElement<T>> to)
      This will defer the actual instantiation of structure element until the structure code is actually called. This will allow the structure element constructor to access properties only present on the context object (e.g. GT5 multiblock controller), e.g. hatch texture index to use. Use this if it might change for the same structure definition, e.g. if your structure might switch mode and change some parameter, while basically remain the same shape. Using this while lazy(Supplier) is enough will not break anything, but would incur unnecessary performance overhead.

      This variant also passes the trigger item to the function, allowing it to get more info.

      Parameters:
      to - downstream element supplier
    • defer

      @Deprecated public static <T,K> IStructureElementDeferred<T> defer(BiFunction<T, ItemStack, K> keyExtractor, Map<K, IStructureElement<T>> map)
      Deprecated.
      renamed to partitionBy
      This is the switch block for structure code.

      This allows you to extract or compute a key from context object, and lookup a map for actual structure element to use. This will usually, but not guaranteed, to throw an exception at runtime if keyExtractor returns a key not found in map.

      Do pay attention to what properties your map has though. You need to pay attention to how they consider equality and how they consider null key/values. Guava ImmutableMap is usually a good enough choice.

      This variant also passes the trigger item to the function, allowing it to get more info.

      Parameters:
      keyExtractor - extract a key from the context object and trigger item
      map - all possible structure element
    • partitionBy

      public static <T,K> IStructureElementDeferred<T> partitionBy(BiFunction<T, ItemStack, K> keyExtractor, Map<K, IStructureElement<T>> map)
      This is the switch block for structure code.

      This allows you to extract or compute a key from context object, and lookup a map for actual structure element to use. This will usually, but not guaranteed, to throw an exception at runtime if keyExtractor returns a key not found in map.

      Do pay attention to what properties your map has though. You need to pay attention to how they consider equality and how they consider null key/values. Guava ImmutableMap is usually a good enough choice.

      This variant also passes the trigger item to the function, allowing it to get more info.

      Parameters:
      keyExtractor - extract a key from the context object and trigger item
      map - all possible structure element
    • defer

      @Deprecated public static <T,K> IStructureElementDeferred<T> defer(BiFunction<T, ItemStack, K> keyExtractor, Map<K, IStructureElement<T>> map, IStructureElement<T> defaultElem)
      Deprecated.
      renamed to partitionBy
      This is the switch block for structure code, with default case support.

      This allows you to extract or compute a key from context object, and lookup a map for actual structure element to use. The fallback will only be used when keyExtractor returns a value not found in given map. This will play nicely in combination with error()

      Do pay attention to what properties your map has though. You need to pay attention to how they consider equality and how they consider null key/values. Guava ImmutableMap is usually a good enough choice.

      This variant also passes the trigger item to the function, allowing it to get more info.

      Parameters:
      keyExtractor - extract a key from the context object and trigger item
      map - all possible structure element
      defaultElem - element to use when keyExtractor returns a value not found in given map
    • partitionBy

      public static <T,K> IStructureElementDeferred<T> partitionBy(BiFunction<T, ItemStack, K> keyExtractor, Map<K, IStructureElement<T>> map, IStructureElement<T> defaultElem)
      This is the switch block for structure code, with default case support.

      This allows you to extract or compute a key from context object, and lookup a map for actual structure element to use. The fallback will only be used when keyExtractor returns a value not found in given map. This will play nicely in combination with error()

      Do pay attention to what properties your map has though. You need to pay attention to how they consider equality and how they consider null key/values. Guava ImmutableMap is usually a good enough choice.

      This variant also passes the trigger item to the function, allowing it to get more info.

      Parameters:
      keyExtractor - extract a key from the context object and trigger item
      map - all possible structure element
      defaultElem - element to use when keyExtractor returns a value not found in given map
    • defer

      @SafeVarargs public static <T> IStructureElementDeferred<T> defer(BiFunction<T, ItemStack, Integer> keyExtractor, IStructureElement<T>... array)
      This is the switch block for structure code.

      This allows you to extract or compute an index from context object, and lookup an array for actual structure element to use. This will usually, but not guaranteed, to throw an exception at runtime if keyExtractor returns an index not within the array bound

      Do pay place null values in the array.

      This variant also passes the trigger item to the function, allowing it to get more info.

      Parameters:
      keyExtractor - extract a key from the context object and trigger item
      array - all possible structure element
    • defer

      public static <T> IStructureElementDeferred<T> defer(BiFunction<T, ItemStack, Integer> keyExtractor, List<IStructureElement<T>> array)
      This is the switch block for structure code.

      This allows you to extract or compute an index from context object, and lookup an array for actual structure element to use. This will usually, but not guaranteed, to throw an exception at runtime if keyExtractor returns an index not within the array bound

      Do pay place null values in the array.

      This variant also passes the trigger item to the function, allowing it to get more info.

      Parameters:
      keyExtractor - extract a key from the context object and trigger item
      array - all possible structure element
    • defer

      public static <T> IStructureElementDeferred<T> defer(Function<T, IStructureElement<T>> toCheck, BiFunction<T, ItemStack, IStructureElement<T>> to)
      This will defer the actual instantiation of structure element until the first time structure code is actually called.

      Similar to defer, but caches the first returned element returned and won't call it again. Initialization is not thread safe. This will allow the structure element constructor to access properties only present on the context object (e.g. GT5 multiblock controller), e.g. hatch texture index to use. Use this if the data you access will remain constant.

      This variant will override the check function of the structure element from second function with the one returned from the structure element from first function.

      Parameters:
      toCheck - override the check function with the returned element
      to - create structure element from the context object passed in
    • defer

      @Deprecated public static <T,K> IStructureElementDeferred<T> defer(Function<T,K> keyExtractorCheck, BiFunction<T, ItemStack, K> keyExtractor, Map<K, IStructureElement<T>> map)
      Deprecated.
      renamed to partitionBy
      This is the switch block for structure code.

      This allows you to extract or compute a key from context object, and lookup a map for actual structure element to use. This will usually, but not guaranteed, to throw an exception at runtime if keyExtractor returns a key not found in map.

      Do pay attention to what properties your map has though. You need to pay attention to how they consider equality and how they consider null key/values. Guava ImmutableMap is usually a good enough choice.

      This variant also passes the trigger item to the function, allowing it to get more info.

      This variant will override the check function of the structure element from second function with the one returned from the structure element from first function.

      Parameters:
      keyExtractorCheck - key extractor of the structure element that will be used for check.
      keyExtractor - extract a key from the context object and trigger item
      map - all possible structure element
    • partitionBy

      public static <T,K> IStructureElementDeferred<T> partitionBy(Function<T,K> keyExtractorCheck, BiFunction<T, ItemStack, K> keyExtractor, Map<K, IStructureElement<T>> map)
      This is the switch block for structure code.

      This allows you to extract or compute a key from context object, and lookup a map for actual structure element to use. This will usually, but not guaranteed, to throw an exception at runtime if keyExtractor returns a key not found in map.

      Do pay attention to what properties your map has though. You need to pay attention to how they consider equality and how they consider null key/values. Guava ImmutableMap is usually a good enough choice.

      This variant also passes the trigger item to the function, allowing it to get more info.

      This variant will override the check function of the structure element from second function with the one returned from the structure element from first function.

      Parameters:
      keyExtractorCheck - key extractor of the structure element that will be used for check.
      keyExtractor - extract a key from the context object and trigger item
      map - all possible structure element
    • defer

      @Deprecated public static <T,K> IStructureElementDeferred<T> defer(Function<T,K> keyExtractorCheck, BiFunction<T, ItemStack, K> keyExtractor, Map<K, IStructureElement<T>> map, IStructureElement<T> defaultElem)
      Deprecated.
      renamed to partitionBy
      This is the switch block for structure code, with default case.

      This allows you to extract or compute a key from context object, and lookup a map for actual structure element to use. defaultElem will be used if either extractor returned a key not found in map.

      Do pay attention to what properties your map has though. You need to pay attention to how they consider equality and how they consider null key/values. Guava ImmutableMap is usually a good enough choice.

      This variant also passes the trigger item to the function, allowing it to get more info.

      This variant will override the check function of the structure element from second function with the one returned from the structure element from first function.

      Parameters:
      keyExtractorCheck - key extractor of the structure element that will be used for check.
      keyExtractor - extract a key from the context object and trigger item
      map - all possible structure element
    • partitionBy

      public static <T,K> IStructureElementDeferred<T> partitionBy(Function<T,K> keyExtractorCheck, BiFunction<T, ItemStack, K> keyExtractor, Map<K, IStructureElement<T>> map, IStructureElement<T> defaultElem)
      This is the switch block for structure code, with default case.

      This allows you to extract or compute a key from context object, and lookup a map for actual structure element to use. defaultElem will be used if either extractor returned a key not found in map.

      Do pay attention to what properties your map has though. You need to pay attention to how they consider equality and how they consider null key/values. Guava ImmutableMap is usually a good enough choice.

      This variant also passes the trigger item to the function, allowing it to get more info.

      This variant will override the check function of the structure element from second function with the one returned from the structure element from first function.

      Parameters:
      keyExtractorCheck - key extractor of the structure element that will be used for check.
      keyExtractor - extract a key from the context object and trigger item
      map - all possible structure element
    • defer

      @SafeVarargs @Deprecated public static <T> IStructureElementDeferred<T> defer(Function<T,Integer> keyExtractorCheck, BiFunction<T, ItemStack, Integer> keyExtractor, IStructureElement<T>... array)
      Deprecated.
      renamed to partitionBy
      This is the switch block for structure code, with default case.

      This allows you to extract or compute an index from context object, and lookup an array for actual structure element to use. This will usually, but not guaranteed, to throw an exception at runtime if keyExtractor returns an index not within the array bound

      Do pay place null values in the array.

      This variant also passes the trigger item to the function, allowing it to get more info.

      This variant will override the check function of the structure element from second function with the one returned from the structure element from first function.

      Parameters:
      keyExtractorCheck - key extractor of the structure element that will be used for check.
      keyExtractor - extract a key from the context object and trigger item
      array - all possible structure element
    • partitionBy

      @SafeVarargs public static <T> IStructureElementDeferred<T> partitionBy(Function<T,Integer> keyExtractorCheck, BiFunction<T, ItemStack, Integer> keyExtractor, IStructureElement<T>... array)
      This is the switch block for structure code, with default case.

      This allows you to extract or compute an index from context object, and lookup an array for actual structure element to use. This will usually, but not guaranteed, to throw an exception at runtime if keyExtractor returns an index not within the array bound

      Do pay place null values in the array.

      This variant also passes the trigger item to the function, allowing it to get more info.

      This variant will override the check function of the structure element from second function with the one returned from the structure element from first function.

      Parameters:
      keyExtractorCheck - key extractor of the structure element that will be used for check.
      keyExtractor - extract a key from the context object and trigger item
      array - all possible structure element
    • defer

      @Deprecated public static <T> IStructureElementDeferred<T> defer(Function<T,Integer> keyExtractorCheck, BiFunction<T, ItemStack, Integer> keyExtractor, List<IStructureElement<T>> array)
      Deprecated.
      renamed to partitionBy
      This is the switch block for structure code, with default case.

      This allows you to extract or compute an index from context object, and lookup an array for actual structure element to use. This will usually, but not guaranteed, to throw an exception at runtime if keyExtractor returns an index not within the array bound

      This variant also passes the trigger item to the function, allowing it to get more info.

      This variant will override the check function of the structure element from second function with the one returned from the structure element from first function.

      Parameters:
      keyExtractorCheck - key extractor of the structure element that will be used for check.
      keyExtractor - extract a key from the context object and trigger item
      array - all possible structure element
    • partitionBy

      public static <T> IStructureElementDeferred<T> partitionBy(Function<T,Integer> keyExtractorCheck, BiFunction<T, ItemStack, Integer> keyExtractor, List<IStructureElement<T>> array)
      This is the switch block for structure code, with default case.

      This allows you to extract or compute an index from context object, and lookup an array for actual structure element to use. This will usually, but not guaranteed, to throw an exception at runtime if keyExtractor returns an index not within the array bound

      This variant also passes the trigger item to the function, allowing it to get more info.

      This variant will override the check function of the structure element from second function with the one returned from the structure element from first function.

      Parameters:
      keyExtractorCheck - key extractor of the structure element that will be used for check.
      keyExtractor - extract a key from the context object and trigger item
      array - all possible structure element
    • withChannel

      public static <T> IStructureElement<T> withChannel(String channel, IStructureElement<T> backing)
      See channels.md in docs folder
    • step

      public static <T> com.gtnewhorizon.structurelib.structure.IStructureNavigate<T> step(int a, int b, int c)
      Used internally, to generate skips for structure definitions
    • step

      public static <T> com.gtnewhorizon.structurelib.structure.IStructureNavigate<T> step(Vec3Impl step)
      Used internally, to generate skips for structure definitions
    • getPseudoJavaCode

      public static String getPseudoJavaCode(World world, ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB, int basePositionC, Function<? super TileEntity, String> tileEntityClassifier, int sizeA, int sizeB, int sizeC, boolean transpose)
      Used only to get pseudo code in structure writer...

      NOTE: GT specific code got removed. TODO add a mean

      Parameters:
      tileEntityClassifier - return a string that denote the type of a tile entity, or null if it's nothing special. useful if the tile entity cannot be simply distinguished via getClass.
    • iterate

      public static void iterate(World world, ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB, int basePositionC, int sizeA, int sizeB, int sizeC, IBlockPosConsumer iBlockPosConsumer)
    • iterate

      public static void iterate(World world, ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB, int basePositionC, boolean transpose, int sizeA, int sizeB, int sizeC, IBlockPosConsumer iBlockPosConsumer, Runnable nextB, Runnable nextC)
    • transpose

      public static String[][] transpose(String[][] structurePiece)
      Transposes shape (swaps B and C axis, can be used to un-transpose transposed shape) WARNING! Do not use on old api...
      Parameters:
      structurePiece - shape (transposed shape)
      Returns:
      transposed shape (untransposed shape)