Package redempt.redlib.multiblock
Class MultiBlockStructure
java.lang.Object
redempt.redlib.multiblock.MultiBlockStructure
A utility class intended to create interactive multi-block structures.
Can also be used to store and copy large sections of blocks.
-
Field Summary
Modifier and TypeFieldDescriptionprotected StructureData[][][]
protected int
protected int
protected int
protected boolean
protected boolean
protected EnumSet<org.bukkit.Material>
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addStrictModeExclusions
(org.bukkit.Material... materials) Add a list of Materials to be excluded from strict data checks rather than disabling strict mode for all blocksassumeAt
(org.bukkit.Location loc) Gets the Structure at the given block, performing no checks to ensure it exists.assumeAt
(org.bukkit.Location loc, int rotation) Gets the Structure at the given block, performing no checks to ensure it exists.assumeAt
(org.bukkit.Location loc, int rotation, boolean mirror) Gets the Structure at the given block, performing no checks to ensure it exists.assumeAt
(org.bukkit.Location loc, int relX, int relY, int relZ, int rotation, boolean mirror) Gets the Structure at the given block, performing no checks to ensure it exists.build
(org.bukkit.Location loc) Builds this multi-block structure at the given locationbuild
(org.bukkit.Location loc, int rotation) Builds this multi-block structure at the given locationbuild
(org.bukkit.Location loc, int relX, int relY, int relZ) Builds this multi-block structure at the given locationbuild
(org.bukkit.Location loc, int relX, int relY, int relZ, int rotation) Builds this multi-block structure at the given locationbuild
(org.bukkit.Location loc, int relX, int relY, int relZ, int rotation, boolean mirror) Builds this multi-block structure at the given locationint
buildAsync
(org.bukkit.Location loc, int rotation, boolean mirror, int blocksPerTick, Consumer<Structure> callback) Build this multi-block structure over multiple ticksint
buildAsync
(org.bukkit.Location loc, int relX, int relY, int relZ, int rotation, boolean mirror, int blocksPerTick, Consumer<Structure> callback) Build this multi-block structure over multiple ticksint
buildAsync
(org.bukkit.Location loc, int rotation, int blocksPerTick, Consumer<Structure> callback) Build this multi-block structure over multiple ticksint
buildAsync
(org.bukkit.Location loc, int blocksPerTick, Consumer<Structure> callback) Build this multi-block structure over multiple ticksboolean
canBuild
(org.bukkit.Location loc, int rotation, boolean mirror, Predicate<org.bukkit.Location> filter) Uses a Predicate to test each block where this structure would be builtboolean
canBuild
(org.bukkit.Location loc, int relX, int relY, int relZ, int rotation, boolean mirror, Predicate<org.bukkit.Location> filter) Uses a Predicate to test each block where this structure would be builtboolean
Uses a Predicate to test each block where this structure would be builtboolean
Uses a Predicate to test each block where this structure would be builtprotected boolean
compare
(StructureData data, org.bukkit.block.Block block, Rotator rotator) static MultiBlockStructure
create
(InputStream stream, String name) Creates a MultiBlockStructure instance from an input stream containing the info stringstatic MultiBlockStructure
create
(InputStream stream, String name, boolean strictMode) Creates a MultiBlockStructure instance from an input stream containing the info stringstatic MultiBlockStructure
create
(InputStream stream, String name, boolean strictMode, boolean ignoreAir) Creates a MultiBlockStructure instance from an input stream containing the info stringstatic MultiBlockStructure
Creates a MultiBlockStructure instance from an info stringstatic MultiBlockStructure
Creates a MultiBlockStructure instance from an info stringstatic MultiBlockStructure
Creates a MultiBlockStructure instance from an info stringboolean
void
forEachBlock
(org.bukkit.Location loc, int rotation, boolean mirror, Consumer<org.bukkit.block.BlockState> callback) Iterates each block which would be set if this structure is builtvoid
forEachBlock
(org.bukkit.Location loc, int relX, int relY, int relZ, int rotation, boolean mirror, Consumer<org.bukkit.block.BlockState> callback) Iterates each block which would be set if this structure is builtvoid
forEachBlock
(org.bukkit.Location loc, int rotation, Consumer<org.bukkit.block.BlockState> callback) Iterates each block which would be set if this structure is builtvoid
forEachBlock
(org.bukkit.Location loc, Consumer<org.bukkit.block.BlockState> callback) Iterates each block which would be set if this structure is builtgetAt
(org.bukkit.Location loc) Gets the Structure at the given block, if it exists.getAt
(org.bukkit.Location loc, int relX, int relY, int relZ, int rotation, boolean mirror) Gets the Structure at the given block, if it exists.org.bukkit.block.BlockState
getData
(int relX, int relY, int relZ) Gets the data of this structure at a given relative locationorg.bukkit.block.BlockState
getData
(org.bukkit.Location loc, int relX, int relY, int relZ) Gets the data of this structure at a given relative location, set with a BlockState at the given locationint[]
Gets the dimensions of this multi-block structure.getName()
Gets this multi-block structure's name.getRegion
(org.bukkit.Location loc) Gets the Region this multi-block structure would occupy, were it built heregetRegion
(org.bukkit.Location loc, int rotation) Gets the Region this multi-block structure would occupy, were it built heregetRegion
(org.bukkit.Location loc, int rotation, boolean mirror) Gets the Region this multi-block structure would occupy, were it built heregetRegion
(org.bukkit.Location loc, int relX, int relY, int relZ, int rotation, boolean mirror) Gets the Region this multi-block structure would occupy, were it built hereSet<org.bukkit.Material>
getStructureData
(int relX, int relY, int relZ) Gets the StructureData at a certain relative positionorg.bukkit.Material
getType
(int relX, int relY, int relZ) Gets the Material at a certain relative positionint
int
hashCode()
boolean
boolean
static String
stringify
(org.bukkit.Location start, org.bukkit.Location end) Use this to get the info to construct a multi-block structure.static String
stringify
(org.bukkit.Location start, org.bukkit.Location end, org.bukkit.Material skip) Use this to get the info to construct a multi-block structure.toString()
void
visualize
(org.bukkit.entity.Player player, org.bukkit.Location loc, int relX, int relY, int relZ) Sends ghost blocks of this multi-block structure to the given player at the given locationvoid
visualize
(org.bukkit.entity.Player player, org.bukkit.Location loc, int relX, int relY, int relZ, int rotation, boolean mirror) Sends ghost blocks of this multi-block structure to the given player at the given location
-
Field Details
-
data
-
dimX
protected int dimX -
dimY
protected int dimY -
dimZ
protected int dimZ -
strictMode
protected boolean strictMode -
ignoreAir
protected boolean ignoreAir -
strictModeExclude
-
-
Method Details
-
stringify
public static String stringify(org.bukkit.Location start, org.bukkit.Location end, org.bukkit.Material skip) Use this to get the info to construct a multi-block structure. Should be hard-coded. You can use the multi-block structure tool (/struct wand) as long as devMode is true- Parameters:
start
- One bounding corner of the regionend
- The other bounding corner of the regionskip
- A block type to be skipped, in case it was used to select the corners- Returns:
- A string representing all of the block data for the region
- Throws:
IllegalArgumentException
- if the specified locations are not in the same world
-
stringify
Use this to get the info to construct a multi-block structure. Should be hard-coded. You can use the multi-block structure tool (/struct wand) as long as devMode is true- Parameters:
start
- One bounding corner of the regionend
- The other bounding corner of the region- Returns:
- A string representing all of the block data for the region
- Throws:
IllegalArgumentException
- if the specified locations are not in the same world
-
create
Creates a MultiBlockStructure instance from an info string- Parameters:
info
- The info string. Get this fromstringify(Location, Location)
name
- The name of the multi-block structure- Returns:
- The multi-block structure
-
create
Creates a MultiBlockStructure instance from an info string- Parameters:
info
- The info string. Get this fromstringify(Location, Location)
name
- The name of the multi-block structurestrictMode
- Whether block data is taken into account. Only checks material if false. Defaults to true.- Returns:
- The multi-block structure
-
create
public static MultiBlockStructure create(String info, String name, boolean strictMode, boolean ignoreAir) Creates a MultiBlockStructure instance from an info string- Parameters:
info
- The info string. Get this fromstringify(Location, Location)
name
- The name of the multi-block structurestrictMode
- Whether block data is taken into account. Only checks material if false. Defaults to true.ignoreAir
- If true, air in the original structure is skipped when checking blocks. Defaults to false.- Returns:
- The multi-block structure
-
create
public static MultiBlockStructure create(InputStream stream, String name, boolean strictMode, boolean ignoreAir) Creates a MultiBlockStructure instance from an input stream containing the info string- Parameters:
stream
- The input stream. Get this fromJavaPlugin.getResource(String)
name
- The name of the multi-block structurestrictMode
- Whether block data is taken into account. Only checks material if false. Defaults to true.ignoreAir
- If true, air in the original structure is skipped when checking blocks. Defaults to false.- Returns:
- The multi-block structure
-
create
Creates a MultiBlockStructure instance from an input stream containing the info string- Parameters:
stream
- The input stream. Get this fromJavaPlugin.getResource(String)
name
- The name of the multi-block structurestrictMode
- Whether block data is taken into account. Only checks material if false. Defaults to true.- Returns:
- The multi-block structure
-
create
Creates a MultiBlockStructure instance from an input stream containing the info string- Parameters:
stream
- The input stream. Get this fromJavaPlugin.getResource(String)
name
- The name of the multi-block structure- Returns:
- The multi-block structure
-
addStrictModeExclusions
public void addStrictModeExclusions(org.bukkit.Material... materials) Add a list of Materials to be excluded from strict data checks rather than disabling strict mode for all blocks- Parameters:
materials
- The materials to exclude from strict mode checks
-
getStrictModeExclusions
- Returns:
- A set of Materials to be excluded from strict data checks rather than disabling strict mode for all blocks
-
getRegion
public CuboidRegion getRegion(org.bukkit.Location loc, int relX, int relY, int relZ, int rotation, boolean mirror) Gets the Region this multi-block structure would occupy, were it built here- Parameters:
loc
- The location of the multi-block structurerelX
- The relative X in the structure to center atrelY
- The relative Y in the structure to center atrelZ
- The relative Z in the structure to center atrotation
- The number of 90-degree clockwise rotations to applymirror
- Whether to mirror the structure on the X axis- Returns:
- The Region this multi-block structure would occupy
-
getRegion
Gets the Region this multi-block structure would occupy, were it built here- Parameters:
loc
- The location of the multi-block structurerotation
- The number of 90-degree clockwise rotations to applymirror
- Whether to mirror the structure on the X axis- Returns:
- The Region this multi-block structure would occupy
-
getRegion
Gets the Region this multi-block structure would occupy, were it built here- Parameters:
loc
- The location of the multi-block structurerotation
- The number of 90-degree clockwise rotations to apply- Returns:
- The Region this multi-block structure would occupy
-
getRegion
Gets the Region this multi-block structure would occupy, were it built here- Parameters:
loc
- The location of the multi-block structure- Returns:
- The Region this multi-block structure would occupy
-
forEachBlock
public void forEachBlock(org.bukkit.Location loc, int relX, int relY, int relZ, int rotation, boolean mirror, Consumer<org.bukkit.block.BlockState> callback) Iterates each block which would be set if this structure is built- Parameters:
loc
- The location the structure would be built atrelX
- The relative X in the structure to center atrelY
- The relative Y in the structure to center atrelZ
- The relative Z in the structure to center atrotation
- The number of 90-degree clockwise rotations to applymirror
- Whether to mirror the structure on the X axiscallback
- The callback to be called, passed theBlockState
which would be set if the structure is built here
-
getData
public org.bukkit.block.BlockState getData(org.bukkit.Location loc, int relX, int relY, int relZ) Gets the data of this structure at a given relative location, set with a BlockState at the given location- Parameters:
loc
- The location to use for the BlockStaterelX
- The relative X of the block within this multi-block structurerelY
- The relative Y of the block within this multi-block structurerelZ
- The relative Z of the block within this multi-block structure- Returns:
- A BlockState, with the Location passed, with the data at the specified relative location within this multi-block structure. This is done for compatibility reasons. For 1.8, MaterialData would make the most sense, while for 1.13+, BlockData would. BlockState can be converted to either.
- Throws:
ArrayIndexOutOfBoundsException
- if the relative coordinates do not exist within this structure
-
getData
public org.bukkit.block.BlockState getData(int relX, int relY, int relZ) Gets the data of this structure at a given relative location- Parameters:
relX
- The relative X of the block within this multi-block structurerelY
- The relative Y of the block within this multi-block structurerelZ
- The relative Z of the block within this multi-block structure- Returns:
- A BlockState, with the Location (0, 0, 0) in the default world, with the data at the specified relative location within this multi-block structure. This is done for compatibility reasons. For 1.8, MaterialData would make the most sense, while for 1.13+, BlockData would. BlockState can be converted to either.
- Throws:
ArrayIndexOutOfBoundsException
- if the relative coordinates do not exist within this structure
-
getStructureData
Gets the StructureData at a certain relative position- Parameters:
relX
- The relative X of the block within this multi-block structurerelY
- The relative Y of the block within this multi-block structurerelZ
- The relative Z of the block within this multi-block structure- Returns:
- StructureData for the given relative position
- Throws:
ArrayIndexOutOfBoundsException
- if the relative coordinates are out of bounds
-
getType
public org.bukkit.Material getType(int relX, int relY, int relZ) Gets the Material at a certain relative position- Parameters:
relX
- The relative X of the block within this multi-block structurerelY
- The relative Y of the block within this multi-block structurerelZ
- The relative Z of the block within this multi-block structure- Returns:
- Material for the given relative position
- Throws:
ArrayIndexOutOfBoundsException
- if the relative coordinates are out of bounds
-
forEachBlock
public void forEachBlock(org.bukkit.Location loc, int rotation, boolean mirror, Consumer<org.bukkit.block.BlockState> callback) Iterates each block which would be set if this structure is built- Parameters:
loc
- The location the structure would be built atrotation
- The number of 90-degree clockwise rotations to applymirror
- Whether to mirror the structure on the X axiscallback
- The callback to be called, passed theBlockState
which would be set if the structure is built here
-
forEachBlock
public void forEachBlock(org.bukkit.Location loc, int rotation, Consumer<org.bukkit.block.BlockState> callback) Iterates each block which would be set if this structure is built- Parameters:
loc
- The location the structure would be built atrotation
- The number of 90-degree clockwise rotations to applycallback
- The callback to be called, passed theBlockState
which would be set if the structure is built here
-
forEachBlock
Iterates each block which would be set if this structure is built- Parameters:
loc
- The location the structure would be built atcallback
- The callback to be called, passed theBlockState
which would be set if the structure is built here
-
canBuild
public boolean canBuild(org.bukkit.Location loc, int relX, int relY, int relZ, int rotation, boolean mirror, Predicate<org.bukkit.Location> filter) Uses a Predicate to test each block where this structure would be built- Parameters:
loc
- The location to test the conditions atrelX
- The relative X in the structure to test centered atrelY
- The relative Y in the structure to test centered atrelZ
- The relative Z in the structure to test centered atrotation
- The number of 90-degree clockwise rotations to applymirror
- Whether to mirror the structure on the X axisfilter
- The predicate to check each location- Returns:
- Whether every location passed the check
-
canBuild
public boolean canBuild(org.bukkit.Location loc, int rotation, boolean mirror, Predicate<org.bukkit.Location> filter) Uses a Predicate to test each block where this structure would be built- Parameters:
loc
- The location to test the conditions atrotation
- The number of 90-degree clockwise rotations to applymirror
- Whether to mirror the structure on the X axisfilter
- The predicate to check each location- Returns:
- Whether every location passed the check
-
canBuild
public boolean canBuild(org.bukkit.Location loc, int rotation, Predicate<org.bukkit.Location> filter) Uses a Predicate to test each block where this structure would be built- Parameters:
loc
- The location to test the conditions atrotation
- The number of 90-degree clockwise rotations to applyfilter
- The predicate to check each location- Returns:
- Whether every location passed the check
-
canBuild
Uses a Predicate to test each block where this structure would be built- Parameters:
loc
- The location to test the conditions atfilter
- The predicate to check each location- Returns:
- Whether every location passed the check
-
visualize
public void visualize(org.bukkit.entity.Player player, org.bukkit.Location loc, int relX, int relY, int relZ, int rotation, boolean mirror) Sends ghost blocks of this multi-block structure to the given player at the given location- Parameters:
player
- The player to visualize the structure toloc
- The location to visualize the structure atrelX
- The relative X in the structure to visualize centered atrelY
- The relative Y in the structure to visualize centered atrelZ
- The relative Z in the structure to visualize centered atrotation
- The number of 90-degree clockwise rotations to applymirror
- Whether to mirror the structure on the X axis
-
visualize
public void visualize(org.bukkit.entity.Player player, org.bukkit.Location loc, int relX, int relY, int relZ) Sends ghost blocks of this multi-block structure to the given player at the given location- Parameters:
player
- The player to visualize the structure toloc
- The location to visualize the structure atrelX
- The relative X in the structure to visualize centered atrelY
- The relative Y in the structure to visualize centered atrelZ
- The relative Z in the structure to visualize centered at
-
build
public Structure build(org.bukkit.Location loc, int relX, int relY, int relZ, int rotation, boolean mirror) Builds this multi-block structure at the given location- Parameters:
loc
- The location to build the structure atrelX
- The relative X in the structure to build centered atrelY
- The relative Y in the structure to build centered atrelZ
- The relative Z in the structure to build centered atrotation
- The number of 90-degree clockwise rotations to applymirror
- Whether to mirror the structure on the X axis- Returns:
- The Structure instance that was created
-
build
Builds this multi-block structure at the given location- Parameters:
loc
- The location to build the structure atrelX
- The relative X in the structure to build centered atrelY
- The relative Y in the structure to build centered atrelZ
- The relative Z in the structure to build centered at- Returns:
- The Structure instance that was created
-
build
Builds this multi-block structure at the given location- Parameters:
loc
- The location to build the structure atrelX
- The relative X in the structure to build centered atrelY
- The relative Y in the structure to build centered atrelZ
- The relative Z in the structure to build centered atrotation
- The number of 90-degree clockwise rotations to apply- Returns:
- The Structure instance that was created
-
build
Builds this multi-block structure at the given location- Parameters:
loc
- The location to build the structure at- Returns:
- The Structure instance that was created
-
build
Builds this multi-block structure at the given location- Parameters:
loc
- The location to build the structure atrotation
- The number of 90-degree clockwise rotations to apply- Returns:
- The Structure instance that was created
-
buildAsync
public int buildAsync(org.bukkit.Location loc, int relX, int relY, int relZ, int rotation, boolean mirror, int blocksPerTick, Consumer<Structure> callback) Build this multi-block structure over multiple ticks- Parameters:
loc
- The location to build the structure atrelX
- The relative X in the structure to build centered atrelY
- The relative Y in the structure to build centered atrelZ
- The relative Z in the structure to build centered atrotation
- The number of 90-degree clockwise rotations to applymirror
- Whether to mirror the structure on the X axisblocksPerTick
- The number of blocks to build per tickcallback
- A callback to accept the Structure instance that was created when construction is complete- Returns:
- The task number for the Bukkit scheduler task created by this method
-
buildAsync
public int buildAsync(org.bukkit.Location loc, int rotation, boolean mirror, int blocksPerTick, Consumer<Structure> callback) Build this multi-block structure over multiple ticks- Parameters:
loc
- The location to build the structure atrotation
- The number of 90-degree clockwise rotations to applymirror
- Whether to mirror the structure on the X axisblocksPerTick
- The number of blocks to build per tickcallback
- A callback to accept the Structure instance that was created when construction is complete- Returns:
- The task number for the Bukkit scheduler task created by this method
-
buildAsync
public int buildAsync(org.bukkit.Location loc, int rotation, int blocksPerTick, Consumer<Structure> callback) Build this multi-block structure over multiple ticks- Parameters:
loc
- The location to build the structure atrotation
- The number of 90-degree clockwise rotations to applyblocksPerTick
- The number of blocks to build per tickcallback
- A callback to accept the Structure instance that was created when construction is complete- Returns:
- The task number for the Bukkit scheduler task created by this method
-
buildAsync
Build this multi-block structure over multiple ticks- Parameters:
loc
- The location to build the structure atblocksPerTick
- The number of blocks to build per tickcallback
- A callback to accept the Structure instance that was created when construction is complete- Returns:
- The task number for the Bukkit scheduler task created by this method
-
getName
Gets this multi-block structure's name. May be faster to compare this than to use .equals().- Returns:
- The name of this multi-block structure
-
getDimensions
public int[] getDimensions()Gets the dimensions of this multi-block structure. [x, y, z]- Returns:
- The dimensions of this multi-block structure
-
getVolume
public int getVolume()- Returns:
- The volume of this multi-block structure in blocks
-
ignoresAir
public boolean ignoresAir()- Returns:
- Whether this structure ignores air in the data when building and checking for presence
-
isStrictMode
public boolean isStrictMode()- Returns:
- Whether this structure ignores data other than block type when checking for presence
-
getAt
Gets the Structure at the given block, if it exists. The given location can be any part of the multi-block structure. This is very computationally expensive for larger structures, and should be avoided if possible, as it checks every possible rotation and mirroring of the structure.- Parameters:
loc
- The location to check at- Returns:
- The structure at this block, or null if it does not exist
-
getAt
public Structure getAt(org.bukkit.Location loc, int relX, int relY, int relZ, int rotation, boolean mirror) Gets the Structure at the given block, if it exists. All parameters must be known. Significantly faster thangetAt(Location)
- Parameters:
loc
- The location to check atrelX
- The relative X in the structure of the locationrelY
- The relative Y in the structure of the locationrelZ
- The relative Z in the structure of the locationrotation
- The number of clockwise rotations applied to the structuremirror
- Whether the structure is mirrored- Returns:
- The structure at this block, or null if it does not exist
-
assumeAt
public Structure assumeAt(org.bukkit.Location loc, int relX, int relY, int relZ, int rotation, boolean mirror) Gets the Structure at the given block, performing no checks to ensure it exists.- Parameters:
loc
- The location of the StructurerelX
- The relative X of the location within the StructurerelY
- The relative Y of the location within the StructurerelZ
- The relative Z of the location within the Structurerotation
- The number of clockwise rotations applied to the structuremirror
- Whether the structure is mirrored- Returns:
- The Structure instance
-
assumeAt
Gets the Structure at the given block, performing no checks to ensure it exists.- Parameters:
loc
- The location of the Structurerotation
- The number of clockwise rotations applied to the structuremirror
- Whether the structure is mirrored- Returns:
- The Structure instance
-
assumeAt
Gets the Structure at the given block, performing no checks to ensure it exists.- Parameters:
loc
- The location of the Structurerotation
- The number of clockwise rotations applied to the structure- Returns:
- The Structure instance
-
assumeAt
Gets the Structure at the given block, performing no checks to ensure it exists.- Parameters:
loc
- The location of the Structure- Returns:
- The Structure instance
-
compare
-
equals
-
hashCode
public int hashCode() -
toString
-