carvers go brrrrrrr

This commit is contained in:
dfsek
2020-12-05 15:59:48 -07:00
parent 3d7796d8c3
commit 0e4df43ddb
6 changed files with 52 additions and 56 deletions

View File

@@ -9,7 +9,6 @@ import org.bukkit.util.Vector;
import org.polydev.gaea.biome.Biome;
import org.polydev.gaea.generation.GenerationPhase;
import org.polydev.gaea.math.MathUtil;
import org.polydev.gaea.population.ChunkCoordinate;
import org.polydev.gaea.util.FastRandom;
import org.polydev.gaea.util.GlueList;
import org.polydev.gaea.world.carving.Worm;
@@ -20,31 +19,29 @@ import java.util.Map;
import java.util.Random;
public class CarverCache {
private final Map<ChunkCoordinate, List<Worm.WormPoint>> carvers = new HashMap<>();
private final Map<Long, List<Worm.WormPoint>> carvers = new HashMap<>();
public List<Worm.WormPoint> getPoints(int chunkX, int chunkZ, World w, UserDefinedCarver carver) {
ChunkCoordinate req = new ChunkCoordinate(chunkX, chunkZ, w.getUID());
if(carvers.size() > PluginConfig.getCacheSize() * 2) carvers.clear();
return carvers.computeIfAbsent(req, key -> {
return carvers.computeIfAbsent((((long) chunkX) << 32) | (chunkZ & 0xffffffffL) ^ w.getSeed(), key -> {
TerraBiomeGrid grid = TerraWorld.getWorld(w).getGrid();
long seed = MathUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed());
carver.getSeedVar().setValue(seed);
Random r = new FastRandom(seed);
Worm carving = carver.getWorm(seed, new Vector((chunkX << 4) + r.nextInt(16), carver.getConfig().getHeight().get(r), (chunkZ << 4) + r.nextInt(16)));
List<Worm.WormPoint> points = new GlueList<>();
for(int i = 0; i < carving.getLength(); i++) {
carving.step();
Biome biome = grid.getBiome(carving.getRunning().toLocation(w), GenerationPhase.POPULATE);
if(!((UserDefinedBiome) biome).getConfig().getCarvers().containsKey(carver)) { // Stop if we enter a biome this carver is not present in
return new GlueList<>();
if(carver.isChunkCarved(w, chunkX, chunkZ, new FastRandom(MathUtil.hashToLong(this.getClass().getName() + "_" + chunkX + "&" + chunkZ)))) {
long seed = MathUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed());
carver.getSeedVar().setValue(seed);
Random r = new FastRandom(seed);
Worm carving = carver.getWorm(seed, new Vector((chunkX << 4) + r.nextInt(16), carver.getConfig().getHeight().get(r), (chunkZ << 4) + r.nextInt(16)));
List<Worm.WormPoint> points = new GlueList<>();
for(int i = 0; i < carving.getLength(); i++) {
carving.step();
Biome biome = grid.getBiome(carving.getRunning().toLocation(w), GenerationPhase.POPULATE);
if(!((UserDefinedBiome) biome).getConfig().getCarvers().containsKey(carver)) { // Stop if we enter a biome this carver is not present in
return new GlueList<>();
}
points.add(carving.getPoint());
}
points.add(carving.getPoint());
return points;
}
return points;
return new GlueList<>();
});
}
}

View File

@@ -9,7 +9,6 @@ import net.jafama.FastMath;
import org.bukkit.World;
import org.bukkit.util.Vector;
import org.polydev.gaea.generation.GenerationPhase;
import org.polydev.gaea.math.MathUtil;
import org.polydev.gaea.math.Range;
import org.polydev.gaea.util.FastRandom;
import org.polydev.gaea.world.carving.Carver;
@@ -31,9 +30,6 @@ public class UserDefinedCarver extends Carver {
private final int hash;
private final int topCut;
private final int bottomCut;
private double step = 2;
private Range recalc = new Range(8, 10);
private double recalcMagnitude = 3;
private final CarverTemplate config;
private final Expression xRad;
private final Expression yRad;
@@ -44,6 +40,9 @@ public class UserDefinedCarver extends Carver {
private final Range height;
private final double sixtyFourSq = FastMath.pow(64, 2);
private final CarverCache cache = new CarverCache();
private double step = 2;
private Range recalc = new Range(8, 10);
private double recalcMagnitude = 3;
public UserDefinedCarver(Range height, Range length, double[] start, double[] mutate, List<String> radii, Scope parent, int hash, int topCut, int bottomCut, CarverTemplate config) throws ParseException {
super(height.getMin(), height.getMax());
@@ -105,14 +104,12 @@ public class UserDefinedCarver extends Carver {
int carvingRadius = getCarvingRadius();
for(int x = chunkX - carvingRadius; x <= chunkX + carvingRadius; x++) {
for(int z = chunkZ - carvingRadius; z <= chunkZ + carvingRadius; z++) {
if(isChunkCarved(w, x, z, new FastRandom(MathUtil.hashToLong(this.getClass().getName() + "_" + x + "&" + z)))) {
cache.getPoints(x, z, w, this).forEach(point -> {
Vector origin = point.getOrigin();
if(FastMath.floorDiv(origin.getBlockX(), 16) != chunkX && FastMath.floorDiv(origin.getBlockZ(), 16) != chunkZ)
return;
point.carve(chunkX, chunkZ, consumer);
});
}
cache.getPoints(x, z, w, this).forEach(point -> {
Vector origin = point.getOrigin();
if(FastMath.floorDiv(origin.getBlockX(), 16) != chunkX && FastMath.floorDiv(origin.getBlockZ(), 16) != chunkZ)
return;
point.carve(chunkX, chunkZ, consumer);
});
}
}
}

View File

@@ -38,7 +38,7 @@ public class PacksCommand extends Command {
LangUtil.send("command.packs.main", commandSender);
registry.entries().forEach(entry -> {
ConfigPackTemplate template = entry.getTemplate();
LangUtil.send("command.packs.pack", commandSender, template.getID(), template.getAuthor());
LangUtil.send("command.packs.pack", commandSender, template.getID(), template.getAuthor(), template.getVersion());
});
return true;

View File

@@ -6,7 +6,6 @@ import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.image.ImageLoader;
import com.dfsek.terra.registry.ConfigRegistry;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -80,7 +79,7 @@ public class WorldConfig implements ConfigTemplate {
} catch(IllegalArgumentException | NullPointerException e) {
throw new InvalidConfigurationException(e.getCause());
}
Bukkit.getLogger().log(Level.INFO, "Loaded {0} BiomeGrids from list.", tConfig.getTemplate().getGrids().size());
Debug.info("Loaded " + tConfig.getTemplate().getGrids().size() + " BiomeGrids from list.");
} catch(IOException | InvalidConfigurationException e) {
e.printStackTrace();
LangUtil.log("world-config.error", Level.SEVERE, worldID);

View File

@@ -16,7 +16,6 @@ import org.bukkit.block.data.BlockData;
import org.bukkit.generator.BlockPopulator;
import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.profiler.ProfileFuture;
import org.polydev.gaea.world.carving.Carver;
import java.util.HashMap;
import java.util.HashSet;
@@ -44,26 +43,30 @@ public class CavePopulator extends BlockPopulator {
c.carve(chunk.getX(), chunk.getZ(), world, (v, type) -> {
Block b = chunk.getBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ());
Material m = b.getType();
if(type.equals(Carver.CarvingType.CENTER) && template.getInner().canReplace(m)) {
if(template.getShift().containsKey(b.getType()))
shiftCandidate.put(b.getLocation(), b.getType());
b.setBlockData(template.getInner().get(v.getBlockY()).get(random), false);
} else if(type.equals(Carver.CarvingType.WALL) && template.getOuter().canReplace(m)) {
if(template.getShift().containsKey(b.getType()))
shiftCandidate.put(b.getLocation(), b.getType());
b.setBlockData(template.getOuter().get(v.getBlockY()).get(random), false);
} else if(type.equals(Carver.CarvingType.TOP) && template.getTop().canReplace(m)) {
if(template.getShift().containsKey(b.getType()))
shiftCandidate.put(b.getLocation(), b.getType());
b.setBlockData(template.getTop().get(v.getBlockY()).get(random), false);
} else if(type.equals(Carver.CarvingType.BOTTOM) && template.getBottom().canReplace(m)) {
if(template.getShift().containsKey(b.getType()))
shiftCandidate.put(b.getLocation(), b.getType());
b.setBlockData(template.getBottom().get(v.getBlockY()).get(random), false);
}
if(template.getUpdate().contains(m)) {
updateNeeded.add(b);
switch(type) {
case CENTER:
if(template.getInner().canReplace(m)) {
b.setBlockData(template.getInner().get(v.getBlockY()).get(random), false);
}
break;
case WALL:
if(template.getOuter().canReplace(m)) {
b.setBlockData(template.getOuter().get(v.getBlockY()).get(random), false);
}
break;
case TOP:
if(template.getTop().canReplace(m)) {
b.setBlockData(template.getTop().get(v.getBlockY()).get(random), false);
}
break;
case BOTTOM:
if(template.getBottom().canReplace(m)) {
b.setBlockData(template.getBottom().get(v.getBlockY()).get(random), false);
}
break;
}
if(template.getShift().containsKey(b.getType())) shiftCandidate.put(b.getLocation(), b.getType());
if(template.getUpdate().contains(m)) updateNeeded.add(b);
});
for(Map.Entry<Location, Material> entry : shiftCandidate.entrySet()) {
Location l = entry.getKey();

View File

@@ -30,7 +30,7 @@ command:
in: "You are in \"%s\""
packs:
main: "Currently installed config packs:"
pack: " - %1$s by %2$s"
pack: " - %1$s v%3$s by %2$s"
none: "No config packs are installed."
ore:
main-menu: