mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-08-17 00:45:42 +00:00
Added biome-key-format configuration option to config.yml
This commit is contained in:
parent
6b60246694
commit
8d8034d4e2
@ -8,6 +8,7 @@
|
|||||||
package com.dfsek.terra.api.config;
|
package com.dfsek.terra.api.config;
|
||||||
|
|
||||||
import com.dfsek.terra.api.Platform;
|
import com.dfsek.terra.api.Platform;
|
||||||
|
import com.dfsek.terra.api.registry.key.RegistryKey;
|
||||||
|
|
||||||
|
|
||||||
public interface PluginConfig {
|
public interface PluginConfig {
|
||||||
@ -23,6 +24,20 @@ public interface PluginConfig {
|
|||||||
|
|
||||||
boolean isDebugLog();
|
boolean isDebugLog();
|
||||||
|
|
||||||
|
String getBiomeKeyFormat();
|
||||||
|
|
||||||
|
default RegistryKey getBiomeKey(ConfigPack pack, RegistryKey biomeKey) {
|
||||||
|
String format = this.getBiomeKeyFormat()
|
||||||
|
.replace("%pack_id%", pack.getID().toLowerCase())
|
||||||
|
.replace("%biome_namespace%", biomeKey.getNamespace().toLowerCase())
|
||||||
|
.replace("%biome_id%", biomeKey.getID().toLowerCase());
|
||||||
|
if (format.contains(":")) {
|
||||||
|
return RegistryKey.parse(format);
|
||||||
|
} else {
|
||||||
|
return RegistryKey.of("terra", format);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int getBiomeSearchResolution();
|
int getBiomeSearchResolution();
|
||||||
|
|
||||||
int getStructureCache();
|
int getStructureCache();
|
||||||
|
@ -5,20 +5,20 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
|
|
||||||
public final class RegistryKey implements StringIdentifiable, Namespaced {
|
public final class RegistryKey implements StringIdentifiable, Namespaced {
|
||||||
private static final Pattern ID_PATTERN = Pattern.compile("^[a-zA-Z0-9_-]*$");
|
private static final Pattern ID_PATTERN = Pattern.compile("^[a-zA-Z0-9/_-]*$");
|
||||||
private final String namespace;
|
private final String namespace;
|
||||||
private final String id;
|
private final String id;
|
||||||
|
|
||||||
private RegistryKey(String namespace, String id) {
|
private RegistryKey(String namespace, String id) {
|
||||||
if(!ID_PATTERN.matcher(namespace).matches()) {
|
if(!ID_PATTERN.matcher(namespace).matches()) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Namespace must only contain alphanumeric characters, hyphens, and underscores. \"" + namespace +
|
"Namespace must only contain alphanumeric characters, hyphens, underscores and forward slashes. \"" + namespace +
|
||||||
"\" is not a valid namespace.");
|
"\" is not a valid namespace.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!ID_PATTERN.matcher(id).matches()) {
|
if(!ID_PATTERN.matcher(id).matches()) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"ID must only contain alphanumeric characters, hyphens, and underscores. \"" + id +
|
"ID must only contain alphanumeric characters, hyphens, underscores and forward slashes. \"" + id +
|
||||||
"\" is not a valid ID.");
|
"\" is not a valid ID.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,10 @@ public class PluginConfigImpl implements ConfigTemplate, PluginConfig {
|
|||||||
@Default
|
@Default
|
||||||
private boolean debugLog = false;
|
private boolean debugLog = false;
|
||||||
|
|
||||||
|
@Value("biome-key-format")
|
||||||
|
@Default
|
||||||
|
private String biomeKeyFormat = "%pack_id%/%biome_namespace%/%biome_id%";
|
||||||
|
|
||||||
@Value("biome-search-resolution")
|
@Value("biome-search-resolution")
|
||||||
@Default
|
@Default
|
||||||
private int biomeSearch = 4;
|
private int biomeSearch = 4;
|
||||||
@ -124,6 +128,11 @@ public class PluginConfigImpl implements ConfigTemplate, PluginConfig {
|
|||||||
return debugLog;
|
return debugLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getBiomeKeyFormat() {
|
||||||
|
return biomeKeyFormat;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBiomeSearchResolution() {
|
public int getBiomeSearchResolution() {
|
||||||
return biomeSearch;
|
return biomeSearch;
|
||||||
|
@ -11,6 +11,7 @@ debug:
|
|||||||
profiler: false
|
profiler: false
|
||||||
script: false
|
script: false
|
||||||
dump-default: true
|
dump-default: true
|
||||||
|
biome-key-format: "%pack_id%/%biome_namespace%/%biome_id%"
|
||||||
biome-search-resolution: 4
|
biome-search-resolution: 4
|
||||||
cache:
|
cache:
|
||||||
structure: 32
|
structure: 32
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.dfsek.terra.bukkit.nms.v1_21_7;
|
package com.dfsek.terra.bukkit.nms.v1_21_7;
|
||||||
|
|
||||||
|
import com.dfsek.terra.bukkit.PlatformImpl;
|
||||||
import com.dfsek.terra.bukkit.nms.v1_21_7.config.VanillaBiomeProperties;
|
import com.dfsek.terra.bukkit.nms.v1_21_7.config.VanillaBiomeProperties;
|
||||||
|
|
||||||
import com.dfsek.terra.bukkit.world.BukkitBiomeInfo;
|
import com.dfsek.terra.bukkit.world.BukkitBiomeInfo;
|
||||||
@ -28,7 +29,6 @@ import java.util.Set;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
|
||||||
|
|
||||||
|
|
||||||
public class AwfulBukkitHacks {
|
public class AwfulBukkitHacks {
|
||||||
@ -36,7 +36,7 @@ public class AwfulBukkitHacks {
|
|||||||
|
|
||||||
private static final Map<ResourceLocation, List<ResourceLocation>> terraBiomeMap = new HashMap<>();
|
private static final Map<ResourceLocation, List<ResourceLocation>> terraBiomeMap = new HashMap<>();
|
||||||
|
|
||||||
public static void registerBiomes(ConfigRegistry configRegistry) {
|
public static void registerBiomes(PlatformImpl platform) {
|
||||||
try {
|
try {
|
||||||
LOGGER.info("Hacking biome registry...");
|
LOGGER.info("Hacking biome registry...");
|
||||||
MappedRegistry<Biome> biomeRegistry = (MappedRegistry<Biome>) RegistryFetcher.biomeRegistry();
|
MappedRegistry<Biome> biomeRegistry = (MappedRegistry<Biome>) RegistryFetcher.biomeRegistry();
|
||||||
@ -45,7 +45,7 @@ public class AwfulBukkitHacks {
|
|||||||
Reflection.MAPPED_REGISTRY.setFrozen(biomeRegistry, false);
|
Reflection.MAPPED_REGISTRY.setFrozen(biomeRegistry, false);
|
||||||
|
|
||||||
// Register the terra biomes to the registry
|
// Register the terra biomes to the registry
|
||||||
configRegistry.forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach((key, biome) -> {
|
platform.getRawConfigRegistry().forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach((key, biome) -> {
|
||||||
try {
|
try {
|
||||||
BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome();
|
BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome();
|
||||||
NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey();
|
NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey();
|
||||||
@ -54,14 +54,13 @@ public class AwfulBukkitHacks {
|
|||||||
|
|
||||||
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
|
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
|
||||||
|
|
||||||
Biome platform = NMSBiomeInjector.createBiome(biomeRegistry.get(vanillaMinecraftKey).orElseThrow().value(), vanillaBiomeProperties);
|
Biome nmsBiome = NMSBiomeInjector.createBiome(biomeRegistry.get(vanillaMinecraftKey).orElseThrow().value(), vanillaBiomeProperties);
|
||||||
|
ResourceLocation delegateMinecraftKey = ResourceLocation.tryParse(platform.getTerraConfig().getBiomeKey(pack, key).toString());
|
||||||
ResourceLocation delegateMinecraftKey = ResourceLocation.fromNamespaceAndPath("terra", NMSBiomeInjector.createBiomeID(pack, key));
|
|
||||||
NamespacedKey delegateBukkitKey = NamespacedKey.fromString(delegateMinecraftKey.toString());
|
NamespacedKey delegateBukkitKey = NamespacedKey.fromString(delegateMinecraftKey.toString());
|
||||||
ResourceKey<Biome> delegateKey = ResourceKey.create(Registries.BIOME, delegateMinecraftKey);
|
ResourceKey<Biome> delegateKey = ResourceKey.create(Registries.BIOME, delegateMinecraftKey);
|
||||||
|
|
||||||
Reference<Biome> holder = biomeRegistry.register(delegateKey, platform, RegistrationInfo.BUILT_IN);
|
Reference<Biome> holder = biomeRegistry.register(delegateKey, nmsBiome, RegistrationInfo.BUILT_IN);
|
||||||
Reflection.REFERENCE.invokeBindValue(holder, platform); // IMPORTANT: bind holder.
|
Reflection.REFERENCE.invokeBindValue(holder, nmsBiome); // IMPORTANT: bind holder.
|
||||||
|
|
||||||
platformBiome.getContext().put(new BukkitBiomeInfo(delegateBukkitKey));
|
platformBiome.getContext().put(new BukkitBiomeInfo(delegateBukkitKey));
|
||||||
platformBiome.getContext().put(new NMSBiomeInfo(delegateKey));
|
platformBiome.getContext().put(new NMSBiomeInfo(delegateKey));
|
||||||
|
@ -11,7 +11,7 @@ import com.dfsek.terra.bukkit.nms.Initializer;
|
|||||||
public class NMSInitializer implements Initializer {
|
public class NMSInitializer implements Initializer {
|
||||||
@Override
|
@Override
|
||||||
public void initialize(PlatformImpl platform) {
|
public void initialize(PlatformImpl platform) {
|
||||||
AwfulBukkitHacks.registerBiomes(platform.getRawConfigRegistry());
|
AwfulBukkitHacks.registerBiomes(platform);
|
||||||
Bukkit.getPluginManager().registerEvents(new NMSInjectListener(), platform.getPlugin());
|
Bukkit.getPluginManager().registerEvents(new NMSInjectListener(), platform.getPlugin());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user