clean up chunkgenerator stuff

This commit is contained in:
dfsek
2021-12-02 17:43:44 -07:00
parent 4a8d19cbf2
commit c68d092814
13 changed files with 57 additions and 71 deletions
@@ -49,7 +49,7 @@ import com.dfsek.terra.commands.TerraCommandManager;
public class TerraBukkitPlugin extends JavaPlugin {
private static final Logger logger = LoggerFactory.getLogger(TerraBukkitPlugin.class);
private final PlatformImpl terraPlugin = new PlatformImpl(this);
private final PlatformImpl platform = new PlatformImpl(this);
private final Map<String, com.dfsek.terra.api.world.chunk.generation.ChunkGenerator> generatorMap = new HashMap<>();
@Override
@@ -58,13 +58,13 @@ public class TerraBukkitPlugin extends JavaPlugin {
return;
}
terraPlugin.getEventManager().callEvent(new PlatformInitializationEvent());
platform.getEventManager().callEvent(new PlatformInitializationEvent());
new Metrics(this, 9017); // Set up bStats.
PluginCommand cmd = Objects.requireNonNull(getCommand("terra"));
CommandManager manager = new TerraCommandManager(terraPlugin);
CommandManager manager = new TerraCommandManager(platform);
try {
@@ -91,7 +91,7 @@ public class TerraBukkitPlugin extends JavaPlugin {
try {
Class.forName("io.papermc.paper.event.world.StructureLocateEvent"); // Check if user is on Paper version with event.
Bukkit.getPluginManager().registerEvents(new PaperListener(terraPlugin), this); // Register Paper events.
Bukkit.getPluginManager().registerEvents(new PaperListener(platform), this); // Register Paper events.
} catch(ClassNotFoundException e) {
/*
The command
@@ -130,7 +130,7 @@ public class TerraBukkitPlugin extends JavaPlugin {
|------------------------------------------------------------------------------|
""".strip(), e);
Bukkit.getPluginManager().registerEvents(new SpigotListener(terraPlugin), this); // Register Spigot event listener
Bukkit.getPluginManager().registerEvents(new SpigotListener(platform), this); // Register Spigot event listener
}
}
}
@@ -207,8 +207,8 @@ public class TerraBukkitPlugin extends JavaPlugin {
public @Nullable
ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, String id) {
return new BukkitChunkGeneratorWrapper(generatorMap.computeIfAbsent(worldName, name -> {
ConfigPack pack = terraPlugin.getConfigRegistry().get(id).orElseThrow(() -> new IllegalArgumentException("No such config pack \"" + id + "\""));
ConfigPack pack = platform.getConfigRegistry().get(id).orElseThrow(() -> new IllegalArgumentException("No such config pack \"" + id + "\""));
return pack.getGeneratorProvider().newInstance(pack);
}), terraPlugin.getRawConfigRegistry().get(id).orElseThrow());
}), platform.getRawConfigRegistry().get(id).orElseThrow(), platform);
}
}
@@ -17,10 +17,16 @@
package com.dfsek.terra.bukkit.generator;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.world.ServerWorld;
import com.dfsek.terra.bukkit.world.BukkitProtoWorld;
import com.dfsek.terra.bukkit.world.BukkitServerWorld;
import com.dfsek.terra.world.SamplerProviderImpl;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.generator.BiomeProvider;
@@ -34,22 +40,23 @@ import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import com.dfsek.terra.api.config.WorldConfig;
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
import com.dfsek.terra.api.world.chunk.generation.util.GeneratorWrapper;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGenerator implements GeneratorWrapper {
private final ChunkGenerator delegate;
private WorldConfig worldConfig;
private World world;
private ServerWorld terraWorld;
private final ConfigPack pack;
private final Platform platform;
public BukkitChunkGeneratorWrapper(ChunkGenerator delegate, ConfigPack pack) {
public BukkitChunkGeneratorWrapper(ChunkGenerator delegate, ConfigPack pack, Platform platform) {
this.delegate = delegate;
this.pack = pack;
this.platform = platform;
}
@Override
@@ -59,10 +66,11 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
@Override
public void generateNoise(@NotNull WorldInfo worldInfo, @NotNull Random random, int x, int z, @NotNull ChunkData chunkData) {
if(this.worldConfig == null) {
this.worldConfig = pack.toWorldConfig(BukkitAdapter.adapt(Bukkit.getWorld(worldInfo.getUID())));
if(this.world == null) {
this.world = Bukkit.getWorld(worldInfo.getUID());
this.terraWorld = new BukkitServerWorld(world);
}
delegate.generateChunkData(new BukkitProtoChunk(chunkData), worldConfig.getWorld(), z, x);
delegate.generateChunkData(new BukkitProtoChunk(chunkData), terraWorld, z, x);
}
@Override
@@ -95,8 +103,13 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
return pack.vanillaStructures();
}
public WorldConfig getWorldConfig() {
return worldConfig;
public World getWorld() {
return world;
}
public ConfigPack getPack() {
return pack;
}
@Override
@@ -1,26 +1,22 @@
package com.dfsek.terra.bukkit.world;
import org.bukkit.Location;
import org.bukkit.generator.LimitedRegion;
import com.dfsek.terra.api.block.entity.BlockEntity;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.config.WorldConfig;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.api.world.ServerWorld;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
import com.dfsek.terra.api.world.chunk.generation.ProtoWorld;
import com.dfsek.terra.bukkit.BukkitEntity;
import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper;
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState;
import com.dfsek.terra.bukkit.world.block.state.BukkitBlockEntity;
import com.dfsek.terra.bukkit.world.entity.BukkitEntityType;
import org.bukkit.Location;
import org.bukkit.generator.LimitedRegion;
public class BukkitProtoWorld implements ProtoWorld {
private final LimitedRegion delegate;
@@ -79,12 +75,7 @@ public class BukkitProtoWorld implements ProtoWorld {
@Override
public BiomeProvider getBiomeProvider() {
return ((BukkitChunkGeneratorWrapper) delegate.getWorld().getGenerator()).getWorldConfig().getProvider();
}
@Override
public WorldConfig getConfig() {
return ((BukkitChunkGeneratorWrapper) delegate.getWorld().getGenerator()).getWorldConfig();
return ((BukkitChunkGeneratorWrapper) delegate.getWorld().getGenerator()).getPack().getBiomeProvider();
}
@Override