public class Tile extends InstanceKeeper implements Serializable, UndoListener, Cloneable
Modifier and Type | Class and Description |
---|---|
static interface |
Tile.Listener |
static class |
Tile.TileBuffer |
InstanceKeeper.InstantiationListener<T>
Modifier and Type | Field and Description |
---|---|
protected Map<Layer,BitSet> |
bitLayerData |
protected short[] |
heightMap |
protected Map<Layer,byte[]> |
layerData |
protected int[] |
tallHeightMap |
protected short[] |
tallWaterLevel |
protected byte[] |
terrain |
protected byte[] |
waterLevel |
Modifier | Constructor and Description |
---|---|
|
Tile(int x,
int y,
int minHeight,
int maxHeight) |
protected |
Tile(int x,
int y,
int minHeight,
int maxHeight,
boolean init) |
Modifier and Type | Method and Description |
---|---|
void |
addListener(Tile.Listener listener) |
void |
bufferChanged(BufferKey<?> key)
A buffer has changed due to an undo or redo operation.
|
void |
clearLayerData(int x,
int y,
Set<Layer> excludedLayers)
Clear all layer data at a particular location (by resetting to the
layer's default value), possibly with the exception of certain layers.
|
void |
clearLayerData(Layer layer) |
boolean |
containsOneOf(Layer... layers) |
protected void |
ensureReadable(Tile.TileBuffer buffer) |
boolean |
equals(Object obj) |
List<Layer> |
getActiveLayers(int x,
int y) |
Set<Terrain> |
getAllTerrains() |
int |
getBitLayerCount(Layer layer,
int x,
int y,
int r)
Count the number of blocks where the specified bit layer is set in a
square around a particular location
|
boolean |
getBitLayerValue(Layer layer,
int x,
int y) |
float |
getDistanceToEdge(Layer layer,
int x,
int y,
float maxDistance) |
int |
getFloodedCount(int x,
int y,
int r,
boolean lava)
Count the number of blocks that are flooded in a square around a
particular location
|
float |
getHeight(int x,
int y) |
int |
getHighestIntHeight() |
int |
getIntHeight(int x,
int y) |
List<Layer> |
getLayers() |
List<Layer> |
getLayers(Set<Layer> additionalLayers)
Get a list of all layers in use in the tile, as well as the set of
additional layers provided, the total sorted by layer priority.
|
Map<Layer,Integer> |
getLayersAt(int x,
int y)
Gets all layers that are set at the specified location, along with their
intensities.
|
int |
getLayerValue(Layer layer,
int x,
int y) |
int |
getLowestIntHeight() |
int |
getMaxHeight() |
int |
getMinHeight() |
int |
getRawHeight(int x,
int y)
Get the raw height value.
|
HashSet<Seed> |
getSeeds() |
float |
getSlope(int x,
int y) |
Terrain |
getTerrain(int x,
int y) |
int |
getWaterLevel(int x,
int y) |
int |
getX() |
int |
getY() |
int |
hashCode() |
boolean |
hasLayer(Layer layer) |
void |
inhibitEvents()
Stop firing events when the tile is modified, until
releaseEvents() is invoked. |
boolean |
isEventsInhibited() |
boolean |
plantSeed(Seed seed) |
void |
redoPerformed()
A redo has been performed.
|
void |
register(UndoManager undoManager) |
void |
releaseEvents()
Release an inhibition on firing events.
|
void |
removeListener(Tile.Listener listener) |
void |
removeSeed(Seed seed) |
boolean |
repair(int minHeight,
int maxHeight,
PrintStream out) |
void |
savePointArmed()
A save point has been scheduled.
|
void |
savePointCreated()
A save point has been performed.
|
void |
setBitLayerValue(Layer layer,
int x,
int y,
boolean value) |
void |
setHeight(int x,
int y,
float height) |
void |
setLayerValue(Layer layer,
int x,
int y,
int value) |
void |
setMinMaxHeight(int minHeight,
int maxHeight,
HeightTransform heightTransform) |
void |
setRawHeight(int x,
int y,
int rawHeight)
Set the raw height value.
|
void |
setTerrain(int x,
int y,
Terrain terrain) |
void |
setWaterLevel(int x,
int y,
int waterLevel) |
String |
toString() |
Tile |
transform(CoordinateTransform transform)
Create a new tile based on this one but horizontally transformed according to some transformation.
|
void |
undoPerformed()
An undo has been performed.
|
void |
unregister() |
setInstantiationListener
protected short[] heightMap
protected int[] tallHeightMap
protected byte[] terrain
protected byte[] waterLevel
protected short[] tallWaterLevel
public Tile(int x, int y, int minHeight, int maxHeight)
protected Tile(int x, int y, int minHeight, int maxHeight, boolean init)
public int getX()
public int getY()
public int getMinHeight()
public int getMaxHeight()
public void setMinMaxHeight(int minHeight, int maxHeight, HeightTransform heightTransform)
public int getIntHeight(int x, int y)
public int getLowestIntHeight()
public int getHighestIntHeight()
public float getHeight(int x, int y)
public void setHeight(int x, int y, float height)
public int getRawHeight(int x, int y)
minHeight
.public void setRawHeight(int x, int y, int rawHeight)
minHeight
.public float getSlope(int x, int y)
public Terrain getTerrain(int x, int y)
public void setTerrain(int x, int y, Terrain terrain)
public int getWaterLevel(int x, int y)
public void setWaterLevel(int x, int y, int waterLevel)
public boolean hasLayer(Layer layer)
public List<Layer> getLayers(Set<Layer> additionalLayers)
additionalLayers
- The additional layers to include in the list.public boolean getBitLayerValue(Layer layer, int x, int y)
public int getBitLayerCount(Layer layer, int x, int y, int r)
layer
- The bit layer to count.x
- The X coordinate (local to the tile) of the location around
which to count the layer.y
- The Y coordinate (local to the tile) of the location around
which to count the layer.r
- The radius of the square.public Map<Layer,Integer> getLayersAt(int x, int y)
x
- The X location for which to retrieve all layers.y
- The Y location for which to retrieve all layers.null
or an empty map if no layers are present.public int getFloodedCount(int x, int y, int r, boolean lava)
x
- The X coordinate (local to the tile) of the location around
which to count flooded blocks.y
- The Y coordinate (local to the tile) of the location around
which to count flooded blocks.r
- The radius of the square.lava
- Whether to check for lava (when true
) or water
(when false
).public float getDistanceToEdge(Layer layer, int x, int y, float maxDistance)
public void setBitLayerValue(Layer layer, int x, int y, boolean value)
public int getLayerValue(Layer layer, int x, int y)
public void setLayerValue(Layer layer, int x, int y, int value)
public void clearLayerData(Layer layer)
public void clearLayerData(int x, int y, Set<Layer> excludedLayers)
x
- The X coordinate of the location to clear of layer data.y
- The Y coordinate of the location to clear of layer data.excludedLayers
- The layers to exclude, if any. May be
null
.public boolean plantSeed(Seed seed)
public void removeSeed(Seed seed)
public void addListener(Tile.Listener listener)
public void removeListener(Tile.Listener listener)
public boolean isEventsInhibited()
public void inhibitEvents()
releaseEvents()
is invoked. Make sure that
releaseEvents()
is always invoked, even if an exception is thrown, by using a try-finally statement:
tile.inhibitEvents();
try {
// modify the tile
} finally {
tile.releaseEvents();
}
Note that calls to these methods may be nested, and if so, events will only be released after
the final invocation of releaseEvents()
.
public void releaseEvents()
inhibitEvents()
, but only if this is the last invocation of
releaseEvents()
in a nested set.public void register(UndoManager undoManager)
public void unregister()
public Tile transform(CoordinateTransform transform)
transform
- The transform to apply.public boolean repair(int minHeight, int maxHeight, PrintStream out)
public boolean containsOneOf(Layer... layers)
public void savePointArmed()
UndoListener
savePointArmed
in interface UndoListener
public void savePointCreated()
UndoListener
savePointCreated
in interface UndoListener
public void undoPerformed()
UndoListener
undoPerformed
in interface UndoListener
public void redoPerformed()
UndoListener
redoPerformed
in interface UndoListener
public void bufferChanged(BufferKey<?> key)
UndoListener
bufferChanged
in interface UndoListener
key
- The key of the buffer that has changed.protected void ensureReadable(Tile.TileBuffer buffer)