From 43906e058d98cf47aab9ce7a0c945c49b3ee7eb0 Mon Sep 17 00:00:00 2001 From: mezz Date: Sat, 1 Aug 2015 18:23:45 -0700 Subject: [PATCH] Fix #763 Forestry saplings sometimes use bonemeal infinitely --- .../arboriculture/gadgets/BlockSapling.java | 8 +- .../arboriculture/gadgets/TileSapling.java | 72 +++++++++---- .../genetics/GrowthProvider.java | 17 ++- .../forestry/arboriculture/genetics/Tree.java | 4 +- .../genetics/TreeDefinition.java | 3 +- .../worldgen/WorldGenAcacia.java | 27 +++-- .../worldgen/WorldGenAcaciaVanilla.java | 2 +- .../worldgen/WorldGenArboriculture.java | 100 +++++++++--------- .../arboriculture/worldgen/WorldGenBalsa.java | 21 ++-- .../worldgen/WorldGenBaobab.java | 62 ++++++----- .../arboriculture/worldgen/WorldGenBirch.java | 2 +- .../worldgen/WorldGenCherry.java | 21 ++-- .../worldgen/WorldGenChestnut.java | 27 ++--- .../worldgen/WorldGenCocobolo.java | 29 +++-- .../worldgen/WorldGenCrescentia.java | 54 +++------- .../worldgen/WorldGenDarkOak.java | 2 +- .../arboriculture/worldgen/WorldGenDate.java | 20 ++-- .../arboriculture/worldgen/WorldGenEbony.java | 36 +++---- .../worldgen/WorldGenGiganteum.java | 13 +-- .../worldgen/WorldGenGreenheart.java | 39 ++++--- .../arboriculture/worldgen/WorldGenIpe.java | 33 +++--- .../worldgen/WorldGenJungle.java | 16 +-- .../arboriculture/worldgen/WorldGenKapok.java | 38 +++---- .../arboriculture/worldgen/WorldGenLarch.java | 21 ++-- .../arboriculture/worldgen/WorldGenLemon.java | 16 ++- .../arboriculture/worldgen/WorldGenLime.java | 20 ++-- .../arboriculture/worldgen/WorldGenMahoe.java | 16 ++- .../worldgen/WorldGenMahogany.java | 27 +++-- .../arboriculture/worldgen/WorldGenMaple.java | 21 ++-- .../arboriculture/worldgen/WorldGenOak.java | 2 +- .../worldgen/WorldGenPadauk.java | 34 +++--- .../worldgen/WorldGenPapaya.java | 16 ++- .../arboriculture/worldgen/WorldGenPine.java | 21 ++-- .../arboriculture/worldgen/WorldGenPlum.java | 18 ++-- .../worldgen/WorldGenPoplar.java | 16 ++- .../worldgen/WorldGenSequoia.java | 45 ++++---- .../worldgen/WorldGenSpruce.java | 21 ++-- .../arboriculture/worldgen/WorldGenTeak.java | 27 +++-- .../arboriculture/worldgen/WorldGenTree.java | 61 ++++++----- .../worldgen/WorldGenTreeVanilla.java | 19 ++++ .../worldgen/WorldGenWalnut.java | 29 +++-- .../arboriculture/worldgen/WorldGenWenge.java | 24 ++--- .../worldgen/WorldGenWillow.java | 33 +++--- .../worldgen/WorldGenZebrawood.java | 35 +++--- .../forestry/core/worldgen/WorldGenBase.java | 38 +++---- 45 files changed, 583 insertions(+), 623 deletions(-) create mode 100644 src/main/java/forestry/arboriculture/worldgen/WorldGenTreeVanilla.java diff --git a/src/main/java/forestry/arboriculture/gadgets/BlockSapling.java b/src/main/java/forestry/arboriculture/gadgets/BlockSapling.java index 656aafd26..55314425d 100755 --- a/src/main/java/forestry/arboriculture/gadgets/BlockSapling.java +++ b/src/main/java/forestry/arboriculture/gadgets/BlockSapling.java @@ -188,14 +188,18 @@ public class BlockSapling extends BlockTreeContainer implements IGrowable { @Override /** canFertilize */ - public boolean func_149851_a(World worldIn, int x, int y, int z, boolean isClient) { + public boolean func_149851_a(World world, int x, int y, int z, boolean isClient) { + TileSapling saplingTile = getSaplingTile(world, x, y, z); + if (saplingTile != null) { + return saplingTile.canAcceptBoneMeal(); + } return true; } @Override /** shouldFertilize */ public boolean func_149852_a(World world, Random random, int x, int y, int z) { - return (double) world.rand.nextFloat() < 0.45D; + return world.rand.nextFloat() < 0.45F; } @Override diff --git a/src/main/java/forestry/arboriculture/gadgets/TileSapling.java b/src/main/java/forestry/arboriculture/gadgets/TileSapling.java index 90e8bed37..46d13d95d 100755 --- a/src/main/java/forestry/arboriculture/gadgets/TileSapling.java +++ b/src/main/java/forestry/arboriculture/gadgets/TileSapling.java @@ -11,9 +11,15 @@ package forestry.arboriculture.gadgets; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; import net.minecraft.world.gen.feature.WorldGenerator; +import forestry.api.arboriculture.ITree; +import forestry.api.arboriculture.ITreekeepingMode; import forestry.api.arboriculture.TreeManager; +import forestry.api.genetics.IBreedingTracker; +import forestry.arboriculture.worldgen.WorldGenArboriculture; +import forestry.core.worldgen.WorldGenBase; public class TileSapling extends TileTreeContainer { @@ -41,32 +47,62 @@ public class TileSapling extends TileTreeContainer { tryGrow(false); } - public int tryGrow(boolean bonemealed) { + private static int getRequiredMaturity(World world, ITree tree) { + ITreekeepingMode treekeepingMode = TreeManager.treeRoot.getTreekeepingMode(world); + float maturationModifier = treekeepingMode.getMaturationModifier(tree.getGenome(), 1f); + return Math.round(tree.getRequiredMaturity() * maturationModifier); + } - int result = 0; - if (this.getTree() == null) { - return result; - } - - int maturity = (int) (getTree().getRequiredMaturity() * TreeManager.treeRoot.getTreekeepingMode(worldObj).getMaturationModifier( - getTree().getGenome(), 1f)); - - if (bonemealed && timesTicked < maturity) { - timesTicked++; - result = 1; + public boolean canAcceptBoneMeal() { + ITree tree = getTree(); + + if (tree == null) { + return false; } + int maturity = getRequiredMaturity(worldObj, tree); if (timesTicked < maturity) { - return result; + return true; } - WorldGenerator generator = this.getTree().getTreeGenerator(worldObj, xCoord, yCoord, zCoord, bonemealed); - if (generator.generate(worldObj, worldObj.rand, xCoord, yCoord, zCoord)) { - TreeManager.treeRoot.getBreedingTracker(worldObj, getOwner()).registerBirth(getTree()); - return 2; + WorldGenerator generator = tree.getTreeGenerator(worldObj, xCoord, yCoord, zCoord, true); + if (generator instanceof WorldGenArboriculture) { + WorldGenArboriculture arboricultureGenerator = (WorldGenArboriculture) generator; + arboricultureGenerator.preGenerate(worldObj, xCoord, yCoord, zCoord); + return arboricultureGenerator.canGrow(worldObj, xCoord, yCoord, zCoord); + } else { + return true; + } + } + + public void tryGrow(boolean bonemealed) { + + ITree tree = getTree(); + + if (tree == null) { + return; } - return 3; + int maturity = getRequiredMaturity(worldObj, tree); + if (timesTicked < maturity) { + if (bonemealed) { + timesTicked = maturity; + } + return; + } + + WorldGenerator generator = tree.getTreeGenerator(worldObj, xCoord, yCoord, zCoord, bonemealed); + final boolean generated; + if (generator instanceof WorldGenBase) { + generated = ((WorldGenBase) generator).generate(worldObj, worldObj.rand, xCoord, yCoord, zCoord, bonemealed); + } else { + generated = generator.generate(worldObj, worldObj.rand, xCoord, yCoord, zCoord); + } + + if (generated) { + IBreedingTracker breedingTracker = TreeManager.treeRoot.getBreedingTracker(worldObj, getOwner()); + breedingTracker.registerBirth(tree); + } } } diff --git a/src/main/java/forestry/arboriculture/genetics/GrowthProvider.java b/src/main/java/forestry/arboriculture/genetics/GrowthProvider.java index ab442b873..7c49687db 100755 --- a/src/main/java/forestry/arboriculture/genetics/GrowthProvider.java +++ b/src/main/java/forestry/arboriculture/genetics/GrowthProvider.java @@ -27,9 +27,15 @@ public class GrowthProvider implements IGrowthProvider { @Override public boolean canGrow(ITreeGenome genome, World world, int xPos, int yPos, int zPos, int expectedGirth, int expectedHeight) { - return hasRoom(genome, world, xPos, yPos, zPos, expectedGirth, expectedHeight) - && getGrowthConditions(genome, world, xPos, yPos, zPos) != EnumGrowthConditions.HOSTILE - && hasSufficientSaplings(genome, world, xPos, yPos, zPos, expectedGirth); + if (!hasRoom(genome, world, xPos, yPos, zPos, expectedGirth, expectedHeight)) { + return false; + } + + if (getGrowthConditions(genome, world, xPos, yPos, zPos) == EnumGrowthConditions.HOSTILE) { + return false; + } + + return hasSufficientSaplings(genome, world, xPos, yPos, zPos, expectedGirth); } @Override @@ -99,9 +105,10 @@ public class GrowthProvider implements IGrowthProvider { int offset = (expectedGirth - 1) / 2; // if(offset <= 0) // offset = 1; + Vect start = new Vect(xPos - offset, yPos + 1, zPos + offset); + Vect area = new Vect(-offset + expectedGirth, expectedHeight + 1, -offset + expectedGirth); - return checkArea(world, new Vect(xPos - offset, yPos + 1, zPos + offset), - new Vect(-offset + expectedGirth, expectedHeight + 1, -offset + expectedGirth)); + return checkArea(world, start, area); } protected static boolean checkArea(World world, Vect start, Vect area) { diff --git a/src/main/java/forestry/arboriculture/genetics/Tree.java b/src/main/java/forestry/arboriculture/genetics/Tree.java index 27c3f1c74..1658b8f59 100755 --- a/src/main/java/forestry/arboriculture/genetics/Tree.java +++ b/src/main/java/forestry/arboriculture/genetics/Tree.java @@ -37,6 +37,7 @@ import forestry.api.arboriculture.IAlleleLeafEffect; import forestry.api.arboriculture.IAlleleTreeSpecies; import forestry.api.arboriculture.IArboristTracker; import forestry.api.arboriculture.IFruitProvider; +import forestry.api.arboriculture.IGrowthProvider; import forestry.api.arboriculture.ITree; import forestry.api.arboriculture.ITreeGenome; import forestry.api.arboriculture.ITreeMutation; @@ -188,7 +189,8 @@ public class Tree extends Individual implements ITree, IPlantable { @Override public boolean canGrow(World world, int x, int y, int z, int expectedGirth, int expectedHeight) { - return genome.getGrowthProvider().canGrow(genome, world, x, y, z, expectedGirth, expectedHeight); + IGrowthProvider growthProvider = genome.getGrowthProvider(); + return growthProvider.canGrow(genome, world, x, y, z, expectedGirth, expectedHeight); } @Override diff --git a/src/main/java/forestry/arboriculture/genetics/TreeDefinition.java b/src/main/java/forestry/arboriculture/genetics/TreeDefinition.java index 7de679743..f7496964c 100644 --- a/src/main/java/forestry/arboriculture/genetics/TreeDefinition.java +++ b/src/main/java/forestry/arboriculture/genetics/TreeDefinition.java @@ -64,6 +64,7 @@ import forestry.arboriculture.worldgen.WorldGenJungle; import forestry.arboriculture.worldgen.WorldGenKapok; import forestry.arboriculture.worldgen.WorldGenLarch; import forestry.arboriculture.worldgen.WorldGenLemon; +import forestry.arboriculture.worldgen.WorldGenLime; import forestry.arboriculture.worldgen.WorldGenMahoe; import forestry.arboriculture.worldgen.WorldGenMahogany; import forestry.arboriculture.worldgen.WorldGenMaple; @@ -158,7 +159,7 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator { Lime(TreeBranchDefinition.TILIA, "silverLime", "pendula", true, EnumLeafType.DECIDUOUS, new Color(0x5ea107), new Color(0x5ea107).brighter(), WoodType.LIME) { @Override public WorldGenerator getWorldGenerator(ITreeGenData tree) { - return new WorldGenDarkOak(tree); + return new WorldGenLime(tree); } @Override diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenAcacia.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenAcacia.java index 9ca8140ff..9bf75104b 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenAcacia.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenAcacia.java @@ -10,42 +10,39 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenAcacia extends WorldGenTree { public WorldGenAcacia(ITreeGenData tree) { - super(tree); + super(tree, 5, 2); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int leafSpawn = height + 1; float rnd = world.rand.nextFloat(); int offset = 0; if (rnd > 0.6f) { - offset = rand.nextInt(girth); + offset = world.rand.nextInt(girth); } else if (rnd > 0.3) { - offset = -rand.nextInt(girth); + offset = -world.rand.nextInt(girth); } - generateAdjustedCylinder(leafSpawn--, offset, 0, 1, leaf, EnumReplaceMode.NONE); - generateAdjustedCylinder(leafSpawn--, offset, 1.5f, 1, leaf, EnumReplaceMode.NONE); + generateAdjustedCylinder(world, leafSpawn--, offset, 0, 1, leaf, EnumReplaceMode.NONE); + generateAdjustedCylinder(world, leafSpawn--, offset, 1.5f, 1, leaf, EnumReplaceMode.NONE); - if (rand.nextBoolean()) { - generateAdjustedCylinder(leafSpawn--, offset, 3.9f, 1, leaf, EnumReplaceMode.NONE); + if (world.rand.nextBoolean()) { + generateAdjustedCylinder(world, leafSpawn--, offset, 3.9f, 1, leaf, EnumReplaceMode.NONE); } else { - generateAdjustedCylinder(leafSpawn--, offset, 2.9f, 1, leaf, EnumReplaceMode.NONE); + generateAdjustedCylinder(world, leafSpawn--, offset, 2.9f, 1, leaf, EnumReplaceMode.NONE); } } - @Override - public void preGenerate() { - height = determineHeight(5, 2); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenAcaciaVanilla.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenAcaciaVanilla.java index 3f64bba97..eb4b15846 100644 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenAcaciaVanilla.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenAcaciaVanilla.java @@ -12,7 +12,7 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -public class WorldGenAcaciaVanilla extends WorldGenTree { +public class WorldGenAcaciaVanilla extends WorldGenTreeVanilla { public WorldGenAcaciaVanilla(ITreeGenData tree) { super(tree); diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenArboriculture.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenArboriculture.java index b15d61dff..27bf4c547 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenArboriculture.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenArboriculture.java @@ -10,13 +10,15 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import java.util.Random; + import net.minecraft.init.Blocks; -import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; import com.mojang.authlib.GameProfile; import forestry.api.world.ITreeGenData; -import forestry.arboriculture.gadgets.TileSapling; +import forestry.arboriculture.gadgets.TileTreeContainer; import forestry.core.utils.Utils; import forestry.core.worldgen.BlockType; import forestry.core.worldgen.BlockTypeVoid; @@ -47,55 +49,53 @@ public abstract class WorldGenArboriculture extends WorldGenBase { } @Override - public boolean subGenerate(int x, int y, int z, boolean forced) { - this.startX = x; - this.startY = y; - this.startZ = z; - + public boolean generate(World world, Random random, int x, int y, int z, boolean forced) { this.spawnPods = tree.allowsFruitBlocks(); - this.leaf = getLeaf(getOwner()); + this.leaf = getLeaf(getOwner(world, x, y, z)); this.wood = getWood(); - preGenerate(); - if (!forced && !canGrow()) { - return false; - } else { - generate(); + preGenerate(world, x, y, z); + if (forced || canGrow(world, x, y, z)) { + generate(world); return true; } + return false; } - private GameProfile getOwner() { - TileEntity tile = world.getTileEntity(startX, startY, startZ); - if (tile instanceof TileSapling) { - return ((TileSapling) tile).getOwner(); - } else { + private static GameProfile getOwner(World world, int x, int y, int z) { + TileTreeContainer tile = Utils.getTile(world, x, y, z, TileTreeContainer.class); + if (tile == null) { return null; } + return tile.getOwner(); } - public abstract void preGenerate(); + public void preGenerate(World world, int startX, int startY, int startZ) { + this.startX = startX; + this.startY = startY; + this.startZ = startZ; + } - public abstract void generate(); + public abstract void generate(World world); - public abstract boolean canGrow(); + public abstract boolean canGrow(World world, int x, int y, int z); public abstract TreeBlockTypeLeaf getLeaf(GameProfile owner); public abstract ITreeBlockType getWood(); - protected void generateTreeTrunk(int height, int girth) { - generateTreeTrunk(height, girth, 0); + protected void generateTreeTrunk(World world, int height, int girth) { + generateTreeTrunk(world, height, girth, 0); } - protected void generateTreeTrunk(int height, int girth, float vines) { + protected void generateTreeTrunk(World world, int height, int girth, float vines) { int offset = (girth - 1) / 2; for (int x = 0; x < girth; x++) { for (int z = 0; z < girth; z++) { for (int y = 0; y < height; y++) { - addWood(x - offset, y, z - offset, EnumReplaceMode.ALL); - addVines(x - offset, y, z - offset, vines); + addWood(world, x - offset, y, z - offset, EnumReplaceMode.ALL); + addVines(world, x - offset, y, z - offset, vines); } } } @@ -104,6 +104,11 @@ public abstract class WorldGenArboriculture extends WorldGenBase { return; } + generatePods(world, height, girth); + + } + + protected void generatePods(World world, int height, int girth) { for (int y = minPodHeight; y < height; y++) { for (int x = 0; x < girth; x++) { for (int z = 0; z < girth; z++) { @@ -119,10 +124,9 @@ public abstract class WorldGenArboriculture extends WorldGenBase { } } } - } - protected void generateSupportStems(int height, int girth, float chance, float maxHeight) { + protected void generateSupportStems(World world, int height, int girth, float chance, float maxHeight) { int offset = 1; @@ -142,10 +146,10 @@ public abstract class WorldGenArboriculture extends WorldGenBase { continue; } - int stemHeight = rand.nextInt(Math.round(height * maxHeight)); - if (rand.nextFloat() < chance) { + int stemHeight = world.rand.nextInt(Math.round(height * maxHeight)); + if (world.rand.nextFloat() < chance) { for (int i = 0; i < stemHeight; i++) { - addWood(x, i, z, EnumReplaceMode.SOFT); + addWood(world, x, i, z, EnumReplaceMode.SOFT); } } } @@ -154,7 +158,7 @@ public abstract class WorldGenArboriculture extends WorldGenBase { } @Override - protected void addBlock(int x, int y, int z, ITreeBlockType type, EnumReplaceMode replace) { + protected void addBlock(World world, int x, int y, int z, ITreeBlockType type, EnumReplaceMode replace) { if (replace == EnumReplaceMode.ALL || (replace == EnumReplaceMode.SOFT && Utils.isReplaceableBlock(world, startX + x, startY + y, startZ + z)) || world.isAirBlock(startX + x, startY + y, startZ + z)) { @@ -162,38 +166,38 @@ public abstract class WorldGenArboriculture extends WorldGenBase { } } - protected final void clearBlock(int x, int y, int z) { + protected final void clearBlock(World world, int x, int y, int z) { air.setBlock(world, startX + x, startY + y, startZ + z); } - protected final void addWood(int x, int y, int z, EnumReplaceMode replace) { - addBlock(x, y, z, wood, replace); + protected final void addWood(World world, int x, int y, int z, EnumReplaceMode replace) { + addBlock(world, x, y, z, wood, replace); } - protected final void addLeaf(int x, int y, int z, EnumReplaceMode replace) { - addBlock(x, y, z, leaf, replace); + protected final void addLeaf(World world, int x, int y, int z, EnumReplaceMode replace) { + addBlock(world, x, y, z, leaf, replace); } - protected final void addVine(int x, int y, int z, ITreeBlockType vine) { - addBlock(x, y, z, vine, EnumReplaceMode.NONE); + protected final void addVine(World world, int x, int y, int z, ITreeBlockType vine) { + addBlock(world, x, y, z, vine, EnumReplaceMode.NONE); } - protected final void addVines(int x, int y, int z, float chance) { + protected final void addVines(World world, int x, int y, int z, float chance) { if (chance <= 0) { return; } - if (rand.nextFloat() < chance) { - addVine(x - 1, y, z, vineWest); + if (world.rand.nextFloat() < chance) { + addVine(world, x - 1, y, z, vineWest); } - if (rand.nextFloat() < chance) { - addVine(x + 1, y, z, vineEast); + if (world.rand.nextFloat() < chance) { + addVine(world, x + 1, y, z, vineEast); } - if (rand.nextFloat() < chance) { - addVine(x, y, z - 1, vineNorth); + if (world.rand.nextFloat() < chance) { + addVine(world, x, y, z - 1, vineNorth); } - if (rand.nextFloat() < chance) { - addVine(x, y, z + 1, vineSouth); + if (world.rand.nextFloat() < chance) { + addVine(world, x, y, z + 1, vineSouth); } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenBalsa.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenBalsa.java index 0e9ca632e..78c63f47b 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenBalsa.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenBalsa.java @@ -10,39 +10,36 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenBalsa extends WorldGenTree { public WorldGenBalsa(ITreeGenData tree) { - super(tree); + super(tree, 6, 6); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int leafSpawn = height; - addLeaf(0, leafSpawn--, 0, EnumReplaceMode.NONE); - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); + addLeaf(world, 0, leafSpawn--, 0, EnumReplaceMode.NONE); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); if (height > 10) { - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); } leafSpawn--; while (leafSpawn > 6) { - generateAdjustedCylinder(leafSpawn, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn, 0, 1, leaf); leafSpawn--; } } - @Override - public void preGenerate() { - height = determineHeight(6, 6); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenBaobab.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenBaobab.java index 1b8f0f1dd..ced50a4ed 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenBaobab.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenBaobab.java @@ -10,59 +10,65 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenBaobab extends WorldGenTree { public WorldGenBaobab(ITreeGenData tree) { - super(tree); + super(tree, 6, 6); } @Override - public void generate() { - generateTreeTrunk(height - 1, girth); + public void generate(World world) { + generateTreeTrunk(world, height - 1, girth); - if (rand.nextFloat() < 0.3f) { - generateCylinder(new Vector(0, height - 1, 0), girth, 1, wood, EnumReplaceMode.NONE); - } else if (rand.nextBoolean()) { - generateCylinder(new Vector(0, height - 1, 0), girth - 1, 1, wood, EnumReplaceMode.NONE); + if (world.rand.nextFloat() < 0.3f) { + generateCylinder(world, new Vector(0, height - 1, 0), girth, 1, wood, EnumReplaceMode.NONE); + } else if (world.rand.nextBoolean()) { + generateCylinder(world, new Vector(0, height - 1, 0), girth - 1, 1, wood, EnumReplaceMode.NONE); } int leafSpawn = height + 1; - generateAdjustedCylinder(leafSpawn--, 2f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1.5f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 2f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1f, 1, leaf); // Add tree top for (int times = 0; times < height / 2; times++) { - int h = height - 1 + rand.nextInt(4); - if (rand.nextBoolean() && h < height / 2) { - h = height / 2 + rand.nextInt(height / 2); + int h = height - 1 + world.rand.nextInt(4); + if (world.rand.nextBoolean() && h < height / 2) { + h = height / 2 + world.rand.nextInt(height / 2); } - int x_off = -girth + rand.nextInt(2 * girth); - int y_off = -girth + rand.nextInt(2 * girth); - generateSphere(new Vector(x_off, h, y_off), 1 + (girth > 1 ? rand.nextInt(girth - 1) : 0), leaf, EnumReplaceMode.NONE); + int x_off = -girth + world.rand.nextInt(2 * girth); + int y_off = -girth + world.rand.nextInt(2 * girth); + + Vector center = new Vector(x_off, h, y_off); + int radius = 1; + if (girth > 1) { + radius += world.rand.nextInt(girth - 1); + } + generateSphere(world, center, radius, leaf, EnumReplaceMode.NONE); } // Add some smaller twigs below for flavour for (int times = 0; times < height / 4; times++) { - int delim = modifyByHeight(6, 0, height); - int h = delim + (delim < height ? rand.nextInt(height - delim) : 0); - if (rand.nextBoolean() && h < height / 2) { - h = height / 2 + rand.nextInt(height / 2); + int delim = modifyByHeight(world, 6, 0, height); + int h = delim + (delim < height ? world.rand.nextInt(height - delim) : 0); + if (world.rand.nextBoolean() && h < height / 2) { + h = height / 2 + world.rand.nextInt(height / 2); } - int x_off = -1 + rand.nextInt(3); - int y_off = -1 + rand.nextInt(3); - generateSphere(new Vector(x_off, h, y_off), 1 + rand.nextInt(2), leaf, EnumReplaceMode.NONE); + int x_off = -1 + world.rand.nextInt(3); + int y_off = -1 + world.rand.nextInt(3); + + Vector center = new Vector(x_off, h, y_off); + int radius = 1 + world.rand.nextInt(2); + generateSphere(world, center, radius, leaf, EnumReplaceMode.NONE); } } - @Override - public void preGenerate() { - height = determineHeight(6, 6); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenBirch.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenBirch.java index 5b22ee685..582a22ece 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenBirch.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenBirch.java @@ -12,7 +12,7 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -public class WorldGenBirch extends WorldGenTree { +public class WorldGenBirch extends WorldGenTreeVanilla { public WorldGenBirch(ITreeGenData tree) { super(tree); diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenCherry.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenCherry.java index f26ca749f..848dd8e9a 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenCherry.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenCherry.java @@ -10,32 +10,29 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenCherry extends WorldGenTree { public WorldGenCherry(ITreeGenData tree) { - super(tree); + super(tree, 4, 4); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int leafSpawn = height + 1; - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf); while (leafSpawn > 2) { - generateAdjustedCylinder(leafSpawn--, 2, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 2, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf); } } - @Override - public void preGenerate() { - height = determineHeight(4, 4); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenChestnut.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenChestnut.java index 4dcda7ec5..acd250bc0 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenChestnut.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenChestnut.java @@ -10,38 +10,33 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenChestnut extends WorldGenTree { public WorldGenChestnut(ITreeGenData tree) { - super(tree); - - minHeight = 7; + super(tree, 7, 3); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int leafSpawn = height + 1; - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 0.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf); while (leafSpawn > 4) { - generateAdjustedCylinder(leafSpawn--, 2f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 2f, 1, leaf); } - if (rand.nextBoolean()) { - generateAdjustedCylinder(leafSpawn--, 2f, 1, leaf); + if (world.rand.nextBoolean()) { + generateAdjustedCylinder(world, leafSpawn--, 2f, 1, leaf); } - generateAdjustedCylinder(leafSpawn--, 1.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.5f, 1, leaf); } - @Override - public void preGenerate() { - height = determineHeight(7, 3); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenCocobolo.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenCocobolo.java index db61eb2e0..d9ba5dfa1 100644 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenCocobolo.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenCocobolo.java @@ -10,51 +10,48 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenCocobolo extends WorldGenTree { public WorldGenCocobolo(ITreeGenData tree) { - super(tree); + super(tree, 8, 8); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int leafSpawn = height; - addLeaf(0, leafSpawn--, 0, EnumReplaceMode.NONE); - generateAdjustedCylinder(leafSpawn--, 1, 1, leaf); + addLeaf(world, 0, leafSpawn--, 0, EnumReplaceMode.NONE); + generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf); if (height > 10) { - generateAdjustedCylinder(leafSpawn--, 2, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 2, 1, leaf); } - generateAdjustedCylinder(leafSpawn, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn, 0, 1, leaf); leafSpawn--; while (leafSpawn > 4) { int offset = 1; if (leafSpawn % 2 == 0) { - if (rand.nextBoolean()) { + if (world.rand.nextBoolean()) { offset = -1; } - generateAdjustedCylinder(leafSpawn, offset, 2, 1, leaf, EnumReplaceMode.NONE); + generateAdjustedCylinder(world, leafSpawn, offset, 2, 1, leaf, EnumReplaceMode.NONE); } else { - if (rand.nextBoolean()) { + if (world.rand.nextBoolean()) { offset = -1; } - generateAdjustedCylinder(leafSpawn, offset, 0, 1, leaf, EnumReplaceMode.NONE); + generateAdjustedCylinder(world, leafSpawn, offset, 0, 1, leaf, EnumReplaceMode.NONE); } leafSpawn--; } } - @Override - public void preGenerate() { - height = determineHeight(8, 8); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenCrescentia.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenCrescentia.java index cbaa95934..26fc2ba04 100644 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenCrescentia.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenCrescentia.java @@ -10,39 +10,40 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenCrescentia extends WorldGenTree { public WorldGenCrescentia(ITreeGenData tree) { - super(tree); + super(tree, 6, 3); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int leafSpawn = height + 1; - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 0.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1.9f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1.9f, 1, leaf); - if (rand.nextBoolean()) { - generateAdjustedCylinder(leafSpawn--, 1.9f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.9f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.9f, 1, leaf); + if (world.rand.nextBoolean()) { + generateAdjustedCylinder(world, leafSpawn--, 1.9f, 1, leaf); } - generateAdjustedCylinder(leafSpawn--, 0.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf); } @Override - public void generateTreeTrunk(int height, int girth) { + public void generateTreeTrunk(World world, int height, int girth) { int offset = (girth - 1) / 2; - - + //Trunk generation for (int x = 0; x < girth; x++) //offsets trunk in x direction { @@ -73,7 +74,7 @@ public class WorldGenCrescentia extends WorldGenTree { } } else { //these are center pieces for (int i = 0; i < height; i++) { //grows trunk straight up in y direction to the correct height - addWood(x - offset, i, z - offset, EnumReplaceMode.ALL); + addWood(world, x - offset, i, z - offset, EnumReplaceMode.ALL); } } } @@ -82,28 +83,7 @@ public class WorldGenCrescentia extends WorldGenTree { //End trunk generation //Spawn pods - for (int y = minPodHeight; y < height; y++) { - for (int x = 0; x < girth; x++) { - for (int z = 0; z < girth; z++) { - - if ((x > 0 && x < girth) && (z > 0 && z < girth)) { - continue; - } - - tree.trySpawnFruitBlock(world, startX + x + 1, startY + y, startZ + z); - tree.trySpawnFruitBlock(world, startX + x - 1, startY + y, startZ + z); - tree.trySpawnFruitBlock(world, startX + x, startY + y, startZ + z + 1); - tree.trySpawnFruitBlock(world, startX + x, startY + y, startZ + z - 1); - } - } - } - - - } - - @Override - public void preGenerate() { - height = determineHeight(6, 3); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); + generatePods(world, height, girth); } + } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenDarkOak.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenDarkOak.java index 8f369cde6..e0db60335 100644 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenDarkOak.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenDarkOak.java @@ -12,7 +12,7 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -public class WorldGenDarkOak extends WorldGenTree { +public class WorldGenDarkOak extends WorldGenTreeVanilla { public WorldGenDarkOak(ITreeGenData tree) { super(tree); diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenDate.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenDate.java index 5cbaef155..7d602654b 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenDate.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenDate.java @@ -10,30 +10,26 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenDate extends WorldGenTree { public WorldGenDate(ITreeGenData tree) { - super(tree); + super(tree, 6, 2); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int leafSpawn = height + 1; - generateAdjustedCylinder(leafSpawn--, 2f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 0.5f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 2f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); } - @Override - public void preGenerate() { - height = determineHeight(6, 2); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } - } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenEbony.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenEbony.java index b5cc214da..700a80f28 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenEbony.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenEbony.java @@ -10,33 +10,35 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenEbony extends WorldGenTree { public WorldGenEbony(ITreeGenData tree) { - super(tree); + super(tree, 10, 4); } @Override - public void generate() { + public void generate(World world) { int offset = (girth - 1) / 2; int trunksgenerated = 0; for (int x = -offset; x < -offset + girth; x++) { for (int z = -offset; z < -offset + girth; z++) { - if (rand.nextFloat() < 0.6f) { + if (world.rand.nextFloat() < 0.6f) { for (int i = 0; i < height; i++) { - addWood(x, i, z, EnumReplaceMode.ALL); - if (i > height / 2 && rand.nextFloat() < 0.1f * (10 / height)) { + addWood(world, x, i, z, EnumReplaceMode.ALL); + if (i > height / 2 && world.rand.nextFloat() < 0.1f * (10 / height)) { break; } } trunksgenerated++; } else { for (int i = 0; i < 1; i++) { - clearBlock(x, i, z); + clearBlock(world, x, i, z); } } } @@ -44,26 +46,24 @@ public class WorldGenEbony extends WorldGenTree { // Generate backup trunk, if we failed to generate any. if (trunksgenerated <= 0) { - generateTreeTrunk(height, 1, 0.6f); + generateTreeTrunk(world, height, 1, 0.6f); } // Add tree top for (int times = 0; times < 2 * height; times++) { - int h = 2 * girth + rand.nextInt(height - girth); - if (rand.nextBoolean() && h < height / 2) { - h = height / 2 + rand.nextInt(height / 2); + int h = 2 * girth + world.rand.nextInt(height - girth); + if (world.rand.nextBoolean() && h < height / 2) { + h = height / 2 + world.rand.nextInt(height / 2); } - int x_off = -(girth) + rand.nextInt(2 * girth); - int y_off = -(girth) + rand.nextInt(2 * girth); - generateSphere(new Vector(x_off, h, y_off), 1 + rand.nextInt(girth), leaf, EnumReplaceMode.NONE); + int x_off = -(girth) + world.rand.nextInt(2 * girth); + int y_off = -(girth) + world.rand.nextInt(2 * girth); + + Vector center = new Vector(x_off, h, y_off); + int radius = 1 + world.rand.nextInt(girth); + generateSphere(world, center, radius, leaf, EnumReplaceMode.NONE); } } - @Override - public void preGenerate() { - height = determineHeight(10, 4); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenGiganteum.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenGiganteum.java index 168ac42ca..66a8cf42f 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenGiganteum.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenGiganteum.java @@ -10,23 +10,20 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenGiganteum extends WorldGenSequoia { public WorldGenGiganteum(ITreeGenData tree) { - super(tree); + super(tree, 35, 15); } @Override - public void generate() { - super.generate(); + public void generate(World world) { + super.generate(world); //generateSupportStems(height, girth, 0.8f, 0.6f); } - @Override - public void preGenerate() { - height = determineHeight(35, 15); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenGreenheart.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenGreenheart.java index 0852da113..e7c0daf90 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenGreenheart.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenGreenheart.java @@ -10,49 +10,46 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenGreenheart extends WorldGenTree { public WorldGenGreenheart(ITreeGenData tree) { - super(tree); + super(tree, 10, 8); } @Override - public void generate() { + public void generate(World world) { - generateTreeTrunk(height, girth, 0.4f); - generateSupportStems(height, girth, 0.1f, 0.2f); + generateTreeTrunk(world, height, girth, 0.4f); + generateSupportStems(world, height, girth, 0.1f, 0.2f); int leafSpawn = height + 1; - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 0.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.5f, 1, leaf); while (leafSpawn > height - 4) { - generateAdjustedCylinder(leafSpawn--, 1.9f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.9f, 1, leaf); } - generateAdjustedCylinder(leafSpawn--, 1.5f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 0.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf); // Add some smaller twigs below for flavour for (int times = 0; times < height / 4; times++) { - int h = 10 + rand.nextInt(height - 10); - if (rand.nextBoolean() && h < height / 2) { - h = height / 2 + rand.nextInt(height / 2); + int h = 10 + world.rand.nextInt(height - 10); + if (world.rand.nextBoolean() && h < height / 2) { + h = height / 2 + world.rand.nextInt(height / 2); } - int x_off = -1 + rand.nextInt(3); - int y_off = -1 + rand.nextInt(3); - generateSphere(new Vector(x_off, h, y_off), 1 + rand.nextInt(1), leaf, EnumReplaceMode.NONE); + int x_off = -1 + world.rand.nextInt(3); + int y_off = -1 + world.rand.nextInt(3); + generateSphere(world, new Vector(x_off, h, y_off), 1 + world.rand.nextInt(1), leaf, EnumReplaceMode.NONE); } } - @Override - public void preGenerate() { - height = determineHeight(10, 8); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenIpe.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenIpe.java index ba7d6fd09..f1513f6f8 100644 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenIpe.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenIpe.java @@ -10,45 +10,42 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenIpe extends WorldGenTree { public WorldGenIpe(ITreeGenData tree) { - super(tree); + super(tree, 8, 8); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int leafSpawn = height + 1; float adjustedGirth = girth * .65f; - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 0.2f * adjustedGirth, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 0.2f * adjustedGirth, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0.2f * adjustedGirth, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0.2f * adjustedGirth, 1, leaf); while (leafSpawn > 7) { - generateAdjustedCylinder(leafSpawn, (float) (1.25f * (adjustedGirth * .65)), 1, leaf); + generateAdjustedCylinder(world, leafSpawn, (float) (1.25f * (adjustedGirth * .65)), 1, leaf); leafSpawn--; } - generateAdjustedCylinder(leafSpawn--, 1.6f * adjustedGirth, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1.6f * adjustedGirth, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1.6f * adjustedGirth, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.6f * adjustedGirth, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.6f * adjustedGirth, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.6f * adjustedGirth, 1, leaf); - if (rand.nextBoolean()) { - generateAdjustedCylinder(leafSpawn--, 1.25f * adjustedGirth, 1, leaf); + if (world.rand.nextBoolean()) { + generateAdjustedCylinder(world, leafSpawn--, 1.25f * adjustedGirth, 1, leaf); } - generateAdjustedCylinder(leafSpawn--, 1f * adjustedGirth, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1f * adjustedGirth, 1, leaf); } - @Override - public void preGenerate() { - height = determineHeight(8, 8); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenJungle.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenJungle.java index b12db5404..1873fcfb5 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenJungle.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenJungle.java @@ -10,29 +10,31 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; /** * This is a dummy and needs to be replaced with something proper. */ -public class WorldGenJungle extends WorldGenTree { +public class WorldGenJungle extends WorldGenTreeVanilla { public WorldGenJungle(ITreeGenData tree) { super(tree); } @Override - public void generate() { + public void generate(World world) { - generateTreeTrunk(height, girth); + generateTreeTrunk(world, height, girth); int leafSpawn = height + 1; - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 0.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1.9f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1.9f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.9f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.9f, 1, leaf); } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenKapok.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenKapok.java index b20dbc0dc..2c80f0e90 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenKapok.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenKapok.java @@ -10,48 +10,44 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenKapok extends WorldGenTree { public WorldGenKapok(ITreeGenData tree) { - super(tree); + super(tree, 10, 8); } @Override - public void generate() { + public void generate(World world) { - generateTreeTrunk(height, girth, 0.6f); - generateSupportStems(height, girth, 0.2f, 0.2f); + generateTreeTrunk(world, height, girth, 0.6f); + generateSupportStems(world, height, girth, 0.2f, 0.2f); int leafSpawn = height + 1; - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 0.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1.9f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.9f, 1, leaf); while (leafSpawn > height - 4) { - generateAdjustedCylinder(leafSpawn--, 2.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 2.5f, 1, leaf); } - generateAdjustedCylinder(leafSpawn--, 1.9f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.9f, 1, leaf); // Add some smaller twigs below for flavour for (int times = 0; times < height / 4; times++) { - int h = 10 + rand.nextInt(Math.max(1, height - 10)); - if (rand.nextBoolean() && h < height / 2) { - h = height / 2 + rand.nextInt(height / 2); + int h = 10 + world.rand.nextInt(Math.max(1, height - 10)); + if (world.rand.nextBoolean() && h < height / 2) { + h = height / 2 + world.rand.nextInt(height / 2); } - int x_off = -1 + rand.nextInt(3); - int y_off = -1 + rand.nextInt(3); - generateSphere(new Vector(x_off, h, y_off), 1 + rand.nextInt(1), leaf, EnumReplaceMode.NONE); + int x_off = -1 + world.rand.nextInt(3); + int y_off = -1 + world.rand.nextInt(3); + generateSphere(world, new Vector(x_off, h, y_off), 1 + world.rand.nextInt(1), leaf, EnumReplaceMode.NONE); } - } - @Override - public void preGenerate() { - height = determineHeight(10, 8); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenLarch.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenLarch.java index 4ca3a5426..fa53c4464 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenLarch.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenLarch.java @@ -10,33 +10,30 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenLarch extends WorldGenTree { public WorldGenLarch(ITreeGenData tree) { - super(tree); + super(tree, 6, 5); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int leafSpawn = height + 1; - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf); while (leafSpawn > 2) { - generateAdjustedCylinder(leafSpawn--, 2, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 2, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf); } } - @Override - public void preGenerate() { - height = determineHeight(6, 5); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenLemon.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenLemon.java index 1b648a842..d5092ae6a 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenLemon.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenLemon.java @@ -10,28 +10,24 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenLemon extends WorldGenTree { public WorldGenLemon(ITreeGenData tree) { - super(tree); + super(tree, 6, 3); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int yCenter = height - girth; yCenter = yCenter > 2 ? yCenter : 3; - generateSphere(getCenteredAt(yCenter, 0), 2 + rand.nextInt(girth), leaf, EnumReplaceMode.NONE); + generateSphere(world, getCenteredAt(yCenter, 0), 2 + world.rand.nextInt(girth), leaf, EnumReplaceMode.NONE); } - @Override - public void preGenerate() { - height = determineHeight(6, 3); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } - } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenLime.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenLime.java index aeef06883..b9c45213b 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenLime.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenLime.java @@ -10,31 +10,27 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenLime extends WorldGenTree { public WorldGenLime(ITreeGenData tree) { - super(tree); + super(tree, 6, 4); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int leafSpawn = height + 1; - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf); while (leafSpawn > 1) { - generateAdjustedCylinder(leafSpawn--, 1, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf); } - } - @Override - public void preGenerate() { - height = determineHeight(6, 4); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenMahoe.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenMahoe.java index f3a23c7c7..1cc8c7c87 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenMahoe.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenMahoe.java @@ -10,28 +10,24 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenMahoe extends WorldGenTree { public WorldGenMahoe(ITreeGenData tree) { - super(tree); + super(tree, 6, 3); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int yCenter = height - girth; yCenter = yCenter > 3 ? yCenter : 4; - generateSphere(getCenteredAt(yCenter, 0), 3 + rand.nextInt(girth), leaf, EnumReplaceMode.NONE); + generateSphere(world, getCenteredAt(yCenter, 0), 3 + world.rand.nextInt(girth), leaf, EnumReplaceMode.NONE); } - @Override - public void preGenerate() { - height = determineHeight(6, 3); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } - } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenMahogany.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenMahogany.java index 859852398..67be5dd34 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenMahogany.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenMahogany.java @@ -10,35 +10,32 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenMahogany extends WorldGenTree { public WorldGenMahogany(ITreeGenData tree) { - super(tree); + super(tree, 12, 6); } @Override - public void generate() { - generateTreeTrunk(height, girth, 0.6f); - generateSupportStems(height, girth, 0.4f, 0.4f); + public void generate(World world) { + generateTreeTrunk(world, height, girth, 0.6f); + generateSupportStems(world, height, girth, 0.4f, 0.4f); int leafSpawn = height + 1; - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1.5f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 2f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 2f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 3f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 3f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 2f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 3f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 3f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 2f, 1, leaf); } - @Override - public void preGenerate() { - height = determineHeight(12, 6); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenMaple.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenMaple.java index ada933fab..4c5a5f24a 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenMaple.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenMaple.java @@ -10,36 +10,33 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenMaple extends WorldGenTree { public WorldGenMaple(ITreeGenData tree) { - super(tree); + super(tree, 7, 5); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int leafSpawn = height + 1; float diameterchange = (float) 1 / height; int leafSpawned = 2; - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf); while (leafSpawn > 1) { - generateAdjustedCylinder(leafSpawn--, 3 * diameterchange * leafSpawned, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 2 * diameterchange * leafSpawned, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 3 * diameterchange * leafSpawned, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 2 * diameterchange * leafSpawned, 1, leaf); leafSpawned += 2; } } - @Override - public void preGenerate() { - height = determineHeight(7, 5); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenOak.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenOak.java index eb079d5f8..d495115ee 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenOak.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenOak.java @@ -12,7 +12,7 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -public class WorldGenOak extends WorldGenTree { +public class WorldGenOak extends WorldGenTreeVanilla { public WorldGenOak(ITreeGenData tree) { super(tree); diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenPadauk.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenPadauk.java index 948b96625..70032e1d2 100644 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenPadauk.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenPadauk.java @@ -12,6 +12,8 @@ package forestry.arboriculture.worldgen; import java.util.Random; +import net.minecraft.world.World; + import net.minecraftforge.common.util.ForgeDirection; import forestry.api.world.ITreeGenData; @@ -19,33 +21,30 @@ import forestry.api.world.ITreeGenData; public class WorldGenPadauk extends WorldGenTree { public WorldGenPadauk(ITreeGenData tree) { - super(tree); - - minHeight = 7; + super(tree, 6, 6); } @Override - public void generate() { - generateTreeTrunk(height, girth); - + public void generate(World world) { + generateTreeTrunk(world, height, girth); int leafSpawn = height + 1; - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1.5f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 3f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 3f, 1, leaf); int count = 0; int max = 3; int min = 1; - int canopyHeight = rand.nextInt(max - min + 1) + min; + int canopyHeight = world.rand.nextInt(max - min + 1) + min; while (leafSpawn > 3 && count < canopyHeight) { - generateAdjustedCylinder(leafSpawn--, 4.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 4.5f, 1, leaf); count++; //Random Trunk Branches for (int i = 0; i < girth * 4; i++) { - if (rand.nextBoolean()) { + if (world.rand.nextBoolean()) { int[] offset = {-1, 1}; int offsetValue = (offset[new Random().nextInt(offset.length)]); @@ -56,15 +55,15 @@ public class WorldGenPadauk extends WorldGenTree { int branchSpawn = leafSpawn; for (int j = 1; j < branchLength + 1; j++) { - if (j == branchLength && rand.nextBoolean()) { //Just adding a bit of variation to the ends for character + if (j == branchLength && world.rand.nextBoolean()) { //Just adding a bit of variation to the ends for character branchSpawn += 1; } wood.setDirection(directionValue); if (directionValue == ForgeDirection.NORTH) { - addWood(0, branchSpawn, j * offsetValue, EnumReplaceMode.ALL); + addWood(world, 0, branchSpawn, j * offsetValue, EnumReplaceMode.ALL); } else if (directionValue == ForgeDirection.EAST) { - addWood(j * offsetValue, branchSpawn, 0, EnumReplaceMode.ALL); + addWood(world, j * offsetValue, branchSpawn, 0, EnumReplaceMode.ALL); } } } @@ -72,9 +71,4 @@ public class WorldGenPadauk extends WorldGenTree { } } - @Override - public void preGenerate() { - height = determineHeight(6, 6); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenPapaya.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenPapaya.java index cc63160d8..da474a830 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenPapaya.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenPapaya.java @@ -10,28 +10,24 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenPapaya extends WorldGenTree { public WorldGenPapaya(ITreeGenData tree) { - super(tree); + super(tree, 7, 2); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int yCenter = height - girth; yCenter = yCenter > 3 ? yCenter : 4; - generateSphere(getCenteredAt(yCenter, 0), 2 + rand.nextInt(girth), leaf, EnumReplaceMode.NONE); + generateSphere(world, getCenteredAt(yCenter, 0), 2 + world.rand.nextInt(girth), leaf, EnumReplaceMode.NONE); } - @Override - public void preGenerate() { - height = determineHeight(7, 2); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } - } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenPine.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenPine.java index 75e6a605a..23d9efd65 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenPine.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenPine.java @@ -10,36 +10,33 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenPine extends WorldGenTree { public WorldGenPine(ITreeGenData tree) { - super(tree); + super(tree, 6, 4); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int leafSpawn = height + 1; float diameterchange = (float) 1 / height; int leafSpawned = 2; - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf); while (leafSpawn > 1) { - generateAdjustedCylinder(leafSpawn--, 3 * diameterchange * leafSpawned, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 2 * diameterchange * leafSpawned, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 3 * diameterchange * leafSpawned, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 2 * diameterchange * leafSpawned, 1, leaf); leafSpawned += 2; } } - @Override - public void preGenerate() { - height = determineHeight(6, 4); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenPlum.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenPlum.java index 5c10bc480..5839b72f1 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenPlum.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenPlum.java @@ -10,28 +10,26 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenPlum extends WorldGenTree { public WorldGenPlum(ITreeGenData tree) { - super(tree); + super(tree, 6, 3); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int yCenter = height - girth; yCenter = yCenter > 2 ? yCenter : 3; - generateSphere(getCenteredAt(yCenter, 0), 2 + rand.nextInt(girth), leaf, EnumReplaceMode.NONE); - } - - @Override - public void preGenerate() { - height = determineHeight(6, 3); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); + Vector center = getCenteredAt(yCenter, 0); + int radius = 2 + world.rand.nextInt(girth); + generateSphere(world, center, radius, leaf, EnumReplaceMode.NONE); } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenPoplar.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenPoplar.java index ee703e9e1..1a316e753 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenPoplar.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenPoplar.java @@ -10,30 +10,26 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenPoplar extends WorldGenTree { public WorldGenPoplar(ITreeGenData tree) { - super(tree); + super(tree, 8, 3); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int leafSpawn = height + 1; while (leafSpawn > girth - 1) { - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); } } - @Override - public void preGenerate() { - height = determineHeight(8, 3); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } - } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenSequoia.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenSequoia.java index b641fb394..61660836b 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenSequoia.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenSequoia.java @@ -10,49 +10,52 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenSequoia extends WorldGenTree { public WorldGenSequoia(ITreeGenData tree) { - super(tree); + this(tree, 20, 5); + } + + protected WorldGenSequoia(ITreeGenData tree, int baseHeight, int heightVariation) { + super(tree, baseHeight, heightVariation); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int topLength = height / 4; - int topHeight = height - topLength + rand.nextInt(height / 4); + int topHeight = height - topLength + world.rand.nextInt(height / 4); int leafSpawn = height + 2; - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf); while (leafSpawn > topHeight) { - generateAdjustedCylinder(leafSpawn--, 1, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf); } - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); for (int times = 0; times < height / 4; times++) { - int h = (height / 3) + rand.nextInt(height - (height / 3)); - if (rand.nextBoolean() && h < height / 3) { - h = height / 2 + rand.nextInt(height / 3); + int h = (height / 3) + world.rand.nextInt(height - (height / 3)); + if (world.rand.nextBoolean() && h < height / 3) { + h = height / 2 + world.rand.nextInt(height / 3); } - int x_off = -1 + rand.nextInt(3); - int y_off = -1 + rand.nextInt(3); - generateSphere(new Vector(x_off, h, y_off), 1 + rand.nextInt(2), leaf, EnumReplaceMode.NONE); + int x_off = -1 + world.rand.nextInt(3); + int y_off = -1 + world.rand.nextInt(3); + + Vector center = new Vector(x_off, h, y_off); + int radius = 1 + world.rand.nextInt(2); + generateSphere(world, center, radius, leaf, EnumReplaceMode.NONE); } - } - @Override - public void preGenerate() { - height = determineHeight(20, 5); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenSpruce.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenSpruce.java index a8662a08a..4c3c93f5c 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenSpruce.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenSpruce.java @@ -10,33 +10,30 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenSpruce extends WorldGenTree { public WorldGenSpruce(ITreeGenData tree) { - super(tree); + super(tree, 5, 3); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int leafSpawn = height + 1; - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf); while (leafSpawn > 2) { - generateAdjustedCylinder(leafSpawn--, 2, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 2, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf); } } - @Override - public void preGenerate() { - height = determineHeight(5, 3); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenTeak.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenTeak.java index 842bf7482..c7c50239a 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenTeak.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenTeak.java @@ -10,36 +10,33 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenTeak extends WorldGenTree { public WorldGenTeak(ITreeGenData tree) { - super(tree); + super(tree, 6, 3); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int leafSpawn = height + 1; - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 0.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1.9f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1.9f, 1, leaf); - if (rand.nextBoolean()) { - generateAdjustedCylinder(leafSpawn--, 1.9f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.9f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.9f, 1, leaf); + if (world.rand.nextBoolean()) { + generateAdjustedCylinder(world, leafSpawn--, 1.9f, 1, leaf); } - generateAdjustedCylinder(leafSpawn--, 0.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf); } - @Override - public void preGenerate() { - height = determineHeight(6, 3); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenTree.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenTree.java index 678d656e7..30a9429d3 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenTree.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenTree.java @@ -10,6 +10,8 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import com.mojang.authlib.GameProfile; import forestry.api.arboriculture.ITreeModifier; @@ -17,29 +19,32 @@ import forestry.api.arboriculture.TreeManager; import forestry.api.world.ITreeGenData; public abstract class WorldGenTree extends WorldGenArboriculture { + private static final int minHeight = 4; + private static final int maxHeight = 80; + + private final int baseHeight; + private final int heightVariation; protected int girth; protected int height; - protected int minHeight = 4; - protected int maxHeight = 80; - - public WorldGenTree(ITreeGenData tree) { + public WorldGenTree(ITreeGenData tree, int baseHeight, int heightVariation) { super(tree); + this.baseHeight = baseHeight; + this.heightVariation = heightVariation; } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int leafSpawn = height + 1; - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf, EnumReplaceMode.NONE); - generateAdjustedCylinder(leafSpawn--, 0.5f, 1, leaf, EnumReplaceMode.NONE); - - generateAdjustedCylinder(leafSpawn--, 1.9f, 1, leaf, EnumReplaceMode.NONE); - generateAdjustedCylinder(leafSpawn--, 1.9f, 1, leaf, EnumReplaceMode.NONE); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf, EnumReplaceMode.NONE); + generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf, EnumReplaceMode.NONE); + generateAdjustedCylinder(world, leafSpawn--, 1.9f, 1, leaf, EnumReplaceMode.NONE); + generateAdjustedCylinder(world, leafSpawn--, 1.9f, 1, leaf, EnumReplaceMode.NONE); } protected Vector getCenteredAt(int yCenter, int offset) { @@ -47,42 +52,40 @@ public abstract class WorldGenTree extends WorldGenArboriculture { return new Vector(cent + offset, yCenter, cent + offset); } - protected void generateAdjustedCylinder(int yCenter, float radius, int height, ITreeBlockType block) { - generateAdjustedCylinder(yCenter, 0, radius, height, block, EnumReplaceMode.NONE); + protected void generateAdjustedCylinder(World world, int yCenter, float radius, int height, ITreeBlockType block) { + generateAdjustedCylinder(world, yCenter, 0, radius, height, block, EnumReplaceMode.NONE); } - protected void generateAdjustedCylinder(int yCenter, float radius, int height, ITreeBlockType block, EnumReplaceMode replace) { - generateAdjustedCylinder(yCenter, 0, radius, height, block, replace); + protected void generateAdjustedCylinder(World world, int yCenter, float radius, int height, ITreeBlockType block, EnumReplaceMode replace) { + generateAdjustedCylinder(world, yCenter, 0, radius, height, block, replace); } - protected void generateAdjustedCylinder(int yCenter, int offset, float radius, int height, ITreeBlockType block, EnumReplaceMode replace) { - generateCylinder(getCenteredAt(yCenter, offset), radius + girth, height, block, replace); + protected void generateAdjustedCylinder(World world, int yCenter, int offset, float radius, int height, ITreeBlockType block, EnumReplaceMode replace) { + Vector center = getCenteredAt(yCenter, offset); + generateCylinder(world, center, radius + girth, height, block, replace); } @Override - public boolean canGrow() { - return tree.canGrow(world, startX, startY, startZ, tree.getGirth(world, startX, startY, startZ), height); + public boolean canGrow(World world, int x, int y, int z) { + return tree.canGrow(world, x, y, z, girth, height); } @Override - public void preGenerate() { - height = determineHeight(5, 2); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); + public final void preGenerate(World world, int startX, int startY, int startZ) { + super.preGenerate(world, startX, startY, startZ); + height = determineHeight(world, baseHeight, heightVariation); + girth = tree.getGirth(world, startX, startY, startZ); } - protected int determineGirth(int base) { - return base; - } - - protected int modifyByHeight(int val, int min, int max) { + protected int modifyByHeight(World world, int val, int min, int max) { ITreeModifier treeModifier = TreeManager.treeRoot.getTreekeepingMode(world); int determined = Math.round(val * tree.getHeightModifier() * treeModifier.getHeightModifier(tree.getGenome(), 1f)); return determined < min ? min : determined > max ? max : determined; } - protected int determineHeight(int required, int variation) { + protected int determineHeight(World world, int required, int variation) { ITreeModifier treeModifier = TreeManager.treeRoot.getTreekeepingMode(world); - int baseHeight = required + rand.nextInt(variation); + int baseHeight = required + world.rand.nextInt(variation); int height = Math.round(baseHeight * tree.getHeightModifier() * treeModifier.getHeightModifier(tree.getGenome(), 1f)); return height < minHeight ? minHeight : height > maxHeight ? maxHeight : height; } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenTreeVanilla.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenTreeVanilla.java new file mode 100644 index 000000000..02f4da79d --- /dev/null +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenTreeVanilla.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.arboriculture.worldgen; + +import forestry.api.world.ITreeGenData; + +public class WorldGenTreeVanilla extends WorldGenTree { + public WorldGenTreeVanilla(ITreeGenData tree) { + super(tree, 5, 2); + } +} diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenWalnut.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenWalnut.java index f2f9017b9..bfb4bbaf8 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenWalnut.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenWalnut.java @@ -10,40 +10,35 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenWalnut extends WorldGenTree { public WorldGenWalnut(ITreeGenData tree) { - super(tree); - - minHeight = 7; + super(tree, 7, 3); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int leafSpawn = height + 1; - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 0.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1.5f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 2f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 2f, 1, leaf); while (leafSpawn > 3) { - generateAdjustedCylinder(leafSpawn--, 3f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 3f, 1, leaf); } - if (rand.nextBoolean()) { - generateAdjustedCylinder(leafSpawn--, 2f, 1, leaf); + if (world.rand.nextBoolean()) { + generateAdjustedCylinder(world, leafSpawn--, 2f, 1, leaf); } } - @Override - public void preGenerate() { - height = determineHeight(7, 3); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenWenge.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenWenge.java index 4f8b4a944..7ede29aed 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenWenge.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenWenge.java @@ -10,36 +10,32 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenWenge extends WorldGenTree { public WorldGenWenge(ITreeGenData tree) { - super(tree); - minHeight = 6; + super(tree, 6, 2); } @Override - public void generate() { - generateTreeTrunk(height, girth); + public void generate(World world) { + generateTreeTrunk(world, height, girth); int leafSpawn = height + 1; - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 0.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1.5f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 2f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 2f, 1, leaf); while (leafSpawn > 1) { - generateAdjustedCylinder(leafSpawn--, 3f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 3f, 1, leaf); } } - @Override - public void preGenerate() { - height = determineHeight(6, 2); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenWillow.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenWillow.java index b0f623356..0bae0cb5e 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenWillow.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenWillow.java @@ -10,40 +10,37 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenWillow extends WorldGenTree { public WorldGenWillow(ITreeGenData tree) { - super(tree); + super(tree, 5, 2); } @Override - public void generate() { + public void generate(World world) { - generateTreeTrunk(height, girth, 0.8f); - generateSupportStems(height, girth, 0.2f, 0.2f); + generateTreeTrunk(world, height, girth, 0.8f); + generateSupportStems(world, height, girth, 0.2f, 0.2f); int leafSpawn = height + 1; - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.5f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 2.5f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 3f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 3f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 2.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 3f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 3f, 1, leaf); while (leafSpawn > 2) { - generateCircle(new Vector(0f, leafSpawn--, 0f), 4f, 2, 1, leaf, EnumReplaceMode.NONE); + generateCircle(world, new Vector(0f, leafSpawn--, 0f), 4f, 2, 1, leaf, EnumReplaceMode.NONE); } - generateCircle(new Vector(0f, leafSpawn--, 0f), 4f, 1, 1, leaf, EnumReplaceMode.NONE); - generateCircle(new Vector(0f, leafSpawn--, 0f), 4f, 1, 1, leaf, EnumReplaceMode.NONE); - generateCircle(new Vector(0f, leafSpawn--, 0f), 4f, 1, 1, leaf, 0.4f, EnumReplaceMode.NONE); + generateCircle(world, new Vector(0f, leafSpawn--, 0f), 4f, 1, 1, leaf, EnumReplaceMode.NONE); + generateCircle(world, new Vector(0f, leafSpawn--, 0f), 4f, 1, 1, leaf, EnumReplaceMode.NONE); + generateCircle(world, new Vector(0f, leafSpawn--, 0f), 4f, 1, 1, leaf, 0.4f, EnumReplaceMode.NONE); } - @Override - public void preGenerate() { - height = determineHeight(5, 2); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenZebrawood.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenZebrawood.java index 7843c275d..1667c2186 100644 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenZebrawood.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenZebrawood.java @@ -10,47 +10,44 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; +import net.minecraft.world.World; + import forestry.api.world.ITreeGenData; public class WorldGenZebrawood extends WorldGenTree { public WorldGenZebrawood(ITreeGenData tree) { - super(tree); + super(tree, 8, 8); } @Override - public void generate() { + public void generate(World world) { - generateTreeTrunk(height, girth); + generateTreeTrunk(world, height, girth); int leafSpawn = height + 1; - generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 0.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf); - generateAdjustedCylinder(leafSpawn--, 1.9f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.9f, 1, leaf); while (leafSpawn > height - 4) { - generateAdjustedCylinder(leafSpawn--, 2.5f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 2.5f, 1, leaf); } - generateAdjustedCylinder(leafSpawn--, 1.9f, 1, leaf); + generateAdjustedCylinder(world, leafSpawn--, 1.9f, 1, leaf); // Add some smaller twigs below for flavour for (int times = 0; times < height / 4; times++) { - int h = 10 + rand.nextInt(Math.max(1, height - 10)); - if (rand.nextBoolean() && h < height / 2) { - h = height / 2 + rand.nextInt(height / 2); + int h = 10 + world.rand.nextInt(Math.max(1, height - 10)); + if (world.rand.nextBoolean() && h < height / 2) { + h = height / 2 + world.rand.nextInt(height / 2); } - int x_off = -1 + rand.nextInt(3); - int y_off = -1 + rand.nextInt(3); - generateSphere(new Vector(x_off, h, y_off), 1 + rand.nextInt(1), leaf, EnumReplaceMode.NONE); + int x_off = -1 + world.rand.nextInt(3); + int y_off = -1 + world.rand.nextInt(3); + generateSphere(world, new Vector(x_off, h, y_off), 1 + world.rand.nextInt(1), leaf, EnumReplaceMode.NONE); } } - @Override - public void preGenerate() { - height = determineHeight(8, 8); - girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); - } } diff --git a/src/main/java/forestry/core/worldgen/WorldGenBase.java b/src/main/java/forestry/core/worldgen/WorldGenBase.java index 757a7a5e2..9c39e3fa5 100755 --- a/src/main/java/forestry/core/worldgen/WorldGenBase.java +++ b/src/main/java/forestry/core/worldgen/WorldGenBase.java @@ -41,34 +41,22 @@ public abstract class WorldGenBase extends WorldGenerator { } } - protected World world; - protected Random rand; - @Override public final boolean generate(World world, Random random, int x, int y, int z) { return generate(world, random, x, y, z, false); } - public final boolean generate(World world, Random random, int x, int y, int z, boolean forced) { - this.world = world; - this.rand = random; - boolean result = subGenerate(x, y, z, forced); - this.world = null; - this.rand = null; - return result; - } - - public boolean subGenerate(int x, int y, int z, boolean forced) { + public boolean generate(World world, Random random, int x, int y, int z, boolean forced) { return false; } - protected abstract void addBlock(int x, int y, int z, ITreeBlockType type, EnumReplaceMode replace); + protected abstract void addBlock(World world, int x, int y, int z, ITreeBlockType type, EnumReplaceMode replace); - protected final void generateCuboid(Vector start, Vector area, ITreeBlockType block, EnumReplaceMode replace) { + protected final void generateCuboid(World world, Vector start, Vector area, ITreeBlockType block, EnumReplaceMode replace) { for (int x = (int) start.x; x < (int) start.x + area.x; x++) { for (int y = (int) start.y; y < (int) start.y + area.y; y++) { for (int z = (int) start.z; z < (int) start.z + area.z; z++) { - addBlock(x, y, z, block, replace); + addBlock(world, x, y, z, block, replace); } } } @@ -77,25 +65,25 @@ public abstract class WorldGenBase extends WorldGenerator { /* * Center is the bottom middle of the cylinder */ - protected final void generateCylinder(Vector center, float radius, int height, ITreeBlockType block, EnumReplaceMode replace) { + protected final void generateCylinder(World world, Vector center, float radius, int height, ITreeBlockType block, EnumReplaceMode replace) { Vector start = new Vector(center.x - radius, center.y, center.z - radius); Vector area = new Vector(radius * 2 + 1, height, radius * 2 + 1); for (int x = (int) start.x; x < (int) start.x + area.x; x++) { for (int y = (int) start.y; y < (int) start.y + area.y; y++) { for (int z = (int) start.z; z < (int) start.z + area.z; z++) { if (Vector.distance(new Vector(x, y, z), new Vector(center.x, y, center.z)) <= (radius) + 0.01) { - addBlock(x, y, z, block, replace); + addBlock(world, x, y, z, block, replace); } } } } } - protected final void generateCircle(Vector center, float radius, int width, int height, ITreeBlockType block, EnumReplaceMode replace) { - generateCircle(center, radius, width, height, block, 1.0f, replace); + protected final void generateCircle(World world, Vector center, float radius, int width, int height, ITreeBlockType block, EnumReplaceMode replace) { + generateCircle(world, center, radius, width, height, block, 1.0f, replace); } - protected final void generateCircle(Vector center, float radius, int width, int height, ITreeBlockType block, float chance, EnumReplaceMode replace) { + protected final void generateCircle(World world, Vector center, float radius, int width, int height, ITreeBlockType block, float chance, EnumReplaceMode replace) { Vector start = new Vector(center.x - radius, center.y, center.z - radius); Vector area = new Vector(radius * 2 + 1, height, radius * 2 + 1); @@ -103,27 +91,27 @@ public abstract class WorldGenBase extends WorldGenerator { for (int y = (int) start.y; y < (int) start.y + area.y; y++) { for (int z = (int) start.z; z < (int) start.z + area.z; z++) { - if (rand.nextFloat() > chance) { + if (world.rand.nextFloat() > chance) { continue; } double distance = Vector.distance(new Vector(x, y, z), new Vector(center.x, y, center.z)); if ((radius - width - 0.01 < distance && distance <= (radius) + 0.01)) { - addBlock(x, y, z, block, replace); + addBlock(world, x, y, z, block, replace); } } } } } - protected final void generateSphere(Vector center, int radius, ITreeBlockType block, EnumReplaceMode replace) { + protected final void generateSphere(World world, Vector center, int radius, ITreeBlockType block, EnumReplaceMode replace) { Vector start = new Vector(center.x - radius, center.y - radius, center.z - radius); Vector area = new Vector(radius * 2 + 1, radius * 2 + 1, radius * 2 + 1); for (int x = (int) start.x; x < (int) start.x + area.x; x++) { for (int y = (int) start.y; y < (int) start.y + area.y; y++) { for (int z = (int) start.z; z < (int) start.z + area.z; z++) { if (Vector.distance(new Vector(x, y, z), new Vector(center.x, center.y, center.z)) <= (radius) + 0.01) { - addBlock(x, y, z, block, replace); + addBlock(world, x, y, z, block, replace); } } }