mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-26 05:50:08 +00:00
Merge remote-tracking branch 'origin/master' into dev/repeat-script
# Conflicts: # common/src/main/java/com/dfsek/terra/api/TerraPlugin.java # common/src/test/java/biome/DistributionTest.java # platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java # platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java # platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java # platforms/sponge/src/main/java/com/dfsek/terra/sponge/TerraSpongePlugin.java
This commit is contained in:
commit
8f9fc3e08f
191 files changed
+4588
-1581
No files matched your search
@@ -70,8 +70,8 @@ fun installServer(dir: String) {
|
||||
// Cloning test setup.
|
||||
gitClone("https://github.com/PolyhedralDev/WorldGenTestServer")
|
||||
// Copying plugins
|
||||
Files.move(Paths.get("WorldGenTestServer/plugins"),
|
||||
Paths.get("$testDir/$dir/plugins"),
|
||||
Files.move(file("WorldGenTestServer/plugins").toPath(),
|
||||
file("$testDir/$dir/plugins").toPath(),
|
||||
StandardCopyOption.REPLACE_EXISTING)
|
||||
// Copying config
|
||||
val serverText = URL("https://raw.githubusercontent.com/PolyhedralDev/WorldGenTestServer/master/server.properties").readText()
|
||||
|
||||
@@ -36,12 +36,15 @@ import com.dfsek.terra.bukkit.listeners.TerraListener;
|
||||
import com.dfsek.terra.bukkit.task.BukkitTaskScheduler;
|
||||
import com.dfsek.terra.bukkit.util.PaperUtil;
|
||||
import com.dfsek.terra.bukkit.world.BukkitBiome;
|
||||
import com.dfsek.terra.bukkit.world.BukkitWorld;
|
||||
import com.dfsek.terra.commands.CommandUtil;
|
||||
import com.dfsek.terra.config.GenericLoaders;
|
||||
import com.dfsek.terra.config.PluginConfig;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.config.lang.Language;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.profiler.Profiler;
|
||||
import com.dfsek.terra.profiler.ProfilerImpl;
|
||||
import com.dfsek.terra.registry.master.AddonRegistry;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
@@ -66,6 +69,8 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
|
||||
private final Map<World, TerraWorld> worldMap = new HashMap<>();
|
||||
private final Map<String, ConfigPack> worlds = new HashMap<>();
|
||||
|
||||
private final Profiler profiler = new ProfilerImpl();
|
||||
|
||||
private final TaskScheduler scheduler = new BukkitTaskScheduler(this);
|
||||
|
||||
private final ConfigRegistry registry = new ConfigRegistry();
|
||||
@@ -145,6 +150,11 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
|
||||
Bukkit.getScheduler().runTask(this, task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profiler getProfiler() {
|
||||
return profiler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskScheduler getScheduler() {
|
||||
return scheduler;
|
||||
@@ -268,14 +278,15 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
|
||||
return checkedRegistry;
|
||||
}
|
||||
|
||||
public TerraWorld getWorld(World w) {
|
||||
if(!TerraWorld.isTerraWorld(w))
|
||||
public TerraWorld getWorld(World world) {
|
||||
BukkitWorld w = (BukkitWorld) world;
|
||||
if(!w.isTerraWorld())
|
||||
throw new IllegalArgumentException("Not a Terra world! " + w.getGenerator());
|
||||
if(!worlds.containsKey(w.getName())) {
|
||||
getLogger().warning("Unexpected world load detected: \"" + w.getName() + "\"");
|
||||
return new TerraWorld(w, ((TerraChunkGenerator) w.getGenerator().getHandle()).getConfigPack(), this);
|
||||
}
|
||||
return worldMap.computeIfAbsent(w, world -> new TerraWorld(w, worlds.get(w.getName()), this));
|
||||
return worldMap.computeIfAbsent(w, w2 -> new TerraWorld(w, worlds.get(w.getName()), this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-14
@@ -3,19 +3,11 @@ package com.dfsek.terra.bukkit.generator;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper;
|
||||
import com.dfsek.terra.api.world.generation.TerraBlockPopulator;
|
||||
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.bukkit.population.PopulationManager;
|
||||
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||
import com.dfsek.terra.bukkit.world.BukkitBiomeGrid;
|
||||
import com.dfsek.terra.profiler.DataType;
|
||||
import com.dfsek.terra.profiler.Measurement;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import com.dfsek.terra.world.population.CavePopulator;
|
||||
import com.dfsek.terra.world.population.FloraPopulator;
|
||||
import com.dfsek.terra.world.population.OrePopulator;
|
||||
import com.dfsek.terra.world.population.StructurePopulator;
|
||||
import com.dfsek.terra.world.population.TreePopulator;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
@@ -24,13 +16,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BukkitChunkGeneratorWrapper extends ChunkGenerator implements GeneratorWrapper {
|
||||
|
||||
@@ -63,7 +52,7 @@ public class BukkitChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
}
|
||||
|
||||
public static synchronized void fixChunk(Chunk c) {
|
||||
if(!TerraWorld.isTerraWorld(c.getWorld())) throw new IllegalArgumentException();
|
||||
if(!c.getWorld().isTerraWorld()) throw new IllegalArgumentException();
|
||||
popMap.get(c.getWorld()).checkNeighbors(c.getX(), c.getZ(), c.getWorld());
|
||||
}
|
||||
|
||||
@@ -76,8 +65,6 @@ public class BukkitChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
e.printStackTrace();
|
||||
}
|
||||
popMap.put(w, popMan);
|
||||
main.getWorld(w).getProfiler().addMeasurement(new Measurement(15000000, DataType.PERIOD_MILLISECONDS), "PopulationManagerTime");
|
||||
popMan.attachProfiler(main.getWorld(w).getProfiler());
|
||||
needsLoad = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public class CommonListener implements Listener {
|
||||
public void onSaplingGrow(StructureGrowEvent e) {
|
||||
if(e.isCancelled()) return;
|
||||
World bukkit = BukkitAdapter.adapt(e.getWorld());
|
||||
if(!TerraWorld.isTerraWorld(bukkit)) return;
|
||||
if(!bukkit.isTerraWorld()) return;
|
||||
TerraWorld tw = main.getWorld(bukkit);
|
||||
WorldConfig c = tw.getConfig();
|
||||
if(c.getTemplate().isDisableSaplings()) return;
|
||||
|
||||
@@ -18,7 +18,7 @@ public class PaperListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onStructureLocate(StructureLocateEvent e) {
|
||||
if(!TerraWorld.isTerraWorld(BukkitAdapter.adapt(e.getWorld()))) return;
|
||||
if(!BukkitAdapter.adapt(e.getWorld()).isTerraWorld()) return;
|
||||
e.setResult(null); // Assume no result.
|
||||
String name = "minecraft:" + e.getType().getName();
|
||||
main.getDebugLogger().info("Overriding structure location for \"" + name + "\"");
|
||||
|
||||
@@ -34,7 +34,7 @@ public class SpigotListener implements Listener {
|
||||
Entity entity = e.getEntity();
|
||||
if(e.getEntityType().equals(EntityType.ENDER_SIGNAL)) {
|
||||
main.getDebugLogger().info("Detected Ender Signal...");
|
||||
if(!TerraWorld.isTerraWorld(BukkitAdapter.adapt(e.getEntity().getWorld()))) return;
|
||||
if(!BukkitAdapter.adapt(e.getEntity().getWorld()).isTerraWorld()) return;
|
||||
TerraWorld tw = main.getWorld(BukkitAdapter.adapt(e.getEntity().getWorld()));
|
||||
EnderSignal signal = (EnderSignal) entity;
|
||||
TerraStructure config = tw.getConfig().getStructureRegistry().get(tw.getConfig().getTemplate().getLocatable().get("STRONGHOLD"));
|
||||
@@ -53,7 +53,7 @@ public class SpigotListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onCartographerChange(VillagerAcquireTradeEvent e) {
|
||||
if(!TerraWorld.isTerraWorld(BukkitAdapter.adapt(e.getEntity().getWorld()))) return;
|
||||
if(!BukkitAdapter.adapt(e.getEntity().getWorld()).isTerraWorld()) return;
|
||||
if(!(e.getEntity() instanceof Villager)) return;
|
||||
if(((Villager) e.getEntity()).getProfession().equals(Villager.Profession.CARTOGRAPHER)) {
|
||||
main.logger().severe("Prevented server crash by stopping Cartographer villager from spawning.");
|
||||
@@ -65,7 +65,7 @@ public class SpigotListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onCartographerLevel(VillagerCareerChangeEvent e) {
|
||||
if(!TerraWorld.isTerraWorld(BukkitAdapter.adapt(e.getEntity().getWorld()))) return;
|
||||
if(!BukkitAdapter.adapt(e.getEntity().getWorld()).isTerraWorld()) return;
|
||||
if(e.getProfession().equals(Villager.Profession.CARTOGRAPHER)) {
|
||||
main.logger().severe("Prevented server crash by stopping Cartographer villager from spawning.");
|
||||
main.logger().severe("Please upgrade to Paper, which has a StructureLocateEvent that fixes this issue");
|
||||
|
||||
+2
-1
@@ -2,6 +2,7 @@ package com.dfsek.terra.bukkit.population;
|
||||
|
||||
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.bukkit.world.BukkitWorld;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
@@ -21,7 +22,7 @@ public class ChunkCoordinate implements Serializable {
|
||||
public ChunkCoordinate(Chunk c) {
|
||||
this.x = c.getX();
|
||||
this.z = c.getZ();
|
||||
this.worldID = c.getWorld().getUID();
|
||||
this.worldID = ((BukkitWorld) c.getWorld()).getUID();
|
||||
}
|
||||
|
||||
public UUID getWorldID() {
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.population;
|
||||
|
||||
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Gaea {
|
||||
private static boolean debug;
|
||||
|
||||
public static File getGaeaFolder(World w) {
|
||||
File f = new File(w.getWorldFolder(), "gaea");
|
||||
f.mkdirs();
|
||||
return f;
|
||||
}
|
||||
|
||||
public static boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
}
|
||||
+15
-18
@@ -5,12 +5,11 @@ import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.util.FastRandom;
|
||||
import com.dfsek.terra.api.world.generation.Chunkified;
|
||||
import com.dfsek.terra.api.world.generation.TerraBlockPopulator;
|
||||
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
|
||||
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||
import com.dfsek.terra.profiler.ProfileFuture;
|
||||
import com.dfsek.terra.profiler.WorldProfiler;
|
||||
import com.dfsek.terra.bukkit.world.BukkitWorld;
|
||||
import com.dfsek.terra.profiler.ProfileFrame;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -26,39 +25,36 @@ public class PopulationManager extends BlockPopulator {
|
||||
private final TerraChunkGenerator generator;
|
||||
private final HashSet<ChunkCoordinate> needsPop = new HashSet<>();
|
||||
private final TerraPlugin main;
|
||||
private WorldProfiler profiler;
|
||||
|
||||
public PopulationManager(TerraChunkGenerator generator, TerraPlugin main) {
|
||||
this.generator = generator;
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
private ProfileFuture measure() {
|
||||
if(profiler != null) return profiler.measure("PopulationManagerTime");
|
||||
return null;
|
||||
}
|
||||
|
||||
public void attachProfiler(WorldProfiler p) {
|
||||
this.profiler = p;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public synchronized void saveBlocks(World w) throws IOException {
|
||||
File f = new File(Gaea.getGaeaFolder(w), "chunks.bin");
|
||||
File f = new File(getDataFolder(w), "chunks.bin");
|
||||
f.createNewFile();
|
||||
SerializationUtil.toFile((HashSet<ChunkCoordinate>) needsPop.clone(), f);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public synchronized void loadBlocks(World w) throws IOException, ClassNotFoundException {
|
||||
File f = new File(Gaea.getGaeaFolder(w), "chunks.bin");
|
||||
File f = new File(getDataFolder(w), "chunks.bin");
|
||||
needsPop.addAll((HashSet<ChunkCoordinate>) SerializationUtil.fromFile(f));
|
||||
}
|
||||
|
||||
public static File getDataFolder(World w) {
|
||||
File f = new File(((BukkitWorld) w).getWorldFolder(), "gaea");
|
||||
f.mkdirs();
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
// Synchronize to prevent chunks from being queued for population multiple times.
|
||||
public synchronized void checkNeighbors(int x, int z, World w) {
|
||||
ChunkCoordinate c = new ChunkCoordinate(x, z, w.getUID());
|
||||
public synchronized void checkNeighbors(int x, int z, World world) {
|
||||
BukkitWorld w = (BukkitWorld) world;
|
||||
ChunkCoordinate c = new ChunkCoordinate(x, z, (w).getUID());
|
||||
if(w.isChunkGenerated(x + 1, z)
|
||||
&& w.isChunkGenerated(x - 1, z)
|
||||
&& w.isChunkGenerated(x, z + 1)
|
||||
@@ -78,8 +74,9 @@ public class PopulationManager extends BlockPopulator {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("try")
|
||||
public void populate(org.bukkit.@NotNull World world, @NotNull Random random, org.bukkit.@NotNull Chunk source) {
|
||||
try(ProfileFuture ignored = measure()) {
|
||||
try(ProfileFrame ignore = main.getProfiler().profile("popman")) {
|
||||
Chunk chunk = BukkitAdapter.adapt(source);
|
||||
needsPop.add(new ChunkCoordinate(chunk));
|
||||
int x = chunk.getX();
|
||||
|
||||
@@ -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 {
|
||||
@@ -40,8 +42,11 @@ public class BukkitTree implements Tree {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("try")
|
||||
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
|
||||
|
||||
@@ -37,17 +37,14 @@ public class BukkitWorld implements World {
|
||||
return new BukkitChunkGenerator(delegate.getGenerator());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return delegate.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUID() {
|
||||
return delegate.getUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChunkGenerated(int x, int z) {
|
||||
return delegate.isChunkGenerated(x, z);
|
||||
}
|
||||
@@ -57,7 +54,6 @@ public class BukkitWorld implements World {
|
||||
return BukkitAdapter.adapt(delegate.getChunkAt(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getWorldFolder() {
|
||||
return delegate.getWorldFolder();
|
||||
}
|
||||
|
||||
+1
@@ -4,6 +4,7 @@ import com.dfsek.terra.api.platform.block.state.SerialState;
|
||||
import com.dfsek.terra.api.platform.block.state.Sign;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class BukkitSign extends BukkitBlockState implements Sign {
|
||||
protected BukkitSign(org.bukkit.block.Sign block) {
|
||||
super(block);
|
||||
|
||||
Reference in new issue
Block a user