Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package weather.blocks.structure.tree;
- import java.util.ArrayList;
- import java.util.Random;
- import net.minecraft.block.Block;
- import net.minecraft.util.Vec3;
- public class GrowthNode {
- public GrowthManager growMan;
- public int type = 0;
- public int childIteration = 0;
- public int age = 0;
- public int stageCur = 0;
- public int stageMax = 8;
- public int stageTicksBetween = 100;
- public Vec3 curPos;
- public Vec3 curDir;
- public ArrayList<Vec3> growthPoints; //a sort of growth waypoint, for making rigid branches
- public float growthRate = 0.1F;
- public float distBetweenPoints = 2.5F;
- //Keep like this or make own class, how would leafs slowly grow?
- //public ArrayList<Vec3> leafPos;
- //public ArrayList<Vec3> leafDir;
- public GrowthNode parentNode;
- public ArrayList<GrowthNode> childNodes;
- public GrowthNode(GrowthManager parGrowMan, GrowthNode parParent) {
- growMan = parGrowMan;
- childNodes = new ArrayList<GrowthNode>();
- parentNode = parParent;
- growthPoints = new ArrayList<Vec3>();
- if (parentNode != null) {
- childIteration = parentNode.childIteration + 1;
- curPos = parentNode.curPos;
- //curDir = parentNode.curDir; //needed?
- Random rand = new Random();
- curDir = Vec3.createVectorHelper(rand.nextDouble() - rand.nextDouble(), rand.nextDouble()/* - rand.nextDouble()*/, rand.nextDouble() - rand.nextDouble());
- growthPoints.add(curPos);
- } else {
- curDir = Vec3.createVectorHelper(0, 1, 0);
- }
- }
- public void tickGrowth(boolean recursive) {
- age++; //??
- grow();
- if (recursive) {
- for (int i = 0; i < childNodes.size(); i++) {
- GrowthNode gn = childNodes.get(i);
- //if (gn.isActive()) {
- gn.tickGrowth(recursive);
- //}
- }
- }
- }
- public void grow() {
- //move in a direction
- curPos = curPos.addVector(curDir.xCoord * growthRate, curDir.yCoord * growthRate, curDir.zCoord * growthRate);
- if (growMan.worldObj.getBlockId((int)curPos.xCoord, (int)curPos.yCoord, (int)curPos.zCoord) == 0) {
- growMan.worldObj.setBlock((int)curPos.xCoord, (int)curPos.yCoord, (int)curPos.zCoord, Block.wood.blockID);
- }
- if (curPos.distanceTo(growthPoints.get(growthPoints.size()-1)) > distBetweenPoints) {
- growthPoints.add(curPos);
- if (growMan.worldObj.rand.nextInt(2+(childIteration * 2)) == 0 && childIteration < 10) {
- newNode();
- }
- //change direction a little bit
- nextStage();
- }
- //if (age > stageCur * stageTicksBetween) nextStage();
- }
- public void nextStage() {
- stageCur++;
- System.out.println("growth next stage - " + (int)curPos.xCoord + " - " + (int)curPos.yCoord + " - " + (int)curPos.zCoord);
- }
- public void newNode() {
- GrowthNode gn = new GrowthNode(growMan, this);
- childNodes.add(gn);
- growMan.activeGrowths.add(gn);
- }
- public boolean isActive() {
- return stageCur < stageMax;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement