Advertisement
Corosus

Untitled

May 5th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. package weather.blocks.structure.tree;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Random;
  5.  
  6. import net.minecraft.block.Block;
  7. import net.minecraft.util.Vec3;
  8.  
  9. public class GrowthNode {
  10.  
  11. public GrowthManager growMan;
  12.  
  13. public int type = 0;
  14. public int childIteration = 0;
  15.  
  16. public int age = 0;
  17. public int stageCur = 0;
  18. public int stageMax = 8;
  19. public int stageTicksBetween = 100;
  20.  
  21. public Vec3 curPos;
  22. public Vec3 curDir;
  23. public ArrayList<Vec3> growthPoints; //a sort of growth waypoint, for making rigid branches
  24. public float growthRate = 0.1F;
  25. public float distBetweenPoints = 2.5F;
  26.  
  27. //Keep like this or make own class, how would leafs slowly grow?
  28. //public ArrayList<Vec3> leafPos;
  29. //public ArrayList<Vec3> leafDir;
  30.  
  31. public GrowthNode parentNode;
  32. public ArrayList<GrowthNode> childNodes;
  33.  
  34. public GrowthNode(GrowthManager parGrowMan, GrowthNode parParent) {
  35. growMan = parGrowMan;
  36. childNodes = new ArrayList<GrowthNode>();
  37. parentNode = parParent;
  38.  
  39. growthPoints = new ArrayList<Vec3>();
  40.  
  41. if (parentNode != null) {
  42. childIteration = parentNode.childIteration + 1;
  43.  
  44. curPos = parentNode.curPos;
  45. //curDir = parentNode.curDir; //needed?
  46. Random rand = new Random();
  47. curDir = Vec3.createVectorHelper(rand.nextDouble() - rand.nextDouble(), rand.nextDouble()/* - rand.nextDouble()*/, rand.nextDouble() - rand.nextDouble());
  48. growthPoints.add(curPos);
  49. } else {
  50. curDir = Vec3.createVectorHelper(0, 1, 0);
  51. }
  52. }
  53.  
  54. public void tickGrowth(boolean recursive) {
  55.  
  56. age++; //??
  57.  
  58. grow();
  59.  
  60. if (recursive) {
  61. for (int i = 0; i < childNodes.size(); i++) {
  62. GrowthNode gn = childNodes.get(i);
  63. //if (gn.isActive()) {
  64. gn.tickGrowth(recursive);
  65. //}
  66. }
  67. }
  68. }
  69.  
  70. public void grow() {
  71. //move in a direction
  72. curPos = curPos.addVector(curDir.xCoord * growthRate, curDir.yCoord * growthRate, curDir.zCoord * growthRate);
  73.  
  74. if (growMan.worldObj.getBlockId((int)curPos.xCoord, (int)curPos.yCoord, (int)curPos.zCoord) == 0) {
  75. growMan.worldObj.setBlock((int)curPos.xCoord, (int)curPos.yCoord, (int)curPos.zCoord, Block.wood.blockID);
  76. }
  77.  
  78. if (curPos.distanceTo(growthPoints.get(growthPoints.size()-1)) > distBetweenPoints) {
  79. growthPoints.add(curPos);
  80. if (growMan.worldObj.rand.nextInt(2+(childIteration * 2)) == 0 && childIteration < 10) {
  81. newNode();
  82. }
  83. //change direction a little bit
  84. nextStage();
  85. }
  86.  
  87. //if (age > stageCur * stageTicksBetween) nextStage();
  88. }
  89.  
  90. public void nextStage() {
  91. stageCur++;
  92. System.out.println("growth next stage - " + (int)curPos.xCoord + " - " + (int)curPos.yCoord + " - " + (int)curPos.zCoord);
  93.  
  94.  
  95. }
  96.  
  97. public void newNode() {
  98. GrowthNode gn = new GrowthNode(growMan, this);
  99. childNodes.add(gn);
  100. growMan.activeGrowths.add(gn);
  101. }
  102.  
  103. public boolean isActive() {
  104. return stageCur < stageMax;
  105. }
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement