mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-11-28 00:45:03 +00:00
Merge PR #568 (Wyck) from OakLoaf
This commit is contained in:
commit
12a5c8b1f5
60 files changed
+646
-1798
No files matched your search
+1
-5
@@ -15,7 +15,7 @@ allprojects {
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.isFork = true
|
||||
options.isIncremental = true
|
||||
options.release.set(21)
|
||||
options.release.set(25)
|
||||
}
|
||||
|
||||
tasks.withType<Test>().configureEach {
|
||||
@@ -48,10 +48,6 @@ afterEvaluate {
|
||||
forSubProjects(":common:addons") {
|
||||
apply(plugin = "com.gradleup.shadow")
|
||||
|
||||
tasks.named("build") {
|
||||
finalizedBy(tasks.named("shadowJar"))
|
||||
}
|
||||
|
||||
dependencies {
|
||||
"compileOnly"(project(":common:api"))
|
||||
"testImplementation"(project(":common:api"))
|
||||
|
||||
@@ -22,9 +22,8 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
//TODO Allow pulling from Versions.kt
|
||||
implementation("com.gradleup.shadow", "shadow-gradle-plugin", "8.3.9")
|
||||
implementation("com.gradleup.shadow", "shadow-gradle-plugin", "9.3.1")
|
||||
|
||||
implementation("io.papermc.paperweight.userdev", "io.papermc.paperweight.userdev.gradle.plugin", "2.0.0-beta.21")
|
||||
implementation("org.ow2.asm", "asm", "9.9")
|
||||
implementation("org.ow2.asm", "asm-tree", "9.9")
|
||||
implementation("com.dfsek.tectonic", "common", "4.3.1")
|
||||
|
||||
@@ -57,6 +57,9 @@ fun Project.configureDependencies() {
|
||||
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") {
|
||||
name = "Sonatype Snapshots"
|
||||
}
|
||||
maven("https://repo.wyck.dev/snapshots") {
|
||||
name = "Wyck Snapshots"
|
||||
}
|
||||
maven("https://repo.onarandombox.com/multiverse-releases") {
|
||||
name = "onarandombox"
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import io.papermc.paperweight.util.path
|
||||
import java.io.File
|
||||
import java.io.FileWriter
|
||||
import java.net.URL
|
||||
@@ -81,7 +80,7 @@ fun Project.configureDistribution() {
|
||||
|
||||
doLast {
|
||||
// https://github.com/johnrengelman/shadow/issues/111
|
||||
val dest = tasks.named<ShadowJar>("shadowJar").get().archiveFile.get().path
|
||||
val dest = tasks.named<ShadowJar>("shadowJar").get().archiveFile.get().asFile.toPath()
|
||||
installAddonsInto(dest)
|
||||
}
|
||||
}
|
||||
@@ -91,7 +90,7 @@ fun Project.configureDistribution() {
|
||||
dependsOn(compileAddons)
|
||||
|
||||
doLast {
|
||||
val dest = tasks.named<Jar>("jar").get().archiveFile.get().path
|
||||
val dest = tasks.named<Jar>("jar").get().archiveFile.get().asFile.toPath()
|
||||
installAddonsInto(dest)
|
||||
}
|
||||
}
|
||||
@@ -161,7 +160,7 @@ fun Project.configureDistribution() {
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
// Tell shadow to download the packs
|
||||
dependsOn(downloadDefaultPacks)
|
||||
configurations = listOf(project.configurations["shaded"])
|
||||
configurations.set(listOf(project.configurations["shaded"]))
|
||||
archiveClassifier.set("shaded")
|
||||
version = project.version
|
||||
relocate("org.apache.commons", "com.dfsek.terra.lib.commons")
|
||||
|
||||
@@ -19,7 +19,7 @@ object Versions {
|
||||
const val slf4j = "2.0.17"
|
||||
|
||||
object Internal {
|
||||
const val shadow = "8.3.9"
|
||||
const val shadow = "9.3.1"
|
||||
const val apacheText = "1.14.0"
|
||||
const val apacheIO = "2.20.0"
|
||||
const val guava = "33.5.0-jre"
|
||||
@@ -59,16 +59,12 @@ object Versions {
|
||||
// }
|
||||
|
||||
object Bukkit {
|
||||
const val minecraft = "26.1.2"
|
||||
const val nms = "$minecraft-R0.1"
|
||||
const val paperBuild = "26.1.2.build.60-stable"
|
||||
const val minecraft = "26.3"
|
||||
const val paperBuild = "$minecraft.build.244-stable"
|
||||
const val paper = paperBuild
|
||||
const val paperLib = "1.0.8"
|
||||
const val reflectionRemapper = "0.1.3"
|
||||
const val paperDevBundle = paperBuild
|
||||
const val paperDevBundle26_3 = "26.3.build.156-beta"
|
||||
const val runPaper = "3.0.2"
|
||||
const val paperWeight = "2.0.0-beta.21"
|
||||
const val wyck = "4.0.0-837d6ec"
|
||||
const val cloud = "2.0.1"
|
||||
const val multiverse = "5.3.0"
|
||||
}
|
||||
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
package com.dfsek.terra.registry;
|
||||
|
||||
import com.google.errorprone.annotations.MustBeClosed;
|
||||
import org.intellij.lang.annotations.Pattern;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
/**
|
||||
* A file-discoverable registry that can be extended by system properties
|
||||
* <br>
|
||||
* The main use-case for this is to allow for customized locations of file-system-based key entries,
|
||||
* such as putting config packs into custom locations.
|
||||
* <br>
|
||||
* Two system properties are used to define the search path:
|
||||
* <br>
|
||||
* <code>terra.registry.{searchPathName}.searchPath</code> is a list of "parent folder" paths (like the pack directory) that
|
||||
* will be searched for contained files.
|
||||
* <br>
|
||||
* <code>terra.registry.{searchPathName}.extraPath</code> is a list of files that will be directly evaluated for membership and
|
||||
* as such will be directly treated as members of the registry.
|
||||
* <br>
|
||||
* These system properties are formatted like UNIX-style paths, with each path separated by a colon (':') character.
|
||||
*/
|
||||
public interface ExtensibleRegistry {
|
||||
/**
|
||||
* Get a lowercase search path name for this registry that will get plugged into
|
||||
* <br>
|
||||
* <code>terra.registry.{searchPathName}.searchPath</code>
|
||||
* <br>
|
||||
* and
|
||||
* <br>
|
||||
* <code>terra.registry.{searchPathName}.extraPath</code>
|
||||
*/
|
||||
@Pattern("^[a-z._]+$")
|
||||
String getRegistryName();
|
||||
|
||||
/**
|
||||
* Check if a path may be a member of this registry heuristically.
|
||||
*
|
||||
* @param path Path to check
|
||||
*
|
||||
* @return True if the path is a member of this registry.
|
||||
*/
|
||||
boolean validatePathIsMember(Path path);
|
||||
|
||||
default @MustBeClosed Stream<Path> getMemberPaths(Path baseSearchPath) {
|
||||
String basePropertyName = "terra.registry." + getRegistryName();
|
||||
|
||||
Stream<Path> searchPath = Stream.concat(
|
||||
parseValidPaths(System.getProperty(basePropertyName + ".search-path")),
|
||||
Stream.of(baseSearchPath)
|
||||
);
|
||||
|
||||
Stream<Path> extraPath = parseValidPaths(System.getProperty(basePropertyName + ".extra-path"));
|
||||
|
||||
return Stream.concat(
|
||||
searchPath
|
||||
.filter(Files::isDirectory)
|
||||
.flatMap(ExtensibleRegistry::listDirectory),
|
||||
extraPath
|
||||
)
|
||||
.filter(this::validatePathIsMember);
|
||||
}
|
||||
|
||||
private static Stream<Path> parseValidPaths(@Nullable String paths) {
|
||||
return Stream.ofNullable(paths)
|
||||
.flatMap(p -> Arrays.stream(p.split(":")))
|
||||
.filter(v -> !v.isBlank())
|
||||
.map(v -> {
|
||||
try {
|
||||
return Path.of(v).toAbsolutePath().normalize();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull);
|
||||
}
|
||||
|
||||
private static Stream<Path> listDirectory(Path dir) {
|
||||
try {
|
||||
return Files.list(dir);
|
||||
} catch(IOException e) {
|
||||
return Stream.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
-2
@@ -29,13 +29,14 @@ import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.config.pack.ConfigPackImpl;
|
||||
import com.dfsek.terra.registry.ExtensibleRegistry;
|
||||
import com.dfsek.terra.registry.OpenRegistryImpl;
|
||||
|
||||
|
||||
/**
|
||||
* Class to hold config packs
|
||||
*/
|
||||
public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> {
|
||||
public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> implements ExtensibleRegistry {
|
||||
|
||||
public ConfigRegistry() {
|
||||
super(TypeKey.of(ConfigPack.class));
|
||||
@@ -45,7 +46,7 @@ public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> {
|
||||
Path packsDirectory = platform.getDataFolder().toPath().resolve("packs");
|
||||
Files.createDirectories(packsDirectory);
|
||||
List<Exception> failedLoads = new CopyOnWriteArrayList<>();
|
||||
try(Stream<Path> packs = Files.list(packsDirectory)) {
|
||||
try(Stream<Path> packs = getMemberPaths(packsDirectory)) {
|
||||
packs.parallel().forEach(path -> {
|
||||
try {
|
||||
ConfigPack pack = new ConfigPackImpl(path, platform);
|
||||
@@ -60,6 +61,16 @@ public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRegistryName() {
|
||||
return "config";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validatePathIsMember(Path path) {
|
||||
return Files.isDirectory(path)|| path.getFileName().endsWith(".zip");
|
||||
}
|
||||
|
||||
public static class PackLoadFailuresException extends Exception {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 538998844645186306L;
|
||||
|
||||
+14
-3
@@ -28,6 +28,7 @@ import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.config.MetaPack;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.config.pack.MetaPackImpl;
|
||||
import com.dfsek.terra.registry.ExtensibleRegistry;
|
||||
import com.dfsek.terra.registry.OpenRegistryImpl;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry.PackLoadFailuresException;
|
||||
|
||||
@@ -35,7 +36,7 @@ import com.dfsek.terra.registry.master.ConfigRegistry.PackLoadFailuresException;
|
||||
/**
|
||||
* Class to hold config packs
|
||||
*/
|
||||
public class MetaConfigRegistry extends OpenRegistryImpl<MetaPack> {
|
||||
public class MetaConfigRegistry extends OpenRegistryImpl<MetaPack> implements ExtensibleRegistry {
|
||||
|
||||
public MetaConfigRegistry() {
|
||||
super(TypeKey.of(MetaPack.class));
|
||||
@@ -45,8 +46,8 @@ public class MetaConfigRegistry extends OpenRegistryImpl<MetaPack> {
|
||||
Path packsDirectory = platform.getDataFolder().toPath().resolve("metapacks");
|
||||
Files.createDirectories(packsDirectory);
|
||||
List<IOException> failedLoads = new ArrayList<>();
|
||||
try(Stream<Path> packs = Files.list(packsDirectory)) {
|
||||
packs.forEach(path -> {
|
||||
try(Stream<Path> paths = getMemberPaths(packsDirectory)) {
|
||||
paths.forEach(path -> {
|
||||
try {
|
||||
MetaPack pack = new MetaPackImpl(path, platform, configRegistry);
|
||||
registerChecked(pack.getRegistryKey(), pack);
|
||||
@@ -59,4 +60,14 @@ public class MetaConfigRegistry extends OpenRegistryImpl<MetaPack> {
|
||||
throw new PackLoadFailuresException(failedLoads);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRegistryName() {
|
||||
return "metaconfig";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validatePathIsMember(Path path) {
|
||||
return Files.isDirectory(path) || path.getFileName().endsWith(".zip");
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,9 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
id("xyz.jpenilla.run-paper") version Versions.Bukkit.runPaper
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Required for :platforms:bukkit:runDevBundleServer task
|
||||
paperweight.paperDevBundle(Versions.Bukkit.paperDevBundle)
|
||||
|
||||
shaded(project(":platforms:bukkit:common"))
|
||||
shaded(project(path = ":platforms:bukkit:nms:common", configuration = "runtimeElements"))
|
||||
shaded(project(path = ":platforms:bukkit:nms:26.1", configuration = "runtimeElements"))
|
||||
shaded(project(path = ":platforms:bukkit:nms:26.3", configuration = "runtimeElements"))
|
||||
shaded("xyz.jpenilla", "reflection-remapper", Versions.Bukkit.reflectionRemapper)
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
@@ -38,8 +30,9 @@ tasks {
|
||||
pluginJars(shadowJar.get().archiveFile)
|
||||
|
||||
downloadPlugins {
|
||||
modrinth("viaversion", "5.5.0")
|
||||
modrinth("viabackwards", "5.5.0")
|
||||
modrinth("viaversion", "5.12.2")
|
||||
modrinth("viabackwards", "5.12.2")
|
||||
modrinth("wyck", Versions.Bukkit.wyck)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ dependencies {
|
||||
|
||||
compileOnly("io.papermc.paper", "paper-api", Versions.Bukkit.paper)
|
||||
|
||||
compileOnly("dev.wyck", "Wyck", Versions.Bukkit.wyck)
|
||||
|
||||
compileOnly("org.mvplugins.multiverse.core", "multiverse-core", Versions.Bukkit.multiverse)
|
||||
|
||||
shadedApi("io.papermc", "paperlib", Versions.Bukkit.paperLib)
|
||||
|
||||
@@ -4,17 +4,20 @@ import ca.solostudios.strata.Versions;
|
||||
import ca.solostudios.strata.version.Version;
|
||||
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigurationLoadEvent;
|
||||
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.bukkit.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.bukkit.config.VanillaBiomeProperties;
|
||||
|
||||
|
||||
public class BukkitAddon implements BaseAddon {
|
||||
private static final Version VERSION = Versions.getVersion(1, 0, 0);
|
||||
|
||||
protected final PlatformImpl terraBukkitPlugin;
|
||||
protected final BukkitPlatform terraBukkitPlugin;
|
||||
|
||||
public BukkitAddon(PlatformImpl terraBukkitPlugin) {
|
||||
public BukkitAddon(BukkitPlatform terraBukkitPlugin) {
|
||||
this.terraBukkitPlugin = terraBukkitPlugin;
|
||||
}
|
||||
|
||||
@@ -25,6 +28,16 @@ public class BukkitAddon implements BaseAddon {
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> event.getPack().getContext().put(event.loadTemplate(new PreLoadCompatibilityOptions())))
|
||||
.global();
|
||||
|
||||
terraBukkitPlugin.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigurationLoadEvent.class)
|
||||
.then(event -> {
|
||||
if(event.is(Biome.class)) {
|
||||
event.getLoadedObject(Biome.class).getContext().put(event.load(new VanillaBiomeProperties()));
|
||||
}
|
||||
})
|
||||
.global();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+61
-5
@@ -20,16 +20,43 @@ package com.dfsek.terra.bukkit;
|
||||
import com.dfsek.tectonic.api.TypeRegistry;
|
||||
import com.dfsek.tectonic.api.depth.DepthTracker;
|
||||
import com.dfsek.tectonic.api.exception.LoadException;
|
||||
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.bukkit.config.BiomeAdditionsSoundTemplate;
|
||||
import com.dfsek.terra.bukkit.config.BiomeMoodSoundTemplate;
|
||||
import com.dfsek.terra.bukkit.config.BiomeParticleConfigTemplate;
|
||||
import com.dfsek.terra.bukkit.config.EntityTypeTemplate;
|
||||
import com.dfsek.terra.bukkit.config.MusicSoundTemplate;
|
||||
import com.dfsek.terra.bukkit.config.SoundEventTemplate;
|
||||
import com.dfsek.terra.bukkit.config.SpawnCostConfig;
|
||||
import com.dfsek.terra.bukkit.config.SpawnEntryConfig;
|
||||
import com.dfsek.terra.bukkit.config.SpawnSettingsTemplate;
|
||||
import com.dfsek.terra.bukkit.config.SpawnTypeConfig;
|
||||
import com.dfsek.terra.bukkit.config.VillagerTypeTemplate;
|
||||
|
||||
import dev.wyck.biome.TemperatureModifier;
|
||||
import dev.wyck.biome.entity.MobCategory;
|
||||
import dev.wyck.biome.entity.MobSpawnSettings;
|
||||
import dev.wyck.environment.GrassColorModifier;
|
||||
import dev.wyck.environment.particle.ParticleCatalog;
|
||||
import dev.wyck.environment.sounds.AmbientAdditionsSettings;
|
||||
import dev.wyck.environment.sounds.AmbientMoodSettings;
|
||||
import dev.wyck.environment.sounds.Music;
|
||||
import dev.wyck.environment.sounds.SoundEvent;
|
||||
import dev.wyck.keys.ResourceKey;
|
||||
import io.papermc.paper.registry.RegistryAccess;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.dfsek.terra.AbstractPlatform;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
@@ -42,8 +69,8 @@ import com.dfsek.terra.bukkit.handles.BukkitWorldHandle;
|
||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||
|
||||
|
||||
public class PlatformImpl extends AbstractPlatform {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PlatformImpl.class);
|
||||
public class BukkitPlatform extends AbstractPlatform {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(BukkitPlatform.class);
|
||||
|
||||
private final ItemHandle itemHandle = new BukkitItemHandle();
|
||||
|
||||
@@ -53,7 +80,7 @@ public class PlatformImpl extends AbstractPlatform {
|
||||
|
||||
private int generationThreads;
|
||||
|
||||
public PlatformImpl(TerraBukkitPlugin plugin) {
|
||||
public BukkitPlatform(TerraBukkitPlugin plugin) {
|
||||
generationThreads = getMoonriseGenerationThreadsWithReflection();
|
||||
if(generationThreads == 0) {
|
||||
generationThreads = 1;
|
||||
@@ -88,6 +115,11 @@ public class PlatformImpl extends AbstractPlatform {
|
||||
return "Bukkit";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Iterable<BaseAddon> platformAddon() {
|
||||
return List.of(new BukkitAddon(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runPossiblyUnsafeTask(@NotNull Runnable runnable) {
|
||||
plugin.getGlobalRegionScheduler().run(plugin, task -> runnable.run());
|
||||
@@ -118,8 +150,32 @@ public class PlatformImpl extends AbstractPlatform {
|
||||
super.register(registry);
|
||||
registry.registerLoader(BlockState.class, (type, o, loader, depthTracker) -> handle.createBlockState((String) o))
|
||||
.registerLoader(PlatformBiome.class, (type, o, loader, depthTracker) -> parseBiome((String) o, depthTracker))
|
||||
.registerLoader(EntityType.class, (type, o, loader, depthTracker) -> EntityType.valueOf((String) o));
|
||||
|
||||
.registerLoader(EntityType.class, (type, o, loader, depthTracker) -> EntityType.valueOf((String) o))
|
||||
.registerLoader(PlatformBiome.class, (type, o, loader, depthTracker) -> parseBiome((String) o, depthTracker))
|
||||
.registerLoader(ResourceKey.class, (type, o, loader, depthTracker) -> {
|
||||
String[] parts = ((String) o).split(":", 2);
|
||||
if(parts.length == 0 || parts.length > 2)
|
||||
throw new LoadException("Invalid identifier: " + o, depthTracker);
|
||||
return ResourceKey.of(parts[0], parts[1]);
|
||||
})
|
||||
.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(ParticleCatalog.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(Villager.Type.class, VillagerTypeTemplate::new);
|
||||
}
|
||||
|
||||
protected BukkitPlatformBiome parseBiome(String id, DepthTracker depthTracker) throws LoadException {
|
||||
@@ -1,66 +0,0 @@
|
||||
package com.dfsek.terra.bukkit;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.bukkit.util.VersionUtil;
|
||||
import com.dfsek.terra.bukkit.util.BukkitNMSAccess;
|
||||
import com.dfsek.terra.bukkit.util.BukkitUtils;
|
||||
|
||||
|
||||
public interface NMSInitializer {
|
||||
List<String> SUPPORTED_VERSIONS = List.of("v26.1.2", "v26.2", "v26.3");
|
||||
String MINECRAFT_VERSION = VersionUtil.getMinecraftVersionInfo().toString();
|
||||
String TERRA_PACKAGE = NMSInitializer.class.getPackageName();
|
||||
|
||||
static PlatformImpl init(TerraBukkitPlugin plugin) {
|
||||
Logger logger = LoggerFactory.getLogger(NMSInitializer.class);
|
||||
|
||||
if(!SUPPORTED_VERSIONS.contains(MINECRAFT_VERSION)) {
|
||||
logger.error("You are running your server on Minecraft version {} which is not supported by this version of Terra.",
|
||||
MINECRAFT_VERSION);
|
||||
|
||||
String bypassKey = "IKnowThereAreNoNMSBindingsFor" + MINECRAFT_VERSION.replace(".", "_") + "ButIWillProceedAnyway";
|
||||
if(System.getProperty(bypassKey) == null) {
|
||||
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;
|
||||
} else {
|
||||
logger.error("");
|
||||
logger.error("");
|
||||
for(int i = 0; i < 20; i++) {
|
||||
logger.error("PROCEEDING WITH AN EXISTING TERRA WORLD WILL RESULT IN CORRUPTION!!!");
|
||||
}
|
||||
logger.error("");
|
||||
logger.error("");
|
||||
logger.error("We will not give you any support for issues that may arise.");
|
||||
logger.error("Since you enabled the \"{}\" flag, we won't disable Terra. But be warned.", bypassKey);
|
||||
}
|
||||
}
|
||||
|
||||
return constructPlatform(plugin);
|
||||
}
|
||||
|
||||
private static PlatformImpl constructPlatform(TerraBukkitPlugin plugin) {
|
||||
try {
|
||||
String bindingsVersion = switch(MINECRAFT_VERSION) {
|
||||
case "v26.3" -> "v26_3";
|
||||
case "v26.1.2", "v26.2" -> "v26_1";
|
||||
default -> "v26_1";
|
||||
};
|
||||
Class<?> platformClass = Class.forName(TERRA_PACKAGE + ".nms." + bindingsVersion + ".NMSPlatform");
|
||||
PlatformImpl platform = (PlatformImpl) platformClass
|
||||
.getConstructor(TerraBukkitPlugin.class)
|
||||
.newInstance(plugin);
|
||||
if(platform instanceof BukkitNMSAccess nmsAccess) {
|
||||
BukkitUtils.setNMSAccess(nmsAccess);
|
||||
}
|
||||
return platform;
|
||||
} catch(ReflectiveOperationException e) {
|
||||
throw new RuntimeException("Error initializing NMS bindings. Report this to Terra.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.dfsek.terra.bukkit;
|
||||
|
||||
import com.dfsek.terra.bukkit.config.VanillaBiomeProperties;
|
||||
import com.dfsek.terra.bukkit.world.BukkitBiomeInfo;
|
||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||
import com.dfsek.terra.bukkit.world.BiomeHandler;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
|
||||
import dev.wyck.biome.Biome;
|
||||
import dev.wyck.keys.ResourceKey;
|
||||
import dev.wyck.registry.bootstrap.BootstrapBiomeRegistry;
|
||||
import dev.wyck.registry.bootstrap.Composer;
|
||||
import dev.wyck.tags.TagSet;
|
||||
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
|
||||
import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class TerraBootstrapper implements PluginBootstrap {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TerraBootstrapper.class);
|
||||
|
||||
private static final Map<ResourceKey, List<ResourceKey>> terraBiomeMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void bootstrap(BootstrapContext context) {
|
||||
BootstrapBiomeRegistry registry = BootstrapBiomeRegistry.compose(context, Composer.DATAPACK);
|
||||
|
||||
registry.deferring(() -> {
|
||||
registerBiomes(context, ); // TODO: Get raw config registry instance here
|
||||
});
|
||||
}
|
||||
|
||||
public static void registerBiomes(BootstrapContext context, ConfigRegistry configRegistry) {
|
||||
BootstrapBiomeRegistry biomeRegistry = BootstrapBiomeRegistry.compose(context, Composer.DATAPACK);
|
||||
|
||||
// Register the terra biomes to the registry
|
||||
configRegistry.forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach((key, biome) -> {
|
||||
try {
|
||||
BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome();
|
||||
ResourceKey vanillaMinecraftKey = ResourceKey.of(platformBiome.getHandle().getKey());
|
||||
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
|
||||
Biome wyckBiome = BiomeHandler.createBiome(vanillaMinecraftKey, vanillaBiomeProperties);
|
||||
|
||||
ResourceKey delegateKey = ResourceKey.of("terra", BiomeHandler.createBiomeID(pack, key));
|
||||
|
||||
biomeRegistry.queue(wyckBiome);
|
||||
|
||||
platformBiome.getContext().put(new BukkitBiomeInfo(delegateKey));
|
||||
|
||||
// TODO: Reimplement VillagerTypes - ideally this could be made into an EnvironmentAttribute in Wyck
|
||||
// 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.identifier());
|
||||
|
||||
LOGGER.debug("Registered biome: " + delegateKey);
|
||||
} catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}));
|
||||
|
||||
// Add each terra biome to the same tag sets as it's associated vanilla biome
|
||||
terraBiomeMap.forEach((vb, terraBiomes) -> {
|
||||
Biome vanilla = BiomeHandler.getBiome(vb);
|
||||
if(vanilla != null) {
|
||||
terraBiomes.forEach(tb -> {
|
||||
Biome terra = BiomeHandler.getBiome(tb);
|
||||
if(terra != null) {
|
||||
LOGGER.debug("{} (vanilla for {}): {}",
|
||||
vanilla.resourceKey().identifier(),
|
||||
terra.resourceKey().identifier(),
|
||||
vanilla.tags().toList());
|
||||
|
||||
vanilla.tags() // TODO: Waiting on implementation from Wyck
|
||||
.forEach(tag -> TagSet.ofBiomes(tag.key(), terra).append());
|
||||
} else {
|
||||
LOGGER.error("No such biome: {}", tb);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
LOGGER.error("No vanilla biome: {}", vb);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||
public class TerraBukkitPlugin extends JavaPlugin {
|
||||
private static final Logger logger = LoggerFactory.getLogger(TerraBukkitPlugin.class);
|
||||
private final Map<String, com.dfsek.terra.api.world.chunk.generation.ChunkGenerator> generatorMap = new HashMap<>();
|
||||
private PlatformImpl platform;
|
||||
private BukkitPlatform platform;
|
||||
private AsyncScheduler asyncScheduler = this.getServer().getAsyncScheduler();
|
||||
|
||||
private GlobalRegionScheduler globalRegionScheduler = this.getServer().getGlobalRegionScheduler();
|
||||
@@ -59,12 +59,7 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
||||
return;
|
||||
}
|
||||
|
||||
platform = NMSInitializer.init(this);
|
||||
if(platform == null) {
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
platform = new BukkitPlatform(this);
|
||||
platform.getEventManager().callEvent(new PlatformInitializationEvent());
|
||||
|
||||
try {
|
||||
@@ -101,7 +96,7 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
public PlatformImpl getPlatform() {
|
||||
public BukkitPlatform getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
|
||||
+7
-5
@@ -1,11 +1,10 @@
|
||||
package com.dfsek.terra.bukkit.nms.config;
|
||||
package com.dfsek.terra.bukkit.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.sounds.SoundEvent;
|
||||
import net.minecraft.world.attribute.AmbientAdditionsSettings;
|
||||
import dev.wyck.environment.sounds.AmbientAdditionsSettings;
|
||||
import dev.wyck.environment.sounds.SoundEvent;
|
||||
|
||||
|
||||
public class BiomeAdditionsSoundTemplate implements ObjectTemplate<AmbientAdditionsSettings> {
|
||||
@@ -22,7 +21,10 @@ public class BiomeAdditionsSoundTemplate implements ObjectTemplate<AmbientAdditi
|
||||
if(sound == null || soundChance == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new AmbientAdditionsSettings(BuiltInRegistries.SOUND_EVENT.wrapAsHolder(sound), soundChance);
|
||||
return AmbientAdditionsSettings.builder()
|
||||
.soundEvent(sound)
|
||||
.tickChance(soundChance)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-6
@@ -1,11 +1,10 @@
|
||||
package com.dfsek.terra.bukkit.nms.config;
|
||||
package com.dfsek.terra.bukkit.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.sounds.SoundEvent;
|
||||
import net.minecraft.world.attribute.AmbientMoodSettings;
|
||||
import dev.wyck.environment.sounds.AmbientMoodSettings;
|
||||
import dev.wyck.environment.sounds.SoundEvent;
|
||||
|
||||
|
||||
public class BiomeMoodSoundTemplate implements ObjectTemplate<AmbientMoodSettings> {
|
||||
@@ -30,8 +29,12 @@ public class BiomeMoodSoundTemplate implements ObjectTemplate<AmbientMoodSetting
|
||||
if(sound == null || soundCultivationTicks == null || soundSpawnRange == null || soundExtraDistance == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new AmbientMoodSettings(BuiltInRegistries.SOUND_EVENT.wrapAsHolder(sound), soundCultivationTicks, soundSpawnRange,
|
||||
soundExtraDistance);
|
||||
return AmbientMoodSettings.builder()
|
||||
.soundEvent(sound)
|
||||
.tickDelay(soundCultivationTicks)
|
||||
.blockSearchExtent(soundSpawnRange)
|
||||
.soundPositionOffset(soundExtraDistance)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.dfsek.terra.bukkit.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 com.mojang.brigadier.StringReader;
|
||||
import dev.wyck.environment.particle.ParticleCatalog;
|
||||
import dev.wyck.environment.particle.ParticleOptions;
|
||||
|
||||
|
||||
public class BiomeParticleConfigTemplate implements ObjectTemplate<ParticleCatalog> {
|
||||
@Value("particle")
|
||||
@Default
|
||||
private String particle = null;
|
||||
|
||||
@Value("probability")
|
||||
@Default
|
||||
private Float probability = 0.1f;
|
||||
|
||||
@Override
|
||||
public ParticleCatalog get() {
|
||||
if(particle == null) {
|
||||
return null;
|
||||
} else {
|
||||
ParticleOptions particleOptions = ParticleArgument.readParticle(new StringReader(particle));
|
||||
return ParticleCatalog.builder()
|
||||
.particle(particleOptions) // TODO: Check that this supports custom particles
|
||||
.probability(probability)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.dfsek.terra.bukkit.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 dev.wyck.keys.ResourceKey;
|
||||
import io.papermc.paper.registry.RegistryAccess;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
|
||||
public class EntityTypeTemplate implements ObjectTemplate<EntityType> {
|
||||
@Value("id")
|
||||
@Default
|
||||
private ResourceKey id = null;
|
||||
|
||||
@Override
|
||||
public EntityType get() {
|
||||
return RegistryAccess.registryAccess().getRegistry(RegistryKey.ENTITY_TYPE)
|
||||
.getOrThrow(id);
|
||||
}
|
||||
}
|
||||
+9
-5
@@ -1,11 +1,10 @@
|
||||
package com.dfsek.terra.bukkit.nms.config;
|
||||
package com.dfsek.terra.bukkit.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.sounds.Music;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import dev.wyck.environment.sounds.Music;
|
||||
import dev.wyck.environment.sounds.SoundEvent;
|
||||
|
||||
|
||||
public class MusicSoundTemplate implements ObjectTemplate<Music> {
|
||||
@@ -30,7 +29,12 @@ public class MusicSoundTemplate implements ObjectTemplate<Music> {
|
||||
if(sound == null || minDelay == null || maxDelay == null || replaceCurrentMusic == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new Music(BuiltInRegistries.SOUND_EVENT.wrapAsHolder(sound), minDelay, maxDelay, replaceCurrentMusic);
|
||||
return Music.builder()
|
||||
.sound(sound)
|
||||
.minDelay(minDelay)
|
||||
.maxDelay(maxDelay)
|
||||
.replaceCurrentMusic(replaceCurrentMusic)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -1,16 +1,16 @@
|
||||
package com.dfsek.terra.bukkit.nms.config;
|
||||
package com.dfsek.terra.bukkit.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.resources.Identifier;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import dev.wyck.environment.sounds.SoundEvent;
|
||||
import dev.wyck.keys.ResourceKey;
|
||||
|
||||
|
||||
public class SoundEventTemplate implements ObjectTemplate<SoundEvent> {
|
||||
@Value("id")
|
||||
@Default
|
||||
private Identifier id = null;
|
||||
private ResourceKey id = null;
|
||||
|
||||
@Value("distance-to-travel")
|
||||
@Default
|
||||
@@ -21,9 +21,9 @@ public class SoundEventTemplate implements ObjectTemplate<SoundEvent> {
|
||||
if(id == null) {
|
||||
return null;
|
||||
} else if(distanceToTravel == null) {
|
||||
return SoundEvent.createVariableRangeEvent(id);
|
||||
return SoundEvent.variableRange(id);
|
||||
} else {
|
||||
return SoundEvent.createFixedRangeEvent(id, distanceToTravel);
|
||||
return SoundEvent.fixedRange(id, distanceToTravel);
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -1,15 +1,15 @@
|
||||
package com.dfsek.terra.bukkit.nms.config;
|
||||
package com.dfsek.terra.bukkit.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.world.entity.EntityType;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
|
||||
public class SpawnCostConfig implements ObjectTemplate<SpawnCostConfig> {
|
||||
@Value("type")
|
||||
@Default
|
||||
private EntityType<?> type = null;
|
||||
private EntityType type = null;
|
||||
|
||||
@Value("mass")
|
||||
@Default
|
||||
@@ -19,7 +19,7 @@ public class SpawnCostConfig implements ObjectTemplate<SpawnCostConfig> {
|
||||
@Default
|
||||
private Double gravity = null;
|
||||
|
||||
public EntityType<?> getType() {
|
||||
public EntityType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
+8
-13
@@ -1,17 +1,20 @@
|
||||
package com.dfsek.terra.bukkit.nms.config;
|
||||
package com.dfsek.terra.bukkit.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.world.entity.EntityType;
|
||||
|
||||
import com.dfsek.terra.api.util.range.Range;
|
||||
|
||||
import dev.wyck.biome.entity.SpawnerData;
|
||||
import dev.wyck.worldgen.valueproviders.IntProvider;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
|
||||
public class SpawnEntryConfig implements ObjectTemplate<SpawnEntryConfig> {
|
||||
@Value("type")
|
||||
@Default
|
||||
private EntityType<?> type = null;
|
||||
private EntityType type = null;
|
||||
|
||||
@Value("weight")
|
||||
@Default
|
||||
@@ -25,16 +28,8 @@ public class SpawnEntryConfig implements ObjectTemplate<SpawnEntryConfig> {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public EntityType<?> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getMinCount() {
|
||||
return groupSize.getMin();
|
||||
}
|
||||
|
||||
public int getMaxCount() {
|
||||
return groupSize.getMax();
|
||||
public SpawnerData getSpawnEntry() {
|
||||
return SpawnerData.of(type, IntProvider.uniform(groupSize.getMin(), groupSize.getMax()));
|
||||
}
|
||||
|
||||
@Override
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package com.dfsek.terra.bukkit.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 dev.wyck.biome.entity.MobCategory;
|
||||
import dev.wyck.biome.entity.MobSpawnSettings;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class SpawnSettingsTemplate implements ObjectTemplate<MobSpawnSettings> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SpawnTypeConfig.class);
|
||||
private static boolean used = false;
|
||||
|
||||
@Value("spawns")
|
||||
@Default
|
||||
private List<SpawnTypeConfig> spawns = null;
|
||||
|
||||
@Value("costs")
|
||||
@Default
|
||||
private List<SpawnCostConfig> costs = null;
|
||||
|
||||
@Value("probability")
|
||||
@Default
|
||||
private Float probability = null;
|
||||
|
||||
@Override
|
||||
public MobSpawnSettings get() {
|
||||
MobSpawnSettings.Builder builder = MobSpawnSettings.builder();
|
||||
for(SpawnTypeConfig spawn : spawns) {
|
||||
MobCategory group = spawn.getGroup();
|
||||
for(SpawnEntryConfig entry : spawn.getEntries()) {
|
||||
builder.addSpawn(group, entry.getWeight(), entry.getSpawnEntry());
|
||||
}
|
||||
}
|
||||
for(SpawnCostConfig cost : costs) {
|
||||
builder.addMobSpawnCost(cost.getType(), cost.getMass(), cost.getGravity());
|
||||
}
|
||||
if(probability != null) {
|
||||
builder.creatureGenerationProbability(probability);
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package com.dfsek.terra.bukkit.nms.config;
|
||||
package com.dfsek.terra.bukkit.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.world.entity.MobCategory;
|
||||
import dev.wyck.biome.entity.MobCategory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
+16
-15
@@ -1,21 +1,22 @@
|
||||
package com.dfsek.terra.bukkit.nms.config;
|
||||
package com.dfsek.terra.bukkit.config;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.sounds.Music;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.attribute.AmbientAdditionsSettings;
|
||||
import net.minecraft.world.attribute.AmbientMoodSettings;
|
||||
import net.minecraft.world.attribute.AmbientParticle;
|
||||
import net.minecraft.world.entity.npc.villager.VillagerType;
|
||||
import net.minecraft.world.level.biome.Biome.TemperatureModifier;
|
||||
import net.minecraft.world.level.biome.BiomeSpecialEffects.GrassColorModifier;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
|
||||
import dev.wyck.biome.TemperatureModifier;
|
||||
import dev.wyck.biome.entity.MobSpawnSettings;
|
||||
import dev.wyck.environment.GrassColorModifier;
|
||||
import dev.wyck.environment.particle.AmbientParticle;
|
||||
import dev.wyck.environment.particle.ParticleCatalog;
|
||||
import dev.wyck.environment.sounds.AmbientAdditionsSettings;
|
||||
import dev.wyck.environment.sounds.AmbientMoodSettings;
|
||||
import dev.wyck.environment.sounds.Music;
|
||||
import dev.wyck.environment.sounds.SoundEvent;
|
||||
import org.bukkit.entity.Villager;
|
||||
|
||||
|
||||
public class VanillaBiomeProperties implements ConfigTemplate, Properties {
|
||||
@Value("colors.grass")
|
||||
@@ -52,7 +53,7 @@ public class VanillaBiomeProperties implements ConfigTemplate, Properties {
|
||||
|
||||
@Value("particles")
|
||||
@Default
|
||||
private AmbientParticle particleConfig = null;
|
||||
private ParticleCatalog particleConfig = null;
|
||||
|
||||
@Value("climate.precipitation")
|
||||
@Default
|
||||
@@ -96,7 +97,7 @@ public class VanillaBiomeProperties implements ConfigTemplate, Properties {
|
||||
|
||||
@Value("villager-type")
|
||||
@Default
|
||||
private ResourceKey<VillagerType> villagerType = null;
|
||||
private Villager.Type villagerType = null;
|
||||
|
||||
public Integer getFogColor() {
|
||||
return fogColor;
|
||||
@@ -130,7 +131,7 @@ public class VanillaBiomeProperties implements ConfigTemplate, Properties {
|
||||
return grassColorModifier;
|
||||
}
|
||||
|
||||
public AmbientParticle getParticleConfig() {
|
||||
public ParticleCatalog getParticles() {
|
||||
return particleConfig;
|
||||
}
|
||||
|
||||
@@ -174,7 +175,7 @@ public class VanillaBiomeProperties implements ConfigTemplate, Properties {
|
||||
return spawnSettings;
|
||||
}
|
||||
|
||||
public ResourceKey<VillagerType> getVillagerType() {
|
||||
public Villager.Type getVillagerType() {
|
||||
return villagerType;
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.dfsek.terra.bukkit.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 dev.wyck.keys.ResourceKey;
|
||||
import io.papermc.paper.registry.RegistryAccess;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import org.bukkit.entity.Villager;
|
||||
|
||||
|
||||
public class VillagerTypeTemplate implements ObjectTemplate<Villager.Type> {
|
||||
@Value("id")
|
||||
@Default
|
||||
private ResourceKey id = null;
|
||||
|
||||
@Override
|
||||
public Villager.Type get() {
|
||||
return RegistryAccess.registryAccess().getRegistry(RegistryKey.VILLAGER_TYPE)
|
||||
.getOrThrow(id);
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.dfsek.terra.bukkit.listeners;
|
||||
|
||||
import dev.wyck.keys.ResourceKey;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -85,10 +86,10 @@ public class CommonListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
NamespacedKey biomeKey = wolf.getWorld().getBiome(wolf.getLocation()).getKey();
|
||||
ResourceKey biomeKey = ResourceKey.of(wolf.getWorld().getBiome(wolf.getLocation()).getKey());
|
||||
pack.getBiomeProvider().stream()
|
||||
.filter(biome -> {
|
||||
NamespacedKey key = ((BukkitPlatformBiome) biome.getPlatformBiome()).getContext()
|
||||
ResourceKey key = ((BukkitPlatformBiome) biome.getPlatformBiome()).getContext()
|
||||
.get(BukkitBiomeInfo.class)
|
||||
.biomeKey();
|
||||
return key.equals(biomeKey);
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.dfsek.terra.bukkit.world;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.bukkit.config.VanillaBiomeProperties;
|
||||
|
||||
import dev.wyck.biome.Biome;
|
||||
import dev.wyck.biome.Biome.Builder;
|
||||
import dev.wyck.biome.BiomeGenerationSettings;
|
||||
import dev.wyck.biome.BiomeSpecialEffects;
|
||||
import dev.wyck.biome.ClimateSettings;
|
||||
import dev.wyck.environment.attribute.EnvironmentAttributeSupplier;
|
||||
import dev.wyck.environment.attribute.EnvironmentAttributes;
|
||||
import dev.wyck.environment.sounds.AmbientSounds;
|
||||
import dev.wyck.environment.sounds.BackgroundMusic;
|
||||
import dev.wyck.keys.KeyChains;
|
||||
import dev.wyck.keys.ResourceKey;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class BiomeHandler {
|
||||
|
||||
public static Biome getBiome(ResourceKey key) {
|
||||
Biome biome = KeyChains.BIOMES.get(key);
|
||||
return biome != null ? biome.wrap() : null;
|
||||
}
|
||||
|
||||
public static Biome getBiomeOrThrow(ResourceKey key) {
|
||||
return KeyChains.BIOMES.getOrThrow(key).wrap();
|
||||
}
|
||||
|
||||
public static Biome createBiome(ResourceKey vanillaBiomeKey, VanillaBiomeProperties vanillaBiomeProperties)
|
||||
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
|
||||
Biome vanilla = getBiomeOrThrow(vanillaBiomeKey);
|
||||
Builder builder = dev.wyck.biome.Biome.builder();
|
||||
|
||||
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.FOG_COLOR, vanillaBiomeProperties.getFogColor());
|
||||
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.WATER_FOG_COLOR, vanillaBiomeProperties.getWaterFogColor());
|
||||
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.SKY_COLOR, vanillaBiomeProperties.getSkyColor());
|
||||
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.AMBIENT_PARTICLES, vanillaBiomeProperties.getParticles());
|
||||
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.AMBIENT_SOUNDS, AmbientSounds.builder()
|
||||
.loop(vanillaBiomeProperties.getLoopSound())
|
||||
.mood(vanillaBiomeProperties.getMoodSound())
|
||||
.addition(vanillaBiomeProperties.getAdditionsSound())
|
||||
.build());
|
||||
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.BACKGROUND_MUSIC, BackgroundMusic.builder()
|
||||
.defaultMusic(vanillaBiomeProperties.getMusic())
|
||||
.build());
|
||||
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.MUSIC_VOLUME, vanillaBiomeProperties.getMusicVolume());
|
||||
setAttributeOrDefault(builder, vanilla, EnvironmentAttributes.NATURAL_MOB_SPAWNS, vanillaBiomeProperties.getSpawnSettings());
|
||||
|
||||
builder.climateSettings(ClimateSettings.builder()
|
||||
.hasPrecipitation(Objects.requireNonNullElse(vanillaBiomeProperties.getPrecipitation(), vanilla.climateSettings().hasPrecipitation()))
|
||||
.temperature(Objects.requireNonNullElse(vanillaBiomeProperties.getTemperature(), vanilla.climateSettings().temperature()))
|
||||
.temperatureModifier(Objects.requireNonNullElse(vanillaBiomeProperties.getTemperatureModifier(), vanilla.climateSettings().temperatureModifier()))
|
||||
.downfall(Objects.requireNonNullElse(vanillaBiomeProperties.getDownfall(), vanilla.climateSettings().downfall()))
|
||||
.build());
|
||||
|
||||
BiomeSpecialEffects.Builder effects = BiomeSpecialEffects.builder();
|
||||
effects.waterColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.specialEffects().waterColor()));
|
||||
effects.grassColorModifier(Objects.requireNonNullElse(vanillaBiomeProperties.getGrassColorModifier(), vanilla.specialEffects().grassColorModifier()));
|
||||
|
||||
if(vanillaBiomeProperties.getGrassColor() == null) {
|
||||
vanilla.specialEffects().grassColorOverride().ifPresent(effects::grassColorOverride);
|
||||
} else {
|
||||
effects.grassColorOverride(vanillaBiomeProperties.getGrassColor());
|
||||
}
|
||||
|
||||
if(vanillaBiomeProperties.getFoliageColor() == null) {
|
||||
vanilla.specialEffects().foliageColorOverride().ifPresent(effects::foliageColorOverride);
|
||||
} else {
|
||||
effects.foliageColorOverride(vanillaBiomeProperties.getFoliageColor());
|
||||
}
|
||||
|
||||
return builder
|
||||
.specialEffects(effects.build())
|
||||
.generationSettings(BiomeGenerationSettings.builder()
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) {
|
||||
return pack.getID().toLowerCase(Locale.ROOT)
|
||||
+ "/" + biomeID.getNamespace().toLowerCase(Locale.ROOT)
|
||||
+ "/" + biomeID.getID().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private static <T> void setAttributeOrDefault(Biome.Builder builder, Biome def, EnvironmentAttributeSupplier<T> attribute, T value) {
|
||||
builder.attribute(attribute, Objects.requireNonNullElse(value, def.attributes().get(attribute)));
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package com.dfsek.terra.bukkit.world;
|
||||
|
||||
import org.bukkit.NamespacedKey;
|
||||
import dev.wyck.keys.ResourceKey;
|
||||
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
|
||||
|
||||
public record BukkitBiomeInfo(NamespacedKey biomeKey) implements Properties {
|
||||
public record BukkitBiomeInfo(ResourceKey biomeKey) implements Properties {
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.dfsek.terra.bukkit.world;
|
||||
|
||||
import dev.wyck.biome.Biome;
|
||||
import dev.wyck.worldgen.biome.custom.BiomeSourceContext;
|
||||
import dev.wyck.worldgen.biome.custom.CustomBiomeSource;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
|
||||
public class BukkitBiomeProvider extends CustomBiomeSource {
|
||||
private final BiomeProvider delegate;
|
||||
private final long seed;
|
||||
|
||||
public BukkitBiomeProvider(BiomeProvider delegate, long seed) {
|
||||
super();
|
||||
this.delegate = delegate;
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome biome(BiomeSourceContext context) {
|
||||
return BiomeHandler.getBiomeOrThrow(((BukkitPlatformBiome) delegate.getBiome(context.blockX() << 2, context.blockY() << 2, context.blockZ() << 2, seed)
|
||||
.getPlatformBiome()).getContext()
|
||||
.get(BukkitBiomeInfo.class)
|
||||
.biomeKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Biome> possibleBiomes() {
|
||||
return delegate.stream()
|
||||
.map(biome -> BiomeHandler.getBiomeOrThrow(((BukkitPlatformBiome) biome.getPlatformBiome())
|
||||
.getContext()
|
||||
.get(BukkitBiomeInfo.class)
|
||||
.biomeKey()))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
+13
-1
@@ -4,6 +4,18 @@ version: "@VERSION@"
|
||||
load: "STARTUP"
|
||||
authors: [ "dfsek", "duplexsystem", "Astrash", "solonovamax", "Sancires", "Aureus", "RogueShade", "OakLoaf" ]
|
||||
website: "@WIKI@"
|
||||
api-version: "1.21.1"
|
||||
api-version: "26.3"
|
||||
bootstrapper: "com.dfsek.terra.bukkit.TerraBootstrapper"
|
||||
description: "@DESCRIPTION@"
|
||||
folia-supported: true
|
||||
depend:
|
||||
bootstrap:
|
||||
Wyck:
|
||||
load: BEFORE
|
||||
required: true
|
||||
join-classpath: true
|
||||
server:
|
||||
Wyck:
|
||||
load: BEFORE
|
||||
required: true
|
||||
join-classpath: true
|
||||
@@ -1,13 +0,0 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.release = 25
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":platforms:bukkit:common"))
|
||||
compileOnly(project(":platforms:bukkit:nms:common"))
|
||||
paperweight.paperDevBundle(Versions.Bukkit.paperDevBundle)
|
||||
}
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms.v26_1;
|
||||
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.level.levelgen.Beardifier;
|
||||
import net.minecraft.world.level.levelgen.DensityFunction.SinglePointContext;
|
||||
import net.minecraft.world.level.StructureManager;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.attribute.EnvironmentAttributes;
|
||||
import net.minecraft.world.attribute.modifier.AttributeModifier;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
import com.dfsek.terra.bukkit.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.bukkit.nms.NMSStructureBeardifier;
|
||||
import com.dfsek.terra.bukkit.nms.NMSVersionBindings;
|
||||
import com.dfsek.terra.bukkit.nms.config.VanillaBiomeProperties;
|
||||
|
||||
|
||||
public final class Bindings implements NMSVersionBindings {
|
||||
@Override
|
||||
public void addSpawn(MobSpawnSettings.Builder builder, MobCategory category, EntityType<?> type, int weight,
|
||||
int minCount, int maxCount) {
|
||||
builder.addSpawn(category, weight, new SpawnerData(type, minCount, maxCount));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSpawnCost(MobSpawnSettings.Builder builder, EntityType<?> type, double mass, double gravity) {
|
||||
builder.addMobCharge(type, mass, gravity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setCreatureGenerationProbability(MobSpawnSettings.Builder builder, float probability) {
|
||||
builder.creatureGenerationProbability(probability);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyVanillaSpawnSettings(Biome.BiomeBuilder builder, Biome biome) {
|
||||
builder.mobSpawnSettings(biome.getMobSettings());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpawnSettings(Biome.BiomeBuilder builder, MobSpawnSettings settings) {
|
||||
builder.mobSpawnSettings(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyBiomeColorOverrides(Biome.BiomeBuilder builder, VanillaBiomeProperties properties) {
|
||||
if(properties.getFogColor() != null) {
|
||||
builder.modifyAttribute(EnvironmentAttributes.FOG_COLOR, AttributeModifier.override(), properties.getFogColor());
|
||||
}
|
||||
if(properties.getWaterFogColor() != null) {
|
||||
builder.modifyAttribute(EnvironmentAttributes.WATER_FOG_COLOR, AttributeModifier.override(), properties.getWaterFogColor());
|
||||
}
|
||||
if(properties.getSkyColor() != null) {
|
||||
builder.modifyAttribute(EnvironmentAttributes.SKY_COLOR, AttributeModifier.override(), properties.getSkyColor());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyStructureBeard(ChunkGenerator generator, StructureManager structures, ChunkAccess chunk, WorldProperties world,
|
||||
BiomeProvider biomeProvider, PreLoadCompatibilityOptions options) {
|
||||
Beardifier beardifier = Beardifier.forStructuresInChunk(structures, chunk.getPos());
|
||||
NMSStructureBeardifier.apply(generator, chunk, world, biomeProvider, options,
|
||||
(x, y, z) -> beardifier.compute(new SinglePointContext(x, y, z)));
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms.v26_1;
|
||||
|
||||
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
|
||||
import com.dfsek.terra.bukkit.nms.NMSPlatformBase;
|
||||
|
||||
|
||||
public final class NMSPlatform extends NMSPlatformBase {
|
||||
public NMSPlatform(TerraBukkitPlugin plugin) {
|
||||
super(plugin, new Bindings());
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.release = 25
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":platforms:bukkit:common"))
|
||||
compileOnly(project(":platforms:bukkit:nms:common"))
|
||||
paperweight.paperDevBundle(Versions.Bukkit.paperDevBundle26_3)
|
||||
}
|
||||
-95
@@ -1,95 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms.v26_3;
|
||||
|
||||
import net.minecraft.util.valueproviders.UniformInt;
|
||||
import net.minecraft.world.attribute.EnvironmentAttributes;
|
||||
import net.minecraft.world.attribute.modifier.AttributeModifier;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.level.StructureManager;
|
||||
import net.minecraft.world.level.levelgen.Beardifier;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.levelgen.densityfunction.SamplerContext;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
import com.dfsek.terra.bukkit.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.bukkit.nms.NMSBiomeProvider;
|
||||
import com.dfsek.terra.bukkit.nms.NMSChunkGeneratorDelegate;
|
||||
import com.dfsek.terra.bukkit.nms.NMSStructureBeardifier;
|
||||
import com.dfsek.terra.bukkit.nms.NMSVersionBindings;
|
||||
import com.dfsek.terra.bukkit.nms.config.VanillaBiomeProperties;
|
||||
|
||||
|
||||
public final class Bindings implements NMSVersionBindings {
|
||||
@Override
|
||||
public NMSBiomeProvider createBiomeProvider(BiomeProvider delegate, long seed) {
|
||||
return new BiomeProvider26_3(delegate, seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSChunkGeneratorDelegate createChunkGenerator(
|
||||
net.minecraft.world.level.chunk.ChunkGenerator vanilla, ConfigPack pack,
|
||||
NMSBiomeProvider biomeProvider, long seed) {
|
||||
return new ChunkGenerator26_3(vanilla, pack, biomeProvider, seed, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSpawn(MobSpawnSettings.Builder builder, MobCategory category, EntityType<?> type, int weight,
|
||||
int minCount, int maxCount) {
|
||||
builder.addSpawn(type, category, weight, UniformInt.of(minCount, maxCount));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSpawnCost(MobSpawnSettings.Builder builder, EntityType<?> type, double mass, double gravity) {
|
||||
builder.addMobSpawnCost(type, mass, gravity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setCreatureGenerationProbability(MobSpawnSettings.Builder builder, float probability) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyVanillaSpawnSettings(Biome.BiomeBuilder builder, Biome biome) {
|
||||
// 26.3 stores natural spawn settings in the biome's environment attributes,
|
||||
// which NMSBiomeInjector already copies into its builder.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpawnSettings(Biome.BiomeBuilder builder, MobSpawnSettings settings) {
|
||||
builder.setAttribute(EnvironmentAttributes.NATURAL_MOB_SPAWNS, settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyBiomeColorOverrides(Biome.BiomeBuilder builder, VanillaBiomeProperties properties) {
|
||||
if(properties.getFogColor() != null) {
|
||||
builder.modifyAttribute(EnvironmentAttributes.FOG_COLOR, AttributeModifier.override(), color(properties.getFogColor()));
|
||||
}
|
||||
if(properties.getWaterFogColor() != null) {
|
||||
builder.modifyAttribute(EnvironmentAttributes.WATER_FOG_COLOR, AttributeModifier.override(), color(properties.getWaterFogColor()));
|
||||
}
|
||||
if(properties.getSkyColor() != null) {
|
||||
builder.modifyAttribute(EnvironmentAttributes.SKY_COLOR, AttributeModifier.override(), color(properties.getSkyColor()));
|
||||
}
|
||||
}
|
||||
|
||||
private static org.joml.Vector3f color(int rgb) {
|
||||
return new org.joml.Vector3f(
|
||||
((rgb >>> 16) & 0xFF) / 255.0f,
|
||||
((rgb >>> 8) & 0xFF) / 255.0f,
|
||||
(rgb & 0xFF) / 255.0f
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyStructureBeard(ChunkGenerator generator, StructureManager structures, ChunkAccess chunk, WorldProperties world,
|
||||
BiomeProvider biomeProvider, PreLoadCompatibilityOptions options) {
|
||||
Beardifier beardifier = Beardifier.forStructuresInChunk(structures, chunk.getPos());
|
||||
NMSStructureBeardifier.apply(generator, chunk, world, biomeProvider, options,
|
||||
(x, y, z) -> beardifier.sampleValue(SamplerContext.EMPTY_UNCACHED, x, y, z));
|
||||
}
|
||||
}
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms.v26_3;
|
||||
|
||||
import net.minecraft.world.level.biome.BiomeResolver;
|
||||
import net.minecraft.world.level.biome.Climate.Sampler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.bukkit.nms.NMSBiomeProvider;
|
||||
|
||||
|
||||
public final class BiomeProvider26_3 extends NMSBiomeProvider {
|
||||
public BiomeProvider26_3(BiomeProvider delegate, long seed) {
|
||||
super(delegate, seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull BiomeResolver createResolver(@NotNull Sampler sampler) {
|
||||
return (x, y, z) -> getNoiseBiome(x, y, z, sampler);
|
||||
}
|
||||
}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms.v26_3;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.server.level.WorldGenRegion;
|
||||
import net.minecraft.world.level.StructureManager;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeManager;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.levelgen.RandomState;
|
||||
import net.minecraft.world.level.levelgen.blending.Blender;
|
||||
import net.minecraft.world.level.levelgen.densityfunction.SamplerContext;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.bukkit.nms.NMSBiomeProvider;
|
||||
import com.dfsek.terra.bukkit.nms.NMSChunkGeneratorDelegate;
|
||||
import com.dfsek.terra.bukkit.nms.NMSVersionBindings;
|
||||
|
||||
|
||||
public final class ChunkGenerator26_3 extends NMSChunkGeneratorDelegate {
|
||||
private final ChunkGenerator vanilla;
|
||||
|
||||
public ChunkGenerator26_3(ChunkGenerator vanilla, ConfigPack pack, NMSBiomeProvider biomeProvider, long seed,
|
||||
NMSVersionBindings bindings) {
|
||||
super(vanilla, pack, biomeProvider, seed, bindings);
|
||||
this.vanilla = vanilla;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ChunkAccess> buildTerrain(ChunkAccess chunk, Blender blender, RandomState randomState,
|
||||
StructureManager structures, BiomeManager biomeManager,
|
||||
WorldGenRegion region, Set<Holder<Biome>> biomes) {
|
||||
return vanilla.buildTerrain(chunk, blender, randomState, structures, biomeManager, region, biomes)
|
||||
.thenApply(result -> {
|
||||
applyStructureBeard(structures, result);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDebugScreenInfo(List<String> text, RandomState randomState, BlockPos pos, SamplerContext context) {
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms.v26_3;
|
||||
|
||||
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
|
||||
import com.dfsek.terra.bukkit.nms.NMSPlatformBase;
|
||||
|
||||
|
||||
public final class NMSPlatform extends NMSPlatformBase {
|
||||
public NMSPlatform(TerraBukkitPlugin plugin) {
|
||||
super(plugin, new Bindings());
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
plugins {
|
||||
`java-library`
|
||||
}
|
||||
|
||||
subprojects {
|
||||
group = "com.dfsek.terra.bukkit.nms"
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.release = 25
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(project(path = ":platforms:bukkit:nms:common", configuration = "runtimeElements"))
|
||||
api(project(path = ":platforms:bukkit:nms:26.1", configuration = "runtimeElements"))
|
||||
api(project(path = ":platforms:bukkit:nms:26.3", configuration = "runtimeElements"))
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.release = 25
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":platforms:bukkit:common"))
|
||||
compileOnly("xyz.jpenilla", "reflection-remapper", Versions.Bukkit.reflectionRemapper)
|
||||
paperweight.paperDevBundle(Versions.Bukkit.paperDevBundle)
|
||||
}
|
||||
|
||||
tasks.withType<Jar>().configureEach {
|
||||
archiveBaseName.set("terra-bukkit-nms-common")
|
||||
}
|
||||
-283
@@ -1,283 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms;
|
||||
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.commands.arguments.blocks.BlockStateParser;
|
||||
import net.minecraft.commands.arguments.blocks.BlockStateParser.BlockResult;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Holder.Reference;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.HolderSet.Named;
|
||||
import net.minecraft.core.MappedRegistry;
|
||||
import net.minecraft.core.RegistrationInfo;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.TagParser;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.entity.EntitySpawnReason;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.npc.villager.VillagerType;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntitySnapshot;
|
||||
import org.bukkit.craftbukkit.generator.CraftLimitedRegion;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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.api.entity.EntityTypeExtended;
|
||||
import com.dfsek.terra.bukkit.world.BukkitBiomeInfo;
|
||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||
import com.dfsek.terra.bukkit.nms.config.VanillaBiomeProperties;
|
||||
import com.dfsek.terra.bukkit.world.entity.BukkitEntityType;
|
||||
import com.dfsek.terra.bukkit.world.entity.BukkitEntityTypeExtended;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
|
||||
|
||||
public class AwfulBukkitHacks {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AwfulBukkitHacks.class);
|
||||
|
||||
private static final Map<Identifier, List<Identifier>> terraBiomeMap = new HashMap<>();
|
||||
|
||||
public static void registerBiomes(ConfigRegistry configRegistry, NMSVersionBindings bindings) {
|
||||
try {
|
||||
LOGGER.info("Hacking biome registry...");
|
||||
MappedRegistry<Biome> biomeRegistry = (MappedRegistry<Biome>) RegistryFetcher.biomeRegistry();
|
||||
|
||||
// Unfreeze the biome registry to allow modification
|
||||
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) -> {
|
||||
try {
|
||||
BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome();
|
||||
|
||||
NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey();
|
||||
Identifier vanillaMinecraftKey = Identifier.fromNamespaceAndPath(vanillaBukkitKey.getNamespace(),
|
||||
vanillaBukkitKey.getKey());
|
||||
|
||||
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
|
||||
|
||||
Biome platform = NMSBiomeInjector.createBiome(biomeRegistry.get(vanillaMinecraftKey).orElseThrow().value(),
|
||||
vanillaBiomeProperties, bindings);
|
||||
|
||||
Identifier delegateMinecraftKey = Identifier.fromNamespaceAndPath("terra",
|
||||
NMSBiomeInjector.createBiomeID(pack, key));
|
||||
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.
|
||||
|
||||
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.identifier());
|
||||
|
||||
LOGGER.debug("Registered biome: " + delegateKey);
|
||||
} catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}));
|
||||
|
||||
Reflection.MAPPED_REGISTRY.setFrozen(biomeRegistry, true); // freeze registry again :)
|
||||
|
||||
LOGGER.info("Doing tag garbage....");
|
||||
Map<TagKey<Biome>, List<Holder<Biome>>> collect = biomeRegistry
|
||||
.getTags() // streamKeysAndEntries
|
||||
.collect(HashMap::new,
|
||||
(map, pair) ->
|
||||
map.put(pair.key(), new ArrayList<>(Reflection.HOLDER_SET.invokeContents(pair).stream().toList())),
|
||||
HashMap::putAll);
|
||||
|
||||
terraBiomeMap
|
||||
.forEach((vb, terraBiomes) ->
|
||||
NMSBiomeInjector.getEntry(biomeRegistry, vb).ifPresentOrElse(
|
||||
vanilla -> terraBiomes.forEach(
|
||||
tb -> NMSBiomeInjector.getEntry(biomeRegistry, tb).ifPresentOrElse(
|
||||
terra -> {
|
||||
LOGGER.debug("{} (vanilla for {}): {}",
|
||||
vanilla.unwrapKey().orElseThrow().identifier(),
|
||||
terra.unwrapKey().orElseThrow().identifier(),
|
||||
vanilla.tags().toList());
|
||||
vanilla.tags()
|
||||
.forEach(tag -> collect
|
||||
.computeIfAbsent(tag, t -> new ArrayList<>())
|
||||
.add(terra));
|
||||
},
|
||||
() -> LOGGER.error("No such biome: {}", tb))),
|
||||
() -> LOGGER.error("No vanilla biome: {}", vb)));
|
||||
|
||||
resetTags(biomeRegistry);
|
||||
bindTags(biomeRegistry, collect);
|
||||
|
||||
} catch(SecurityException | IllegalArgumentException exception) {
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> void bindTags(MappedRegistry<T> registry, Map<TagKey<T>, List<Holder<T>>> tagEntries) {
|
||||
Map<Reference<T>, List<TagKey<T>>> map = new IdentityHashMap<>();
|
||||
Reflection.MAPPED_REGISTRY.getByKey(registry).values().forEach(entry -> map.put(entry, new ArrayList<>()));
|
||||
tagEntries.forEach((tag, entries) -> {
|
||||
for(Holder<T> holder : entries) {
|
||||
// if (!holder.canSerializeIn(registry.asLookup())) {
|
||||
// throw new IllegalStateException("Can't create named set " + tag + " containing value " + holder + "
|
||||
// from outside registry " + this);
|
||||
// }
|
||||
|
||||
if(!(holder instanceof Holder.Reference<T> reference)) {
|
||||
throw new IllegalStateException("Found direct holder " + holder + " value in tag " + tag);
|
||||
}
|
||||
|
||||
map.get(reference).add(tag);
|
||||
}
|
||||
});
|
||||
// Set<TagKey<T>> set = Sets.difference(registry.tags.keySet(), tagEntries.keySet());
|
||||
// if (!set.isEmpty()) {
|
||||
// LOGGER.warn(
|
||||
// "Not all defined tags for registry {} are present in data pack: {}",
|
||||
// registry.key(),
|
||||
// set.stream().map(tag -> tag.location().toString()).sorted().collect(Collectors.joining(", "))
|
||||
// );
|
||||
// }
|
||||
|
||||
Map<TagKey<T>, Named<T>> map2 = new IdentityHashMap<>(registry.getTags().collect(Collectors.toMap(
|
||||
Named::key,
|
||||
(named) -> named
|
||||
)));
|
||||
tagEntries.forEach((tag, entries) -> Reflection.HOLDER_SET.invokeBind(
|
||||
map2.computeIfAbsent(tag, key -> Reflection.MAPPED_REGISTRY.invokeCreateTag(registry, key)), entries));
|
||||
map.forEach(Reflection.HOLDER_REFERENCE::invokeBindTags);
|
||||
Reflection.MAPPED_REGISTRY.setAllTags(registry, Reflection.MAPPED_REGISTRY_TAG_SET.invokeFromMap(map2));
|
||||
}
|
||||
|
||||
private static void resetTags(MappedRegistry<?> registry) {
|
||||
registry.getTags().forEach(entryList -> Reflection.HOLDER_SET.invokeBind(entryList, List.of()));
|
||||
Reflection.MAPPED_REGISTRY.getByKey(registry).values().forEach(
|
||||
entry -> Reflection.HOLDER_REFERENCE.invokeBindTags(entry, Set.of()));
|
||||
}
|
||||
|
||||
// used by BukkitWorldHandle
|
||||
public static BlockData createBlockState(@NotNull String data) throws CommandSyntaxException {
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
HolderLookup.Provider lookup = server.registryAccess();
|
||||
final HolderLookup<Block> blocks = lookup.lookupOrThrow(Registries.BLOCK);
|
||||
BlockResult result = BlockStateParser.parseForBlock(blocks, new StringReader(data), true);
|
||||
return CraftBlockData.createData(result.blockState());
|
||||
}
|
||||
|
||||
public static com.dfsek.terra.api.entity.EntityType getEntityType(@NotNull String data) {
|
||||
StringReader reader = new StringReader(data);
|
||||
Identifier identifier;
|
||||
CompoundTag entityNbt = null;
|
||||
try {
|
||||
identifier = Identifier.read(reader);
|
||||
if(reader.canRead()) {
|
||||
if(reader.peek() != '{') throw new IllegalArgumentException("Unexpected data after entity identifier: " + data);
|
||||
entityNbt = TagParser.parseCompoundAsArgument(reader);
|
||||
if(reader.canRead()) throw new IllegalArgumentException("Unexpected data after entity NBT: " + data);
|
||||
entityNbt.putString("id", identifier.toString());
|
||||
}
|
||||
} catch(CommandSyntaxException e) {
|
||||
throw new IllegalArgumentException("Invalid entity data: " + data, e);
|
||||
}
|
||||
|
||||
if(BuiltInRegistries.ENTITY_TYPE.getOptional(identifier).isEmpty()) {
|
||||
throw new IllegalArgumentException("Unknown entity type: " + identifier);
|
||||
}
|
||||
|
||||
NamespacedKey key = NamespacedKey.fromString(identifier.toString());
|
||||
org.bukkit.entity.EntityType bukkitType = key == null ? null : Registry.ENTITY_TYPE.get(key);
|
||||
if(bukkitType == null) throw new IllegalArgumentException("Bukkit has no entity type for " + identifier);
|
||||
|
||||
if(entityNbt == null) return new BukkitEntityType(bukkitType);
|
||||
return new BukkitEntityTypeExtended(bukkitType, entityNbt.toString());
|
||||
}
|
||||
|
||||
public static org.bukkit.entity.Entity spawnEntity(Object target, org.bukkit.Location location,
|
||||
com.dfsek.terra.api.entity.EntityType type) {
|
||||
if(!(type instanceof BukkitEntityTypeExtended extended)) {
|
||||
throw new IllegalArgumentException("Expected a Bukkit entity type with NBT data");
|
||||
}
|
||||
CompoundTag nbt = parseEntityNbt(extended);
|
||||
|
||||
CraftLimitedRegion limitedRegion = target instanceof CraftLimitedRegion region ? region : null;
|
||||
World world = limitedRegion == null ? (World) target : limitedRegion.getWorld();
|
||||
if(!(world instanceof CraftWorld craftWorld)) throw new IllegalArgumentException("Unsupported Bukkit world: " + world);
|
||||
ServerLevel level = craftWorld.getHandle();
|
||||
|
||||
String entityIDText = nbt.getString("id")
|
||||
.orElseThrow(() -> new IllegalArgumentException("Missing entity identifier in NBT"));
|
||||
Identifier entityID;
|
||||
try {
|
||||
entityID = Identifier.read(new StringReader(entityIDText));
|
||||
} catch(CommandSyntaxException e) {
|
||||
throw new IllegalArgumentException("Invalid entity identifier in NBT: " + entityIDText, e);
|
||||
}
|
||||
EntityType<?> entityType = BuiltInRegistries.ENTITY_TYPE.getOptional(entityID)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Unknown entity type in NBT: " + entityID));
|
||||
|
||||
net.minecraft.world.entity.Entity entity = EntityType.loadEntityRecursive(entityType, nbt, level, EntitySpawnReason.STRUCTURE, loaded -> {
|
||||
loaded.snapTo(location.getX(), location.getY(), location.getZ(), loaded.getYRot(), loaded.getXRot());
|
||||
return loaded;
|
||||
});
|
||||
if(entity == null) throw new IllegalArgumentException("Could not load entity from NBT: " + nbt);
|
||||
|
||||
if(limitedRegion != null) {
|
||||
limitedRegion.addEntityWithPassengers(entity, CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||
} else if(!level.tryAddFreshEntityWithPassengers(entity, CreatureSpawnEvent.SpawnReason.CUSTOM)) {
|
||||
throw new IllegalStateException("Could not add entity to world: " + nbt);
|
||||
}
|
||||
|
||||
return entity.getBukkitEntity();
|
||||
}
|
||||
|
||||
public static void setSpawnerEntity(CreatureSpawner spawner, EntityTypeExtended type) {
|
||||
if(!(type instanceof BukkitEntityTypeExtended extended)) {
|
||||
throw new IllegalArgumentException("Expected a Bukkit entity type with NBT data");
|
||||
}
|
||||
spawner.setSpawnedEntity(CraftEntitySnapshot.create(parseEntityNbt(extended), extended.getHandle()));
|
||||
}
|
||||
|
||||
private static CompoundTag parseEntityNbt(BukkitEntityTypeExtended extended) {
|
||||
Object rawData = extended.getData().getHandle();
|
||||
if(!(rawData instanceof String snbt)) throw new IllegalArgumentException("Bukkit entity data must contain SNBT text");
|
||||
|
||||
try {
|
||||
return TagParser.parseCompoundFully(snbt);
|
||||
} catch(CommandSyntaxException e) {
|
||||
throw new IllegalArgumentException("Invalid entity NBT: " + snbt, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms;
|
||||
|
||||
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.config.VanillaBiomeProperties;
|
||||
|
||||
|
||||
public class NMSAddon extends BukkitAddon {
|
||||
|
||||
public NMSAddon(PlatformImpl platform) {
|
||||
super(platform);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
super.initialize();
|
||||
|
||||
terraBukkitPlugin.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigurationLoadEvent.class)
|
||||
.then(event -> {
|
||||
if(event.is(Biome.class)) {
|
||||
event.getLoadedObject(Biome.class).getContext().put(event.load(new VanillaBiomeProperties()));
|
||||
}
|
||||
})
|
||||
.global();
|
||||
}
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms;
|
||||
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
|
||||
|
||||
public record NMSBiomeInfo(ResourceKey<Biome> biomeKey) implements Properties {
|
||||
}
|
||||
-131
@@ -1,131 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms;
|
||||
|
||||
import com.dfsek.terra.api.registry.key.RegistryKey;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.attribute.AmbientAdditionsSettings;
|
||||
import net.minecraft.world.attribute.AmbientMoodSettings;
|
||||
import net.minecraft.world.attribute.AmbientSounds;
|
||||
import net.minecraft.world.attribute.BackgroundMusic;
|
||||
import net.minecraft.world.attribute.EnvironmentAttribute;
|
||||
import net.minecraft.world.attribute.EnvironmentAttributeMap;
|
||||
import net.minecraft.world.attribute.EnvironmentAttributeMap.Entry;
|
||||
import net.minecraft.world.attribute.EnvironmentAttributes;
|
||||
import net.minecraft.world.attribute.modifier.AttributeModifier;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.Biome.BiomeBuilder;
|
||||
import net.minecraft.world.level.biome.BiomeGenerationSettings;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.biome.BiomeSpecialEffects;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.bukkit.nms.config.VanillaBiomeProperties;
|
||||
|
||||
|
||||
public class NMSBiomeInjector {
|
||||
|
||||
public static <T> Optional<Holder<T>> getEntry(Registry<T> registry, Identifier identifier) {
|
||||
return registry.getOptional(identifier).flatMap(registry::getResourceKey).flatMap(registry::get);
|
||||
}
|
||||
|
||||
public static Biome createBiome(Biome vanilla, VanillaBiomeProperties vanillaBiomeProperties, NMSVersionBindings bindings)
|
||||
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
|
||||
Biome.BiomeBuilder builder = new Biome.BiomeBuilder();
|
||||
|
||||
BiomeSpecialEffects.Builder effects = new BiomeSpecialEffects.Builder();
|
||||
EnvironmentAttributeMap attributes = vanilla.getAttributes();
|
||||
builder.putAttributes(attributes);
|
||||
|
||||
bindings.applyBiomeColorOverrides(builder, vanillaBiomeProperties);
|
||||
if(vanillaBiomeProperties.getMusicVolume() != null) {
|
||||
builder.modifyAttribute(EnvironmentAttributes.MUSIC_VOLUME, AttributeModifier.override(), vanillaBiomeProperties.getMusicVolume());
|
||||
}
|
||||
|
||||
effects.waterColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.getWaterColor()));
|
||||
effects.grassColorModifier(
|
||||
Objects.requireNonNullElse(vanillaBiomeProperties.getGrassColorModifier(), vanilla.getSpecialEffects().grassColorModifier()));
|
||||
|
||||
if(vanillaBiomeProperties.getGrassColor() == null) {
|
||||
vanilla.getSpecialEffects().grassColorOverride().ifPresent(effects::grassColorOverride);
|
||||
} else {
|
||||
effects.grassColorOverride(vanillaBiomeProperties.getGrassColor());
|
||||
}
|
||||
|
||||
if(vanillaBiomeProperties.getFoliageColor() == null) {
|
||||
vanilla.getSpecialEffects().foliageColorOverride().ifPresent(effects::foliageColorOverride);
|
||||
} else {
|
||||
effects.foliageColorOverride(vanillaBiomeProperties.getFoliageColor());
|
||||
}
|
||||
|
||||
if(vanillaBiomeProperties.getParticleConfig() != null) {
|
||||
builder.modifyAttribute(EnvironmentAttributes.AMBIENT_PARTICLES, AttributeModifier.override(),
|
||||
List.of(vanillaBiomeProperties.getParticleConfig()));
|
||||
}
|
||||
|
||||
Optional<Holder<SoundEvent>> loop = Optional.empty();
|
||||
Optional<AmbientMoodSettings> mood = Optional.empty();
|
||||
List<AmbientAdditionsSettings> additions = Collections.emptyList();
|
||||
|
||||
AmbientSounds sounds = getAttribute(attributes, EnvironmentAttributes.AMBIENT_SOUNDS);
|
||||
if(sounds != null) {
|
||||
loop = sounds.loop();
|
||||
mood = sounds.mood();
|
||||
additions = sounds.additions();
|
||||
}
|
||||
|
||||
if(vanillaBiomeProperties.getLoopSound() != null) {
|
||||
loop = RegistryFetcher.soundEventRegistry()
|
||||
.get(vanillaBiomeProperties.getLoopSound().location())
|
||||
.map(ref -> ref);
|
||||
}
|
||||
|
||||
if(vanillaBiomeProperties.getMoodSound() != null) {
|
||||
mood = Optional.ofNullable(vanillaBiomeProperties.getMoodSound());
|
||||
}
|
||||
|
||||
if(vanillaBiomeProperties.getAdditionsSound() != null) {
|
||||
additions = Collections.singletonList(vanillaBiomeProperties.getAdditionsSound());
|
||||
}
|
||||
|
||||
builder.modifyAttribute(EnvironmentAttributes.AMBIENT_SOUNDS, AttributeModifier.override(),
|
||||
new AmbientSounds(loop, mood, additions));
|
||||
|
||||
if(vanillaBiomeProperties.getMusic() != null) {
|
||||
builder.modifyAttribute(EnvironmentAttributes.BACKGROUND_MUSIC, AttributeModifier.override(),
|
||||
new BackgroundMusic(vanillaBiomeProperties.getMusic()));
|
||||
}
|
||||
|
||||
builder.hasPrecipitation(Objects.requireNonNullElse(vanillaBiomeProperties.getPrecipitation(), vanilla.hasPrecipitation()));
|
||||
builder.temperature(Objects.requireNonNullElse(vanillaBiomeProperties.getTemperature(), vanilla.getBaseTemperature()));
|
||||
builder.downfall(Objects.requireNonNullElse(vanillaBiomeProperties.getDownfall(), vanilla.climateSettings.downfall()));
|
||||
builder.temperatureAdjustment(
|
||||
Objects.requireNonNullElse(vanillaBiomeProperties.getTemperatureModifier(), vanilla.climateSettings.temperatureModifier()));
|
||||
MobSpawnSettings spawnSettings = vanillaBiomeProperties.getSpawnSettings();
|
||||
if(spawnSettings == null) {
|
||||
bindings.copyVanillaSpawnSettings(builder, vanilla);
|
||||
} else {
|
||||
bindings.setSpawnSettings(builder, spawnSettings);
|
||||
}
|
||||
|
||||
return builder.specialEffects(effects.build()).generationSettings(new BiomeGenerationSettings.PlainBuilder().build()).build();
|
||||
}
|
||||
|
||||
public static String createBiomeID(ConfigPack pack, RegistryKey biomeID) {
|
||||
return pack.getID().toLowerCase() + "/" + biomeID.getNamespace().toLowerCase(Locale.ROOT) + "/" + biomeID.getID().toLowerCase(
|
||||
Locale.ROOT);
|
||||
}
|
||||
|
||||
private static <T> T getAttribute(EnvironmentAttributeMap attributes, EnvironmentAttribute<T> key) {
|
||||
Entry<T, ?> entry = attributes.get(key);
|
||||
return entry == null ? null : entry.applyModifier(key.defaultValue());
|
||||
}
|
||||
}
|
||||
-53
@@ -1,53 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms;
|
||||
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
import net.minecraft.world.level.biome.Climate.Sampler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||
|
||||
|
||||
public class NMSBiomeProvider extends BiomeSource {
|
||||
private final BiomeProvider delegate;
|
||||
private final long seed;
|
||||
private final Registry<Biome> biomeRegistry = RegistryFetcher.biomeRegistry();
|
||||
|
||||
public NMSBiomeProvider(BiomeProvider delegate, long seed) {
|
||||
super();
|
||||
this.delegate = delegate;
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<Holder<Biome>> collectPossibleBiomes() {
|
||||
return delegate.stream()
|
||||
.map(biome -> RegistryFetcher.biomeRegistry()
|
||||
.getOrThrow(((BukkitPlatformBiome) biome.getPlatformBiome()).getContext()
|
||||
.get(NMSBiomeInfo.class)
|
||||
.biomeKey()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull MapCodec<? extends BiomeSource> codec() {
|
||||
return MapCodec.assumeMapUnsafe(BiomeSource.CODEC);
|
||||
// return MapCodec.unit(null);
|
||||
// BuiltInRegistries.BIOME_SOURCE.byNameCodec().dispatchMap(this::codec, Function.identity());
|
||||
// BuiltInRegistries.BIOME_SOURCE.byNameCodec().dispatchStable(BiomeSource::codec, Function.identity());
|
||||
// return BiomeSource.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Holder<Biome> getNoiseBiome(int x, int y, int z, @NotNull Sampler sampler) {
|
||||
return biomeRegistry.getOrThrow(((BukkitPlatformBiome) delegate.getBiome(x << 2, y << 2, z << 2, seed)
|
||||
.getPlatformBiome()).getContext()
|
||||
.get(NMSBiomeInfo.class)
|
||||
.biomeKey());
|
||||
}
|
||||
}
|
||||
-142
@@ -1,142 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms;
|
||||
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.WorldGenRegion;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.LevelHeightAccessor;
|
||||
import net.minecraft.world.level.NoiseColumn;
|
||||
import net.minecraft.world.level.StructureManager;
|
||||
import net.minecraft.world.level.WorldGenLevel;
|
||||
import net.minecraft.world.level.biome.BiomeManager;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.levelgen.Heightmap.Types;
|
||||
import net.minecraft.world.level.levelgen.RandomState;
|
||||
import net.minecraft.world.level.levelgen.blending.Blender;
|
||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
import com.dfsek.terra.bukkit.config.PreLoadCompatibilityOptions;
|
||||
|
||||
|
||||
public class NMSChunkGeneratorDelegate extends ChunkGenerator {
|
||||
private final com.dfsek.terra.api.world.chunk.generation.ChunkGenerator delegate;
|
||||
|
||||
private final ChunkGenerator vanilla;
|
||||
private final ConfigPack pack;
|
||||
private final NMSVersionBindings bindings;
|
||||
|
||||
private final long seed;
|
||||
|
||||
public NMSChunkGeneratorDelegate(ChunkGenerator vanilla, ConfigPack pack, NMSBiomeProvider biomeProvider, long seed,
|
||||
NMSVersionBindings bindings) {
|
||||
super(biomeProvider);
|
||||
this.delegate = pack.getGeneratorProvider().newInstance(pack);
|
||||
this.vanilla = vanilla;
|
||||
this.pack = pack;
|
||||
this.seed = seed;
|
||||
this.bindings = bindings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull MapCodec<? extends ChunkGenerator> codec() {
|
||||
return MapCodec.assumeMapUnsafe(ChunkGenerator.CODEC);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyCarvers(@NotNull WorldGenRegion chunkRegion, long seed, @NotNull RandomState noiseConfig, @NotNull BiomeManager world,
|
||||
@NotNull StructureManager structureAccessor, @NotNull ChunkAccess chunk) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildSurface(@NotNull WorldGenRegion region, @NotNull StructureManager structures, @NotNull RandomState noiseConfig,
|
||||
@NotNull ChunkAccess chunk) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyBiomeDecoration(@NotNull WorldGenLevel world, @NotNull ChunkAccess chunk,
|
||||
@NotNull StructureManager structureAccessor) {
|
||||
vanilla.applyBiomeDecoration(world, chunk, structureAccessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnOriginalMobs(@NotNull WorldGenRegion region) {
|
||||
vanilla.spawnOriginalMobs(region);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGenDepth() {
|
||||
return vanilla.getGenDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ChunkAccess> fillFromNoise(@NotNull Blender blender,
|
||||
@NotNull RandomState noiseConfig,
|
||||
@NotNull StructureManager structureAccessor, @NotNull ChunkAccess chunk) {
|
||||
return vanilla.fillFromNoise(blender, noiseConfig, structureAccessor, chunk)
|
||||
.thenApply(c -> {
|
||||
applyStructureBeard(structureAccessor, chunk);
|
||||
return c;
|
||||
});
|
||||
}
|
||||
|
||||
protected void applyStructureBeard(StructureManager structureAccessor, ChunkAccess chunk) {
|
||||
LevelAccessor level = Reflection.STRUCTURE_MANAGER.getLevel(structureAccessor);
|
||||
BiomeProvider biomeProvider = pack.getBiomeProvider();
|
||||
PreLoadCompatibilityOptions compatibilityOptions = pack.getContext().get(PreLoadCompatibilityOptions.class);
|
||||
if(compatibilityOptions.isBeard()) {
|
||||
bindings.applyStructureBeard(delegate, structureAccessor, chunk,
|
||||
new com.dfsek.terra.bukkit.world.BukkitWorldProperties(level.getMinecraftWorld().getWorld()),
|
||||
biomeProvider, compatibilityOptions);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSeaLevel() {
|
||||
return vanilla.getSeaLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinY() {
|
||||
return vanilla.getMinY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBaseHeight(int x, int z, @NotNull Types heightmap, @NotNull LevelHeightAccessor world, @NotNull RandomState noiseConfig) {
|
||||
WorldProperties properties = new NMSWorldProperties(seed, world);
|
||||
int y = properties.getMaxHeight();
|
||||
BiomeProvider biomeProvider = pack.getBiomeProvider();
|
||||
while(y > properties.getMinHeight() && !heightmap.isOpaque().test(
|
||||
((CraftBlockData) delegate.getBlock(properties, x, y - 1, z, biomeProvider).getHandle()).getState())) {
|
||||
y--;
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull NoiseColumn getBaseColumn(int x, int z, @NotNull LevelHeightAccessor world, @NotNull RandomState noiseConfig) {
|
||||
BlockState[] array = new BlockState[world.getHeight()];
|
||||
WorldProperties properties = new NMSWorldProperties(seed, world);
|
||||
BiomeProvider biomeProvider = pack.getBiomeProvider();
|
||||
for(int y = properties.getMaxHeight() - 1; y >= properties.getMinHeight(); y--) {
|
||||
array[y - properties.getMinHeight()] = ((CraftBlockData) delegate.getBlock(properties, x, y, z, biomeProvider)
|
||||
.getHandle()).getState();
|
||||
}
|
||||
return new NoiseColumn(properties.getMinHeight(), array);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDebugScreenInfo(@NotNull List<String> text, @NotNull RandomState noiseConfig, @NotNull BlockPos pos) {
|
||||
|
||||
}
|
||||
}
|
||||
-66
@@ -1,66 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms;
|
||||
|
||||
import net.minecraft.server.level.ChunkMap;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.chunk.status.WorldGenContext;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.WorldInitEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper;
|
||||
|
||||
|
||||
public class NMSInjectListener implements Listener {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NMSInjectListener.class);
|
||||
private static final Set<World> INJECTED = new HashSet<>();
|
||||
private static final ReentrantLock INJECT_LOCK = new ReentrantLock();
|
||||
private final NMSVersionBindings bindings;
|
||||
|
||||
public NMSInjectListener(NMSVersionBindings bindings) {
|
||||
this.bindings = bindings;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onWorldInit(WorldInitEvent event) {
|
||||
if(!INJECTED.contains(event.getWorld()) &&
|
||||
event.getWorld().getGenerator() instanceof BukkitChunkGeneratorWrapper bukkitChunkGeneratorWrapper) {
|
||||
INJECT_LOCK.lock();
|
||||
try {
|
||||
LOGGER.info("Preparing to take over the world: {}", event.getWorld().getName());
|
||||
CraftWorld craftWorld = (CraftWorld) event.getWorld();
|
||||
ServerLevel serverWorld = craftWorld.getHandle();
|
||||
|
||||
ConfigPack pack = bukkitChunkGeneratorWrapper.getPack();
|
||||
|
||||
ChunkGenerator vanilla = serverWorld.getChunkSource().getGenerator();
|
||||
NMSBiomeProvider provider = bindings.createBiomeProvider(pack.getBiomeProvider(), craftWorld.getSeed());
|
||||
ChunkMap chunkMap = serverWorld.getChunkSource().chunkMap;
|
||||
WorldGenContext worldGenContext = Reflection.CHUNKMAP.getWorldGenContext(chunkMap);
|
||||
Reflection.CHUNKMAP.setWorldGenContext(chunkMap, new WorldGenContext(
|
||||
worldGenContext.level(),
|
||||
bindings.createChunkGenerator(vanilla, pack, provider, craftWorld.getSeed()),
|
||||
worldGenContext.structureManager(),
|
||||
worldGenContext.lightEngine(),
|
||||
worldGenContext.mainThreadExecutor(),
|
||||
worldGenContext.unsavedListener()
|
||||
));
|
||||
|
||||
INJECTED.add(event.getWorld());
|
||||
LOGGER.info("Successfully injected into world.");
|
||||
|
||||
} finally {
|
||||
INJECT_LOCK.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-121
@@ -1,121 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms;
|
||||
|
||||
import com.dfsek.tectonic.api.TypeRegistry;
|
||||
import com.dfsek.tectonic.api.exception.LoadException;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.sounds.Music;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.attribute.AmbientAdditionsSettings;
|
||||
import net.minecraft.world.attribute.AmbientMoodSettings;
|
||||
import net.minecraft.world.attribute.AmbientParticle;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.entity.npc.villager.VillagerType;
|
||||
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 org.bukkit.block.CreatureSpawner;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.dfsek.terra.addon.InternalAddon;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.entity.EntityTypeExtended;
|
||||
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.util.BukkitNMSAccess;
|
||||
import com.dfsek.terra.bukkit.nms.config.BiomeAdditionsSoundTemplate;
|
||||
import com.dfsek.terra.bukkit.nms.config.BiomeMoodSoundTemplate;
|
||||
import com.dfsek.terra.bukkit.nms.config.BiomeParticleConfigTemplate;
|
||||
import com.dfsek.terra.bukkit.nms.config.EntityTypeTemplate;
|
||||
import com.dfsek.terra.bukkit.nms.config.MusicSoundTemplate;
|
||||
import com.dfsek.terra.bukkit.nms.config.SoundEventTemplate;
|
||||
import com.dfsek.terra.bukkit.nms.config.SpawnCostConfig;
|
||||
import com.dfsek.terra.bukkit.nms.config.SpawnEntryConfig;
|
||||
import com.dfsek.terra.bukkit.nms.config.SpawnSettingsTemplate;
|
||||
import com.dfsek.terra.bukkit.nms.config.SpawnTypeConfig;
|
||||
import com.dfsek.terra.bukkit.nms.config.VillagerTypeTemplate;
|
||||
|
||||
|
||||
public class NMSPlatformBase extends PlatformImpl implements BukkitNMSAccess {
|
||||
private final NMSVersionBindings bindings;
|
||||
|
||||
public NMSPlatformBase(TerraBukkitPlugin plugin, NMSVersionBindings bindings) {
|
||||
super(plugin);
|
||||
this.bindings = bindings;
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new NMSInjectListener(bindings), plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.dfsek.terra.api.entity.EntityType getEntityType(String data) {
|
||||
return AwfulBukkitHacks.getEntityType(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawnEntity(Object target, org.bukkit.Location location,
|
||||
com.dfsek.terra.api.entity.EntityType type) {
|
||||
return AwfulBukkitHacks.spawnEntity(target, location, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpawnerEntity(CreatureSpawner spawner, EntityTypeExtended type) {
|
||||
AwfulBukkitHacks.setSpawnerEntity(spawner, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
super.register(registry);
|
||||
registry.registerLoader(PlatformBiome.class, (type, o, loader, depthTracker) -> parseBiome((String) o, depthTracker))
|
||||
.registerLoader(Identifier.class, (type, o, loader, depthTracker) -> {
|
||||
Identifier identifier = Identifier.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(AmbientParticle.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, () -> new SpawnSettingsTemplate(bindings))
|
||||
.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(), bindings))
|
||||
.global();
|
||||
|
||||
return internalAddon;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Iterable<BaseAddon> platformAddon() {
|
||||
return List.of(new NMSAddon(this));
|
||||
}
|
||||
}
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
import com.dfsek.terra.bukkit.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState;
|
||||
|
||||
|
||||
public final class NMSStructureBeardifier {
|
||||
private NMSStructureBeardifier() { }
|
||||
|
||||
public static void apply(ChunkGenerator delegate, ChunkAccess chunk, WorldProperties world,
|
||||
BiomeProvider biomeProvider, PreLoadCompatibilityOptions compatibilityOptions,
|
||||
StructureDensitySampler sampler) {
|
||||
double threshold = compatibilityOptions.getBeardThreshold();
|
||||
double airThreshold = compatibilityOptions.getAirThreshold();
|
||||
int chunkX = chunk.getPos().x() << 4;
|
||||
int chunkZ = chunk.getPos().z() << 4;
|
||||
|
||||
for(int x = 0; x < 16; x++) {
|
||||
for(int z = 0; z < 16; z++) {
|
||||
int depth = 0;
|
||||
for(int y = world.getMaxHeight() - 1; y >= world.getMinHeight(); y--) {
|
||||
int worldX = x + chunkX;
|
||||
int worldZ = z + chunkZ;
|
||||
double density = sampler.sample(worldX, y, worldZ);
|
||||
if(density > threshold) {
|
||||
chunk.setBlockState(new BlockPos(x, y, z), ((CraftBlockData) ((BukkitBlockState) delegate
|
||||
.getPalette(worldX, y, worldZ, world, biomeProvider)
|
||||
.get(depth, worldX, y, worldZ, world.getSeed())).getHandle()).getState(), 0);
|
||||
depth++;
|
||||
} else if(density < airThreshold) {
|
||||
chunk.setBlockState(new BlockPos(x, y, z), Blocks.AIR.defaultBlockState(), 0);
|
||||
} else {
|
||||
depth = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface StructureDensitySampler {
|
||||
double sample(int x, int y, int z);
|
||||
}
|
||||
}
|
||||
-44
@@ -1,44 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms;
|
||||
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.level.StructureManager;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.Biome.BiomeBuilder;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
import com.dfsek.terra.bukkit.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.bukkit.nms.config.VanillaBiomeProperties;
|
||||
|
||||
|
||||
public interface NMSVersionBindings {
|
||||
default NMSBiomeProvider createBiomeProvider(BiomeProvider delegate, long seed) {
|
||||
return new NMSBiomeProvider(delegate, seed);
|
||||
}
|
||||
|
||||
default NMSChunkGeneratorDelegate createChunkGenerator(net.minecraft.world.level.chunk.ChunkGenerator vanilla,
|
||||
ConfigPack pack,
|
||||
NMSBiomeProvider biomeProvider, long seed) {
|
||||
return new NMSChunkGeneratorDelegate(vanilla, pack, biomeProvider, seed, this);
|
||||
}
|
||||
|
||||
void addSpawn(MobSpawnSettings.Builder builder, MobCategory category, EntityType<?> type, int weight, int minCount, int maxCount);
|
||||
|
||||
void addSpawnCost(MobSpawnSettings.Builder builder, EntityType<?> type, double mass, double gravity);
|
||||
|
||||
boolean setCreatureGenerationProbability(MobSpawnSettings.Builder builder, float probability);
|
||||
|
||||
void copyVanillaSpawnSettings(BiomeBuilder builder, Biome biome);
|
||||
|
||||
void setSpawnSettings(BiomeBuilder builder, MobSpawnSettings settings);
|
||||
|
||||
void applyBiomeColorOverrides(BiomeBuilder builder, VanillaBiomeProperties properties);
|
||||
|
||||
void applyStructureBeard(ChunkGenerator generator, StructureManager structures, ChunkAccess chunk, WorldProperties world,
|
||||
BiomeProvider biomeProvider, PreLoadCompatibilityOptions options);
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms;
|
||||
|
||||
import net.minecraft.world.level.LevelHeightAccessor;
|
||||
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
|
||||
|
||||
public class NMSWorldProperties implements WorldProperties {
|
||||
private final long seed;
|
||||
private final LevelHeightAccessor height;
|
||||
|
||||
public NMSWorldProperties(long seed, LevelHeightAccessor height) {
|
||||
this.seed = seed;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getHandle() {
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSeed() {
|
||||
return seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight() {
|
||||
return height.getMaxY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinHeight() {
|
||||
return height.getMinY();
|
||||
}
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Holder.Reference;
|
||||
import net.minecraft.core.HolderSet;
|
||||
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.villager.VillagerType;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.StructureManager;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.chunk.status.WorldGenContext;
|
||||
import xyz.jpenilla.reflectionremapper.ReflectionRemapper;
|
||||
import xyz.jpenilla.reflectionremapper.proxy.ReflectionProxyFactory;
|
||||
import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldGetter;
|
||||
import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldSetter;
|
||||
import xyz.jpenilla.reflectionremapper.proxy.annotation.MethodName;
|
||||
import xyz.jpenilla.reflectionremapper.proxy.annotation.Proxies;
|
||||
import xyz.jpenilla.reflectionremapper.proxy.annotation.Static;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Reflection {
|
||||
public static final MappedRegistryProxy MAPPED_REGISTRY;
|
||||
public static final MappedRegistryTagSetProxy MAPPED_REGISTRY_TAG_SET;
|
||||
public static final StructureManagerProxy STRUCTURE_MANAGER;
|
||||
|
||||
public static final ReferenceProxy REFERENCE;
|
||||
|
||||
|
||||
public static final ChunkMapProxy CHUNKMAP;
|
||||
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();
|
||||
ReflectionProxyFactory reflectionProxyFactory = ReflectionProxyFactory.create(reflectionRemapper,
|
||||
Reflection.class.getClassLoader());
|
||||
|
||||
MAPPED_REGISTRY = reflectionProxyFactory.reflectionProxy(MappedRegistryProxy.class);
|
||||
MAPPED_REGISTRY_TAG_SET = reflectionProxyFactory.reflectionProxy(MappedRegistryTagSetProxy.class);
|
||||
STRUCTURE_MANAGER = reflectionProxyFactory.reflectionProxy(StructureManagerProxy.class);
|
||||
REFERENCE = reflectionProxyFactory.reflectionProxy(ReferenceProxy.class);
|
||||
CHUNKMAP = reflectionProxyFactory.reflectionProxy(ChunkMapProxy.class);
|
||||
HOLDER_REFERENCE = reflectionProxyFactory.reflectionProxy(HolderReferenceProxy.class);
|
||||
HOLDER_SET = reflectionProxyFactory.reflectionProxy(HolderSetNamedProxy.class);
|
||||
BIOME = reflectionProxyFactory.reflectionProxy(BiomeProxy.class);
|
||||
VILLAGER_TYPE = reflectionProxyFactory.reflectionProxy(VillagerTypeProxy.class);
|
||||
}
|
||||
|
||||
|
||||
@Proxies(MappedRegistry.class)
|
||||
public interface MappedRegistryProxy {
|
||||
@FieldGetter("byKey")
|
||||
<T> Map<ResourceKey<T>, Reference<T>> getByKey(MappedRegistry<T> instance);
|
||||
|
||||
@FieldSetter("allTags")
|
||||
<T> void setAllTags(MappedRegistry<T> instance, Object obj);
|
||||
|
||||
@FieldSetter("frozen")
|
||||
void setFrozen(MappedRegistry<?> instance, boolean frozen);
|
||||
|
||||
@MethodName("createTag")
|
||||
<T> HolderSet.Named<T> invokeCreateTag(MappedRegistry<T> instance, TagKey<T> tag);
|
||||
}
|
||||
|
||||
|
||||
@Proxies(className = "net.minecraft.core.MappedRegistry$TagSet")
|
||||
public interface MappedRegistryTagSetProxy {
|
||||
@MethodName("fromMap")
|
||||
@Static
|
||||
<T> Object invokeFromMap(Map<TagKey<T>, HolderSet.Named<T>> map);
|
||||
}
|
||||
|
||||
|
||||
@Proxies(StructureManager.class)
|
||||
public interface StructureManagerProxy {
|
||||
@FieldGetter("level")
|
||||
LevelAccessor getLevel(StructureManager instance);
|
||||
}
|
||||
|
||||
|
||||
@Proxies(Holder.Reference.class)
|
||||
public interface ReferenceProxy {
|
||||
@MethodName("bindValue")
|
||||
<T> void invokeBindValue(Reference<T> instance, T value);
|
||||
|
||||
@MethodName("bindTags")
|
||||
<T> void invokeBindTags(Reference<T> instance, Collection<TagKey<T>> tags);
|
||||
}
|
||||
|
||||
|
||||
@Proxies(ChunkMap.class)
|
||||
public interface ChunkMapProxy {
|
||||
@FieldGetter("worldGenContext")
|
||||
WorldGenContext getWorldGenContext(ChunkMap instance);
|
||||
|
||||
@FieldSetter("worldGenContext")
|
||||
void setWorldGenContext(ChunkMap instance, WorldGenContext worldGenContext);
|
||||
}
|
||||
|
||||
|
||||
@Proxies(Holder.Reference.class)
|
||||
public interface HolderReferenceProxy {
|
||||
@MethodName("bindTags")
|
||||
<T> void invokeBindTags(Holder.Reference<T> instance, Collection<TagKey<T>> tags);
|
||||
}
|
||||
|
||||
|
||||
@Proxies(HolderSet.Named.class)
|
||||
public interface HolderSetNamedProxy {
|
||||
@MethodName("bind")
|
||||
<T> void invokeBind(HolderSet.Named<T> instance, List<Holder<T>> entries);
|
||||
|
||||
@MethodName("contents")
|
||||
<T> List<Holder<T>> invokeContents(HolderSet.Named<T> instance);
|
||||
}
|
||||
|
||||
|
||||
@Proxies(Biome.class)
|
||||
public interface BiomeProxy {
|
||||
@MethodName("getGrassColorFromTexture")
|
||||
int invokeGrassColorFromTexture(Biome instance);
|
||||
}
|
||||
|
||||
|
||||
@Proxies(VillagerType.class)
|
||||
public interface VillagerTypeProxy {
|
||||
@Static
|
||||
@FieldGetter("BY_BIOME")
|
||||
Map<ResourceKey<Biome>, ResourceKey<VillagerType>> getByBiome();
|
||||
}
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
|
||||
|
||||
public class RegistryFetcher {
|
||||
private static <T> Registry<T> getRegistry(ResourceKey<Registry<T>> key) {
|
||||
return MinecraftServer.getServer()
|
||||
.registryAccess()
|
||||
.lookupOrThrow(key);
|
||||
}
|
||||
|
||||
public static Registry<Biome> biomeRegistry() {
|
||||
return getRegistry(Registries.BIOME);
|
||||
}
|
||||
|
||||
public static Registry<SoundEvent> soundEventRegistry() {
|
||||
return getRegistry(Registries.SOUND_EVENT);
|
||||
}
|
||||
}
|
||||
-71
@@ -1,71 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms.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 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.registries.BuiltInRegistries;
|
||||
import net.minecraft.world.attribute.AmbientParticle;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
public class BiomeParticleConfigTemplate implements ObjectTemplate<AmbientParticle> {
|
||||
private static final Pattern LEGACY_BLOCK_PARTICLE = Pattern.compile(
|
||||
"^((?:[a-z0-9_.-]+:)?[a-z0-9_./-]+)\\{block_state:\\{Name:((?:[a-z0-9_.-]+:)?[a-z0-9_./-]+)\\}\\}$"
|
||||
);
|
||||
|
||||
@Value("particle")
|
||||
@Default
|
||||
private String particle = null;
|
||||
|
||||
@Value("probability")
|
||||
@Default
|
||||
private Float probability = 0.1f;
|
||||
|
||||
@Override
|
||||
public AmbientParticle get() {
|
||||
if(particle == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return new AmbientParticle(parseParticle(particle), probability);
|
||||
} catch(CommandSyntaxException e) {
|
||||
String normalized = normalizeLegacyBlockParticle(particle);
|
||||
if(normalized == null) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
return new AmbientParticle(parseParticle(normalized), probability);
|
||||
} catch(CommandSyntaxException fallbackException) {
|
||||
fallbackException.addSuppressed(e);
|
||||
throw new RuntimeException(fallbackException);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static net.minecraft.core.particles.ParticleOptions parseParticle(String value) throws CommandSyntaxException {
|
||||
return ParticleArgument.readParticle(new StringReader(value),
|
||||
HolderLookup.Provider.create(Stream.of(BuiltInRegistries.PARTICLE_TYPE)));
|
||||
}
|
||||
|
||||
private static String normalizeLegacyBlockParticle(String value) {
|
||||
Matcher matcher = LEGACY_BLOCK_PARTICLE.matcher(value);
|
||||
if(!matcher.matches()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String block = matcher.group(2);
|
||||
if(!block.contains(":")) {
|
||||
block = "minecraft:" + block;
|
||||
}
|
||||
return matcher.group(1) + "{block_state:\"" + block + "\"}";
|
||||
}
|
||||
}
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms.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.Identifier;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
|
||||
|
||||
public class EntityTypeTemplate implements ObjectTemplate<EntityType<?>> {
|
||||
@Value("id")
|
||||
@Default
|
||||
private Identifier id = null;
|
||||
|
||||
@Override
|
||||
public EntityType<?> get() {
|
||||
return BuiltInRegistries.ENTITY_TYPE.get(id).orElseThrow().value();
|
||||
}
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms.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.world.entity.MobCategory;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import com.dfsek.terra.bukkit.nms.NMSVersionBindings;
|
||||
|
||||
|
||||
public class SpawnSettingsTemplate implements ObjectTemplate<MobSpawnSettings> {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SpawnSettingsTemplate.class);
|
||||
private static final AtomicBoolean PROBABILITY_WARNING_LOGGED = new AtomicBoolean();
|
||||
|
||||
private final NMSVersionBindings bindings;
|
||||
|
||||
@Value("spawns")
|
||||
@Default
|
||||
private List<SpawnTypeConfig> spawns = List.of();
|
||||
|
||||
@Value("costs")
|
||||
@Default
|
||||
private List<SpawnCostConfig> costs = List.of();
|
||||
|
||||
@Value("probability")
|
||||
@Default
|
||||
private Float probability = null;
|
||||
|
||||
public SpawnSettingsTemplate(NMSVersionBindings bindings) {
|
||||
this.bindings = bindings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobSpawnSettings get() {
|
||||
MobSpawnSettings.Builder builder = new MobSpawnSettings.Builder();
|
||||
for(SpawnTypeConfig spawn : spawns) {
|
||||
MobCategory category = spawn.getGroup();
|
||||
for(SpawnEntryConfig entry : spawn.getEntries()) {
|
||||
bindings.addSpawn(builder, category, entry.getType(), entry.getWeight(), entry.getMinCount(), entry.getMaxCount());
|
||||
}
|
||||
}
|
||||
for(SpawnCostConfig cost : costs) {
|
||||
bindings.addSpawnCost(builder, cost.getType(), cost.getMass(), cost.getGravity());
|
||||
}
|
||||
if(probability != null && !bindings.setCreatureGenerationProbability(builder, probability) &&
|
||||
PROBABILITY_WARNING_LOGGED.compareAndSet(false, true)) {
|
||||
LOGGER.warn("This server version ignores biome creature-generation probability values.");
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
package com.dfsek.terra.bukkit.nms.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.Identifier;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.entity.npc.villager.VillagerType;
|
||||
|
||||
|
||||
public class VillagerTypeTemplate implements ObjectTemplate<ResourceKey<VillagerType>> {
|
||||
@Value("id")
|
||||
@Default
|
||||
private Identifier id = null;
|
||||
|
||||
@Override
|
||||
public ResourceKey<VillagerType> get() {
|
||||
return ResourceKey.create(BuiltInRegistries.VILLAGER_TYPE.key(), id);
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,6 @@ includeImmediateChildren(file("common/addons"), "addon")
|
||||
|
||||
includeImmediateChildren(file("platforms"), "platform")
|
||||
|
||||
includeImmediateChildren(file("platforms/bukkit/nms"), "Bukkit NMS")
|
||||
|
||||
include(":platforms:bukkit:common")
|
||||
include(":platforms:minestom:example")
|
||||
|
||||
|
||||
Reference in new issue
Block a user