mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-09 17:26:07 +00:00
clean up chunkgenerator stuff
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
package com.dfsek.terra.addons.chunkgenerator;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.config.NoiseChunkGeneratorPackConfigTemplate;
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.generators.NoiseChunkGenerator3D;
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.PaletteHolder;
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.PaletteHolderLoader;
|
||||
@@ -36,12 +37,16 @@ public class NoiseChunkGenerator3DAddon implements AddonInitializer {
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(addon, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
event.getPack().getOrCreateRegistry(ChunkGeneratorProvider.class).register("NOISE_3D",
|
||||
pack -> new NoiseChunkGenerator3D(pack,
|
||||
platform));
|
||||
NoiseChunkGeneratorPackConfigTemplate config = event.loadTemplate(new NoiseChunkGeneratorPackConfigTemplate());
|
||||
|
||||
event.getPack()
|
||||
.getOrCreateRegistry(ChunkGeneratorProvider.class)
|
||||
.register("NOISE_3D",
|
||||
pack -> new NoiseChunkGenerator3D(pack, platform, config.getElevationBlend()));
|
||||
event.getPack()
|
||||
.applyLoader(SlantHolder.class, new SlantHolderLoader())
|
||||
.applyLoader(PaletteHolder.class, new PaletteHolderLoader());
|
||||
|
||||
})
|
||||
.failThrough();
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.WritableWorld;
|
||||
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.math.SamplerProvider;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -39,12 +41,17 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
private final Platform platform;
|
||||
private final List<GenerationStage> generationStages = new ArrayList<>();
|
||||
|
||||
private final int elevationBlend;
|
||||
|
||||
private final SamplerProvider samplerCache;
|
||||
|
||||
private final BlockState air;
|
||||
|
||||
public NoiseChunkGenerator3D(ConfigPack c, Platform platform) {
|
||||
public NoiseChunkGenerator3D(ConfigPack c, Platform platform, int elevationBlend) {
|
||||
this.configPack = c;
|
||||
this.platform = platform;
|
||||
this.air = platform.getWorldHandle().air();
|
||||
this.elevationBlend = elevationBlend;
|
||||
c.getStages().forEach(stage -> generationStages.add(stage.newInstance(c)));
|
||||
}
|
||||
|
||||
@@ -59,7 +66,7 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
int xOrig = (chunkX << 4);
|
||||
int zOrig = (chunkZ << 4);
|
||||
|
||||
Sampler sampler = world.getConfig().getSamplerCache().getChunk(chunkX, chunkZ);
|
||||
Sampler sampler = samplerCache.getChunk(chunkX, chunkZ);
|
||||
|
||||
long seed = world.getSeed();
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.world;
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.math.samplers;
|
||||
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.math.SamplerProvider;
|
||||
@@ -109,8 +109,7 @@ public class NoiseAddon implements AddonInitializer {
|
||||
noiseRegistry.register("EXPRESSION", () -> new ExpressionFunctionTemplate(packSamplers, packFunctions));
|
||||
|
||||
|
||||
NoiseConfigPackTemplate template = new NoiseConfigPackTemplate();
|
||||
event.loadTemplate(template);
|
||||
NoiseConfigPackTemplate template = event.loadTemplate(new NoiseConfigPackTemplate());
|
||||
packSamplers.putAll(template.getSamplers());
|
||||
packFunctions.putAll(template.getFunctions());
|
||||
})
|
||||
|
||||
@@ -13,18 +13,13 @@ import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.util.StringIdentifiable;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.math.SamplerProvider;
|
||||
|
||||
|
||||
public interface WorldConfig extends StringIdentifiable {
|
||||
int elevationBlend();
|
||||
|
||||
<T> Registry<T> getRegistry(Class<T> clazz);
|
||||
|
||||
ServerWorld getWorld();
|
||||
|
||||
SamplerProvider getSamplerCache();
|
||||
|
||||
BiomeProvider getProvider();
|
||||
|
||||
ConfigPack getPack();
|
||||
|
||||
@@ -32,8 +32,9 @@ public abstract class ConfigPackLoadEvent implements PackEvent, FailThroughEvent
|
||||
*
|
||||
* @param template Template to register.
|
||||
*/
|
||||
public void loadTemplate(ConfigTemplate template) throws ConfigException {
|
||||
public <T extends ConfigTemplate> T loadTemplate(T template) throws ConfigException {
|
||||
configLoader.accept(template);
|
||||
return template;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.dfsek.terra.api.world;
|
||||
|
||||
import com.dfsek.terra.api.Handle;
|
||||
import com.dfsek.terra.api.config.WorldConfig;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||
|
||||
@@ -16,6 +15,4 @@ public interface World extends Handle {
|
||||
ChunkGenerator getGenerator();
|
||||
|
||||
BiomeProvider getBiomeProvider();
|
||||
|
||||
WorldConfig getConfig();
|
||||
}
|
||||
|
||||
@@ -166,7 +166,6 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
logger.error("Failed to load config pack from folder \"{}\"", folder.getAbsolutePath(), e);
|
||||
throw e;
|
||||
}
|
||||
toWorldConfig(new DummyServerWorld()); // Build now to catch any errors immediately.
|
||||
}
|
||||
|
||||
public ConfigPackImpl(ZipFile file, Platform platform) throws ConfigException {
|
||||
@@ -219,8 +218,6 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
logger.error("Failed to load config pack from ZIP archive \"{}\"", file.getName());
|
||||
throw e;
|
||||
}
|
||||
|
||||
toWorldConfig(new DummyServerWorld()); // Build now to catch any errors immediately.
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,14 +27,11 @@ import com.dfsek.terra.api.config.WorldConfig;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.math.SamplerProvider;
|
||||
import com.dfsek.terra.registry.LockedRegistryImpl;
|
||||
import com.dfsek.terra.world.SamplerProviderImpl;
|
||||
|
||||
|
||||
public class WorldConfigImpl implements WorldConfig {
|
||||
private final SamplerProvider samplerProvider;
|
||||
|
||||
private final BiomeProvider provider;
|
||||
|
||||
private final ServerWorld world;
|
||||
@@ -45,18 +42,12 @@ public class WorldConfigImpl implements WorldConfig {
|
||||
public WorldConfigImpl(ServerWorld world, ConfigPackImpl pack, Platform platform) {
|
||||
this.world = world;
|
||||
this.pack = pack;
|
||||
this.samplerProvider = new SamplerProviderImpl(platform, world);
|
||||
|
||||
pack.getRegistryMap().forEach((clazz, pair) -> registryMap.put(clazz, new LockedRegistryImpl<>(pair.getLeft())));
|
||||
|
||||
this.provider = pack.getBiomeProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int elevationBlend() {
|
||||
return pack.getTemplate().getElevationBlend();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Registry<T> getRegistry(Class<T> clazz) {
|
||||
@@ -68,11 +59,6 @@ public class WorldConfigImpl implements WorldConfig {
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SamplerProvider getSamplerCache() {
|
||||
return samplerProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeProvider getProvider() {
|
||||
return provider;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -59,13 +59,12 @@ public final class FabricAddon implements BaseAddon {
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
PreLoadCompatibilityOptions template = new PreLoadCompatibilityOptions();
|
||||
try {
|
||||
event.loadTemplate(template);
|
||||
PreLoadCompatibilityOptions template = event.loadTemplate(new PreLoadCompatibilityOptions());
|
||||
templates.put(event.getPack(), Mutable.of(template, null));
|
||||
} catch(ConfigException e) {
|
||||
logger.error("Error loading config template", e);
|
||||
}
|
||||
templates.put(event.getPack(), Mutable.of(template, null));
|
||||
})
|
||||
.global();
|
||||
|
||||
@@ -73,15 +72,11 @@ public final class FabricAddon implements BaseAddon {
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPostLoadEvent.class)
|
||||
.then(event -> {
|
||||
PostLoadCompatibilityOptions template = new PostLoadCompatibilityOptions();
|
||||
|
||||
try {
|
||||
event.loadTemplate(template);
|
||||
templates.get(event.getPack()).setRight(event.loadTemplate(new PostLoadCompatibilityOptions()));
|
||||
} catch(ConfigException e) {
|
||||
logger.error("Error loading config template", e);
|
||||
}
|
||||
|
||||
templates.get(event.getPack()).setRight(template);
|
||||
})
|
||||
.priority(100)
|
||||
.global();
|
||||
|
||||
Reference in New Issue
Block a user