Implement new parsing library, implement TerraProfiler

This commit is contained in:
dfsek
2020-09-13 02:18:26 -07:00
parent d626e8c735
commit 0eddcf429c
12 changed files with 146 additions and 123 deletions

View File

@@ -1,5 +1,7 @@
package com.dfsek.terra.population;
import com.dfsek.terra.Terra;
import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.biome.TerraBiomeGrid;
import org.bukkit.Chunk;
import org.bukkit.World;
@@ -7,6 +9,7 @@ import org.bukkit.block.Block;
import org.bukkit.generator.BlockPopulator;
import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.biome.Biome;
import org.polydev.gaea.profiler.ProfileFuture;
import org.polydev.gaea.world.Fauna;
import java.util.Random;
@@ -14,16 +17,19 @@ import java.util.Random;
public class FaunaPopulator extends BlockPopulator {
@Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
ProfileFuture fauna = TerraProfiler.fromWorld(world).measure("FaunaTime");
for(int x = 0; x < 16; x++) {
for(int z = 0; z < 16; z++) {
Biome biome = TerraBiomeGrid.fromWorld(world).getBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z);
if(biome.getDecorator().getFaunaChance() <= 0 || random.nextInt(100) > biome.getDecorator().getFaunaChance())
continue;
Block highest = Fauna.getHighestValidSpawnAt(chunk, x, z);
Fauna item = biome.getDecorator().getFauna().get(random);
Block highest = item.getHighestValidSpawnAt(chunk, x, z);
try {
if(highest != null) biome.getDecorator().getFauna().get(random).plant(highest.getLocation());
if(highest != null) item.plant(highest.getLocation());
} catch(NullPointerException ignored) {}
}
}
if(fauna!=null) fauna.complete();
}
}

View File

@@ -1,6 +1,7 @@
package com.dfsek.terra.population;
import com.dfsek.terra.Terra;
import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedDecorator;
import org.bukkit.Chunk;
@@ -10,6 +11,7 @@ import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.biome.Biome;
import org.polydev.gaea.population.GaeaBlockPopulator;
import org.polydev.gaea.population.PopulationManager;
import org.polydev.gaea.profiler.ProfileFuture;
import org.polydev.gaea.util.WorldUtil;
import java.util.Random;
@@ -22,6 +24,7 @@ public class TreePopulator extends GaeaBlockPopulator {
@Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
ProfileFuture tree = TerraProfiler.fromWorld(world).measure("TreeGenTime");
int x = random.nextInt(16); // Decrease chances of chunk-crossing trees
int z = random.nextInt(16);
Location origin = chunk.getBlock(x, 0, z).getLocation();
@@ -41,5 +44,6 @@ public class TreePopulator extends GaeaBlockPopulator {
x = random.nextInt(16); // Decrease chances of chunk-crossing trees
z = random.nextInt(16);
}
if(tree!=null) tree.complete();
}
}