mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-04 23:06:05 +00:00
profile more things
This commit is contained in:
@@ -18,7 +18,7 @@ public class OreHolderLoader implements TypeLoader<OreHolder> {
|
||||
Map<String, Object> map = (Map<String, Object>) o;
|
||||
|
||||
for(Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
holder.add(configLoader.loadClass(Ore.class, entry.getKey()), (OreConfig) configLoader.loadType(OreConfig.class, entry.getValue()));
|
||||
holder.add(configLoader.loadClass(Ore.class, entry.getKey()), configLoader.loadClass(OreConfig.class, entry.getValue()), entry.getKey());
|
||||
}
|
||||
|
||||
return holder;
|
||||
|
||||
@@ -49,38 +49,40 @@ public class CavePopulator implements TerraBlockPopulator, Chunkified {
|
||||
Map<Location, BlockData> shiftCandidate = new HashMap<>();
|
||||
Set<Block> updateNeeded = new HashSet<>();
|
||||
c.carve(chunk.getX(), chunk.getZ(), world, (v, type) -> {
|
||||
Block b = chunk.getBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ());
|
||||
BlockData m = b.getBlockData();
|
||||
BlockType re = m.getBlockType();
|
||||
switch(type) {
|
||||
case CENTER:
|
||||
if(template.getInner().canReplace(re)) {
|
||||
b.setBlockData(template.getInner().get(v.getBlockY()).get(random), false);
|
||||
if(template.getUpdate().contains(re)) updateNeeded.add(b);
|
||||
if(template.getShift().containsKey(re)) shiftCandidate.put(b.getLocation(), m);
|
||||
}
|
||||
break;
|
||||
case WALL:
|
||||
if(template.getOuter().canReplace(re)) {
|
||||
b.setBlockData(template.getOuter().get(v.getBlockY()).get(random), false);
|
||||
if(template.getUpdate().contains(re)) updateNeeded.add(b);
|
||||
if(template.getShift().containsKey(re)) shiftCandidate.put(b.getLocation(), m);
|
||||
}
|
||||
break;
|
||||
case TOP:
|
||||
if(template.getTop().canReplace(re)) {
|
||||
b.setBlockData(template.getTop().get(v.getBlockY()).get(random), false);
|
||||
if(template.getUpdate().contains(re)) updateNeeded.add(b);
|
||||
if(template.getShift().containsKey(re)) shiftCandidate.put(b.getLocation(), m);
|
||||
}
|
||||
break;
|
||||
case BOTTOM:
|
||||
if(template.getBottom().canReplace(re)) {
|
||||
b.setBlockData(template.getBottom().get(v.getBlockY()).get(random), false);
|
||||
if(template.getUpdate().contains(re)) updateNeeded.add(b);
|
||||
if(template.getShift().containsKey(re)) shiftCandidate.put(b.getLocation(), m);
|
||||
}
|
||||
break;
|
||||
try(ProfileFrame ignored = main.getProfiler().profile("carving:" + c.getConfig().getID())) {
|
||||
Block b = chunk.getBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ());
|
||||
BlockData m = b.getBlockData();
|
||||
BlockType re = m.getBlockType();
|
||||
switch(type) {
|
||||
case CENTER:
|
||||
if(template.getInner().canReplace(re)) {
|
||||
b.setBlockData(template.getInner().get(v.getBlockY()).get(random), false);
|
||||
if(template.getUpdate().contains(re)) updateNeeded.add(b);
|
||||
if(template.getShift().containsKey(re)) shiftCandidate.put(b.getLocation(), m);
|
||||
}
|
||||
break;
|
||||
case WALL:
|
||||
if(template.getOuter().canReplace(re)) {
|
||||
b.setBlockData(template.getOuter().get(v.getBlockY()).get(random), false);
|
||||
if(template.getUpdate().contains(re)) updateNeeded.add(b);
|
||||
if(template.getShift().containsKey(re)) shiftCandidate.put(b.getLocation(), m);
|
||||
}
|
||||
break;
|
||||
case TOP:
|
||||
if(template.getTop().canReplace(re)) {
|
||||
b.setBlockData(template.getTop().get(v.getBlockY()).get(random), false);
|
||||
if(template.getUpdate().contains(re)) updateNeeded.add(b);
|
||||
if(template.getShift().containsKey(re)) shiftCandidate.put(b.getLocation(), m);
|
||||
}
|
||||
break;
|
||||
case BOTTOM:
|
||||
if(template.getBottom().canReplace(re)) {
|
||||
b.setBlockData(template.getBottom().get(v.getBlockY()).get(random), false);
|
||||
if(template.getUpdate().contains(re)) updateNeeded.add(b);
|
||||
if(template.getShift().containsKey(re)) shiftCandidate.put(b.getLocation(), m);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
for(Map.Entry<Location, BlockData> entry : shiftCandidate.entrySet()) {
|
||||
|
||||
@@ -40,11 +40,13 @@ public class OrePopulator implements TerraBlockPopulator {
|
||||
BiomeTemplate config = ((UserDefinedBiome) b).getConfig();
|
||||
int finalCx = cx;
|
||||
int finalCz = cz;
|
||||
config.getOreHolder().forEach((ore, oreConfig) -> {
|
||||
int amount = oreConfig.getAmount().get(random);
|
||||
for(int i = 0; i < amount; i++) {
|
||||
Vector3 location = new Vector3(random.nextInt(16) + 16 * finalCx, oreConfig.getHeight().get(random), random.nextInt(16) + 16 * finalCz);
|
||||
ore.generate(location, chunk, random);
|
||||
config.getOreHolder().forEach((id, orePair) -> {
|
||||
try(ProfileFrame ignored = main.getProfiler().profile("ore:" + id)) {
|
||||
int amount = orePair.getRight().getAmount().get(random);
|
||||
for(int i = 0; i < amount; i++) {
|
||||
Vector3 location = new Vector3(random.nextInt(16) + 16 * finalCx, orePair.getRight().getHeight().get(random), random.nextInt(16) + 16 * finalCz);
|
||||
orePair.getLeft().generate(location, chunk, random);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -42,8 +42,9 @@ public class TreePopulator implements TerraBlockPopulator {
|
||||
for(int z = 0; z < 16; z += 2) {
|
||||
UserDefinedBiome biome = (UserDefinedBiome) provider.getBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z);
|
||||
for(TreeLayer layer : biome.getConfig().getTrees()) {
|
||||
if(layer.getDensity() >= random.nextDouble() * 100)
|
||||
if(layer.getDensity() >= random.nextDouble() * 100) {
|
||||
layer.place(chunk, new Vector2(offset(random, x), offset(random, z)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ public abstract class Ore {
|
||||
protected TerraPlugin main;
|
||||
|
||||
public Ore(BlockData material, MaterialSet replaceable, boolean applyGravity, TerraPlugin main) {
|
||||
|
||||
this.material = material;
|
||||
this.replaceable = replaceable;
|
||||
this.applyGravity = applyGravity;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.world.population.items.ores;
|
||||
|
||||
import com.dfsek.terra.api.util.GlueList;
|
||||
import com.dfsek.terra.api.util.generic.pair.ImmutablePair;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
@@ -11,22 +12,24 @@ import java.util.function.BiConsumer;
|
||||
public class OreHolder {
|
||||
private final List<Entry> entries = new GlueList<>();
|
||||
|
||||
public void forEach(BiConsumer<Ore, OreConfig> consumer) {
|
||||
entries.forEach(entry -> consumer.accept(entry.getOre(), entry.getConfig()));
|
||||
public void forEach(BiConsumer<String, ImmutablePair<Ore, OreConfig>> consumer) {
|
||||
entries.forEach(entry -> consumer.accept(entry.getId(), ImmutablePair.of(entry.getOre(), entry.getConfig())));
|
||||
}
|
||||
|
||||
public OreHolder add(Ore ore, OreConfig config) {
|
||||
entries.add(new Entry(ore, config));
|
||||
public OreHolder add(Ore ore, OreConfig config, String id) {
|
||||
entries.add(new Entry(ore, config, id));
|
||||
return this;
|
||||
}
|
||||
|
||||
private static final class Entry {
|
||||
private final Ore ore;
|
||||
private final OreConfig config;
|
||||
private final String id;
|
||||
|
||||
private Entry(Ore ore, OreConfig config) {
|
||||
private Entry(Ore ore, OreConfig config, String id) {
|
||||
this.ore = ore;
|
||||
this.config = config;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public OreConfig getConfig() {
|
||||
@@ -36,5 +39,9 @@ public class OreHolder {
|
||||
public Ore getOre() {
|
||||
return ore;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,10 @@ import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.platform.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.platform.world.Tree;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
import com.dfsek.terra.profiler.ProfileFrame;
|
||||
import org.bukkit.TreeType;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
public class BukkitTree implements Tree {
|
||||
@@ -41,7 +43,9 @@ public class BukkitTree implements Tree {
|
||||
|
||||
@Override
|
||||
public boolean plant(Location l, Random r) {
|
||||
return ((BukkitWorld) l.getWorld()).getHandle().generateTree(BukkitAdapter.adapt(l), delegate);
|
||||
try(ProfileFrame ignore = main.getProfiler().profile("bukkit_tree:" + delegate.toString().toLowerCase(Locale.ROOT))) {
|
||||
return ((BukkitWorld) l.getWorld()).getHandle().generateTree(BukkitAdapter.adapt(l), delegate);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,11 +6,13 @@ import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.world.generator.FabricChunkGenerator;
|
||||
import com.dfsek.terra.fabric.world.handles.world.FabricWorldAccess;
|
||||
import com.dfsek.terra.profiler.ProfileFrame;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
public class FabricTree implements Tree {
|
||||
@@ -22,9 +24,11 @@ public class FabricTree implements Tree {
|
||||
|
||||
@Override
|
||||
public boolean plant(Location l, Random r) {
|
||||
FabricWorldAccess fabricWorldAccess = ((FabricWorldAccess) l.getWorld());
|
||||
ChunkGenerator generatorWrapper = ((FabricChunkGenerator) fabricWorldAccess.getGenerator()).getHandle();
|
||||
return delegate.generate((StructureWorldAccess) fabricWorldAccess.getHandle(), generatorWrapper, r, new BlockPos(l.getBlockX(), l.getBlockY(), l.getBlockZ()));
|
||||
try(ProfileFrame ignore = TerraFabricPlugin.getInstance().getProfiler().profile("fabric_tree:" + delegate.toString().toLowerCase(Locale.ROOT))) {
|
||||
FabricWorldAccess fabricWorldAccess = ((FabricWorldAccess) l.getWorld());
|
||||
ChunkGenerator generatorWrapper = ((FabricChunkGenerator) fabricWorldAccess.getGenerator()).getHandle();
|
||||
return delegate.generate((StructureWorldAccess) fabricWorldAccess.getHandle(), generatorWrapper, r, new BlockPos(l.getBlockX(), l.getBlockY(), l.getBlockZ()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user