public final class MinecraftWorldObject extends java.lang.Object implements MinecraftWorld, WPObject
MinecraftWorld
and WPObject
, allowing to render worlds and layers to it
and then treat it as an object, for instance for generating previews. As such it does not support entities, tile
entities, lighting information, etc., just basic block info. Trying to use the unsupported features will fail
silently.
For the MinecraftWorld
interface the supported coordinates are those specified by the volume
parameter. For the WPObject
interface, the coordinates are translated so that the lower north west corner is
at 0,0,0. In other words, the WPObject
has no offset and all the coordinates are positive.
An offset may in fact be specified but it has no effect on the coordinates used by this object; it is purely meant
to communicate to a consumer of the WPObject
that the object should be shifted when placed.
WPObject.BlockVisitor
ATTRIBUTE_COLLISION_MODE, ATTRIBUTE_CONNECT_BLOCKS, ATTRIBUTE_EXTEND_FOUNDATION, ATTRIBUTE_FILE, ATTRIBUTE_FREQUENCY, ATTRIBUTE_HEIGHT_MODE, ATTRIBUTE_LEAF_DECAY_MODE, ATTRIBUTE_MANAGE_WATERLOGGED, ATTRIBUTE_NEEDS_FOUNDATION, ATTRIBUTE_OFFSET, ATTRIBUTE_RANDOM_MIRRORING_ONLY, ATTRIBUTE_RANDOM_ROTATION, ATTRIBUTE_RANDOM_ROTATION_ONLY, ATTRIBUTE_REPLACE_WITH_AIR, ATTRIBUTE_REPLACE_WITH_AIR_MATERIAL, ATTRIBUTE_SPAWN_IN_LAVA, ATTRIBUTE_SPAWN_IN_WATER, ATTRIBUTE_SPAWN_ON_LAND, ATTRIBUTE_SPAWN_ON_LAVA, ATTRIBUTE_SPAWN_ON_WATER, ATTRIBUTE_SPAWN_ON_WATER_NO_COLLIDE, ATTRIBUTE_UNDERGROUND_MODE, ATTRIBUTE_VERTICAL_OFFSET, ATTRIBUTE_Y_VARIATION, COLLISION_MODE_ALL, COLLISION_MODE_NONE, COLLISION_MODE_SOLID, HEIGHT_MODE_FIXED, HEIGHT_MODE_TERRAIN, LEAF_DECAY_NO_CHANGE, LEAF_DECAY_OFF, LEAF_DECAY_ON
Constructor and Description |
---|
MinecraftWorldObject(java.lang.String name,
org.pepsoft.util.Box volume,
int maxHeight,
int waterLevel)
Create a new
MinecraftWorldObject which is initialised with
all air and has no offset. |
MinecraftWorldObject(java.lang.String name,
org.pepsoft.util.Box volume,
int maxHeight,
int waterLevel,
Material[] lowestBlocks,
javax.vecmath.Point3i offset)
Create a new
MinecraftWorldObject . |
Modifier and Type | Method and Description |
---|---|
void |
addChunk(Chunk chunk)
Copies the block IDs and data values from the specified chunk to this
object, insofar as it intersects the object bounds.
|
void |
addEntity(double x,
double y,
double height,
Entity entity) |
void |
addTileEntity(int x,
int y,
int height,
TileEntity tileEntity) |
MinecraftWorldObject |
clone()
Create a clone of the object.
|
void |
close()
Close the chunk provider, flushing any changes and closing any system
resources.
|
<T extends java.io.Serializable> |
getAttribute(org.pepsoft.util.AttributeKey<T> key)
Convencience method for getting the value of an attribute stored in the
external metadata, if any.
|
java.util.Map<java.lang.String,java.io.Serializable> |
getAttributes()
Get a live view of the object metadata.
|
int |
getBlockLightLevel(int x,
int y,
int height)
Returns
0 if height is too large. |
int |
getBlockTypeAt(int x,
int y,
int height)
Returns
Constants.BLK_AIR if height is too large. |
Chunk |
getChunk(int x,
int z)
Retrieve a chunk.
|
Chunk |
getChunkForEditing(int x,
int z)
Retrieve a chunk for editing.
|
int |
getDataAt(int x,
int y,
int height)
Returns
0 if height is too large. |
javax.vecmath.Point3i |
getDimensions()
Get the dimensions of the object.
|
java.util.List<Entity> |
getEntities()
Get any entities contained in the object.
|
int |
getHighestNonAirBlock(int x,
int y)
Get the Z coordinate of the highest non-air block in a specific column.
|
boolean |
getMask(int x,
int y,
int z)
Determine whether a block should be placed at the specified relative coordinates.
|
Material |
getMaterial(int x,
int y,
int z)
Get the material to place at the specified relative coordinates.
|
Material |
getMaterialAt(int x,
int y,
int height)
Returns
null if height is too large. |
int |
getMaxHeight() |
int |
getMinHeight() |
java.lang.String |
getName()
Get the name of the object.
|
javax.vecmath.Point3i |
getOffset()
Get the offset to apply to this object when placing it.
|
int |
getSkyLightLevel(int x,
int y,
int height)
Returns
15 if height is too large. |
java.util.List<TileEntity> |
getTileEntities()
Get any tile entities contained in the object.
|
org.pepsoft.util.Box |
getVolume() |
int |
getWaterLevel() |
boolean |
isChunkPresent(int x,
int y)
Determine whether the world contains any data in a particular chunk (a
16 by 16 block area).
|
void |
markForUpdateWorld(int x,
int y,
int height)
Mark a block to be updated by Minecraft when next loaded.
|
void |
prepareForExport(Dimension dimension)
Make preparations, if necessary, for exporting the object.
|
void |
reset() |
<T extends java.io.Serializable> |
setAttribute(org.pepsoft.util.AttributeKey<T> key,
T value)
Convenience method for setting the value of an attribute stored in the
external metadata, if any.
|
void |
setAttributes(java.util.Map<java.lang.String,java.io.Serializable> attributes)
Store external metadata about the object.
|
void |
setBlockLightLevel(int x,
int y,
int height,
int blockLightLevel)
Fails silently if
height is too large. |
void |
setBlockTypeAt(int x,
int y,
int height,
int blockType)
Fails silently if
height is too large. |
void |
setDataAt(int x,
int y,
int height,
int data)
Fails silently if
height is too large. |
void |
setMaterialAt(int x,
int y,
int height,
Material material)
Fails silently if
height is too large. |
void |
setName(java.lang.String name)
Set the name of the object.
|
void |
setSkyLightLevel(int x,
int y,
int height,
int skyLightLevel)
Fails silently if
height is too large. |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
dump, getAllMaterials, guessConnectBlocks, guessManageWaterlogged, guestimateOffset, hasAttribute, visitBlocks
public MinecraftWorldObject(java.lang.String name, org.pepsoft.util.Box volume, int maxHeight, int waterLevel)
MinecraftWorldObject
which is initialised with
all air and has no offset.name
- The name of the world/object.volume
- The volume of blocks in world coordinates which the object should encompass. Blocks outside this
volume are returned as air for read operations and silently ignored for write operations.maxHeight
- The height to return from MinecraftWorld.getMaxHeight()
. Must be a power of two and may
be higher than the volume; that just means the blocks between the top of the volume and
maxHeight won't be stored.public MinecraftWorldObject(java.lang.String name, org.pepsoft.util.Box volume, int maxHeight, int waterLevel, Material[] lowestBlocks, javax.vecmath.Point3i offset)
MinecraftWorldObject
.name
- The name of the world/object.volume
- The volume of blocks in world coordinates which the object should encompass. Blocks outside this
volume are returned as air for read operations and silently ignored for write operations.maxHeight
- The height to return from MinecraftWorld.getMaxHeight()
. Must be a power of two and may
be higher than the volume; that just means the blocks between the top of the volume and
maxHeight won't be stored.lowestBlocks
- An optional column of materials with which the bottom of the volume should be filled. All
other blocks will be initialised as air. May be null
, in which case all blocks
will be initialised as air.offset
- The offset to return from WPObject.getOffset()
.public void reset()
public org.pepsoft.util.Box getVolume()
public int getWaterLevel()
public int getBlockTypeAt(int x, int y, int height)
MinecraftWorld
Constants.BLK_AIR
if height
is too large.getBlockTypeAt
in interface MinecraftWorld
public int getDataAt(int x, int y, int height)
MinecraftWorld
0
if height
is too large.getDataAt
in interface MinecraftWorld
public Material getMaterialAt(int x, int y, int height)
MinecraftWorld
null
if height
is too large.getMaterialAt
in interface MinecraftWorld
public void setBlockTypeAt(int x, int y, int height, int blockType)
MinecraftWorld
height
is too large.setBlockTypeAt
in interface MinecraftWorld
public void setDataAt(int x, int y, int height, int data)
MinecraftWorld
height
is too large.setDataAt
in interface MinecraftWorld
public void setMaterialAt(int x, int y, int height, Material material)
MinecraftWorld
height
is too large.setMaterialAt
in interface MinecraftWorld
public void markForUpdateWorld(int x, int y, int height)
MinecraftWorld
The default implementation uses ChunkProvider.getChunk(int, int)
to get the chunk, and if it exists invokes
Chunk.markForUpdateChunk(int, int, int)
on it.
markForUpdateWorld
in interface MinecraftWorld
public int getMinHeight()
getMinHeight
in interface MinecraftWorld
public int getMaxHeight()
getMaxHeight
in interface MinecraftWorld
public void addEntity(double x, double y, double height, Entity entity)
addEntity
in interface MinecraftWorld
public void addTileEntity(int x, int y, int height, TileEntity tileEntity)
addTileEntity
in interface MinecraftWorld
public int getBlockLightLevel(int x, int y, int height)
MinecraftWorld
0
if height
is too large.getBlockLightLevel
in interface MinecraftWorld
public void setBlockLightLevel(int x, int y, int height, int blockLightLevel)
MinecraftWorld
height
is too large.setBlockLightLevel
in interface MinecraftWorld
public int getSkyLightLevel(int x, int y, int height)
MinecraftWorld
15
if height
is too large.getSkyLightLevel
in interface MinecraftWorld
public void setSkyLightLevel(int x, int y, int height, int skyLightLevel)
MinecraftWorld
height
is too large.setSkyLightLevel
in interface MinecraftWorld
public boolean isChunkPresent(int x, int y)
MinecraftWorld
isChunkPresent
in interface ChunkProvider
isChunkPresent
in interface MinecraftWorld
x
- The X coordinate in chunk coordinates.y
- The Y coordinate in chunk coordinates.true
if data is present for the specified chunk.public void addChunk(Chunk chunk)
addChunk
in interface MinecraftWorld
chunk
- The chunk to copy.public int getHighestNonAirBlock(int x, int y)
MinecraftWorld
getHighestNonAirBlock
in interface MinecraftWorld
x
- The X coordinate of the column.y
- The Y coordinate of the column.Integer.MIN_VALUE
if the
column is empty or no data is present
for the specified coordinates.public Chunk getChunk(int x, int z)
ChunkProvider
null
is
returned. The returned chunk may be read-only.getChunk
in interface ChunkProvider
x
- The X coordinate of the chunk to retrieve.z
- The Z coordinate of the chunk to retrieve.null
if there is no chunk at
the specified coordinates.public Chunk getChunkForEditing(int x, int z)
ChunkProvider
null
may be returned, or the provider may
create a new, empty chunk. The returned chunk is guaranteed not to be
read-only.getChunkForEditing
in interface ChunkProvider
x
- The X coordinate of the chunk to retrieve.z
- The Z coordinate of the chunk to retrieve.null
if there is no chunk at
the specified coordinates, and this chunk provider does not create new
chunks.public void close()
ChunkProvider
close
in interface java.lang.AutoCloseable
close
in interface ChunkProvider
public java.lang.String getName()
WPObject
public void setName(java.lang.String name)
WPObject
public javax.vecmath.Point3i getDimensions()
WPObject
getDimensions
in interface WPObject
public Material getMaterial(int x, int y, int z)
WPObject
WPObject.getMask(int, int, int)
returns true
. These coordinates are zero-based and must never be
negative.getMaterial
in interface WPObject
x
- The relative X coordinate.y
- The relative Y coordinate.z
- The relative Z coordinate.public boolean getMask(int x, int y, int z)
WPObject
public java.util.List<Entity> getEntities()
WPObject
getEntities
in interface WPObject
null
.public java.util.List<TileEntity> getTileEntities()
WPObject
getTileEntities
in interface WPObject
null
.public void prepareForExport(Dimension dimension)
WPObject
WPObject.getMask(int, int, int)
or
WPObject.getMaterial(int, int, int)
are invoked.prepareForExport
in interface WPObject
dimension
- The dimension for which the object is being exported.public java.util.Map<java.lang.String,java.io.Serializable> getAttributes()
WPObject
getAttributes
in interface WPObject
null
.public <T extends java.io.Serializable> T getAttribute(org.pepsoft.util.AttributeKey<T> key)
WPObject
null
) if it is
not.getAttribute
in interface WPObject
T
- The type of the attribute.key
- The key of the attribute.public void setAttributes(java.util.Map<java.lang.String,java.io.Serializable> attributes)
WPObject
setAttributes
in interface WPObject
attributes
- The external metadata to store.public <T extends java.io.Serializable> void setAttribute(org.pepsoft.util.AttributeKey<T> key, T value)
WPObject
null
will
delete the attribute from the store. If the store becomes empty it is
deleted entirely.setAttribute
in interface WPObject
T
- The type of the attribute.key
- The key of the attribute to set or delete.value
- The value of the attribute to set, or null
to
delete it.public javax.vecmath.Point3i getOffset()
WPObject
This is a convenience method which must return the same as invoking
getAttribute(ATTRIBUTE_OFFSET)
. See
WPObject.getAttribute(AttributeKey)
and WPObject.ATTRIBUTE_OFFSET
.
public MinecraftWorldObject clone()
WPObject