public class Tile extends InstanceKeeper implements java.io.Serializable, org.pepsoft.util.undo.UndoListener, java.lang.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 java.util.Map<Layer,java.util.BitSet> |
bitLayerData |
protected short[] |
heightMap |
protected java.util.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(org.pepsoft.util.undo.BufferKey<?> key) |
void |
clearLayerData(int x,
int y,
java.util.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 java.util.List<Layer> |
doGetLayers(java.util.Set<Layer> additionalLayers) |
protected float |
doGetSlope(int x,
int y) |
protected void |
ensureReadable(Tile.TileBuffer buffer) |
boolean |
equals(java.lang.Object obj) |
java.util.List<Layer> |
getActiveLayers(int x,
int y) |
java.util.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) |
float |
getHighestHeight() |
int |
getHighestIntHeight() |
int |
getHighestRawHeight() |
int |
getHighestWaterLevel() |
int |
getIntHeight(int x,
int y) |
java.util.List<Layer> |
getLayers() |
java.util.List<Layer> |
getLayers(java.util.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.
|
java.util.Map<Layer,java.lang.Integer> |
getLayersAt(int x,
int y)
Gets all layers that are set at the specified location, along with their intensities or values.
|
int |
getLayerValue(Layer layer,
int x,
int y) |
float |
getLowestHeight() |
int |
getLowestIntHeight() |
int |
getLowestRawHeight() |
int |
getMaxHeight() |
int |
getMinHeight() |
int |
getRawHeight(int x,
int y)
Get the raw height value.
|
int[] |
getRawHeightRange() |
java.util.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() |
void |
register(org.pepsoft.util.undo.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,
java.io.PrintStream out) |
void |
savePointArmed() |
void |
savePointCreated() |
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) |
java.lang.String |
toString() |
Tile |
transform(CoordinateTransform transform)
Create a new tile based on this one but horizontally transformed according to some transformation.
|
void |
undoPerformed() |
void |
unregister() |
setInstantiationListener
protected short[] heightMap
protected int[] tallHeightMap
protected byte[] terrain
protected byte[] waterLevel
protected short[] tallWaterLevel
protected java.util.Map<Layer,byte[]> layerData
protected java.util.Map<Layer,java.util.BitSet> bitLayerData
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 float getLowestHeight()
public float getHighestHeight()
public void setHeight(int x, int y, float height)
public int getRawHeight(int x, int y)
minHeight
.public int getLowestRawHeight()
public int getHighestRawHeight()
public int[] getRawHeightRange()
public void setRawHeight(int x, int y, int rawHeight)
minHeight
.public float getSlope(int x, int y)
protected final float doGetSlope(int x, int y)
public Terrain getTerrain(int x, int y)
public void setTerrain(int x, int y, Terrain terrain)
public java.util.Set<Terrain> getAllTerrains()
public int getWaterLevel(int x, int y)
public int getHighestWaterLevel()
public void setWaterLevel(int x, int y, int waterLevel)
public java.util.List<Layer> getLayers()
public boolean hasLayer(Layer layer)
public java.util.List<Layer> getActiveLayers(int x, int y)
public java.util.List<Layer> getLayers(java.util.Set<Layer> additionalLayers)
additionalLayers
- The additional layers to include in the list.protected final java.util.List<Layer> doGetLayers(java.util.Set<Layer> additionalLayers)
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 java.util.Map<Layer,java.lang.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, java.util.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 java.util.HashSet<Seed> getSeeds()
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(org.pepsoft.util.undo.UndoManager undoManager)
public void unregister()
public Tile transform(CoordinateTransform transform)
transform
- The transform to apply.public boolean repair(int minHeight, int maxHeight, java.io.PrintStream out)
public boolean containsOneOf(Layer... layers)
public void savePointArmed()
savePointArmed
in interface org.pepsoft.util.undo.UndoListener
public void savePointCreated()
savePointCreated
in interface org.pepsoft.util.undo.UndoListener
public void undoPerformed()
undoPerformed
in interface org.pepsoft.util.undo.UndoListener
public void redoPerformed()
redoPerformed
in interface org.pepsoft.util.undo.UndoListener
public void bufferChanged(org.pepsoft.util.undo.BufferKey<?> key)
bufferChanged
in interface org.pepsoft.util.undo.UndoListener
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
protected void ensureReadable(Tile.TileBuffer buffer)