Class StructureUtility
- java.lang.Object
-
- com.gtnewhorizon.structurelib.structure.StructureUtility
-
public class StructureUtility extends java.lang.ObjectA brief index of everything containedControl blocks
A lot of these might seem to make more sense as a default function onIStructureElement. However, in that case javac generic will often fail to infer the type for you, so we have to define them as static methodsIf block
Provide if block, allowing downstream call only if user specified conditions are meet (i.e. predicate returns true)onlyIf(Predicate, IStructureElement)and its overloads
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.partitionBy(Function, IStructureElement[])and its overloads
Or Chain
Provide a short-circuiting OR chain.ofChain(IStructureElement[])and its overloads
Side effect
Provide callbacks on various occasiononElementPass(Consumer, IStructureElement): Call an callback upon element check successonElementFail(Consumer, IStructureElement): Call an callback upon element check failure
Other Primitives
Error statement
Unconditionally return false.Context Object Change
Switch the context object.withContext(IStructureElement): switch context to the extended context
Channel Change
Change the channel. See Channels section on overview for more information.withChannel(String, IStructureElement): switch channel usingChannelDataAccessor.withChannel(ItemStack, String)when a trigger item is present.
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.ofHint(int),ofHintDeferred(Supplier)and its overloads
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 customIStructureElementimplementations.Simple Block Element
These accept one or more different block types in one location.ofBlock(Block, int, Block, int),ofBlocksFlat(Map, Block, int),ofBlocksMap(Map, Block, int)and their overloads: the most basic formofBlockHint(Block, int, Block, int),ofBlocksFlatHint(Map, Block, int),ofBlocksMapHint(Map, Block, int): these are the same as above, but will not do autoplaceisAir(),notAir(): They are supplied by default under the identifier'-'and'+'respectively, but are provided here regardless in case you want to use them as a fallback.
Complex Block Element
In case your logic on determining which block is accepted is complex, use these.ofBlockAdder(IBlockAdder, Block, int),ofBlockAdderHint(IBlockAdder, Block, int)and their overloads: hands off actual adder logic to anIBlockAdderyou supplied. Save you the boilerplate of querying block type and block meta fromWorldofBlocksTiered(ITierConverter, Object, BiConsumer, Function)and its overloads: accept a series of blocks that each may have different tier, but only allow one single tier for anywhere this element is used (e.g. coils).ofTileAdder(ITileAdder, Block, int),ofSpecificTileAdder(BiPredicate, Class, Block, int): Similar to block adder, but for tile entities.
Helper Methods
These don't construct aIStructureElement, but is helpful to the instantiation or implementation of these.survivalPlaceBlock(Block, int, World, int, int, int, IItemSource, EntityPlayer, Consumer)and its overloads: Helper method to cut common boilerplate for implementingIStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)getPseudoJavaCode(World, ExtendedFacing, int, int, int, int, int, int, Function, int, int, int, boolean): Generate a structure code template from existing structure.iterate(World, ExtendedFacing, int, int, int, int, int, int, boolean, int, int, int, IBlockPosConsumer, Runnable, Runnable)and its overloads: help iterate over a coordinate space.
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T> IStructureElementDeferred<T>defer(java.util.function.BiFunction<T,ItemStack,IStructureElement<T>> to)This will defer the actual instantiation of structure element until the structure code is actually called.static <T> IStructureElementDeferred<T>defer(java.util.function.BiFunction<T,ItemStack,java.lang.Integer> keyExtractor, IStructureElement<T>... array)This is the switch block for structure code.static <T> IStructureElementDeferred<T>defer(java.util.function.BiFunction<T,ItemStack,java.lang.Integer> keyExtractor, java.util.List<IStructureElement<T>> array)This is the switch block for structure code.static <T,K>
IStructureElementDeferred<T>defer(java.util.function.BiFunction<T,ItemStack,K> keyExtractor, java.util.Map<K,IStructureElement<T>> map)Deprecated.renamed to partitionBystatic <T,K>
IStructureElementDeferred<T>defer(java.util.function.BiFunction<T,ItemStack,K> keyExtractor, java.util.Map<K,IStructureElement<T>> map, IStructureElement<T> defaultElem)Deprecated.renamed to partitionBystatic <T> IStructureElementDeferred<T>defer(java.util.function.Function<T,IStructureElement<T>> to)This will defer the actual instantiation of structure element until the structure code is actually called.static <T> IStructureElementDeferred<T>defer(java.util.function.Function<T,IStructureElement<T>> toCheck, java.util.function.BiFunction<T,ItemStack,IStructureElement<T>> to)This will defer the actual instantiation of structure element until the first time structure code is actually called.static <T> IStructureElementDeferred<T>defer(java.util.function.Function<T,java.lang.Integer> keyExtractor, IStructureElement<T>... array)Deprecated.renamed to partitionBystatic <T> IStructureElementDeferred<T>defer(java.util.function.Function<T,java.lang.Integer> keyExtractorCheck, java.util.function.BiFunction<T,ItemStack,java.lang.Integer> keyExtractor, IStructureElement<T>... array)Deprecated.renamed to partitionBystatic <T> IStructureElementDeferred<T>defer(java.util.function.Function<T,java.lang.Integer> keyExtractorCheck, java.util.function.BiFunction<T,ItemStack,java.lang.Integer> keyExtractor, java.util.List<IStructureElement<T>> array)Deprecated.renamed to partitionBystatic <T> IStructureElementDeferred<T>defer(java.util.function.Function<T,java.lang.Integer> keyExtractor, java.util.List<IStructureElement<T>> array)Deprecated.renamed to partitionBystatic <T,K>
IStructureElementDeferred<T>defer(java.util.function.Function<T,K> keyExtractorCheck, java.util.function.BiFunction<T,ItemStack,K> keyExtractor, java.util.Map<K,IStructureElement<T>> map)Deprecated.renamed to partitionBystatic <T,K>
IStructureElementDeferred<T>defer(java.util.function.Function<T,K> keyExtractorCheck, java.util.function.BiFunction<T,ItemStack,K> keyExtractor, java.util.Map<K,IStructureElement<T>> map, IStructureElement<T> defaultElem)Deprecated.renamed to partitionBystatic <T,K>
IStructureElementDeferred<T>defer(java.util.function.Function<T,K> keyExtractor, java.util.Map<K,IStructureElement<T>> map)Deprecated.renamed to partitionBystatic <T,K>
IStructureElementDeferred<T>defer(java.util.function.Function<T,K> keyExtractor, java.util.Map<K,IStructureElement<T>> map, IStructureElement<T> defaultElem)Deprecated.renamed to partitionBystatic <T> IStructureElementDeferred<T>defer(java.util.function.Supplier<IStructureElement<T>> to)This will defer the actual instantiation of structure element until the structure code is actually called.static <T> IStructureElement<T>error()Check returns false.static java.lang.StringgetPseudoJavaCode(World world, ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB, int basePositionC, java.util.function.Function<? super TileEntity,java.lang.String> tileEntityClassifier, int sizeA, int sizeB, int sizeC, boolean transpose)Used only to get pseudo code in structure writer...static <T> IStructureElement<T>isAir()Return a structure element that only allow air (or air equivalents, like Railcraft hidden blocks).static voiditerate(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, java.lang.Runnable nextB, java.lang.Runnable nextC)static voiditerate(World world, ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB, int basePositionC, int sizeA, int sizeB, int sizeC, IBlockPosConsumer iBlockPosConsumer)static <T> IStructureElementDeferred<T>lazy(java.util.function.Function<T,IStructureElement<T>> to)This will defer the actual instantiation of structure element until the first time structure code is actually called.static <T> IStructureElementDeferred<T>lazy(java.util.function.Supplier<IStructureElement<T>> to)Similar to defer, but caches the first returned element returned and won't call it again.static <T> IStructureElement<T>notAir()Return a structure element that allow anything but air (or air equivalents, like Railcraft hidden blocks).static <T> IStructureElement<T>ofBlock(Block block, int meta)Accept a single block with a fixed meta.static <T> IStructureElement<T>ofBlock(Block block, int meta, Block defaultBlock, int defaultMeta)Accept a block.static <T> IStructureElement<T>ofBlockAdder(IBlockAdder<T> iBlockAdder, int dots)static <T> IStructureElement<T>ofBlockAdder(IBlockAdder<T> iBlockAdder, Block defaultBlock, int defaultMeta)Add a block using block adder.static <T> IStructureElementNoPlacement<T>ofBlockAdderHint(IBlockAdder<T> iBlockAdder, Block hintBlock, int hintMeta)Add a block using block adder.static <T> IStructureElement<T>ofBlockAnyMeta(Block block)Accept a single block, but accept any meta.static <T> IStructureElement<T>ofBlockAnyMeta(Block block, int defaultMeta)Accept a single block, but accept any meta.static <T> IStructureElement<T>ofBlockAnyMeta(Block block, Block defaultBlock, int defaultMeta)Same asofBlock(Block, int, Block, int)but ignores target meta idstatic <T> IStructureElementNoPlacement<T>ofBlockHint(Block block, int meta)Accept one (block, meta).static <T> IStructureElementNoPlacement<T>ofBlockHint(Block block, int meta, Block hintBlock, int hintMeta)Accept one (block, meta).static <T> IStructureElement<T>ofBlocksFlat(java.util.Map<Block,java.lang.Integer> blocsMap, Block defaultBlock, int defaultMeta)Accept a set of blocks.static <T> IStructureElementNoPlacement<T>ofBlocksFlatHint(java.util.Map<Block,java.lang.Integer> blocsMap, Block hintBlock, int hintMeta)Accept a set of blocks.static <T> IStructureElement<T>ofBlocksMap(java.util.Map<Block,java.util.Collection<java.lang.Integer>> blocsMap, Block defaultBlock, int defaultMeta)Accept a set of blocks.static <T> IStructureElementNoPlacement<T>ofBlocksMapHint(java.util.Map<Block,java.util.Collection<java.lang.Integer>> blocsMap, Block hintBlock, int hintMeta)Accept a set of blocks.static <T,TIER>
IStructureElement<T>ofBlocksTiered(ITierConverter<TIER> tierExtractor, java.util.List<org.apache.commons.lang3.tuple.Pair<Block,java.lang.Integer>> allKnownTiers, TIER notSet, java.util.function.BiConsumer<T,TIER> setter, java.util.function.Function<T,TIER> getter)Element representing a component with different tiers.static <T,TIER>
IStructureElementCheckOnly<T>ofBlocksTiered(ITierConverter<TIER> tierExtractor, TIER notSet, java.util.function.BiConsumer<T,TIER> setter, java.util.function.Function<T,TIER> getter)A more primitive variant ofofBlocksTiered(ITierConverter, List, Object, BiConsumer, Function)Main difference is this one is check only.static <T> IStructureElement<T>ofBlockUnlocalizedName(java.lang.String modid, java.lang.String unlocalizedName, int meta)Denote a block using unlocalized names.static <T> IStructureElement<T>ofBlockUnlocalizedName(java.lang.String modid, java.lang.String registryName, int meta, boolean wildcard)Denote a block using unlocalized names.static <T> IStructureElement<T>ofBlockUnlocalizedName(java.lang.String modid, java.lang.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.static <T> IStructureElementChain<T>ofChain(IStructureElement<T>... elementChain)This allows you to compose differentIStructureElementto form a OR chain.static <T> IStructureElementChain<T>ofChain(java.util.List<IStructureElement<T>> elementChain)This allows you to compose differentIStructureElementto form a OR chain.static <T> IStructureElementNoPlacement<T>ofHint(int dots)Spawn a hint with given amount of dots.static <T> IStructureElementNoPlacement<T>ofHintDeferred(java.util.function.Supplier<IIcon[]> icons)Spawn a hint with given textures.static <T> IStructureElementNoPlacement<T>ofHintDeferred(java.util.function.Supplier<IIcon[]> icons, short[] RGBa)Spawn a hint with given amount of textures and tint.static <T,E>
IStructureElementNoPlacement<T>ofSpecificTileAdder(java.util.function.BiPredicate<T,E> iTileAdder, java.lang.Class<E> tileClass, Block hintBlock, int hintMeta)Try to add a structure element with a particular type of tile entity.static <T> IStructureElementNoPlacement<T>ofTileAdder(ITileAdder<T> iTileAdder, Block hintBlock, int hintMeta)Try to add a structure element with a tile entity.static <B extends IStructureElement<T>,T>
IStructureElement<T>onElementFail(java.util.function.Consumer<T> onFail, B element)Call a callback if downstream element returned false in check.static <B extends IStructureElement<T>,T>
IStructureElement<T>onElementPass(java.util.function.Consumer<T> onCheckPass, B element)Call a callback if downstream element returned true in check.static <T> IStructureElement<T>onlyIf(java.util.function.Predicate<? super T> predicate, IStructureElement<? super T> downstream)Enable this structure element only if given predicate returns true.static <T> IStructureElement<T>onlyIf(java.util.function.Predicate<? super T> predicate, IStructureElement<? super T> downstream, IStructureElement.PlaceResult placeResultWhenDisabled)Enable this structure element only if given predicate returns true.static <T,K>
IStructureElementDeferred<T>partitionBy(java.util.function.BiFunction<T,ItemStack,K> keyExtractor, java.util.Map<K,IStructureElement<T>> map)This is the switch block for structure code.static <T,K>
IStructureElementDeferred<T>partitionBy(java.util.function.BiFunction<T,ItemStack,K> keyExtractor, java.util.Map<K,IStructureElement<T>> map, IStructureElement<T> defaultElem)This is the switch block for structure code, with default case support.static <T> IStructureElementDeferred<T>partitionBy(java.util.function.Function<T,java.lang.Integer> keyExtractor, IStructureElement<T>... array)This is the switch block for structure code.static <T> IStructureElementDeferred<T>partitionBy(java.util.function.Function<T,java.lang.Integer> keyExtractorCheck, java.util.function.BiFunction<T,ItemStack,java.lang.Integer> keyExtractor, IStructureElement<T>... array)This is the switch block for structure code, with default case.static <T> IStructureElementDeferred<T>partitionBy(java.util.function.Function<T,java.lang.Integer> keyExtractorCheck, java.util.function.BiFunction<T,ItemStack,java.lang.Integer> keyExtractor, java.util.List<IStructureElement<T>> array)This is the switch block for structure code, with default case.static <T> IStructureElementDeferred<T>partitionBy(java.util.function.Function<T,java.lang.Integer> keyExtractor, java.util.List<IStructureElement<T>> array)This is the switch block for structure code.static <T,K>
IStructureElementDeferred<T>partitionBy(java.util.function.Function<T,K> keyExtractorCheck, java.util.function.BiFunction<T,ItemStack,K> keyExtractor, java.util.Map<K,IStructureElement<T>> map)This is the switch block for structure code.static <T,K>
IStructureElementDeferred<T>partitionBy(java.util.function.Function<T,K> keyExtractorCheck, java.util.function.BiFunction<T,ItemStack,K> keyExtractor, java.util.Map<K,IStructureElement<T>> map, IStructureElement<T> defaultElem)This is the switch block for structure code, with default case.static <T,K>
IStructureElementDeferred<T>partitionBy(java.util.function.Function<T,K> keyExtractor, java.util.Map<K,IStructureElement<T>> map)This is the switch block for structure code.static <T,K>
IStructureElementDeferred<T>partitionBy(java.util.function.Function<T,K> keyExtractor, java.util.Map<K,IStructureElement<T>> map, IStructureElement<T> defaultElem)This is the switch block for structure code, with default case support.static <T> com.gtnewhorizon.structurelib.structure.IStructureNavigate<T>step(int a, int b, int c)Used internally, to generate skips for structure definitionsstatic <T> com.gtnewhorizon.structurelib.structure.IStructureNavigate<T>step(Vec3Impl step)Used internally, to generate skips for structure definitionsstatic IStructureElement.PlaceResultsurvivalPlaceBlock(Block block, int meta, World world, int x, int y, int z, IItemSource s, EntityPlayer actor)This is a helper method for implementingIStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)static IStructureElement.PlaceResultsurvivalPlaceBlock(Block block, int meta, World world, int x, int y, int z, IItemSource s, EntityPlayerMP actor)This is a helper method for implementingIStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)static IStructureElement.PlaceResultsurvivalPlaceBlock(Block block, int meta, World world, int x, int y, int z, IItemSource s, EntityPlayerMP actor, java.util.function.Consumer<IChatComponent> chatter)This is a helper method for implementingIStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)static IStructureElement.PlaceResultsurvivalPlaceBlock(Block block, int meta, World world, int x, int y, int z, IItemSource s, EntityPlayer actor, java.util.function.Consumer<IChatComponent> chatter)This is a helper method for implementingIStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)static IStructureElement.PlaceResultsurvivalPlaceBlock(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 implementingIStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)static IStructureElement.PlaceResultsurvivalPlaceBlock(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 implementingIStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)static IStructureElement.PlaceResultsurvivalPlaceBlock(ItemStack stack, ItemStackPredicate.NBTMode nbtMode, NBTTagCompound tag, boolean assumeStackPresent, World world, int x, int y, int z, IItemSource s, EntityPlayerMP actor, java.util.function.Consumer<IChatComponent> chatter)This is a helper method for implementingIStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)static IStructureElement.PlaceResultsurvivalPlaceBlock(ItemStack stack, ItemStackPredicate.NBTMode nbtMode, NBTTagCompound tag, boolean assumeStackPresent, World world, int x, int y, int z, IItemSource s, EntityPlayer actor, java.util.function.Consumer<IChatComponent> chatter)This is a helper method for implementingIStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)static java.lang.String[][]transpose(java.lang.String[][] structurePiece)Transposes shape (swaps B and C axis, can be used to un-transpose transposed shape) WARNING! Do not use on old api...static <T> IStructureElement<T>withChannel(java.lang.String channel, IStructureElement<T> backing)See channels.md in docs folderstatic <CTX,T extends IWithExtendedContext<CTX>>
IStructureElement<T>withContext(IStructureElement<CTX> elem)Switch to the extended context object in the downstream element
-
-
-
Method Detail
-
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 implementingIStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)This method will try to look up an
ItemBlockfor given block and meta fromsand 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 placeactor- 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 implementingIStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)This method will try to look up an
ItemBlockfor given block and meta fromsand 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 placeactor- 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, java.util.function.Consumer<IChatComponent> chatter)
This is a helper method for implementingIStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)This method will try to look up an
ItemBlockfor given block and meta fromsand 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 placeactor- 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, java.util.function.Consumer<IChatComponent> chatter)
This is a helper method for implementingIStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)This method will try to look up an
ItemBlockfor given block and meta fromsand 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 placeactor- 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 implementingIStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)This method will try to look up an
ItemBlockfor given block and meta fromsand 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 placeactor- 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 implementingIStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)This method will try to look up an
ItemBlockfor given block and meta fromsand 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 placeactor- 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 java.util.function.Consumer<IChatComponent> chatter)
This is a helper method for implementingIStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)This method will try to look up an
ItemBlockfor given block and meta fromsand 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 placeactor- 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 java.util.function.Consumer<IChatComponent> chatter)
This is a helper method for implementingIStructureElement.survivalPlaceBlock(Object, World, int, int, int, ItemStack, IItemSource, EntityPlayerMP, Consumer)This method will try to look up an
ItemBlockfor given block and meta fromsand 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 placeactor- 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(java.util.function.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(java.util.function.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, java.util.function.BiConsumer<T,TIER> setter, java.util.function.Function<T,TIER> getter)
A more primitive variant ofofBlocksTiered(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.
-
ofBlocksTiered
public static <T,TIER> IStructureElement<T> ofBlocksTiered(ITierConverter<TIER> tierExtractor, @Nullable java.util.List<org.apache.commons.lang3.tuple.Pair<Block,java.lang.Integer>> allKnownTiers, @Nullable TIER notSet, java.util.function.BiConsumer<T,TIER> setter, java.util.function.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 them (*)), but would like to know which is used. Player can use more blueprint to get hints denoting more advanced components.(*): 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)
Above all else, you need to decide what tier you are going to use. For simpler cases, Integer is a good choice. You can also use an existing Enum. Tier can never be null though. It can also be a String or a
ResourceLocation, or basically anything. It doesn't even have to implementComparable.This assumes you will reset the backing storage, and on the first occurrence getter would return notSet. You can also make getter to return other value to forcefully select a certain tier, but you're probably better off using block adders or
ofBlock(Block, int, Block, int)and its overloadsImplementation wise, this allows a block only when we don't yet have a tier, or the block at that location has the same tier as we already have.
There is yet no TileEntity counterpart of this utility. Feel free to submit a PR to add it.
For most typical use cases, you will NOT want to return notSet from your tierExtractor. If you do so, we will have this kind of chain of events:
- at check start, tier is reset to notSet
- at first occurrence, ofBlocksTiered finds your current tier is notSet, and the block's tier is notSet, 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:
Assume you have 16 tier, each map to one 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); } }- 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.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, uselazy(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 fromgetterwhen there were no tier info found in T yet. Can be null.getter- a function to retrieve the current tier from context objectsetter- a function to set the current tier into context object
-
ofBlockUnlocalizedName
public static <T> IStructureElement<T> ofBlockUnlocalizedName(java.lang.String modid, java.lang.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(java.lang.String modid, java.lang.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(java.lang.String modid, java.lang.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(java.util.Map<Block,java.lang.Integer> blocsMap, Block hintBlock, int hintMeta)
Accept a set of blocks. Less cumbersome to use thanofBlocksMapHint(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 usehintMeta- hint meta to use- See Also:
ofBlocksMapHint(Map, Block, int)
-
ofBlocksMapHint
public static <T> IStructureElementNoPlacement<T> ofBlocksMapHint(java.util.Map<Block,java.util.Collection<java.lang.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 usehintMeta- hint meta to use- See Also:
ofBlocksFlatHint(Map, Block, int)
-
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 asofBlock(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(java.util.Map<Block,java.lang.Integer> blocsMap, Block defaultBlock, int defaultMeta)
Accept a set of blocks. Less cumbersome to use thanofBlocksMap(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 hintdefaultMeta- default meta to place/spawn hint- See Also:
ofBlocksMapHint(Map, Block, int)
-
ofBlocksMap
public static <T> IStructureElement<T> ofBlocksMap(java.util.Map<Block,java.util.Collection<java.lang.Integer>> blocsMap, Block defaultBlock, int defaultMeta)
Accept a set of blocks.- Parameters:
blocsMap- Accepted (block, meta) pairs.defaultBlock- default block to place/spawn hintdefaultMeta- default meta to place/spawn hint- See Also:
ofBlocksMapHint(Map, Block, int)
-
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 blockmeta- accepted metadefaultBlock- hint blockdefaultMeta- hint meta
-
ofBlockAnyMeta
public static <T> IStructureElement<T> ofBlockAnyMeta(Block block, Block defaultBlock, int defaultMeta)
Same asofBlock(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(java.util.function.BiPredicate<T,E> iTileAdder, java.lang.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(java.util.function.Consumer<T> onCheckPass, B element)
Call a callback if downstream element returned true in check.- Parameters:
onCheckPass- side effectelement- downstream
-
onElementFail
public static <B extends IStructureElement<T>,T> IStructureElement<T> onElementFail(java.util.function.Consumer<T> onFail, B element)
Call a callback if downstream element returned false in check.- Parameters:
onFail- side effectelement- downstream
-
onlyIf
public static <T> IStructureElement<T> onlyIf(java.util.function.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(java.util.function.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 differentIStructureElementto 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 usingisAir(). 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(java.util.List<IStructureElement<T>> elementChain)
This allows you to compose differentIStructureElementto form a OR chain.Practically no difference with the other overload.
- See Also:
ofChain(IStructureElement[])
-
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 typeT- existing context object type- Parameters:
elem- downstream element
-
lazy
public static <T> IStructureElementDeferred<T> lazy(java.util.function.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(java.util.function.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(java.util.function.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 whilelazy(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(java.util.function.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 whilelazy(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(java.util.function.Function<T,K> keyExtractor, java.util.Map<K,IStructureElement<T>> map)
Deprecated.renamed to partitionByThis 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 objectmap- all possible structure element
-
partitionBy
public static <T,K> IStructureElementDeferred<T> partitionBy(java.util.function.Function<T,K> keyExtractor, java.util.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 objectmap- all possible structure element
-
defer
@Deprecated public static <T,K> IStructureElementDeferred<T> defer(java.util.function.Function<T,K> keyExtractor, java.util.Map<K,IStructureElement<T>> map, IStructureElement<T> defaultElem)
Deprecated.renamed to partitionByThis 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 objectmap- all possible structure elementdefaultElem- element to use when keyExtractor returns a value not found in given map
-
partitionBy
public static <T,K> IStructureElementDeferred<T> partitionBy(java.util.function.Function<T,K> keyExtractor, java.util.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 objectmap- all possible structure elementdefaultElem- element to use when keyExtractor returns a value not found in given map
-
defer
@SafeVarargs @Deprecated public static <T> IStructureElementDeferred<T> defer(java.util.function.Function<T,java.lang.Integer> keyExtractor, IStructureElement<T>... array)
Deprecated.renamed to partitionByThis 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 objectarray- all possible structure element
-
partitionBy
@SafeVarargs public static <T> IStructureElementDeferred<T> partitionBy(java.util.function.Function<T,java.lang.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 objectarray- all possible structure element
-
defer
@Deprecated public static <T> IStructureElementDeferred<T> defer(java.util.function.Function<T,java.lang.Integer> keyExtractor, java.util.List<IStructureElement<T>> array)
Deprecated.renamed to partitionByThis 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 objectarray- all possible structure element
-
partitionBy
public static <T> IStructureElementDeferred<T> partitionBy(java.util.function.Function<T,java.lang.Integer> keyExtractor, java.util.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 objectarray- all possible structure element
-
defer
public static <T> IStructureElementDeferred<T> defer(java.util.function.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 whilelazy(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(java.util.function.BiFunction<T,ItemStack,K> keyExtractor, java.util.Map<K,IStructureElement<T>> map)
Deprecated.renamed to partitionByThis 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 itemmap- all possible structure element
-
partitionBy
public static <T,K> IStructureElementDeferred<T> partitionBy(java.util.function.BiFunction<T,ItemStack,K> keyExtractor, java.util.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 itemmap- all possible structure element
-
defer
@Deprecated public static <T,K> IStructureElementDeferred<T> defer(java.util.function.BiFunction<T,ItemStack,K> keyExtractor, java.util.Map<K,IStructureElement<T>> map, IStructureElement<T> defaultElem)
Deprecated.renamed to partitionByThis 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 itemmap- all possible structure elementdefaultElem- element to use when keyExtractor returns a value not found in given map
-
partitionBy
public static <T,K> IStructureElementDeferred<T> partitionBy(java.util.function.BiFunction<T,ItemStack,K> keyExtractor, java.util.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 itemmap- all possible structure elementdefaultElem- element to use when keyExtractor returns a value not found in given map
-
defer
@SafeVarargs public static <T> IStructureElementDeferred<T> defer(java.util.function.BiFunction<T,ItemStack,java.lang.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 itemarray- all possible structure element
-
defer
public static <T> IStructureElementDeferred<T> defer(java.util.function.BiFunction<T,ItemStack,java.lang.Integer> keyExtractor, java.util.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 itemarray- all possible structure element
-
defer
public static <T> IStructureElementDeferred<T> defer(java.util.function.Function<T,IStructureElement<T>> toCheck, java.util.function.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 elementto- create structure element from the context object passed in
-
defer
@Deprecated public static <T,K> IStructureElementDeferred<T> defer(java.util.function.Function<T,K> keyExtractorCheck, java.util.function.BiFunction<T,ItemStack,K> keyExtractor, java.util.Map<K,IStructureElement<T>> map)
Deprecated.renamed to partitionByThis 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 itemmap- all possible structure element
-
partitionBy
public static <T,K> IStructureElementDeferred<T> partitionBy(java.util.function.Function<T,K> keyExtractorCheck, java.util.function.BiFunction<T,ItemStack,K> keyExtractor, java.util.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 itemmap- all possible structure element
-
defer
@Deprecated public static <T,K> IStructureElementDeferred<T> defer(java.util.function.Function<T,K> keyExtractorCheck, java.util.function.BiFunction<T,ItemStack,K> keyExtractor, java.util.Map<K,IStructureElement<T>> map, IStructureElement<T> defaultElem)
Deprecated.renamed to partitionByThis 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 itemmap- all possible structure element
-
partitionBy
public static <T,K> IStructureElementDeferred<T> partitionBy(java.util.function.Function<T,K> keyExtractorCheck, java.util.function.BiFunction<T,ItemStack,K> keyExtractor, java.util.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 itemmap- all possible structure element
-
defer
@SafeVarargs @Deprecated public static <T> IStructureElementDeferred<T> defer(java.util.function.Function<T,java.lang.Integer> keyExtractorCheck, java.util.function.BiFunction<T,ItemStack,java.lang.Integer> keyExtractor, IStructureElement<T>... array)
Deprecated.renamed to partitionByThis 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 itemarray- all possible structure element
-
partitionBy
@SafeVarargs public static <T> IStructureElementDeferred<T> partitionBy(java.util.function.Function<T,java.lang.Integer> keyExtractorCheck, java.util.function.BiFunction<T,ItemStack,java.lang.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 itemarray- all possible structure element
-
defer
@Deprecated public static <T> IStructureElementDeferred<T> defer(java.util.function.Function<T,java.lang.Integer> keyExtractorCheck, java.util.function.BiFunction<T,ItemStack,java.lang.Integer> keyExtractor, java.util.List<IStructureElement<T>> array)
Deprecated.renamed to partitionByThis 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 itemarray- all possible structure element
-
partitionBy
public static <T> IStructureElementDeferred<T> partitionBy(java.util.function.Function<T,java.lang.Integer> keyExtractorCheck, java.util.function.BiFunction<T,ItemStack,java.lang.Integer> keyExtractor, java.util.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 itemarray- all possible structure element
-
withChannel
public static <T> IStructureElement<T> withChannel(java.lang.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 java.lang.String getPseudoJavaCode(World world, ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB, int basePositionC, java.util.function.Function<? super TileEntity,java.lang.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, java.lang.Runnable nextB, java.lang.Runnable nextC)
-
transpose
public static java.lang.String[][] transpose(java.lang.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)
-
-