Compare commits

..

2 Commits

Author SHA1 Message Date
OakLoaf 140fddf9a5 Removed biome-key-format configuration option from default config.yml 2025-07-06 11:59:47 +01:00
OakLoaf 8d8034d4e2 Added biome-key-format configuration option to config.yml 2025-07-03 21:37:45 +01:00
41 changed files with 175 additions and 253 deletions
+5 -5
View File
@@ -28,8 +28,8 @@ object Versions {
}
object Fabric {
const val fabricAPI = "0.129.0+${Mod.minecraft}"
const val cloud = "2.0.0-beta.11"
const val fabricAPI = "0.128.1+${Mod.minecraft}"
const val cloud = "2.0.0-beta.10"
}
//
// object Quilt {
@@ -41,7 +41,7 @@ object Versions {
const val mixin = "0.15.5+mixin.0.8.7"
const val mixinExtras = "0.4.1"
const val minecraft = "1.21.8"
const val minecraft = "1.21.7"
const val yarn = "$minecraft+build.1"
const val fabricLoader = "0.16.14"
@@ -56,8 +56,8 @@ object Versions {
// }
object Bukkit {
const val minecraft = "1.21.8-R0.1"
const val paperBuild = "$minecraft-20250717.233435-4"
const val minecraft = "1.21.7-R0.1"
const val paperBuild = "$minecraft-20250630.144242-1"
const val paper = paperBuild
const val paperLib = "1.0.8"
const val reflectionRemapper = "0.1.2"
@@ -1,10 +1,10 @@
bool thing1 = 2 > (2 + 2) || false;
bool thing1 = 2 > (2+2) || false;
if (2 > 2 || 3 + 4 <= 2 && 4 + 5 > 2 / 3) {
if(2 > 2 || 3 + 4 <= 2 && 4 + 5 > 2 / 3) {
test("ok", 2);
}
test("minecraft:green_w" + "ool", (2 * (3 + 1) * (2 * (1 + 1))));
test("minecraft:green_w" + "ool", (2 * (3+1) * (2 * (1+1))));
//
num testVar = 3.4;
@@ -21,7 +21,7 @@ bool iftest = false;
bool truetest = false;
num iterator = 0;
num thing = 4 - 2 - 2 + 2 - 2 + 2;
num thing = 4 - 2-2+2-2+2;
test("4 - 2 = " + thing, 2);
thing = -2;
@@ -31,54 +31,54 @@ test("--2 = " + thing, 2);
for (num i = 0; i < 5; i = i + 1) {
for(num i = 0; i < 5; i = i + 1) {
test("i = " + i, iterator);
if (i > 1 + 1) {
if(i > 1 + 1) {
test("more than 2", iterator);
continue;
}
}
for (num i = 0; i < 5; i = i + 1) {
for(num i = 0; i < 5; i = i + 1) {
test("i = " + i, iterator);
}
for (num j = 0; j < 5; j = j + 1) test("single statement j = " + j, iterator);
for(num j = 0; j < 5; j = j + 1) test("single statement j = " + j, iterator);
if (4 + 2 == 2 + 4) {
if(4 + 2 == 2 + 4) {
test("new thing " + 2, iterator);
}
while (iterator < 5) {
while(iterator < 5) {
test("always, even after " + 2, iterator);
iterator = iterator + 1;
if (iterator > 2) {
if(iterator > 2) {
continue;
}
test("not after " + 2, iterator);
}
if (true) test("single statement" + 2, iterator);
else if (true) test("another single statement" + 2, iterator);
if(true) test("single statement" + 2, iterator);
else if(true) test("another single statement" + 2, iterator);
if (true) {
if(true) {
test("true!" + 2, iterator);
} else {
test("false!" + 2, iterator);
}
if(false) {
test("true!" + 2, iterator);
} else {
test("false!" + 2, iterator);
}
if (false) {
test("true!" + 2, iterator);
} else {
test("false!" + 2, iterator);
}
if (false) {
if(false) {
test("true again!" + 2, iterator);
} else if (true == true) {
test("false again!" + 2, iterator);
} else if(true == true) {
test("false again!" + 2, iterator);
} else {
test("not logged!" + 2, iterator);
test("not logged!" + 2, iterator);
}
@@ -91,7 +91,7 @@ fsdfsd
test("fdsgdf" + 2, 1 + testVar);
if (true && !(boolean && false) && true) {
if(true && !(boolean && false) && true) {
num scopedVar = 2;
test("if statement" + 2 + stringVar, 1 + testVar + scopedVar);
}
@@ -8,6 +8,7 @@
package com.dfsek.terra.api.config;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.registry.key.RegistryKey;
public interface PluginConfig {
@@ -23,6 +24,20 @@ public interface PluginConfig {
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 getStructureCache();
@@ -5,20 +5,20 @@ import java.util.regex.Pattern;
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 id;
private RegistryKey(String namespace, String id) {
if(!ID_PATTERN.matcher(namespace).matches()) {
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.");
}
if(!ID_PATTERN.matcher(id).matches()) {
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.");
}
@@ -108,7 +108,7 @@ public abstract class AbstractPlatform implements Platform {
return Collections.emptySet();
}
protected InternalAddon load() {
protected void load() {
if(LOADED.get()) {
throw new IllegalStateException(
"Someone tried to initialize Terra, but Terra has already initialized. This is most likely due to a broken platform " +
@@ -159,8 +159,6 @@ public abstract class AbstractPlatform implements Platform {
logger.info("Terra addons successfully loaded.");
logger.info("Finished initialization.");
return internalAddon;
}
protected InternalAddon loadAddons() {
@@ -55,6 +55,10 @@ public class PluginConfigImpl implements ConfigTemplate, PluginConfig {
@Default
private boolean debugLog = false;
@Value("biome-key-format")
@Default
private String biomeKeyFormat = "%pack_id%/%biome_namespace%/%biome_id%";
@Value("biome-search-resolution")
@Default
private int biomeSearch = 4;
@@ -124,6 +128,11 @@ public class PluginConfigImpl implements ConfigTemplate, PluginConfig {
return debugLog;
}
@Override
public String getBiomeKeyFormat() {
return biomeKeyFormat;
}
@Override
public int getBiomeSearchResolution() {
return biomeSearch;
+1 -1
View File
@@ -8,7 +8,7 @@ dependencies {
paperweight.paperDevBundle(Versions.Bukkit.paperDevBundle)
shaded(project(":platforms:bukkit:common"))
shaded(project(":platforms:bukkit:nms:v1_21_8"))
shaded(project(":platforms:bukkit:nms:v1_21_7"))
shaded("xyz.jpenilla", "reflection-remapper", Versions.Bukkit.reflectionRemapper)
}
@@ -21,6 +21,8 @@ import com.dfsek.tectonic.api.TypeRegistry;
import com.dfsek.tectonic.api.depth.DepthTracker;
import com.dfsek.tectonic.api.exception.LoadException;
import com.dfsek.terra.bukkit.nms.Initializer;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import org.bukkit.Bukkit;
@@ -31,8 +33,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.List;
import com.dfsek.terra.AbstractPlatform;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.handle.ItemHandle;
import com.dfsek.terra.api.handle.WorldHandle;
@@ -95,6 +99,11 @@ public class PlatformImpl extends AbstractPlatform {
plugin.getGlobalRegionScheduler().run(plugin, task -> runnable.run());
}
@Override
protected Iterable<BaseAddon> platformAddon() {
return List.of(Initializer.nmsAddon(this));
}
@Override
public @NotNull WorldHandle getWorldHandle() {
return handle;
@@ -124,7 +133,7 @@ public class PlatformImpl extends AbstractPlatform {
}
protected BukkitPlatformBiome parseBiome(String id, DepthTracker depthTracker) throws LoadException {
private BukkitPlatformBiome parseBiome(String id, DepthTracker depthTracker) throws LoadException {
NamespacedKey key = NamespacedKey.fromString(id);
if(key == null || !key.namespace().equals("minecraft")) throw new LoadException("Invalid biome identifier " + id, depthTracker);
return new BukkitPlatformBiome(RegistryAccess.registryAccess().getRegistry(RegistryKey.BIOME).getOrThrow(key));
@@ -51,7 +51,7 @@ import com.dfsek.terra.bukkit.world.BukkitAdapter;
public class TerraBukkitPlugin extends JavaPlugin {
private static final Logger logger = LoggerFactory.getLogger(TerraBukkitPlugin.class);
private PlatformImpl platform;
private final PlatformImpl platform = new PlatformImpl(this);
private final Map<String, com.dfsek.terra.api.world.chunk.generation.ChunkGenerator> generatorMap = new HashMap<>();
private AsyncScheduler asyncScheduler = this.getServer().getAsyncScheduler();
@@ -64,14 +64,13 @@ public class TerraBukkitPlugin extends JavaPlugin {
return;
}
platform = Initializer.init(this);
if(platform == null) {
platform.getEventManager().callEvent(new PlatformInitializationEvent());
if(!Initializer.init(platform)) {
Bukkit.getPluginManager().disablePlugin(this);
return;
}
platform.getEventManager().callEvent(new PlatformInitializationEvent());
try {
LegacyPaperCommandManager<CommandSender> commandManager = getCommandSenderPaperCommandManager();
@@ -1,6 +1,6 @@
package com.dfsek.terra.bukkit.nms;
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
import com.dfsek.terra.bukkit.BukkitAddon;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -13,11 +13,13 @@ public interface Initializer {
String NMS = VersionUtil.getMinecraftVersionInfo().toString().replace(".", "_");
String TERRA_PACKAGE = Initializer.class.getPackageName();
static PlatformImpl init(TerraBukkitPlugin plugin) {
static boolean init(PlatformImpl platform) {
Logger logger = LoggerFactory.getLogger(Initializer.class);
PlatformImpl platform = constructPlatform(plugin);
if (platform == null) {
Initializer initializer = constructInitializer();
if(initializer != null) {
initializer.initialize(platform);
} else {
logger.error("NMS bindings for version {} do not exist. Support for this version is limited.", NMS);
logger.error("This is usually due to running Terra on an unsupported Minecraft version.");
String bypassKey = "IKnowThereAreNoNMSBindingsFor" + NMS + "ButIWillProceedAnyway";
@@ -25,7 +27,7 @@ public interface Initializer {
logger.error("Because of this **TERRA HAS BEEN DISABLED**.");
logger.error("Do not come ask us why it is not working.");
logger.error("If you wish to proceed anyways, you can add the JVM System Property \"{}\" to enable the plugin.", bypassKey);
return null;
return false;
} else {
logger.error("");
logger.error("");
@@ -41,21 +43,24 @@ public interface Initializer {
}
}
return platform;
return true;
}
private static PlatformImpl constructPlatform(TerraBukkitPlugin plugin) {
static BukkitAddon nmsAddon(PlatformImpl platform) {
Initializer initializer = constructInitializer();
return initializer != null ? initializer.getNMSAddon(platform) : new BukkitAddon(platform);
}
private static Initializer constructInitializer() {
try {
String packageVersion = NMS;
if (NMS.equals("v1_21_5") || NMS.equals("v1_21_6") || NMS.equals("v1_21_7")) {
packageVersion = "v1_21_8";
if (NMS.equals("v1_21_5") || NMS.equals("v1_21_6")) {
packageVersion = "v1_21_7";
}
Class<?> platformClass = Class.forName(TERRA_PACKAGE + "." + packageVersion + ".NMSPlatform");
Class<?> initializerClass = Class.forName(TERRA_PACKAGE + "." + packageVersion + ".NMSInitializer");
try {
return (PlatformImpl) platformClass
.getConstructor(TerraBukkitPlugin.class)
.newInstance(plugin);
return (Initializer) initializerClass.getConstructor().newInstance();
} catch(ReflectiveOperationException e) {
throw new RuntimeException("Error initializing NMS bindings. Report this to Terra.", e);
}
@@ -63,4 +68,8 @@ public interface Initializer {
return null;
}
}
void initialize(PlatformImpl plugin);
BukkitAddon getNMSAddon(PlatformImpl plugin);
}
@@ -1,6 +1,7 @@
package com.dfsek.terra.bukkit.nms.v1_21_8;
package com.dfsek.terra.bukkit.nms.v1_21_7;
import com.dfsek.terra.bukkit.nms.v1_21_8.config.VanillaBiomeProperties;
import com.dfsek.terra.bukkit.PlatformImpl;
import com.dfsek.terra.bukkit.nms.v1_21_7.config.VanillaBiomeProperties;
import com.dfsek.terra.bukkit.world.BukkitBiomeInfo;
@@ -14,7 +15,6 @@ import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.npc.VillagerType;
import net.minecraft.world.level.biome.Biome;
import org.bukkit.NamespacedKey;
import org.slf4j.Logger;
@@ -25,12 +25,10 @@ import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
import com.dfsek.terra.registry.master.ConfigRegistry;
public class AwfulBukkitHacks {
@@ -38,7 +36,7 @@ public class AwfulBukkitHacks {
private static final Map<ResourceLocation, List<ResourceLocation>> terraBiomeMap = new HashMap<>();
public static void registerBiomes(ConfigRegistry configRegistry) {
public static void registerBiomes(PlatformImpl platform) {
try {
LOGGER.info("Hacking biome registry...");
MappedRegistry<Biome> biomeRegistry = (MappedRegistry<Biome>) RegistryFetcher.biomeRegistry();
@@ -47,34 +45,26 @@ public class AwfulBukkitHacks {
Reflection.MAPPED_REGISTRY.setFrozen(biomeRegistry, false);
// 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 {
BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome();
NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey();
ResourceLocation vanillaMinecraftKey = ResourceLocation.fromNamespaceAndPath(vanillaBukkitKey.getNamespace(),
vanillaBukkitKey.getKey());
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
Biome platform = NMSBiomeInjector.createBiome(biomeRegistry.get(vanillaMinecraftKey).orElseThrow().value(), vanillaBiomeProperties);
ResourceLocation delegateMinecraftKey = ResourceLocation.fromNamespaceAndPath("terra", NMSBiomeInjector.createBiomeID(pack, key));
Biome nmsBiome = NMSBiomeInjector.createBiome(biomeRegistry.get(vanillaMinecraftKey).orElseThrow().value(), vanillaBiomeProperties);
ResourceLocation delegateMinecraftKey = ResourceLocation.tryParse(platform.getTerraConfig().getBiomeKey(pack, key).toString());
NamespacedKey delegateBukkitKey = NamespacedKey.fromString(delegateMinecraftKey.toString());
ResourceKey<Biome> delegateKey = ResourceKey.create(Registries.BIOME, delegateMinecraftKey);
Reference<Biome> holder = biomeRegistry.register(delegateKey, platform, RegistrationInfo.BUILT_IN);
Reflection.REFERENCE.invokeBindValue(holder, platform); // IMPORTANT: bind holder.
Reference<Biome> holder = biomeRegistry.register(delegateKey, nmsBiome, RegistrationInfo.BUILT_IN);
Reflection.REFERENCE.invokeBindValue(holder, nmsBiome); // IMPORTANT: bind holder.
platformBiome.getContext().put(new BukkitBiomeInfo(delegateBukkitKey));
platformBiome.getContext().put(new NMSBiomeInfo(delegateKey));
Map<ResourceKey<Biome>, ResourceKey<VillagerType>> villagerMap = Reflection.VILLAGER_TYPE.getByBiome();
villagerMap.put(delegateKey,
Objects.requireNonNullElse(vanillaBiomeProperties.getVillagerType(),
villagerMap.getOrDefault(delegateKey, VillagerType.PLAINS)));
terraBiomeMap.computeIfAbsent(vanillaMinecraftKey, i -> new ArrayList<>()).add(delegateKey.location());
LOGGER.debug("Registered biome: " + delegateKey);
@@ -1,11 +1,11 @@
package com.dfsek.terra.bukkit.nms.v1_21_8;
package com.dfsek.terra.bukkit.nms.v1_21_7;
import com.dfsek.terra.api.event.events.config.ConfigurationLoadEvent;
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
import com.dfsek.terra.api.world.biome.Biome;
import com.dfsek.terra.bukkit.BukkitAddon;
import com.dfsek.terra.bukkit.PlatformImpl;
import com.dfsek.terra.bukkit.nms.v1_21_8.config.VanillaBiomeProperties;
import com.dfsek.terra.bukkit.nms.v1_21_7.config.VanillaBiomeProperties;
public class NMSAddon extends BukkitAddon {
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_21_8;
package com.dfsek.terra.bukkit.nms.v1_21_7;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.biome.Biome;
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_21_8;
package com.dfsek.terra.bukkit.nms.v1_21_7;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
@@ -12,7 +12,7 @@ import java.util.Objects;
import java.util.Optional;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.bukkit.nms.v1_21_8.config.VanillaBiomeProperties;
import com.dfsek.terra.bukkit.nms.v1_21_7.config.VanillaBiomeProperties;
public class NMSBiomeInjector {
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_21_8;
package com.dfsek.terra.bukkit.nms.v1_21_7;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.Holder;
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_21_8;
package com.dfsek.terra.bukkit.nms.v1_21_7;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
@@ -0,0 +1,22 @@
package com.dfsek.terra.bukkit.nms.v1_21_7;
import com.dfsek.terra.bukkit.BukkitAddon;
import org.bukkit.Bukkit;
import com.dfsek.terra.bukkit.PlatformImpl;
import com.dfsek.terra.bukkit.nms.Initializer;
public class NMSInitializer implements Initializer {
@Override
public void initialize(PlatformImpl platform) {
AwfulBukkitHacks.registerBiomes(platform);
Bukkit.getPluginManager().registerEvents(new NMSInjectListener(), platform.getPlugin());
}
@Override
public BukkitAddon getNMSAddon(PlatformImpl plugin) {
return new NMSAddon(plugin);
}
}
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_21_8;
package com.dfsek.terra.bukkit.nms.v1_21_7;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerLevel;
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_21_8;
package com.dfsek.terra.bukkit.nms.v1_21_7;
import net.minecraft.world.level.LevelHeightAccessor;
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_21_8;
package com.dfsek.terra.bukkit.nms.v1_21_7;
import net.minecraft.core.Holder;
import net.minecraft.core.Holder.Reference;
@@ -7,7 +7,6 @@ import net.minecraft.core.MappedRegistry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.npc.VillagerType;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.StructureManager;
import net.minecraft.world.level.biome.Biome;
@@ -37,7 +36,6 @@ public class Reflection {
public static final HolderReferenceProxy HOLDER_REFERENCE;
public static final HolderSetNamedProxy HOLDER_SET;
public static final BiomeProxy BIOME;
public static final VillagerTypeProxy VILLAGER_TYPE;
static {
ReflectionRemapper reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar();
@@ -52,7 +50,6 @@ public class Reflection {
HOLDER_REFERENCE = reflectionProxyFactory.reflectionProxy(HolderReferenceProxy.class);
HOLDER_SET = reflectionProxyFactory.reflectionProxy(HolderSetNamedProxy.class);
BIOME = reflectionProxyFactory.reflectionProxy(BiomeProxy.class);
VILLAGER_TYPE = reflectionProxyFactory.reflectionProxy(VillagerTypeProxy.class);
}
@@ -124,11 +121,4 @@ public class Reflection {
@MethodName("getGrassColorFromTexture")
int invokeGrassColorFromTexture(Biome instance);
}
@Proxies(VillagerType.class)
public interface VillagerTypeProxy {
@Static
@FieldGetter("BY_BIOME")
Map<ResourceKey<Biome>, ResourceKey<VillagerType>> getByBiome();
}
}
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_21_8;
package com.dfsek.terra.bukkit.nms.v1_21_7;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_21_8.config;
package com.dfsek.terra.bukkit.nms.v1_21_7.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_21_8.config;
package com.dfsek.terra.bukkit.nms.v1_21_7.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_21_8.config;
package com.dfsek.terra.bukkit.nms.v1_21_7.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
@@ -6,12 +6,10 @@ import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.commands.arguments.ParticleArgument;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.HolderLookup.Provider;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.level.biome.AmbientParticleSettings;
import java.util.stream.Stream;
public class BiomeParticleConfigTemplate implements ObjectTemplate<AmbientParticleSettings> {
@Value("particle")
@@ -20,18 +18,17 @@ public class BiomeParticleConfigTemplate implements ObjectTemplate<AmbientPartic
@Value("probability")
@Default
private Float probability = 0.1f;
private Integer probability = null;
@Override
public AmbientParticleSettings get() {
if(particle == null) {
if(particle == null || probability == null) {
return null;
}
try {
return new AmbientParticleSettings(ParticleArgument.readParticle(new StringReader(particle),
HolderLookup.Provider.create(Stream.of(BuiltInRegistries.PARTICLE_TYPE))), probability);
(Provider) BuiltInRegistries.PARTICLE_TYPE.asHolderIdMap()), probability);
} catch(CommandSyntaxException e) {
throw new RuntimeException(e);
}
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_21_8.config;
package com.dfsek.terra.bukkit.nms.v1_21_7.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_21_8.config;
package com.dfsek.terra.bukkit.nms.v1_21_7.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_21_8.config;
package com.dfsek.terra.bukkit.nms.v1_21_7.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_21_8.config;
package com.dfsek.terra.bukkit.nms.v1_21_7.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_21_8.config;
package com.dfsek.terra.bukkit.nms.v1_21_7.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
@@ -28,7 +28,7 @@ public class SpawnEntryConfig implements ObjectTemplate<SpawnEntryConfig> {
return weight;
}
public SpawnerData getSpawnEntry() {
public SpawnerData getSpawnerData() {
return new SpawnerData(type, minGroupSize, maxGroupSize);
}
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_21_8.config;
package com.dfsek.terra.bukkit.nms.v1_21_7.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
@@ -33,7 +33,7 @@ public class SpawnSettingsTemplate implements ObjectTemplate<MobSpawnSettings> {
for(SpawnTypeConfig spawn : spawns) {
MobCategory group = spawn.getGroup();
for(SpawnEntryConfig entry : spawn.getEntries()) {
builder.addSpawn(group, entry.getWeight(), entry.getSpawnEntry());
builder.addSpawn(group, entry.getWeight(), entry.getSpawnerData());
}
}
for(SpawnCostConfig cost : costs) {
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_21_8.config;
package com.dfsek.terra.bukkit.nms.v1_21_7.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_21_8.config;
package com.dfsek.terra.bukkit.nms.v1_21_7.config;
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
import com.dfsek.tectonic.api.config.template.annotations.Default;
@@ -6,7 +6,6 @@ import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.terra.api.properties.Properties;
import net.minecraft.resources.ResourceKey;
import net.minecraft.sounds.Music;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.entity.npc.VillagerType;
@@ -97,7 +96,7 @@ public class VanillaBiomeProperties implements ConfigTemplate, Properties {
@Value("villager-type")
@Default
private ResourceKey<VillagerType> villagerType = null;
private VillagerType villagerType = null;
public Integer getFogColor() {
return fogColor;
@@ -175,7 +174,7 @@ public class VanillaBiomeProperties implements ConfigTemplate, Properties {
return spawnSettings;
}
public ResourceKey<VillagerType> getVillagerType() {
public VillagerType getVillagerType() {
return villagerType;
}
}
@@ -1,21 +1,20 @@
package com.dfsek.terra.bukkit.nms.v1_21_8.config;
package com.dfsek.terra.bukkit.nms.v1_21_7.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.npc.VillagerType;
public class VillagerTypeTemplate implements ObjectTemplate<ResourceKey<VillagerType>> {
public class VillagerTypeTemplate implements ObjectTemplate<VillagerType> {
@Value("id")
@Default
private ResourceLocation id = null;
@Override
public ResourceKey<VillagerType> get() {
return ResourceKey.create(BuiltInRegistries.VILLAGER_TYPE.key(), id);
public VillagerType get() {
return BuiltInRegistries.VILLAGER_TYPE.get(id).orElseThrow().value();
}
}
@@ -1,108 +0,0 @@
package com.dfsek.terra.bukkit.nms.v1_21_8;
import com.dfsek.tectonic.api.TypeRegistry;
import com.dfsek.tectonic.api.exception.LoadException;
import com.dfsek.terra.addon.InternalAddon;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
import com.dfsek.terra.api.world.biome.PlatformBiome;
import com.dfsek.terra.bukkit.PlatformImpl;
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
import com.dfsek.terra.bukkit.nms.v1_21_8.config.BiomeAdditionsSoundTemplate;
import com.dfsek.terra.bukkit.nms.v1_21_8.config.BiomeMoodSoundTemplate;
import com.dfsek.terra.bukkit.nms.v1_21_8.config.BiomeParticleConfigTemplate;
import com.dfsek.terra.bukkit.nms.v1_21_8.config.EntityTypeTemplate;
import com.dfsek.terra.bukkit.nms.v1_21_8.config.MusicSoundTemplate;
import com.dfsek.terra.bukkit.nms.v1_21_8.config.SoundEventTemplate;
import com.dfsek.terra.bukkit.nms.v1_21_8.config.SpawnCostConfig;
import com.dfsek.terra.bukkit.nms.v1_21_8.config.SpawnEntryConfig;
import com.dfsek.terra.bukkit.nms.v1_21_8.config.SpawnSettingsTemplate;
import com.dfsek.terra.bukkit.nms.v1_21_8.config.SpawnTypeConfig;
import com.dfsek.terra.bukkit.nms.v1_21_8.config.VillagerTypeTemplate;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.Music;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.entity.npc.VillagerType;
import net.minecraft.world.level.biome.AmbientAdditionsSettings;
import net.minecraft.world.level.biome.AmbientMoodSettings;
import net.minecraft.world.level.biome.AmbientParticleSettings;
import net.minecraft.world.level.biome.Biome.Precipitation;
import net.minecraft.world.level.biome.Biome.TemperatureModifier;
import net.minecraft.world.level.biome.BiomeSpecialEffects.GrassColorModifier;
import net.minecraft.world.level.biome.MobSpawnSettings;
import org.bukkit.Bukkit;
import java.util.List;
import java.util.Locale;
public class NMSPlatform extends PlatformImpl {
public NMSPlatform(TerraBukkitPlugin plugin) {
super(plugin);
Bukkit.getPluginManager().registerEvents(new NMSInjectListener(), plugin);
}
@Override
public void register(TypeRegistry registry) {
super.register(registry);
registry.registerLoader(PlatformBiome.class, (type, o, loader, depthTracker) -> parseBiome((String) o, depthTracker))
.registerLoader(ResourceLocation.class, (type, o, loader, depthTracker) -> {
ResourceLocation identifier = ResourceLocation.tryParse((String) o);
if(identifier == null)
throw new LoadException("Invalid identifier: " + o, depthTracker);
return identifier;
})
.registerLoader(Precipitation.class, (type, o, loader, depthTracker) -> Precipitation.valueOf(((String) o).toUpperCase(
Locale.ROOT)))
.registerLoader(GrassColorModifier.class,
(type, o, loader, depthTracker) -> GrassColorModifier.valueOf(((String) o).toUpperCase(
Locale.ROOT)))
.registerLoader(GrassColorModifier.class,
(type, o, loader, depthTracker) -> TemperatureModifier.valueOf(((String) o).toUpperCase(
Locale.ROOT)))
.registerLoader(MobCategory.class, (type, o, loader, depthTracker) -> MobCategory.valueOf((String) o))
.registerLoader(AmbientParticleSettings.class, BiomeParticleConfigTemplate::new)
.registerLoader(SoundEvent.class, SoundEventTemplate::new)
.registerLoader(AmbientMoodSettings.class, BiomeMoodSoundTemplate::new)
.registerLoader(AmbientAdditionsSettings.class, BiomeAdditionsSoundTemplate::new)
.registerLoader(Music.class, MusicSoundTemplate::new)
.registerLoader(EntityType.class, EntityTypeTemplate::new)
.registerLoader(SpawnCostConfig.class, SpawnCostConfig::new)
.registerLoader(SpawnEntryConfig.class, SpawnEntryConfig::new)
.registerLoader(SpawnTypeConfig.class, SpawnTypeConfig::new)
.registerLoader(MobSpawnSettings.class, SpawnSettingsTemplate::new)
.registerLoader(VillagerType.class, VillagerTypeTemplate::new);
}
@Override
protected InternalAddon load() {
InternalAddon internalAddon = super.load();
this.getEventManager().getHandler(FunctionalEventHandler.class)
.register(internalAddon, PlatformInitializationEvent.class)
.priority(1)
.then(event -> AwfulBukkitHacks.registerBiomes(this.getRawConfigRegistry()))
.global();
return internalAddon;
}
@Override
protected Iterable<BaseAddon> platformAddon() {
return List.of(new NMSAddon(this));
}
}
@@ -90,7 +90,7 @@ public abstract class ModPlatform extends AbstractPlatform {
.registerLoader(MusicSound.class, MusicSoundTemplate::new)
.registerLoader(EntityType.class, EntityTypeTemplate::new)
.registerLoader(SpawnCostConfig.class, SpawnCostConfig::new)
.registerLoader(SpawnEntryConfig.class, SpawnEntryConfig::new)
.registerLoader(SpawnEntry.class, SpawnEntryConfig::new)
.registerLoader(SpawnTypeConfig.class, SpawnTypeConfig::new)
.registerLoader(SpawnSettings.class, SpawnSettingsTemplate::new)
.registerLoader(VillagerType.class, VillagerTypeTemplate::new);
@@ -10,8 +10,6 @@ import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.world.biome.BiomeParticleConfig;
import java.util.stream.Stream;
public class BiomeParticleConfigTemplate implements ObjectTemplate<BiomeParticleConfig> {
@Value("particle")
@@ -20,19 +18,19 @@ public class BiomeParticleConfigTemplate implements ObjectTemplate<BiomeParticle
@Value("probability")
@Default
private Float probability = 0.1f;
private Integer probability = null;
@Override
public BiomeParticleConfig get() {
if(particle == null) {
if(particle == null || probability == null) {
return null;
}
try {
return new BiomeParticleConfig(
ParticleEffectArgumentType.readParameters(new StringReader(particle),
RegistryWrapper.WrapperLookup.of(Stream.of(Registries.PARTICLE_TYPE))),
probability);
(RegistryWrapper.WrapperLookup) Registries.PARTICLE_TYPE),
probability);
} catch(CommandSyntaxException e) {
throw new RuntimeException(e);
}
@@ -7,7 +7,7 @@ import net.minecraft.entity.EntityType;
import net.minecraft.world.biome.SpawnSettings.SpawnEntry;
public class SpawnEntryConfig implements ObjectTemplate<SpawnEntryConfig> {
public class SpawnEntryConfig implements ObjectTemplate<SpawnEntry> {
@Value("type")
@Default
private EntityType<?> type = null;
@@ -28,12 +28,8 @@ public class SpawnEntryConfig implements ObjectTemplate<SpawnEntryConfig> {
return weight;
}
public SpawnEntry getSpawnEntry() {
@Override
public SpawnEntry get() {
return new SpawnEntry(type, minGroupSize, maxGroupSize);
}
@Override
public SpawnEntryConfig get() {
return this;
}
}
@@ -27,8 +27,8 @@ public class SpawnSettingsTemplate implements ObjectTemplate<SpawnSettings> {
SpawnSettings.Builder builder = new SpawnSettings.Builder();
for(SpawnTypeConfig spawn : spawns) {
SpawnGroup group = spawn.getGroup();
for(SpawnEntryConfig entry : spawn.getEntries()) {
builder.spawn(group, entry.getWeight(), entry.getSpawnEntry());
for(SpawnEntryConfig entry : spawn.getEntry()) {
builder.spawn(group, entry.getWeight(), entry.get());
}
}
for(SpawnCostConfig cost : costs) {
@@ -15,14 +15,14 @@ public class SpawnTypeConfig implements ObjectTemplate<SpawnTypeConfig> {
@Value("entries")
@Default
private List<SpawnEntryConfig> entries = null;
private List<SpawnEntryConfig> entry = null;
public SpawnGroup getGroup() {
return group;
}
public List<SpawnEntryConfig> getEntries() {
return entries;
public List<SpawnEntryConfig> getEntry() {
return entry;
}
@Override
@@ -13,10 +13,10 @@ import net.minecraft.village.VillagerType;
public class VillagerTypeTemplate implements ObjectTemplate<RegistryKey<VillagerType>> {
@Value("id")
@Default
private Identifier id = null;
private String id = null;
@Override
public RegistryKey<VillagerType> get() {
return RegistryKey.of(RegistryKeys.VILLAGER_TYPE, id);
return RegistryKey.of(RegistryKeys.VILLAGER_TYPE, Identifier.ofVanilla(id));
}
}