public abstract class Seed extends java.lang.Object implements java.io.Serializable, org.pepsoft.util.undo.Cloneable<Seed>
Garden
for creating complex random
structures that follow rules. A seed has a germination time, which is the
number of ticks after planting when it will try to sprout. When it germinates
it checks whether there is room to sprout and if so does so, optionally
planting new seeds in the process.
Seeds may have parents and form a hierarchy, in which case parents will always sprout before children (and therefore children will not sprout if their parent hasn't), and parents will also be exported before their children during the export process.
Modifier and Type | Class and Description |
---|---|
static interface |
Seed.Task |
Modifier and Type | Field and Description |
---|---|
int |
category |
Garden |
garden |
javax.vecmath.Point3i |
location |
Seed |
parent |
long |
seed |
Constructor and Description |
---|
Seed(Garden garden,
long seed,
Seed parent,
javax.vecmath.Point3i location,
int germinationTime,
int category)
Create a new seed.
|
Modifier and Type | Method and Description |
---|---|
void |
buildFirstPass(Dimension dimension,
Tile tile,
Platform platform,
MinecraftWorld minecraftWorld)
Perform the first export pass.
|
void |
buildSecondPass(Dimension dimension,
Tile tile,
Platform platform,
MinecraftWorld minecraftWorld)
Perform the second export pass.
|
Seed |
clone() |
protected void |
doAlongLine(int x1,
int y1,
int x2,
int y2,
boolean stopWhenOccupied,
Seed.Task task)
Utility method for performing some arbitrary task along a straight line.
|
protected void |
doAlongLine(int x1,
int y1,
int x2,
int y2,
boolean stopWhenOccupied,
Seed.Task task,
int every)
Utility method for performing some arbitrary task at some interval along
a straight line.
|
protected void |
doAlongLine(int x1,
int y1,
int x2,
int y2,
int maxLength,
Seed.Task task)
Utility method for performing some arbitrary task along a straight line.
|
protected void |
doAlongLine(int x1,
int y1,
int x2,
int y2,
int maxLength,
Seed.Task task,
int every)
Utility method for performing some arbitrary task at some interval along
a straight line.
|
protected void |
doAlongLine(int x1,
int y1,
int x2,
int y2,
Seed.Task task)
Utility method for performing some arbitrary task along a straight line,
regardless of whether it is occupied or not.
|
protected void |
doAlongLine(int x1,
int y1,
int x2,
int y2,
Seed.Task task,
int every)
Utility method for performing some arbitrary task at some interval along
a straight line, regardless of whether it is occupied or not.
|
protected void |
drawLine(int x1,
int y1,
int x2,
int y2,
int maxLength,
int category)
Utility method for setting the seed category on the garden along a
straight line.
|
protected void |
drawLine(javax.vecmath.Point3i location1,
javax.vecmath.Point3i location2,
int diameter,
boolean stopWhenOccupied,
int category)
Utility method for setting the seed category on the garden along a
straight line.
|
protected void |
drawLine(javax.vecmath.Point3i location1,
javax.vecmath.Point3i location2,
int diameter,
int maxLength,
int category)
Utility method for setting the seed category on the garden along a
straight line.
|
protected void |
drawLine(java.awt.Point location1,
java.awt.Point location2,
int category)
Utility method for setting the seed category on the garden along a
straight line, regardless of what is already there.
|
protected void |
drawLine(java.awt.Point location1,
java.awt.Point location2,
int diameter,
boolean stopWhenOccupied,
int category)
Utility method for setting the seed category on the garden along a
straight line.
|
protected void |
drawLine(java.awt.Point location1,
java.awt.Point location2,
int diameter,
int maxLength,
int category)
Utility method for setting the seed category on the garden along a
straight line.
|
boolean |
equals(java.lang.Object obj) |
protected void |
fill(int x1,
int y1,
int width,
int height,
int category) |
Garden |
getGarden()
Get the garden in which the seed is planted.
|
javax.vecmath.Point3i |
getLocation()
Get this seed's location.
|
Seed |
getParent()
Get this seed's parent, if any,
|
int |
hashCode() |
boolean |
isFinished()
Determine whether the seed is "alive", i.e.
|
boolean |
isSprouted()
Determine whether the seed has successfully sprouted.
|
void |
neutralise()
"Kill" the seed, i.e.
|
protected int |
scanLine(int x1,
int y1,
int x2,
int y2)
Utility method for testing how much of a straight line is unoccupied.
|
protected abstract boolean |
sprout()
Try to sprout the seed.
|
void |
tick()
Tick the seed over.
|
void |
transform(CoordinateTransform rotation)
Transform the seed's location and rotation according to some coordinate
transform.
|
public final javax.vecmath.Point3i location
public transient Garden garden
public final Seed parent
public final int category
public final long seed
public Seed(Garden garden, long seed, Seed parent, javax.vecmath.Point3i location, int germinationTime, int category)
garden
- The garden in which the seed will be planted.seed
- The random seed which it may use for seeding pseudo random
number generators.parent
- The parent of this seed, if any. May be null
.location
- The location of the seed. The z coordinate may be -1,
meaning "on the surface", or it may be zero or higher to
indicate a specific height.germinationTime
- The number of ticks after planting when the seed
will germinate. If positive a random deviation
will be applied. If negative it will be made
positive without applying a random
deviation.category
- The category of seed, as one of the
CATEGORY_*
constants in the GardenCategory
class.public final Garden getGarden()
public final Seed getParent()
null
if it has none.public final javax.vecmath.Point3i getLocation()
public final void tick()
public final boolean isFinished()
true
if the seed is dead, i.e. it has attempted to
sprout, which either succeeded or failed.public final boolean isSprouted()
true
if the seed has successfully sprouted.public final void neutralise()
public void buildFirstPass(Dimension dimension, Tile tile, Platform platform, MinecraftWorld minecraftWorld)
For buildings it may be advantageous to export the exteriors in the first pass.
dimension
- The dimension which is being exported.tile
- The tile which is being exported. Note that the seed does
not have to constrain its changes to the area of the
tile.platform
- minecraftWorld
- The Minecraft map to which the seed should export
itself.public void buildSecondPass(Dimension dimension, Tile tile, Platform platform, MinecraftWorld minecraftWorld)
For buildings it may be advantageous to export the interiors in the second pass.
dimension
- The dimension which is being exported.tile
- The tile which is being exported. Note that the seed does
not have to constrain its changes to the area of the
tile.platform
- minecraftWorld
- The Minecraft map to which the seed should export
itself.public void transform(CoordinateTransform rotation)
rotation
- The coordinate transform to apply to the seed's location
and rotation.public Seed clone()
clone
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
protected abstract boolean sprout()
false
, the seed will be considered to
have died, and be removed from the garden automatically.true
if the seed sprouted successfully,
false
if it could not sprout for whatever reason.protected final void drawLine(java.awt.Point location1, java.awt.Point location2, int diameter, boolean stopWhenOccupied, int category)
location1
- The start location of the line.location2
- The end location of the line.diameter
- The thickness of the line.stopWhenOccupied
- Whether to stop drawing the line upon reaching a
location which is already occupied.category
- The seed category with which to mark the line, as one of
the CATEGORY_*
constants in the
GardenCategory
class.protected final void drawLine(javax.vecmath.Point3i location1, javax.vecmath.Point3i location2, int diameter, boolean stopWhenOccupied, int category)
location1
- The start location of the line.location2
- The end location of the line.diameter
- The thickness of the line.stopWhenOccupied
- Whether to stop drawing the line upon reaching a
location which is already occupied.category
- The seed category with which to mark the line, as one of
the CATEGORY_*
constants in the
GardenCategory
class.protected final void drawLine(java.awt.Point location1, java.awt.Point location2, int diameter, int maxLength, int category)
location1
- The start location of the line.location2
- The end location of the line.diameter
- The thickness of the line.maxLength
- The maximum lengh of the line. If this is shorter than
the distance between location1
and
location2
, only the first
maxLength
blocks of the line will be
painted.category
- The seed category with which to mark the line, as one of
the CATEGORY_*
constants in the
GardenCategory
class.protected final void drawLine(javax.vecmath.Point3i location1, javax.vecmath.Point3i location2, int diameter, int maxLength, int category)
location1
- The start location of the line.location2
- The end location of the line.diameter
- The thickness of the line.maxLength
- The maximum lengh of the line. If this is shorter than
the distance between location1
and
location2
, only the first
maxLength
blocks of the line will be
painted.category
- The seed category with which to mark the line, as one of
the CATEGORY_*
constants in the
GardenCategory
class.protected final int scanLine(int x1, int y1, int x2, int y2)
x1
- The X coordinate of the start of the line.y1
- The Y coordinate of the start of the line.x2
- The X coordinate of the end of the line.y2
- The Y coordinate of the end of the line.protected final void drawLine(int x1, int y1, int x2, int y2, int maxLength, int category)
x1
- The X coordinate of the start of the line.y1
- The Y coordinate of the start of the line.x2
- The X coordinate of the end of the line.y2
- The Y coordinate of the end of the line.maxLength
- The maximum lengh of the line. If this is shorter than
the distance between location1
and
location2
, only the first
maxLength
blocks of the line will be
painted.category
- The seed category with which to mark the line, as one of
the CATEGORY_*
constants in the
GardenCategory
class.protected final void drawLine(java.awt.Point location1, java.awt.Point location2, int category)
location1
- The start location of the line.location2
- The end location of the line.category
- The seed category with which to mark the line, as one of
the CATEGORY_*
constants in the
GardenCategory
class.protected final void fill(int x1, int y1, int width, int height, int category)
protected final void doAlongLine(int x1, int y1, int x2, int y2, Seed.Task task)
x1
- The X coordinate of the start of the line.y1
- The Y coordinate of the start of the line.x2
- The X coordinate of the end of the line.y2
- The Y coordinate of the end of the line.task
- The task to perform at each loction along the specified line.protected final void doAlongLine(int x1, int y1, int x2, int y2, Seed.Task task, int every)
x1
- The X coordinate of the start of the line.y1
- The Y coordinate of the start of the line.x2
- The X coordinate of the end of the line.y2
- The Y coordinate of the end of the line.task
- The task to perform at each specified interval along the
specified line.every
- The interval between performances of the specified task.protected final void doAlongLine(int x1, int y1, int x2, int y2, boolean stopWhenOccupied, Seed.Task task)
x1
- The X coordinate of the start of the line.y1
- The Y coordinate of the start of the line.x2
- The X coordinate of the end of the line.y2
- The Y coordinate of the end of the line.stopWhenOccupied
- Whether to stop performing the task upon reaching
a location which is occupied.task
- The task to perform at each location along the specified line.protected final void doAlongLine(int x1, int y1, int x2, int y2, boolean stopWhenOccupied, Seed.Task task, int every)
x1
- The X coordinate of the start of the line.y1
- The Y coordinate of the start of the line.x2
- The X coordinate of the end of the line.y2
- The Y coordinate of the end of the line.stopWhenOccupied
- Whether to stop performing the task upon reaching
a location which is occupied.task
- The task to perform at each specified interval along the
specified line.every
- The interval between performances of the specified task.protected final void doAlongLine(int x1, int y1, int x2, int y2, int maxLength, Seed.Task task)
x1
- The X coordinate of the start of the line.y1
- The Y coordinate of the start of the line.x2
- The X coordinate of the end of the line.y2
- The Y coordinate of the end of the line.maxLength
- The maximum length for which to perform the task. If
this is shorter than the distance between
location1
and location2
, the
task will only be performed for the first
maxLength
blocks of the line.task
- The task to perform at each location along the specified
line.protected final void doAlongLine(int x1, int y1, int x2, int y2, int maxLength, Seed.Task task, int every)
x1
- The X coordinate of the start of the line.y1
- The Y coordinate of the start of the line.x2
- The X coordinate of the end of the line.y2
- The Y coordinate of the end of the line.maxLength
- The maximum length for which to perform the task. If
this is shorter than the distance between
location1
and location2
, the
task will only be performed for the first
maxLength
blocks of the line.task
- The task to perform at each specified interval along the
specified line.every
- The interval between performances of the specified task.