22
33import com .khorn .terraincontrol .LocalWorld ;
44import com .khorn .terraincontrol .util .ChunkCoordinate ;
5+ import com .khorn .terraincontrol .util .Rotation ;
56import com .khorn .terraincontrol .util .helpers .RandomHelper ;
67
78import java .util .*;
89
910/**
10- * This class creates the branch structure based on one parent object, and spawns all
11- * objects that should spawn in a chunk.
12- *
13- * Although it shouldn't be too slow to recalculate, a structure cache should be kept .
11+ * Represents a collection of all {@link CustomObject}s in a structure. It is
12+ * calculated by finding the branches of one object, then finding the branches
13+ * of those branches, etc., until
14+ * {@link StructuredCustomObject#getMaxBranchDepth()} is reached .
1415 *
1516 */
1617public class CustomObjectStructure
@@ -19,20 +20,21 @@ public class CustomObjectStructure
1920 protected LocalWorld world ;
2021 protected CustomObjectCoordinate start ;
2122 protected StructurePartSpawnHeight height ;
22- protected Map <ChunkCoordinate , Set <CustomObjectCoordinate >> objectsToSpawn ;
23- protected int maxBranchDepth ;
23+ private Map <ChunkCoordinate , Set <CustomObjectCoordinate >> objectsToSpawn ;
24+ private int maxBranchDepth ;
2425
25- public CustomObjectStructure (LocalWorld world , CustomObjectCoordinate start )
26+ CustomObjectStructure (LocalWorld world , CustomObjectCoordinate start )
2627 {
2728 if (!(start .getObject () instanceof StructuredCustomObject ))
2829 {
2930 throw new IllegalArgumentException ("Start object has to be a structure!" );
3031 }
32+ StructuredCustomObject object = (StructuredCustomObject ) start .getObject ();
3133
3234 this .world = world ;
3335 this .start = start ;
34- this .height = start . getStructuredObject () .getStructurePartSpawnHeight ();
35- this .maxBranchDepth = start . getStructuredObject () .getMaxBranchDepth ();
36+ this .height = object .getStructurePartSpawnHeight ();
37+ this .maxBranchDepth = object .getMaxBranchDepth ();
3638 random = RandomHelper .getRandomForCoords (start .getX (), start .getY (), start .getZ (), world .getSeed ());
3739
3840 // Calculate all branches and add them to a list
@@ -43,7 +45,7 @@ public CustomObjectStructure(LocalWorld world, CustomObjectCoordinate start)
4345
4446 private void addBranches (CustomObjectCoordinate coordObject , int depth )
4547 {
46- for (Branch branch : coordObject .getStructuredObject (). getBranches ( coordObject .getRotation ()))
48+ for (Branch branch : getBranches ( coordObject .getObject (), coordObject .getRotation ()))
4749 {
4850 CustomObjectCoordinate childCoordObject = branch .toCustomObjectCoordinate (world , random , coordObject .getX (),
4951 coordObject .getY (), coordObject .getZ ());
@@ -65,12 +67,21 @@ private void addBranches(CustomObjectCoordinate coordObject, int depth)
6567 }
6668 }
6769
70+ private Branch [] getBranches (CustomObject customObject , Rotation rotation )
71+ {
72+ if (customObject instanceof StructuredCustomObject )
73+ {
74+ return ((StructuredCustomObject ) customObject ).getBranches (rotation );
75+ }
76+ return new Branch [0 ];
77+ }
78+
6879 /**
6980 * Adds the object to the spawn list of each chunk that the object
7081 * touches.
7182 * @param coordObject The object.
7283 */
73- void addToSpawnList (CustomObjectCoordinate coordObject )
84+ private void addToSpawnList (CustomObjectCoordinate coordObject )
7485 {
7586 ChunkCoordinate chunkCoordinate = coordObject .getPopulatingChunk ();
7687
@@ -83,6 +94,10 @@ void addToSpawnList(CustomObjectCoordinate coordObject)
8394 objectsInChunk .add (coordObject );
8495 }
8596
97+ /**
98+ * Spawns all the objects that should be spawned in that chunk.
99+ * @param chunkCoordinate The chunk to spawn in.
100+ */
86101 public void spawnForChunk (ChunkCoordinate chunkCoordinate )
87102 {
88103 Set <CustomObjectCoordinate > objectsInChunk = objectsToSpawn .get (chunkCoordinate );
0 commit comments