Skip to content

Commit

Permalink
Update to 3.2 - Custom trees now naturally spawn. Multiple tree types
Browse files Browse the repository at this point in the history
for a biome!
  • Loading branch information
Capri205 committed Oct 9, 2022
1 parent 1db716a commit 37d8d63
Show file tree
Hide file tree
Showing 21 changed files with 176 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>GiantTrees</groupId>
<artifactId>GiantTrees</artifactId>
<version>3.1-SNAPSHOT</version>
<version>3.2-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/ryanmichela/trees/TreePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ public void onLoad() {
this.saveDefaultConfig();
}
// unpack basic trees
for (final String biome : ImmutableList.of("BIRCH_FOREST", "FOREST", "JUNGLE", "DARK_FOREST",
"SAVANNA", "TAIGA", "MANGROVE_SWAMP", "BADLANDS")) {
ensureTreeFileExists("biome." + biome);
for (final String biome : ImmutableList.of("BIRCH_FOREST-BIRCH", "FOREST-OAK", "FOREST-COTTONWOOD", "JUNGLE-JUNGLE", "DARK_FOREST-DARK_OAK",
"SAVANNA-ACACIA", "TAIGA-SPRUCE", "MANGROVE_SWAMP-MANGROVE", "BADLANDS-MESAPUZZLE")) {
ensureTreeFileExists("biome." + biome);
}
for (final String tree : ImmutableList.of("ACACIA", "BIRCH", "DARK_OAK", "JUNGLE",
"OAK", "SPRUCE", "MANGROVE", "MESAPUZZLE")) {
ensureTreeFileExists("tree." + tree);
for (final String tree : ImmutableList.of("ACACIA", "BIRCH", "DARK_OAK", "JUNGLE", "OAK",
"SPRUCE", "MANGROVE", "MESAPUZZLE", "COTTONWOOD")) {
ensureTreeFileExists("tree." + tree);
}
}

Expand Down
44 changes: 36 additions & 8 deletions src/main/java/com/ryanmichela/trees/TreePopulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
package com.ryanmichela.trees;

import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Random;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.bukkit.Chunk;
import org.bukkit.Location;
Expand Down Expand Up @@ -56,15 +60,39 @@ public void populate(final World world, final Random random, final Chunk chunk)

if (this.isAcceptableBiome(biome) && this.treeCanGrow(random)) {
final String treeType = biome.name();

// get list of available tree files with biome name in
File [] biometreefiles = this.plugin.getDataFolder().listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.startsWith("biome.");
}
});
ArrayList<String> availabletrees = new ArrayList<String>();
String regex = "biome." + biome.name().toUpperCase() + "((-([0-9A-Z-_]*)){0,}).xml";
Pattern pattern = Pattern.compile(regex);
for ( int idx = 0; idx < biometreefiles.length; idx++ ) {
Matcher match = pattern.matcher( biometreefiles[idx].toString() );
if ( match.find() ) {
availabletrees.add(match.group());
}
}

// pick a random file from set
int randtreeidx = (int) ((Math.random() * (availabletrees.size() - 0)) + 0);

//final File treeFile = new File(this.plugin.getDataFolder(), "biome."
// + treeType
// + ".xml");
//final File rootFile = new File(this.plugin.getDataFolder(), "biome."
// + treeType
// + ".root.xml");
File treeFile = null;
File rootFile = null;
treeFile = new File( this.plugin.getDataFolder(), availabletrees.get(randtreeidx) );
rootFile = new File( this.plugin.getDataFolder(), availabletrees.get(randtreeidx).replace( ".xml", ".root.xml" ) );

final File treeFile = new File(this.plugin.getDataFolder(), "biome."
+ treeType
+ ".xml");
final File rootFile = new File(this.plugin.getDataFolder(), "biome."
+ treeType
+ ".root.xml");

if (treeFile.exists()) {
if ( treeFile.exists() && rootFile.exists() ) {
final TreeRenderer renderer = new TreeRenderer(this.plugin);
renderer.renderTree(refPoint, treeFile, rootFile, random.nextInt(), false);
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
58 changes: 58 additions & 0 deletions src/main/resources/biome.FOREST-COTTONWOOD.root.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version='1.0' ?>

<arbaro>
<species name='default'>
<!-- general params -->
<param name='WoodType' value='Birch'/>
<param name='Shape' value='0'/>
<param name='Levels' value='1'/>
<param name='Scale' value='7.0'/>
<param name='ScaleV' value='0.0'/>
<param name='BaseSize' value='0.25'/>
<param name='Ratio' value='0.1'/>
<param name='RatioPower' value='1.0'/>
<param name='Flare' value='0.2'/>
<param name='Lobes' value='0'/>
<param name='LobeDepth' value='0.0'/>
<param name='Smooth' value='0.1'/>
<param name='Leaves' value='0'/>
<param name='LeafShape' value='0'/>
<param name='LeafScale' value='0.2'/>
<param name='LeafScaleX' value='0.5'/>
<param name='LeafQuality' value='1.0'/>
<param name='LeafStemLen' value='0.5'/>
<param name='LeafDistrib' value='4'/>
<param name='LeafBend' value='0.3'/>
<param name='AttractionUp' value='0.0'/>
<param name='PruneRatio' value='0.0'/>
<param name='PrunePowerLow' value='0.5'/>
<param name='PrunePowerHigh' value='0.5'/>
<param name='PruneWidth' value='0.5'/>
<param name='PruneWidthPeak' value='0.5'/>
<param name='0Scale' value='1.0'/>
<param name='0ScaleV' value='0.0'/>
<param name='0BaseSplits' value='3'/>
<!-- level 0 -->
<param name='0DownAngle' value='25.0'/>
<param name='0DownAngleV' value='5.0'/>
<param name='0Rotate' value='30.0'/>
<param name='0RotateV' value='-20.0'/>
<param name='0Branches' value='1'/>
<param name='0BranchDist' value='0.0'/>
<param name='0Length' value='0.5'/>
<param name='0LengthV' value='0.0'/>
<param name='0Taper' value='1.0'/>
<param name='0SegSplits' value='0.0'/>
<param name='0SplitAngle' value='0.0'/>
<param name='0SplitAngleV' value='0.0'/>
<param name='0CurveRes' value='20'/>
<param name='0Curve' value='35.0'/>
<param name='0CurveBack' value='-65.0'/>
<param name='0CurveV' value='0.0'/>
<!-- level 1 -->
<param name='1DownAngle' value='30.0'/>
<param name='1DownAngleV' value='0.0'/>
<param name='1Rotate' value='120.0'/>
<param name='1RotateV' value='0.0'/>
</species>
</arbaro>
75 changes: 75 additions & 0 deletions src/main/resources/biome.FOREST-COTTONWOOD.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version='1.0' ?>

<arbaro>
<species name='default'>
<!-- general params -->
<param name='WoodType' value='Birch'/>
<param name='Shape' value='1'/>
<param name='Levels' value='2'/>
<param name='Scale' value='50.0'/>
<param name='ScaleV' value='5.0'/>
<param name='BaseSize' value='0.4'/>
<param name='Ratio' value='0.05'/>
<param name='RatioPower' value='1.0'/>
<param name='Flare' value='0.3'/>
<param name='Lobes' value='5'/>
<param name='LobeDepth' value='0.1'/>
<param name='Smooth' value='0.1'/>
<param name='Leaves' value='11'/>
<param name='LeafShape' value='disc4'/>
<param name='LeafScale' value='10.0'/>
<param name='LeafScaleX' value='0.45'/>
<param name='LeafQuality' value='1.0'/>
<param name='LeafStemLen' value='0.5'/>
<param name='LeafDistrib' value='4'/>
<param name='LeafBend' value='0.4'/>
<param name='AttractionUp' value='-1.0'/>
<param name='PruneRatio' value='0.0'/>
<param name='PrunePowerLow' value='0.9'/>
<param name='PrunePowerHigh' value='0.9'/>
<param name='PruneWidth' value='1.0'/>
<param name='PruneWidthPeak' value='1.0'/>
<param name='0Scale' value='1.0'/>
<param name='0ScaleV' value='0.0'/>
<param name='0BaseSplits' value='1'/>
<!-- level 0 -->
<param name='0DownAngle' value='12.0'/>
<param name='0DownAngleV' value='0.0'/>
<param name='0Rotate' value='90.0'/>
<param name='0RotateV' value='30.0'/>
<param name='0Branches' value='2'/>
<param name='0BranchDist' value='0.9'/>
<param name='0Length' value='1.0'/>
<param name='0LengthV' value='0.2'/>
<param name='0Taper' value='1.0'/>
<param name='0SegSplits' value='0.4'/>
<param name='0SplitAngle' value='10.0'/>
<param name='0SplitAngleV' value='0.0'/>
<param name='0CurveRes' value='8'/>
<param name='0Curve' value='10.0'/>
<param name='0CurveBack' value='-3.0'/>
<param name='0CurveV' value='8.0'/>
<!-- level 1 -->
<param name='1DownAngle' value='-15.0'/>
<param name='1DownAngleV' value='5.0'/>
<param name='1Rotate' value='135.0'/>
<param name='1RotateV' value='16.0'/>
<param name='1Branches' value='11'/>
<param name='1BranchDist' value='1.0'/>
<param name='1Length' value='0.5'/>
<param name='1LengthV' value='0.3'/>
<param name='1Taper' value='1.0'/>
<param name='1SegSplits' value='0.2'/>
<param name='1SplitAngle' value='10.0'/>
<param name='1SplitAngleV' value='10.0'/>
<param name='1CurveRes' value='10'/>
<param name='1Curve' value='-60.0'/>
<param name='1CurveBack' value='5.0'/>
<param name='1CurveV' value='12.0'/>
<!-- level 2 -->
<param name='2DownAngle' value='40.0'/>
<param name='2DownAngleV' value='10.0'/>
<param name='2Rotate' value='60.0'/>
<param name='2RotateV' value='5.0'/>
</species>
</arbaro>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 37d8d63

Please sign in to comment.