Merge branch 'ver/6.5.0' into dev/7.0-2

This commit is contained in:
Zoe Gidiere
2024-09-17 17:46:33 -06:00
68 changed files with 452 additions and 323 deletions
+2 -2
View File
@@ -18,10 +18,10 @@ jobs:
steps: steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Set up JDK 17 - name: Set up JDK 21
uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93
with: with:
java-version: '17' java-version: '21'
distribution: 'temurin' distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file settings-path: ${{ github.workspace }} # location for the settings.xml file
+2 -1
View File
@@ -15,6 +15,7 @@ allprojects {
tasks.withType<JavaCompile>().configureEach { tasks.withType<JavaCompile>().configureEach {
options.isFork = true options.isFork = true
options.isIncremental = true options.isIncremental = true
options.release.set(21)
} }
tasks.withType<Test>().configureEach { tasks.withType<Test>().configureEach {
@@ -44,7 +45,7 @@ afterEvaluate {
} }
project(":platforms:bukkit:common").configureDistribution() project(":platforms:bukkit:common").configureDistribution()
forSubProjects(":common:addons") { forSubProjects(":common:addons") {
apply(plugin = "com.github.johnrengelman.shadow") apply(plugin = "com.gradleup.shadow")
tasks.named("build") { tasks.named("build") {
finalizedBy(tasks.named("shadowJar")) finalizedBy(tasks.named("shadowJar"))
+6 -6
View File
@@ -9,18 +9,18 @@ repositories {
maven("https://repo.codemc.org/repository/maven-public") { maven("https://repo.codemc.org/repository/maven-public") {
name = "CodeMC" name = "CodeMC"
} }
maven("https://papermc.io/repo/repository/maven-public/") { maven("https://repo.papermc.io/repository/maven-public/") {
name = "PaperMC" name = "PaperMC"
} }
} }
dependencies { dependencies {
//TODO Allow pulling from Versions.kt //TODO Allow pulling from Versions.kt
implementation("com.github.johnrengelman", "shadow", "8.1.1") implementation("com.gradleup.shadow", "shadow-gradle-plugin", "8.3.1")
implementation("io.papermc.paperweight.userdev", "io.papermc.paperweight.userdev.gradle.plugin", "1.5.11") implementation("io.papermc.paperweight.userdev", "io.papermc.paperweight.userdev.gradle.plugin", "1.7.2")
implementation("org.ow2.asm", "asm", "9.6") implementation("org.ow2.asm", "asm", "9.7")
implementation("org.ow2.asm", "asm-tree", "9.6") implementation("org.ow2.asm", "asm-tree", "9.7")
implementation("com.dfsek.tectonic", "common", "4.2.1") implementation("com.dfsek.tectonic", "common", "4.2.1")
implementation("org.yaml", "snakeyaml", "2.2") implementation("org.yaml", "snakeyaml", "2.3")
} }
@@ -22,8 +22,8 @@ fun Project.configureCompilation() {
apply<TectonicDocPlugin>() apply<TectonicDocPlugin>()
configure<JavaPluginExtension> { configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_17 sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_21
} }
tasks.withType<JavaCompile> { tasks.withType<JavaCompile> {
+4 -1
View File
@@ -36,7 +36,7 @@ fun Project.configureDependencies() {
maven("https://repo.codemc.org/repository/maven-public") { maven("https://repo.codemc.org/repository/maven-public") {
name = "CodeMC" name = "CodeMC"
} }
maven("https://papermc.io/repo/repository/maven-public/") { maven("https://repo.papermc.io/repository/maven-public/") {
name = "PaperMC" name = "PaperMC"
} }
maven("https://files.minecraftforge.net/maven/") { maven("https://files.minecraftforge.net/maven/") {
@@ -48,6 +48,9 @@ fun Project.configureDependencies() {
maven("https://jitpack.io") { maven("https://jitpack.io") {
name = "JitPack" name = "JitPack"
} }
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") {
name = "Sonatype Snapshots"
}
} }
dependencies { dependencies {
@@ -21,7 +21,7 @@ import kotlin.io.path.exists
fun Project.configureDistribution() { fun Project.configureDistribution() {
apply(plugin = "com.github.johnrengelman.shadow") apply(plugin = "com.gradleup.shadow")
val downloadDefaultPacks = tasks.create("downloadDefaultPacks") { val downloadDefaultPacks = tasks.create("downloadDefaultPacks") {
group = "terra" group = "terra"
+24 -23
View File
@@ -8,27 +8,28 @@ object Versions {
const val paralithic = "0.7.1" const val paralithic = "0.7.1"
const val strata = "1.3.2" const val strata = "1.3.2"
const val cloud = "1.8.4" const val cloud = "2.0.0"
const val cloudPaper = "2.0.0-beta.10"
const val cloudFabric = "2.0.0-beta.9"
const val caffeine = "3.1.8" const val caffeine = "3.1.8"
const val slf4j = "2.0.9" const val slf4j = "2.0.16"
const val log4j_slf4j_impl = "2.20.0"
object Internal { object Internal {
const val shadow = "8.1.1" const val shadow = "8.3.1"
const val apacheText = "1.11.0" const val apacheText = "1.12.0"
const val apacheIO = "2.15.1" const val apacheIO = "2.16.1"
const val guava = "32.1.3-jre" const val guava = "33.3.0-jre"
const val asm = "9.6" const val asm = "9.7"
const val snakeYml = "2.2" const val snakeYml = "2.3"
const val jetBrainsAnnotations = "24.1.0" const val jetBrainsAnnotations = "24.1.0"
const val junit = "5.10.1" const val junit = "5.11.0"
} }
} }
object Fabric { object Fabric {
const val fabricAPI = "0.91.2+${Mod.minecraft}" const val fabricAPI = "0.104.0+${Mod.minecraft}"
} }
// //
// object Quilt { // object Quilt {
@@ -37,14 +38,14 @@ object Versions {
// } // }
object Mod { object Mod {
const val mixin = "0.12.5+mixin.0.8.5" const val mixin = "0.15.3+mixin.0.8.7"
const val minecraft = "1.20.4" const val minecraft = "1.21.1"
const val yarn = "$minecraft+build.1" const val yarn = "$minecraft+build.3"
const val fabricLoader = "0.15.3" const val fabricLoader = "0.16.5"
const val architecuryLoom = "1.4.369" const val architecuryLoom = "1.7.413"
const val architecturyPlugin = "3.4.151" const val architecturyPlugin = "3.4.159"
} }
// //
// object Forge { // object Forge {
@@ -53,14 +54,14 @@ object Versions {
// } // }
object Bukkit { object Bukkit {
const val minecraft = "1.20.4" const val minecraft = "1.21.1"
const val paperBuild = "$minecraft-R0.1-20231209.173338-2" const val paperBuild = "$minecraft-R0.1-20240917.151311-80"
const val paper = paperBuild const val paper = paperBuild
const val paperLib = "1.0.8" const val paperLib = "1.0.8"
const val reflectionRemapper = "0.1.0" const val reflectionRemapper = "0.1.1"
const val paperDevBundle = paperBuild const val paperDevBundle = paperBuild
const val runPaper = "2.2.2" const val runPaper = "2.3.1"
const val paperWeight = "1.5.11" const val paperWeight = "1.7.2"
} }
// //
@@ -72,6 +73,6 @@ object Versions {
// //
object CLI { object CLI {
const val nbt = "6.1" const val nbt = "6.1"
const val logback = "1.4.14" const val logback = "1.5.8"
} }
} }
@@ -1,8 +1,5 @@
package com.dfsek.terra.addons.commands.addons; package com.dfsek.terra.addons.commands.addons;
import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.CommandManager;
import com.dfsek.terra.addons.manifest.api.AddonInitializer; import com.dfsek.terra.addons.manifest.api.AddonInitializer;
import com.dfsek.terra.api.Platform; import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.addon.BaseAddon; import com.dfsek.terra.api.addon.BaseAddon;
@@ -12,6 +9,9 @@ import com.dfsek.terra.api.event.events.platform.CommandRegistrationEvent;
import com.dfsek.terra.api.event.functional.FunctionalEventHandler; import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
import com.dfsek.terra.api.inject.annotations.Inject; import com.dfsek.terra.api.inject.annotations.Inject;
import org.incendo.cloud.CommandManager;
import org.incendo.cloud.description.Description;
public class AddonsCommandAddon implements AddonInitializer { public class AddonsCommandAddon implements AddonInitializer {
@Inject @Inject
@@ -30,7 +30,7 @@ public class AddonsCommandAddon implements AddonInitializer {
CommandManager<CommandSender> manager = event.getCommandManager(); CommandManager<CommandSender> manager = event.getCommandManager();
manager.command( manager.command(
manager.commandBuilder("addons", ArgumentDescription.of("List installed Terra addons")) manager.commandBuilder("addons", Description.of("List installed Terra addons"))
.permission("terra.addons") .permission("terra.addons")
.handler(context -> { .handler(context -> {
StringBuilder addons = new StringBuilder("Installed addons:\n"); StringBuilder addons = new StringBuilder("Installed addons:\n");
@@ -41,7 +41,7 @@ public class AddonsCommandAddon implements AddonInitializer {
.append('@') .append('@')
.append(addon.getVersion().getFormatted()) .append(addon.getVersion().getFormatted())
.append('\n')); .append('\n'));
context.getSender().sendMessage(addons.toString()); context.sender().sendMessage(addons.toString());
}) })
) )
.command( .command(
@@ -61,7 +61,7 @@ public class AddonsCommandAddon implements AddonInitializer {
.append('@') .append('@')
.append(versions.getFormatted()) .append(versions.getFormatted())
.append('\n')); .append('\n'));
context.getSender().sendMessage(addonInfo.toString()); context.sender().sendMessage(addonInfo.toString());
}) })
); );
}); });
@@ -1,7 +1,7 @@
package com.dfsek.terra.addons.commands.packs; package com.dfsek.terra.addons.commands.packs;
import cloud.commandframework.ArgumentDescription; import org.incendo.cloud.CommandManager;
import cloud.commandframework.CommandManager; import org.incendo.cloud.description.Description;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -35,7 +35,7 @@ public class PacksCommandAddon implements AddonInitializer {
CommandManager<CommandSender> manager = event.getCommandManager(); CommandManager<CommandSender> manager = event.getCommandManager();
manager.command( manager.command(
manager.commandBuilder("packs", ArgumentDescription.of("List installed config packs")) manager.commandBuilder("packs", Description.of("List installed config packs"))
.permission("terra.packs") .permission("terra.packs")
.handler(context -> { .handler(context -> {
StringBuilder packs = new StringBuilder("Installed packs:\n"); StringBuilder packs = new StringBuilder("Installed packs:\n");
@@ -43,12 +43,12 @@ public class PacksCommandAddon implements AddonInitializer {
.append(pack.getID()) .append(pack.getID())
.append('@') .append('@')
.append(pack.getVersion().getFormatted())); .append(pack.getVersion().getFormatted()));
context.getSender().sendMessage(packs.toString()); context.sender().sendMessage(packs.toString());
}) })
) )
.command( .command(
manager.commandBuilder("packs") manager.commandBuilder("packs")
.literal("info", ArgumentDescription.of("Get information about a pack")) .literal("info", Description.of("Get information about a pack"))
.permission("terra.packs.info") .permission("terra.packs.info")
.argument(RegistryArgument.of("pack", platform.getConfigRegistry())) .argument(RegistryArgument.of("pack", platform.getConfigRegistry()))
.handler(context -> { .handler(context -> {
@@ -65,21 +65,21 @@ public class PacksCommandAddon implements AddonInitializer {
.append('@') .append('@')
.append(versions.getFormatted()) .append(versions.getFormatted())
.append('\n')); .append('\n'));
context.getSender().sendMessage(packInfo.toString()); context.sender().sendMessage(packInfo.toString());
})) }))
.command( .command(
manager.commandBuilder("packs") manager.commandBuilder("packs")
.literal("reload", ArgumentDescription.of("Reload config packs")) .literal("reload", Description.of("Reload config packs"))
.permission("terra.packs.reload") .permission("terra.packs.reload")
.handler(context -> { .handler(context -> {
context.getSender().sendMessage("Reloading Terra..."); context.sender().sendMessage("Reloading Terra...");
logger.info("Reloading Terra..."); logger.info("Reloading Terra...");
if(platform.reload()) { if(platform.reload()) {
logger.info("Terra reloaded successfully."); logger.info("Terra reloaded successfully.");
context.getSender().sendMessage("Terra reloaded successfully."); context.sender().sendMessage("Terra reloaded successfully.");
} else { } else {
logger.error("Terra failed to reload."); logger.error("Terra failed to reload.");
context.getSender().sendMessage( context.sender().sendMessage(
"Terra failed to reload. See logs for more information."); "Terra failed to reload. See logs for more information.");
} }
})); }));
@@ -1,7 +1,7 @@
package com.dfsek.terra.addons.commands.profiler; package com.dfsek.terra.addons.commands.profiler;
import cloud.commandframework.ArgumentDescription; import org.incendo.cloud.CommandManager;
import cloud.commandframework.CommandManager; import org.incendo.cloud.description.Description;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -33,24 +33,24 @@ public class ProfilerCommandAddon implements AddonInitializer {
CommandManager<CommandSender> manager = event.getCommandManager(); CommandManager<CommandSender> manager = event.getCommandManager();
manager manager
.command( .command(
manager.commandBuilder("profiler", ArgumentDescription.of("Access the profiler")) manager.commandBuilder("profiler", Description.of("Access the profiler"))
.literal("start", ArgumentDescription.of("Start profiling"), "st") .literal("start", Description.of("Start profiling"), "st")
.permission("terra.profiler.start") .permission("terra.profiler.start")
.handler(context -> { .handler(context -> {
platform.getProfiler().start(); platform.getProfiler().start();
context.getSender().sendMessage("Profiling started."); context.sender().sendMessage("Profiling started.");
})) }))
.command( .command(
manager.commandBuilder("profiler", ArgumentDescription.of("Access the profiler")) manager.commandBuilder("profiler", Description.of("Access the profiler"))
.literal("stop", ArgumentDescription.of("Stop profiling"), "s") .literal("stop", Description.of("Stop profiling"), "s")
.permission("terra.profiler.stop") .permission("terra.profiler.stop")
.handler(context -> { .handler(context -> {
platform.getProfiler().stop(); platform.getProfiler().stop();
context.getSender().sendMessage("Profiling stopped."); context.sender().sendMessage("Profiling stopped.");
})) }))
.command( .command(
manager.commandBuilder("profiler", ArgumentDescription.of("Access the profiler")) manager.commandBuilder("profiler", Description.of("Access the profiler"))
.literal("query", ArgumentDescription.of("Query profiler results"), "q") .literal("query", Description.of("Query profiler results"), "q")
.permission("terra.profiler.query") .permission("terra.profiler.query")
.handler(context -> { .handler(context -> {
StringBuilder data = new StringBuilder("Terra Profiler data: \n"); StringBuilder data = new StringBuilder("Terra Profiler data: \n");
@@ -59,15 +59,15 @@ public class ProfilerCommandAddon implements AddonInitializer {
.append(timings.toString()) .append(timings.toString())
.append('\n')); .append('\n'));
logger.info(data.toString()); logger.info(data.toString());
context.getSender().sendMessage("Profiling data dumped to console."); context.sender().sendMessage("Profiling data dumped to console.");
})) }))
.command( .command(
manager.commandBuilder("profiler", ArgumentDescription.of("Access the profiler")) manager.commandBuilder("profiler", Description.of("Access the profiler"))
.literal("reset", ArgumentDescription.of("Reset the profiler"), "r") .literal("reset", Description.of("Reset the profiler"), "r")
.permission("terra.profiler.reset") .permission("terra.profiler.reset")
.handler(context -> { .handler(context -> {
platform.getProfiler().reset(); platform.getProfiler().reset();
context.getSender().sendMessage("Profiler reset."); context.sender().sendMessage("Profiler reset.");
})); }));
}); });
} }
@@ -8,6 +8,7 @@ import cloud.commandframework.context.CommandContext;
import java.util.random.RandomGenerator; import java.util.random.RandomGenerator;
import java.util.random.RandomGeneratorFactory; import java.util.random.RandomGeneratorFactory;
import java.util.Random;
import com.dfsek.terra.addons.manifest.api.AddonInitializer; import com.dfsek.terra.addons.manifest.api.AddonInitializer;
import com.dfsek.terra.api.Platform; import com.dfsek.terra.api.Platform;
@@ -23,6 +24,13 @@ import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.util.Rotation; import com.dfsek.terra.api.util.Rotation;
import com.dfsek.terra.api.util.reflection.TypeKey; import com.dfsek.terra.api.util.reflection.TypeKey;
import org.incendo.cloud.CommandManager;
import org.incendo.cloud.component.DefaultValue;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.description.Description;
import org.incendo.cloud.parser.standard.EnumParser;
import org.incendo.cloud.parser.standard.LongParser;
public class StructureCommandAddon implements AddonInitializer { public class StructureCommandAddon implements AddonInitializer {
@Inject @Inject
@@ -32,7 +40,7 @@ public class StructureCommandAddon implements AddonInitializer {
private BaseAddon addon; private BaseAddon addon;
private static Registry<Structure> getStructureRegistry(CommandContext<CommandSender> sender) { private static Registry<Structure> getStructureRegistry(CommandContext<CommandSender> sender) {
return sender.getSender().getEntity().orElseThrow().world().getPack().getRegistry(Structure.class); return sender.sender().getEntity().orElseThrow().world().getPack().getRegistry(Structure.class);
} }
@Override @Override
@@ -44,16 +52,16 @@ public class StructureCommandAddon implements AddonInitializer {
CommandManager<CommandSender> manager = event.getCommandManager(); CommandManager<CommandSender> manager = event.getCommandManager();
manager.command( manager.command(
manager.commandBuilder("structures", ArgumentDescription.of("Manage or generate structures")) manager.commandBuilder("structures", Description.of("Manage or generate structures"))
.literal("generate") .literal("generate")
.argument(RegistryArgument.builder("structure", .optional(RegistryArgument.builder("structure",
StructureCommandAddon::getStructureRegistry, StructureCommandAddon::getStructureRegistry,
TypeKey.of(Structure.class))) TypeKey.of(Structure.class)))
.argument(LongArgument.optional("seed", 0)) .optional("seed", LongParser.longParser(), DefaultValue.constant(0L))
.argument(EnumArgument.optional(Rotation.class, "rotation", Rotation.NONE)) .optional("rotation", EnumParser.enumParser(Rotation.class), DefaultValue.constant(Rotation.NONE))
.handler(context -> { .handler(context -> {
Structure structure = context.get("structure"); Structure structure = context.get("structure");
Entity sender = context.getSender().getEntity().orElseThrow(); Entity sender = context.sender().getEntity().orElseThrow();
structure.generate( structure.generate(
sender.position().toInt(), sender.position().toInt(),
sender.world(), sender.world(),
+1 -1
View File
@@ -2,7 +2,7 @@ dependencies {
api("ca.solo-studios", "strata", Versions.Libraries.strata) api("ca.solo-studios", "strata", Versions.Libraries.strata)
compileOnlyApi("org.slf4j", "slf4j-api", Versions.Libraries.slf4j) compileOnlyApi("org.slf4j", "slf4j-api", Versions.Libraries.slf4j)
testImplementation("org.slf4j", "slf4j-api", Versions.Libraries.slf4j) testImplementation("org.slf4j", "slf4j-api", Versions.Libraries.slf4j)
api("cloud.commandframework", "cloud-core", Versions.Libraries.cloud) api("org.incendo", "cloud-core", Versions.Libraries.cloud)
api("com.dfsek.tectonic", "common", Versions.Libraries.tectonic) api("com.dfsek.tectonic", "common", Versions.Libraries.tectonic)
@@ -1,18 +1,10 @@
package com.dfsek.terra.api.command.arguments; package com.dfsek.terra.api.command.arguments;
import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.arguments.parser.ArgumentParseResult;
import cloud.commandframework.arguments.parser.ArgumentParser;
import cloud.commandframework.context.CommandContext;
import io.leangen.geantyref.TypeToken; import io.leangen.geantyref.TypeToken;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Queue; import java.util.concurrent.CompletableFuture;
import java.util.function.BiFunction;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -21,40 +13,33 @@ import com.dfsek.terra.api.registry.exception.NoSuchEntryException;
import com.dfsek.terra.api.registry.key.RegistryKey; import com.dfsek.terra.api.registry.key.RegistryKey;
import com.dfsek.terra.api.util.reflection.TypeKey; import com.dfsek.terra.api.util.reflection.TypeKey;
import org.incendo.cloud.component.CommandComponent;
import org.incendo.cloud.component.DefaultValue;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.context.CommandInput;
import org.incendo.cloud.parser.ArgumentParseResult;
import org.incendo.cloud.parser.ArgumentParser;
import org.incendo.cloud.parser.ParserDescriptor;
import org.incendo.cloud.suggestion.Suggestion;
import org.incendo.cloud.suggestion.SuggestionProvider;
public class RegistryArgument<T, R> extends CommandArgument<T, R> {
private RegistryArgument( public class RegistryArgument {
boolean required,
@NonNull String name,
Function<CommandContext<T>, Registry<R>> registryFunction,
TypeToken<R> typeToken,
@NonNull String defaultValue,
@Nullable BiFunction<CommandContext<T>, String, List<String>> suggestionsProvider,
@NonNull ArgumentDescription description
) {
super(required,
name,
new RegistryArgumentParser<>(registryFunction),
defaultValue,
typeToken,
suggestionsProvider,
description);
}
public static <T, R> Builder<T, R> builder(String name, Registry<R> registry) { public static <T, R> Builder<T, R> builder(String name, Registry<R> registry) {
return new Builder<>(name, registry); return new Builder<>(name, registry);
} }
public static <T, R> CommandArgument<T, R> of(String name, Registry<R> registry) { public static <T, R> CommandComponent<T> of(String name, Registry<R> registry) {
return RegistryArgument.<T, R>builder(name, registry).build(); return RegistryArgument.<T, R>builder(name, registry).build();
} }
public static <T, R> CommandArgument<T, R> optional(String name, Registry<R> registry) { public static <T, R> CommandComponent<T> optional(String name, Registry<R> registry) {
return RegistryArgument.<T, R>builder(name, registry).asOptional().build(); return RegistryArgument.<T, R>builder(name, registry).optional().build();
} }
public static <T, R> CommandArgument<T, R> optional(String name, Registry<R> registry, String defaultKey) { public static <T, R> CommandComponent<T> optional(String name, Registry<R> registry, DefaultValue<T, R> defaultKey) {
return RegistryArgument.<T, R>builder(name, registry).asOptionalWithDefault(defaultKey).build(); return RegistryArgument.<T, R>builder(name, registry).optional(defaultKey).build();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@@ -63,49 +48,36 @@ public class RegistryArgument<T, R> extends CommandArgument<T, R> {
return new Builder<>(name, registryFunction, (TypeToken<R>) TypeToken.get(registryType.getType())); return new Builder<>(name, registryFunction, (TypeToken<R>) TypeToken.get(registryType.getType()));
} }
public static <T, R> CommandArgument<T, R> of(String name, Function<CommandContext<T>, Registry<R>> registryFunction, public static <T, R> CommandComponent<T> of(String name, Function<CommandContext<T>, Registry<R>> registryFunction,
TypeKey<R> registryType) { TypeKey<R> registryType) {
return RegistryArgument.<T, R>builder(name, registryFunction, registryType).build(); return RegistryArgument.<T, R>builder(name, registryFunction, registryType).build();
} }
public static <T, R> CommandArgument<T, R> optional(String name, Function<CommandContext<T>, Registry<R>> registryFunction, public static <T, R> CommandComponent<T> optional(String name, Function<CommandContext<T>, Registry<R>> registryFunction,
TypeKey<R> registryType) { TypeKey<R> registryType) {
return RegistryArgument.builder(name, registryFunction, registryType).asOptional().build(); return RegistryArgument.builder(name, registryFunction, registryType).optional().build();
} }
public static <T, R> CommandArgument<T, R> optional(String name, Function<CommandContext<T>, Registry<R>> registryFunction, public static <T, R> CommandComponent<T> optional(String name, Function<CommandContext<T>, Registry<R>> registryFunction,
TypeKey<R> registryType, String defaultKey) { TypeKey<R> registryType, DefaultValue<T, R> defaultKey) {
return RegistryArgument.builder(name, registryFunction, registryType).asOptionalWithDefault(defaultKey).build(); return RegistryArgument.builder(name, registryFunction, registryType).optional(defaultKey).build();
} }
public static final class Builder<T, R> extends CommandArgument.Builder<T, R> { public static final class Builder<T, R> extends CommandComponent.Builder<T, R> {
private final Function<CommandContext<T>, Registry<R>> registryFunction;
private final TypeToken<R> typeToken;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private Builder(@NonNull String name, Registry<R> registry) { private Builder(@NonNull String name, Registry<R> registry) {
super((TypeToken<R>) TypeToken.get(registry.getType().getType()), name); super();
this.registryFunction = commandContext -> registry; this.name(name);
this.typeToken = (TypeToken<R>) TypeToken.get(registry.getType().getType()); this.parser(ParserDescriptor.of(
new RegistryArgumentParser<>(commandContext -> registry),
(TypeToken<R>) TypeToken.get(registry.getType().getType())));
} }
private Builder(@NonNull String name, Function<CommandContext<T>, Registry<R>> registryFunction, TypeToken<R> typeToken) { private Builder(@NonNull String name, Function<CommandContext<T>, Registry<R>> registryFunction, TypeToken<R> typeToken) {
super(typeToken, name); super();
this.typeToken = typeToken; this.name(name);
this.registryFunction = registryFunction; this.parser(ParserDescriptor.of(new RegistryArgumentParser<>(registryFunction), typeToken));
}
@Override
public @NonNull RegistryArgument<T, R> build() {
return new RegistryArgument<>(
isRequired(),
getName(),
registryFunction,
typeToken,
getDefaultValue(),
getSuggestionsProvider(),
getDefaultDescription()
);
} }
} }
@@ -119,12 +91,12 @@ public class RegistryArgument<T, R> extends CommandArgument<T, R> {
@Override @Override
public @NonNull ArgumentParseResult<@NonNull R> parse(@NonNull CommandContext<@NonNull T> commandContext, public @NonNull ArgumentParseResult<@NonNull R> parse(@NonNull CommandContext<@NonNull T> commandContext,
@NonNull Queue<@NonNull String> inputQueue) { @NonNull CommandInput commandInput) {
String input = inputQueue.remove(); String input = commandInput.readString();
String next = inputQueue.peek(); String next = commandInput.peekString();
if(next != null && next.equals(":")) { if(next.equals(":")) {
input += inputQueue.remove(); input += commandInput.readString();
input += inputQueue.remove(); input += commandInput.readString();
} }
Registry<R> registry = registryFunction.apply(commandContext); Registry<R> registry = registryFunction.apply(commandContext);
@@ -146,8 +118,17 @@ public class RegistryArgument<T, R> extends CommandArgument<T, R> {
} }
@Override @Override
public @NonNull List<@NonNull String> suggestions(@NonNull CommandContext<T> commandContext, @NonNull String input) { public @NonNull SuggestionProvider<T> suggestionProvider() {
return registryFunction.apply(commandContext).keys().stream().map(RegistryKey::toString).sorted().collect(Collectors.toList()); return new SuggestionProvider<>() {
@Override
public @NonNull CompletableFuture<? extends @NonNull Iterable<? extends @NonNull Suggestion>> suggestionsFuture(
@NonNull CommandContext<T> context, @NonNull CommandInput input) {
// TODO: Verify whether this is correct
return CompletableFuture.completedFuture(registryFunction.apply(context).keys().stream().map(
registryKey -> Suggestion.suggestion(registryKey.toString())).sorted().collect(Collectors.toList()));
}
};
} }
} }
} }
@@ -1,10 +1,10 @@
package com.dfsek.terra.api.event.events.platform; package com.dfsek.terra.api.event.events.platform;
import cloud.commandframework.CommandManager;
import com.dfsek.terra.api.command.CommandSender; import com.dfsek.terra.api.command.CommandSender;
import com.dfsek.terra.api.event.events.Event; import com.dfsek.terra.api.event.events.Event;
import org.incendo.cloud.CommandManager;
public class CommandRegistrationEvent implements Event { public class CommandRegistrationEvent implements Event {
private final CommandManager<CommandSender> commandManager; private final CommandManager<CommandSender> commandManager;
@@ -8,6 +8,7 @@
package com.dfsek.terra.api.util.reflection; package com.dfsek.terra.api.util.reflection;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import sun.misc.Unsafe;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement; import java.lang.reflect.AnnotatedElement;
@@ -26,6 +27,18 @@ import java.util.stream.Stream;
public final class ReflectionUtil { public final class ReflectionUtil {
private static final Unsafe UNSAFE;
static {
try{
final Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
unsafeField.setAccessible(true);
UNSAFE = (Unsafe) unsafeField.get(null);
} catch(NoSuchFieldException | IllegalAccessException e){
throw new RuntimeException(e);
}
}
public static Field[] getFields(@NotNull Class<?> type) { public static Field[] getFields(@NotNull Class<?> type) {
Field[] result = type.getDeclaredFields(); Field[] result = type.getDeclaredFields();
Class<?> parentClass = type.getSuperclass(); Class<?> parentClass = type.getSuperclass();
@@ -35,6 +48,14 @@ public final class ReflectionUtil {
return result; return result;
} }
public static void setFinalField(Object obj, String fieldName, Object value) throws NoSuchFieldException {
Field field = obj.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
long fieldOffset = UNSAFE.objectFieldOffset(field);
UNSAFE.putObject(obj, fieldOffset, value);
}
public static Method[] getMethods(@NotNull Class<?> type) { public static Method[] getMethods(@NotNull Class<?> type) {
Method[] result = type.getDeclaredMethods(); Method[] result = type.getDeclaredMethods();
Class<?> parentClass = type.getSuperclass(); Class<?> parentClass = type.getSuperclass();
Binary file not shown.
+2 -2
View File
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionSha256Sum=9d926787066a081739e8200858338b4a69e837c3a821a33aca9db09dd4a41026 distributionSha256Sum=1541fa36599e12857140465f3c91a97409b4512501c26f9631fb113e392c5bd1
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
networkTimeout=10000 networkTimeout=10000
validateDistributionUrl=true validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
Vendored
+1 -1
View File
@@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop. # Darwin, MinGW, and NonStop.
# #
# (3) This script is generated from the Groovy template # (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project. # within the Gradle project.
# #
# You can find Gradle at https://github.com/gradle/gradle/. # You can find Gradle at https://github.com/gradle/gradle/.
Vendored
+10 -10
View File
@@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute if %ERRORLEVEL% equ 0 goto execute
echo. echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. echo location of your Java installation. 1>&2
goto fail goto fail
@@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute if exist "%JAVA_EXE%" goto execute
echo. echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. echo location of your Java installation. 1>&2
goto fail goto fail
+1 -7
View File
@@ -2,15 +2,9 @@ plugins {
id("xyz.jpenilla.run-paper") version Versions.Bukkit.runPaper id("xyz.jpenilla.run-paper") version Versions.Bukkit.runPaper
} }
repositories {
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") {
name = "Sonatype"
}
}
dependencies { dependencies {
shaded(project(":platforms:bukkit:common")) shaded(project(":platforms:bukkit:common"))
shaded(project(":platforms:bukkit:nms:v1_20_R3", configuration = "reobf")) shaded(project(":platforms:bukkit:nms:v1_21", configuration = "reobf"))
shaded("xyz.jpenilla", "reflection-remapper", Versions.Bukkit.reflectionRemapper) shaded("xyz.jpenilla", "reflection-remapper", Versions.Bukkit.reflectionRemapper)
} }
+1 -1
View File
@@ -11,5 +11,5 @@ dependencies {
shadedApi("com.google.guava", "guava", Versions.Libraries.Internal.guava) shadedApi("com.google.guava", "guava", Versions.Libraries.Internal.guava)
shadedApi("cloud.commandframework", "cloud-paper", Versions.Libraries.cloud) shadedApi("org.incendo", "cloud-paper", Versions.Libraries.cloudPaper)
} }
@@ -17,15 +17,16 @@
package com.dfsek.terra.bukkit; package com.dfsek.terra.bukkit;
import cloud.commandframework.brigadier.CloudBrigadierManager;
import cloud.commandframework.bukkit.CloudBukkitCapabilities;
import cloud.commandframework.execution.CommandExecutionCoordinator;
import cloud.commandframework.paper.PaperCommandManager;
import io.papermc.paper.threadedregions.scheduler.AsyncScheduler; import io.papermc.paper.threadedregions.scheduler.AsyncScheduler;
import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler; import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.incendo.cloud.SenderMapper;
import org.incendo.cloud.brigadier.CloudBrigadierManager;
import org.incendo.cloud.bukkit.CloudBukkitCapabilities;
import org.incendo.cloud.execution.ExecutionCoordinator;
import org.incendo.cloud.paper.LegacyPaperCommandManager;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -71,7 +72,7 @@ public class TerraBukkitPlugin extends JavaPlugin {
} }
try { try {
PaperCommandManager<CommandSender> commandManager = getCommandSenderPaperCommandManager(); LegacyPaperCommandManager<CommandSender> commandManager = getCommandSenderPaperCommandManager();
platform.getEventManager().callEvent(new CommandRegistrationEvent(commandManager)); platform.getEventManager().callEvent(new CommandRegistrationEvent(commandManager));
@@ -91,22 +92,26 @@ public class TerraBukkitPlugin extends JavaPlugin {
} }
@NotNull @NotNull
private PaperCommandManager<CommandSender> getCommandSenderPaperCommandManager() throws Exception { private LegacyPaperCommandManager<CommandSender> getCommandSenderPaperCommandManager() throws Exception {
PaperCommandManager<CommandSender> commandManager = new PaperCommandManager<>(this, // TODO: Update to PaperCommandManager
CommandExecutionCoordinator.simpleCoordinator(), LegacyPaperCommandManager<CommandSender> commandManager = new LegacyPaperCommandManager<>(
BukkitAdapter::adapt, this,
BukkitAdapter::adapt); ExecutionCoordinator.simpleCoordinator(),
if(commandManager.hasCapability(CloudBukkitCapabilities.NATIVE_BRIGADIER)) { SenderMapper.create(
BukkitAdapter::adapt,
BukkitAdapter::adapt
));
if (commandManager.hasCapability(CloudBukkitCapabilities.NATIVE_BRIGADIER)) {
commandManager.registerBrigadier(); commandManager.registerBrigadier();
final CloudBrigadierManager<?, ?> brigManager = commandManager.brigadierManager(); final CloudBrigadierManager<?, ?> brigManager = commandManager.brigadierManager();
if(brigManager != null) { if(brigManager != null) {
brigManager.setNativeNumberSuggestions(false); brigManager.setNativeNumberSuggestions(false);
} }
} } else if (commandManager.hasCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) {
if(commandManager.hasCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) {
commandManager.registerAsynchronousCompletions(); commandManager.registerAsynchronousCompletions();
} }
return commandManager; return commandManager;
} }
@@ -58,7 +58,7 @@ public class BukkitWorldHandle implements WorldHandle {
String entityID = id.toUpperCase(Locale.ROOT).substring(10); String entityID = id.toUpperCase(Locale.ROOT).substring(10);
return new BukkitEntityType(switch(entityID) { return new BukkitEntityType(switch(entityID) {
case "END_CRYSTAL" -> org.bukkit.entity.EntityType.ENDER_CRYSTAL; case "END_CRYSTAL" -> org.bukkit.entity.EntityType.END_CRYSTAL;
case "ENDER_CRYSTAL" -> throw new IllegalArgumentException( case "ENDER_CRYSTAL" -> throw new IllegalArgumentException(
"Invalid entity identifier " + id); // make sure this issue can't happen the other way around. "Invalid entity identifier " + id); // make sure this issue can't happen the other way around.
default -> org.bukkit.entity.EntityType.valueOf(entityID); default -> org.bukkit.entity.EntityType.valueOf(entityID);
@@ -1,6 +1,7 @@
package com.dfsek.terra.bukkit.nms; package com.dfsek.terra.bukkit.nms;
import org.bukkit.Bukkit; import com.dfsek.terra.bukkit.util.VersionUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -8,13 +9,18 @@ import com.dfsek.terra.bukkit.PlatformImpl;
public interface Initializer { public interface Initializer {
String NMS = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; String NMS = VersionUtil.getMinecraftVersionInfo().toString().replace(".", "_");
String TERRA_PACKAGE = Initializer.class.getPackageName(); String TERRA_PACKAGE = Initializer.class.getPackageName();
static boolean init(PlatformImpl platform) { static boolean init(PlatformImpl platform) {
Logger logger = LoggerFactory.getLogger(Initializer.class); Logger logger = LoggerFactory.getLogger(Initializer.class);
try { try {
Class<?> initializerClass = Class.forName(TERRA_PACKAGE + "." + NMS + ".NMSInitializer"); String packageVersion = NMS;
if (NMS.equals("v1_21_1")) {
packageVersion = "v1_21";
}
Class<?> initializerClass = Class.forName(TERRA_PACKAGE + "." + packageVersion + ".NMSInitializer");
try { try {
Initializer initializer = (Initializer) initializerClass.getConstructor().newInstance(); Initializer initializer = (Initializer) initializerClass.getConstructor().newInstance();
initializer.initialize(platform); initializer.initialize(platform);
@@ -77,13 +77,13 @@ public final class VersionUtil {
public static final class MinecraftVersionInfo { public static final class MinecraftVersionInfo {
private static final Logger logger = LoggerFactory.getLogger(MinecraftVersionInfo.class); private static final Logger logger = LoggerFactory.getLogger(MinecraftVersionInfo.class);
private static final Pattern VERSION_PATTERN = Pattern.compile("v?(\\d+)_(\\d+)_R(\\d+)"); private static final Pattern VERSION_PATTERN = Pattern.compile("(\\d+)\\.(\\d+)(?:\\.(\\d+))?");
private final int major; private final int major;
private final int minor; private final int minor;
private final int patch; private final int patch;
private MinecraftVersionInfo() { private MinecraftVersionInfo() {
this(Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]); this(Bukkit.getServer().getBukkitVersion().split("-")[0]);
} }
private MinecraftVersionInfo(int major, int minor, int patch) { private MinecraftVersionInfo(int major, int minor, int patch) {
@@ -97,7 +97,7 @@ public final class VersionUtil {
if(versionMatcher.find()) { if(versionMatcher.find()) {
major = Integer.parseInt(versionMatcher.group(1)); major = Integer.parseInt(versionMatcher.group(1));
minor = Integer.parseInt(versionMatcher.group(2)); minor = Integer.parseInt(versionMatcher.group(2));
patch = Integer.parseInt(versionMatcher.group(3)); patch = versionMatcher.group(3) != null ? Integer.parseInt(versionMatcher.group(3)) : -1;
} else { } else {
logger.warn("Error while parsing minecraft version info. Continuing launch, but setting all versions to -1."); logger.warn("Error while parsing minecraft version info. Continuing launch, but setting all versions to -1.");
@@ -112,7 +112,11 @@ public final class VersionUtil {
if(major == -1 && minor == -1 && patch == -1) if(major == -1 && minor == -1 && patch == -1)
return "Unknown"; return "Unknown";
return String.format("v%d.%d.%d", major, minor, patch); if (patch >= 0) {
return String.format("v%d.%d.%d", major, minor, patch);
} else {
return String.format("v%d.%d", major, minor);
}
} }
public int getMajor() { public int getMajor() {
@@ -1,9 +1,5 @@
apply(plugin = "io.papermc.paperweight.userdev") apply(plugin = "io.papermc.paperweight.userdev")
repositories {
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
dependencies { dependencies {
api(project(":platforms:bukkit:common")) api(project(":platforms:bukkit:common"))
paperDevBundle(Versions.Bukkit.paperDevBundle) paperDevBundle(Versions.Bukkit.paperDevBundle)
@@ -1,15 +1,16 @@
package com.dfsek.terra.bukkit.nms.v1_20_R3; package com.dfsek.terra.bukkit.nms.v1_21;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.mojang.serialization.Lifecycle;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.Holder.Reference; import net.minecraft.core.Holder.Reference;
import net.minecraft.core.MappedRegistry; import net.minecraft.core.MappedRegistry;
import net.minecraft.core.RegistrationInfo;
import net.minecraft.core.WritableRegistry; import net.minecraft.core.WritableRegistry;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey; import net.minecraft.tags.TagKey;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -41,15 +42,15 @@ public class AwfulBukkitHacks {
try { try {
BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome(); BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome();
NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey(); NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey();
ResourceLocation vanillaMinecraftKey = new ResourceLocation(vanillaBukkitKey.getNamespace(), vanillaBukkitKey.getKey()); ResourceLocation vanillaMinecraftKey = ResourceLocation.fromNamespaceAndPath(vanillaBukkitKey.getNamespace(), vanillaBukkitKey.getKey());
Biome platform = NMSBiomeInjector.createBiome(biome, Objects.requireNonNull(biomeRegistry.get(vanillaMinecraftKey))); Biome platform = NMSBiomeInjector.createBiome(biome, Objects.requireNonNull(biomeRegistry.get(vanillaMinecraftKey)));
ResourceKey<Biome> delegateKey = ResourceKey.create( ResourceKey<Biome> delegateKey = ResourceKey.create(
Registries.BIOME, Registries.BIOME,
new ResourceLocation("terra", NMSBiomeInjector.createBiomeID(pack, key)) ResourceLocation.fromNamespaceAndPath("terra", NMSBiomeInjector.createBiomeID(pack, key))
); );
Reference<Biome> holder = biomeRegistry.register(delegateKey, platform, Lifecycle.stable()); Reference<Biome> holder = biomeRegistry.register(delegateKey, platform, RegistrationInfo.BUILT_IN);
Reflection.REFERENCE.invokeBindValue(holder, platform); // IMPORTANT: bind holder. Reflection.REFERENCE.invokeBindValue(holder, platform); // IMPORTANT: bind holder.
platformBiome.getContext().put(new NMSBiomeInfo(delegateKey)); platformBiome.getContext().put(new NMSBiomeInfo(delegateKey));
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_20_R3; package com.dfsek.terra.bukkit.nms.v1_21;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_20_R3; package com.dfsek.terra.bukkit.nms.v1_21;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
@@ -1,6 +1,6 @@
package com.dfsek.terra.bukkit.nms.v1_20_R3; package com.dfsek.terra.bukkit.nms.v1_21;
import com.mojang.serialization.Codec; import com.mojang.serialization.MapCodec;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
@@ -35,8 +35,12 @@ public class NMSBiomeProvider extends BiomeSource {
} }
@Override @Override
protected @NotNull Codec<? extends BiomeSource> codec() { protected @NotNull MapCodec<? extends BiomeSource> codec() {
return 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 @Override
@@ -1,6 +1,6 @@
package com.dfsek.terra.bukkit.nms.v1_20_R3; package com.dfsek.terra.bukkit.nms.v1_21;
import com.mojang.serialization.Codec; import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.server.level.WorldGenRegion; import net.minecraft.server.level.WorldGenRegion;
import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelAccessor;
@@ -19,14 +19,13 @@ import net.minecraft.world.level.levelgen.GenerationStep.Carving;
import net.minecraft.world.level.levelgen.Heightmap.Types; import net.minecraft.world.level.levelgen.Heightmap.Types;
import net.minecraft.world.level.levelgen.RandomState; import net.minecraft.world.level.levelgen.RandomState;
import net.minecraft.world.level.levelgen.blending.Blender; import net.minecraft.world.level.levelgen.blending.Blender;
import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData; import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import com.dfsek.terra.api.config.ConfigPack; import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider; import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
@@ -54,8 +53,8 @@ public class NMSChunkGeneratorDelegate extends ChunkGenerator {
} }
@Override @Override
protected @NotNull Codec<? extends ChunkGenerator> codec() { protected @NotNull MapCodec<? extends ChunkGenerator> codec() {
return ChunkGenerator.CODEC; return MapCodec.assumeMapUnsafe(ChunkGenerator.CODEC);
} }
@Override @Override
@@ -87,10 +86,10 @@ public class NMSChunkGeneratorDelegate extends ChunkGenerator {
} }
@Override @Override
public @NotNull CompletableFuture<ChunkAccess> fillFromNoise(@NotNull Executor executor, @NotNull Blender blender, public CompletableFuture<ChunkAccess> fillFromNoise(@NotNull Blender blender,
@NotNull RandomState noiseConfig, @NotNull RandomState noiseConfig,
@NotNull StructureManager structureAccessor, @NotNull ChunkAccess chunk) { @NotNull StructureManager structureAccessor, @NotNull ChunkAccess chunk) {
return vanilla.fillFromNoise(executor, blender, noiseConfig, structureAccessor, chunk) return vanilla.fillFromNoise(blender, noiseConfig, structureAccessor, chunk)
.thenApply(c -> { .thenApply(c -> {
LevelAccessor level = Reflection.STRUCTURE_MANAGER.getLevel(structureAccessor); LevelAccessor level = Reflection.STRUCTURE_MANAGER.getLevel(structureAccessor);
BiomeProvider biomeProvider = pack.getBiomeProvider(); BiomeProvider biomeProvider = pack.getBiomeProvider();
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_20_R3; package com.dfsek.terra.bukkit.nms.v1_21;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -1,9 +1,14 @@
package com.dfsek.terra.bukkit.nms.v1_20_R3; package com.dfsek.terra.bukkit.nms.v1_21;
import com.dfsek.terra.api.util.reflection.ReflectionUtil;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.chunk.status.WorldGenContext;
import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.world.WorldInitEvent; import org.bukkit.event.world.WorldInitEvent;
@@ -37,8 +42,20 @@ public class NMSInjectListener implements Listener {
ChunkGenerator vanilla = serverWorld.getChunkSource().getGenerator(); ChunkGenerator vanilla = serverWorld.getChunkSource().getGenerator();
NMSBiomeProvider provider = new NMSBiomeProvider(pack.getBiomeProvider(), craftWorld.getSeed()); NMSBiomeProvider provider = new NMSBiomeProvider(pack.getBiomeProvider(), craftWorld.getSeed());
ChunkMap chunkMap = serverWorld.getChunkSource().chunkMap;
WorldGenContext worldGenContext = chunkMap.worldGenContext;
serverWorld.getChunkSource().chunkMap.generator = new NMSChunkGeneratorDelegate(vanilla, pack, provider, craftWorld.getSeed()); try {
ReflectionUtil.setFinalField(chunkMap, "worldGenContext", new WorldGenContext(
worldGenContext.level(),
new NMSChunkGeneratorDelegate(vanilla, pack, provider, craftWorld.getSeed()),
worldGenContext.structureManager(),
worldGenContext.lightEngine(),
worldGenContext.mainThreadMailBox()
));
} catch(NoSuchFieldException e) {
throw new RuntimeException(e);
}
LOGGER.info("Successfully injected into world."); LOGGER.info("Successfully injected into world.");
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_20_R3; package com.dfsek.terra.bukkit.nms.v1_21;
import net.minecraft.world.level.LevelHeightAccessor; import net.minecraft.world.level.LevelHeightAccessor;
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_20_R3; package com.dfsek.terra.bukkit.nms.v1_21;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.Holder.Reference; import net.minecraft.core.Holder.Reference;
@@ -1,4 +1,4 @@
package com.dfsek.terra.bukkit.nms.v1_20_R3; package com.dfsek.terra.bukkit.nms.v1_21;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
@@ -6,7 +6,7 @@ import net.minecraft.resources.ResourceKey;
import net.minecraft.server.dedicated.DedicatedServer; import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_20_R3.CraftServer; import org.bukkit.craftbukkit.CraftServer;
public class RegistryFetcher { public class RegistryFetcher {
+2 -6
View File
@@ -26,8 +26,8 @@ dependencies {
modImplementation("net.fabricmc:fabric-loader:${Versions.Mod.fabricLoader}") modImplementation("net.fabricmc:fabric-loader:${Versions.Mod.fabricLoader}")
modImplementation("cloud.commandframework", "cloud-fabric", Versions.Libraries.cloud) modImplementation("org.incendo", "cloud-fabric", Versions.Libraries.cloudFabric)
include("cloud.commandframework", "cloud-fabric", Versions.Libraries.cloud) include("org.incendo", "cloud-fabric", Versions.Libraries.cloudFabric)
modRuntimeOnly("net.fabricmc.fabric-api", "fabric-api", Versions.Fabric.fabricAPI) modRuntimeOnly("net.fabricmc.fabric-api", "fabric-api", Versions.Fabric.fabricAPI)
} }
@@ -45,10 +45,6 @@ loom {
addonDir(project.file("./run/config/Terra/addons"), tasks.named("configureLaunch").get()) addonDir(project.file("./run/config/Terra/addons"), tasks.named("configureLaunch").get())
tasks { tasks {
compileJava {
options.release.set(17)
}
remapJar { remapJar {
dependsOn("installAddons") dependsOn("installAddons")
@@ -26,9 +26,9 @@
"terra.common.mixins.json" "terra.common.mixins.json"
], ],
"depends": { "depends": {
"fabricloader": ">=0.15.1", "fabricloader": ">=0.16.5",
"java": ">=17", "java": ">=21",
"minecraft": ">=1.20.4", "minecraft": ">=1.20.6",
"fabric": "*" "fabric": "*"
} }
} }
@@ -2,7 +2,7 @@
"required": true, "required": true,
"minVersion": "0.8", "minVersion": "0.8",
"package": "com.dfsek.terra.fabric.mixin", "package": "com.dfsek.terra.fabric.mixin",
"compatibilityLevel": "JAVA_17", "compatibilityLevel": "JAVA_21",
"mixins": [ "mixins": [
], ],
"client": [ "client": [
@@ -2,7 +2,7 @@
"required": true, "required": true,
"minVersion": "0.8", "minVersion": "0.8",
"package": "com.dfsek.terra.forge.mixin", "package": "com.dfsek.terra.forge.mixin",
"compatibilityLevel": "JAVA_17", "compatibilityLevel": "JAVA_21",
"mixins": [ "mixins": [
"lifecycle.NoiseConfigMixin" "lifecycle.NoiseConfigMixin"
], ],
@@ -3,6 +3,7 @@ package com.dfsek.terra.mod;
import com.dfsek.tectonic.api.TypeRegistry; import com.dfsek.tectonic.api.TypeRegistry;
import com.dfsek.tectonic.api.depth.DepthTracker; import com.dfsek.tectonic.api.depth.DepthTracker;
import com.dfsek.tectonic.api.exception.LoadException; import com.dfsek.tectonic.api.exception.LoadException;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup; import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.boss.dragon.EnderDragonFight; import net.minecraft.entity.boss.dragon.EnderDragonFight;
@@ -124,6 +125,8 @@ public abstract class ModPlatform extends AbstractPlatform {
public abstract Registry<MultiNoiseBiomeSourceParameterList> multiNoiseBiomeSourceParameterListRegistry(); public abstract Registry<MultiNoiseBiomeSourceParameterList> multiNoiseBiomeSourceParameterListRegistry();
public abstract Registry<Enchantment> enchantmentRegistry();
@Override @Override
public @NotNull WorldHandle getWorldHandle() { public @NotNull WorldHandle getWorldHandle() {
return worldHandle; return worldHandle;
@@ -133,4 +136,6 @@ public abstract class ModPlatform extends AbstractPlatform {
public @NotNull ItemHandle getItemHandle() { public @NotNull ItemHandle getItemHandle() {
return itemHandle; return itemHandle;
} }
} }
@@ -7,6 +7,7 @@ import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.command.argument.ParticleEffectArgumentType; import net.minecraft.command.argument.ParticleEffectArgumentType;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.world.biome.BiomeParticleConfig; import net.minecraft.world.biome.BiomeParticleConfig;
@@ -27,7 +28,7 @@ public class BiomeParticleConfigTemplate implements ObjectTemplate<BiomeParticle
try { try {
return new BiomeParticleConfig( return new BiomeParticleConfig(
ParticleEffectArgumentType.readParameters(new StringReader(particle), Registries.PARTICLE_TYPE.getReadOnlyWrapper()), ParticleEffectArgumentType.readParameters(new StringReader(particle), (RegistryWrapper.WrapperLookup) Registries.PARTICLE_TYPE.getReadOnlyWrapper()),
probability); probability);
} catch(CommandSyntaxException e) { } catch(CommandSyntaxException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@@ -1,6 +1,7 @@
package com.dfsek.terra.mod.data; package com.dfsek.terra.mod.data;
import com.mojang.serialization.Codec; import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder; import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.dfsek.terra.api.config.ConfigPack; import com.dfsek.terra.api.config.ConfigPack;
@@ -34,19 +35,19 @@ public final class Codecs {
"No such config pack " + "No such config pack " +
id))))); id)))));
public static final Codec<TerraBiomeSource> TERRA_BIOME_SOURCE = RecordCodecBuilder public static final MapCodec<TerraBiomeSource> TERRA_BIOME_SOURCE = RecordCodecBuilder
.create(instance -> instance.group( .mapCodec(instance -> instance.group(
CONFIG_PACK.fieldOf("pack") CONFIG_PACK.fieldOf("pack")
.stable() .stable()
.forGetter(TerraBiomeSource::getPack)) .forGetter(TerraBiomeSource::getPack))
.apply(instance, instance.stable(TerraBiomeSource::new))); .apply(instance, instance.stable(TerraBiomeSource::new)));
public static final Codec<ConstantRange> TERRA_CONSTANT_RANGE = RecordCodecBuilder.create(range -> range.group( public static final Codec<ConstantRange> TERRA_CONSTANT_RANGE = RecordCodecBuilder.mapCodec(range -> range.group(
Codec.INT.fieldOf("min").stable().forGetter(ConstantRange::getMin), Codec.INT.fieldOf("min").stable().forGetter(ConstantRange::getMin),
Codec.INT.fieldOf("max").stable().forGetter(ConstantRange::getMax)).apply(range, range.stable(ConstantRange::new))); Codec.INT.fieldOf("max").stable().forGetter(ConstantRange::getMax)).apply(range, range.stable(ConstantRange::new)));
public static final Codec<GenerationSettings> TERRA_GENERATION_SETTINGS = RecordCodecBuilder public static final Codec<GenerationSettings> TERRA_GENERATION_SETTINGS = RecordCodecBuilder
.create(instance -> instance.group( .mapCodec(instance -> instance.group(
TERRA_CONSTANT_RANGE.fieldOf("height").stable().forGetter(GenerationSettings::height), TERRA_CONSTANT_RANGE.fieldOf("height").stable().forGetter(GenerationSettings::height),
Codec.INT.fieldOf("sea_level").forGetter(GenerationSettings::sealevel), Codec.INT.fieldOf("sea_level").forGetter(GenerationSettings::sealevel),
Codec.BOOL.fieldOf("mob_generation").forGetter(GenerationSettings::mobGeneration), Codec.BOOL.fieldOf("mob_generation").forGetter(GenerationSettings::mobGeneration),
@@ -18,6 +18,7 @@
package com.dfsek.terra.mod.generation; package com.dfsek.terra.mod.generation;
import com.mojang.serialization.Codec; import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.registry.entry.RegistryEntry;
@@ -86,7 +87,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
} }
@Override @Override
protected Codec<? extends net.minecraft.world.gen.chunk.ChunkGenerator> getCodec() { protected MapCodec<? extends net.minecraft.world.gen.chunk.ChunkGenerator> getCodec() {
return Codecs.MINECRAFT_CHUNK_GENERATOR_WRAPPER; return Codecs.MINECRAFT_CHUNK_GENERATOR_WRAPPER;
} }
@@ -107,8 +108,8 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
} }
@Override @Override
public CompletableFuture<Chunk> populateNoise(Executor executor, Blender blender, NoiseConfig noiseConfig, public CompletableFuture<Chunk> populateNoise(Blender blender, NoiseConfig noiseConfig, StructureAccessor structureAccessor,
StructureAccessor structureAccessor, Chunk chunk) { Chunk chunk) {
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {
ProtoWorld world = (ProtoWorld) ((StructureAccessorAccessor) structureAccessor).getWorld(); ProtoWorld world = (ProtoWorld) ((StructureAccessorAccessor) structureAccessor).getWorld();
BiomeProvider biomeProvider = pack.getBiomeProvider(); BiomeProvider biomeProvider = pack.getBiomeProvider();
@@ -18,6 +18,7 @@
package com.dfsek.terra.mod.generation; package com.dfsek.terra.mod.generation;
import com.mojang.serialization.Codec; import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.source.BiomeSource; import net.minecraft.world.biome.source.BiomeSource;
@@ -47,7 +48,7 @@ public class TerraBiomeSource extends BiomeSource {
} }
@Override @Override
protected Codec<? extends BiomeSource> getCodec() { protected MapCodec<? extends BiomeSource> getCodec() {
return Codecs.TERRA_BIOME_SOURCE; return Codecs.TERRA_BIOME_SOURCE;
} }
@@ -25,10 +25,13 @@ import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryWrapper; import net.minecraft.registry.RegistryWrapper;
import net.minecraft.registry.RegistryWrapper.Impl;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.dfsek.terra.api.handle.ItemHandle; import com.dfsek.terra.api.handle.ItemHandle;
import com.dfsek.terra.api.inventory.Item; import com.dfsek.terra.api.inventory.Item;
@@ -43,8 +46,13 @@ public class MinecraftItemHandle implements ItemHandle {
try { try {
return (Item) new ItemStackArgumentType(new CommandRegistryAccess() { return (Item) new ItemStackArgumentType(new CommandRegistryAccess() {
@Override @Override
public <T> RegistryWrapper<T> createWrapper(RegistryKey<? extends Registry<T>> registryRef) { public Stream<RegistryKey<? extends Registry<?>>> streamAllRegistryKeys() {
return CommonPlatform.get().getServer().getRegistryManager().getWrapperOrThrow(registryRef); return CommonPlatform.get().getServer().getRegistryManager().streamAllRegistryKeys();
}
@Override
public <T> Optional<Impl<T>> getOptionalWrapper(RegistryKey<? extends Registry<? extends T>> registryRef) {
return Optional.of(CommonPlatform.get().getServer().getRegistryManager().getWrapperOrThrow(registryRef));
} }
}).parse(new StringReader(data)).getItem(); }).parse(new StringReader(data)).getItem();
} catch(CommandSyntaxException e) { } catch(CommandSyntaxException e) {
@@ -54,11 +62,11 @@ public class MinecraftItemHandle implements ItemHandle {
@Override @Override
public Enchantment getEnchantment(String id) { public Enchantment getEnchantment(String id) {
return (Enchantment) (Registries.ENCHANTMENT.get(Identifier.tryParse(id))); return (Enchantment) (Object) (CommonPlatform.get().enchantmentRegistry().get(Identifier.tryParse(id)));
} }
@Override @Override
public Set<Enchantment> getEnchantments() { public Set<Enchantment> getEnchantments() {
return Registries.ENCHANTMENT.stream().map(enchantment -> (Enchantment) enchantment).collect(Collectors.toSet()); return CommonPlatform.get().enchantmentRegistry().stream().map(enchantment -> (Enchantment) (Object) enchantment).collect(Collectors.toSet());
} }
} }
@@ -48,9 +48,9 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
@Shadow @Shadow
public abstract MobSpawnerLogic getLogic(); public abstract MobSpawnerLogic getLogic();
//method_46408
@Shadow @Shadow
public abstract void method_46408(net.minecraft.entity.EntityType<?> entityType, Random random); public abstract void setEntityType(net.minecraft.entity.EntityType<?> entityType, Random random);
public EntityType terra$getSpawnedType() { public EntityType terra$getSpawnedType() {
return (EntityType) Registries.ENTITY_TYPE.get( return (EntityType) Registries.ENTITY_TYPE.get(
@@ -64,7 +64,7 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
} else { } else {
rand = Random.create(); rand = Random.create();
} }
method_46408((net.minecraft.entity.EntityType<?>) creatureType, rand); setEntityType((net.minecraft.entity.EntityType<?>) creatureType, rand);
} }
public int terra$getDelay() { public int terra$getDelay() {
@@ -3,6 +3,7 @@ package com.dfsek.terra.mod.mixin.implementations.terra.block.state;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.mojang.serialization.MapCodec; import com.mojang.serialization.MapCodec;
import it.unimi.dsi.fastutil.objects.Reference2ObjectArrayMap;
import net.minecraft.block.AbstractBlock.AbstractBlockState; import net.minecraft.block.AbstractBlock.AbstractBlockState;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
@@ -24,7 +25,7 @@ import com.dfsek.terra.mod.mixin.access.StateAccessor;
@Mixin(AbstractBlockState.class) @Mixin(AbstractBlockState.class)
@Implements(@Interface(iface = BlockState.class, prefix = "terra$")) @Implements(@Interface(iface = BlockState.class, prefix = "terra$"))
public abstract class BlockStateMixin extends State<Block, net.minecraft.block.BlockState> { public abstract class BlockStateMixin extends State<Block, net.minecraft.block.BlockState> {
private BlockStateMixin(Block owner, ImmutableMap<net.minecraft.state.property.Property<?>, Comparable<?>> entries, private BlockStateMixin(Block owner, Reference2ObjectArrayMap<net.minecraft.state.property.Property<?>, Comparable<?>> entries,
MapCodec<net.minecraft.block.BlockState> codec) { MapCodec<net.minecraft.block.BlockState> codec) {
super(owner, entries, codec); super(owner, entries, codec);
} }
@@ -39,14 +39,14 @@ public abstract class EntityMixin {
private BlockPos blockPos; private BlockPos blockPos;
@Shadow @Shadow
public abstract void teleport(double destX, double destY, double destZ); public abstract void updatePosition(double destX, double destY, double destZ);
public Vector3 terra$position() { public Vector3 terra$position() {
return MinecraftAdapter.adapt(blockPos); return MinecraftAdapter.adapt(blockPos);
} }
public void terra$position(Vector3 location) { public void terra$position(Vector3 location) {
teleport(location.getX(), location.getY(), location.getZ()); updatePosition(location.getX(), location.getY(), location.getZ());
} }
public ServerWorld terra$world() { public ServerWorld terra$world() {
@@ -30,7 +30,7 @@ import com.dfsek.terra.api.inventory.ItemStack;
@Implements(@Interface(iface = com.dfsek.terra.api.inventory.Item.class, prefix = "terra$")) @Implements(@Interface(iface = com.dfsek.terra.api.inventory.Item.class, prefix = "terra$"))
public abstract class ItemMixin { public abstract class ItemMixin {
@Shadow @Shadow
public abstract int getMaxDamage(); public abstract net.minecraft.item.ItemStack getDefaultStack();
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
public ItemStack terra$newItemStack(int amount) { public ItemStack terra$newItemStack(int amount) {
@@ -38,6 +38,7 @@ public abstract class ItemMixin {
} }
public double terra$getMaxDurability() { public double terra$getMaxDurability() {
return getMaxDamage(); //TODO verify this is correct
return getDefaultStack().getMaxDamage();
} }
} }
@@ -17,9 +17,14 @@
package com.dfsek.terra.mod.mixin.implementations.terra.inventory.item; package com.dfsek.terra.mod.mixin.implementations.terra.inventory.item;
import net.minecraft.component.Component;
import net.minecraft.component.ComponentChanges;
import net.minecraft.component.ComponentMap;
import net.minecraft.component.ComponentMapImpl;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Implements; import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface; import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Intrinsic; import org.spongepowered.asm.mixin.Intrinsic;
@@ -46,7 +51,11 @@ public abstract class ItemStackMixin {
public abstract boolean isDamageable(); public abstract boolean isDamageable();
@Shadow @Shadow
public abstract void setNbt(@Nullable NbtCompound tag); public abstract ComponentMap getComponents();
@Shadow
@Final
private ComponentMapImpl components;
public int terra$getAmount() { public int terra$getAmount() {
return getCount(); return getCount();
@@ -66,7 +75,13 @@ public abstract class ItemStackMixin {
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
public void terra$setItemMeta(ItemMeta meta) { public void terra$setItemMeta(ItemMeta meta) {
setNbt(((ItemStack) (Object) meta).getNbt()); ComponentChanges.Builder builder = ComponentChanges.builder();
this.getComponents().getTypes().forEach(builder::remove);
ComponentMap components = ((ItemStack) (Object) meta).getComponents();
components.forEach(builder::add);
this.components.applyChanges(builder.build());
} }
@Intrinsic @Intrinsic
@@ -17,8 +17,13 @@
package com.dfsek.terra.mod.mixin.implementations.terra.inventory.meta; package com.dfsek.terra.mod.mixin.implementations.terra.inventory.meta;
import com.dfsek.terra.mod.CommonPlatform;
import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.Enchantment;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.entry.RegistryEntryList;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Implements; import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface; import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@@ -28,6 +33,8 @@ import java.util.Objects;
import com.dfsek.terra.api.inventory.ItemStack; import com.dfsek.terra.api.inventory.ItemStack;
import static net.minecraft.enchantment.Enchantment.canBeCombined;
@Mixin(Enchantment.class) @Mixin(Enchantment.class)
@Implements(@Interface(iface = com.dfsek.terra.api.inventory.item.Enchantment.class, prefix = "terra$")) @Implements(@Interface(iface = com.dfsek.terra.api.inventory.item.Enchantment.class, prefix = "terra$"))
@@ -36,7 +43,8 @@ public abstract class EnchantmentMixin {
public abstract boolean isAcceptableItem(net.minecraft.item.ItemStack stack); public abstract boolean isAcceptableItem(net.minecraft.item.ItemStack stack);
@Shadow @Shadow
public abstract boolean canCombine(Enchantment other); @Final
private RegistryEntryList<Enchantment> exclusiveSet;
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
public boolean terra$canEnchantItem(ItemStack itemStack) { public boolean terra$canEnchantItem(ItemStack itemStack) {
@@ -44,10 +52,10 @@ public abstract class EnchantmentMixin {
} }
public boolean terra$conflictsWith(com.dfsek.terra.api.inventory.item.Enchantment other) { public boolean terra$conflictsWith(com.dfsek.terra.api.inventory.item.Enchantment other) {
return !canCombine((Enchantment) other); return canBeCombined(RegistryEntry.of((Enchantment) (Object) this), RegistryEntry.of((Enchantment) (Object) other));
} }
public String terra$getID() { public String terra$getID() {
return Objects.requireNonNull(Registries.ENCHANTMENT.getId((Enchantment) (Object) this)).toString(); return Objects.requireNonNull(CommonPlatform.get().enchantmentRegistry().getId((Enchantment) (Object) this)).toString();
} }
} }
@@ -17,10 +17,12 @@
package com.dfsek.terra.mod.mixin.implementations.terra.inventory.meta; package com.dfsek.terra.mod.mixin.implementations.terra.inventory.meta;
import net.minecraft.component.type.ItemEnchantmentsComponent;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList; import net.minecraft.nbt.NbtList;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.entry.RegistryEntry;
import org.spongepowered.asm.mixin.Implements; import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface; import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Intrinsic; import org.spongepowered.asm.mixin.Intrinsic;
@@ -42,13 +44,13 @@ public abstract class ItemStackMetaMixin {
public abstract boolean hasEnchantments(); public abstract boolean hasEnchantments();
@Shadow @Shadow
public abstract NbtList getEnchantments(); public abstract ItemEnchantmentsComponent getEnchantments();
@Shadow @Shadow
public abstract void addEnchantment(net.minecraft.enchantment.Enchantment enchantment, int level); public abstract void addEnchantment(RegistryEntry<net.minecraft.enchantment.Enchantment> enchantment, int level);
public void terra$addEnchantment(Enchantment enchantment, int level) { public void terra$addEnchantment(Enchantment enchantment, int level) { ;
addEnchantment((net.minecraft.enchantment.Enchantment) enchantment, level); addEnchantment(RegistryEntry.of((net.minecraft.enchantment.Enchantment) (Object) enchantment), level);
} }
@Intrinsic(displace = true) @Intrinsic(displace = true)
@@ -56,9 +58,10 @@ public abstract class ItemStackMetaMixin {
if(!hasEnchantments()) return Collections.emptyMap(); if(!hasEnchantments()) return Collections.emptyMap();
Map<Enchantment, Integer> map = new HashMap<>(); Map<Enchantment, Integer> map = new HashMap<>();
getEnchantments().forEach(enchantment -> { ItemEnchantmentsComponent enchantments = getEnchantments();
NbtCompound eTag = (NbtCompound) enchantment; enchantments.getEnchantments().forEach(enchantment -> {
map.put((Enchantment) Registries.ENCHANTMENT.get(eTag.getInt("id")), eTag.getInt("lvl")); net.minecraft.enchantment.Enchantment enchantmentValue = enchantment.value();
map.put((Enchantment) (Object) enchantmentValue, enchantments.getLevel(RegistryEntry.of(enchantmentValue)));
}); });
return map; return map;
} }
@@ -17,12 +17,16 @@
package com.dfsek.terra.mod.mixin.implementations.terra.world; package com.dfsek.terra.mod.mixin.implementations.terra.world;
import com.dfsek.terra.mod.mixin.invoke.FluidBlockInvoker;
import net.minecraft.block.FluidBlock; import net.minecraft.block.FluidBlock;
import net.minecraft.fluid.Fluid; import net.minecraft.fluid.Fluid;
import net.minecraft.util.collection.BoundedRegionArray;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ChunkRegion; import net.minecraft.world.ChunkRegion;
import net.minecraft.world.WorldAccess; import net.minecraft.world.WorldAccess;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkGenerationStep;
import net.minecraft.world.chunk.ChunkStatus; import net.minecraft.world.chunk.ChunkStatus;
import net.minecraft.world.tick.MultiTickScheduler; import net.minecraft.world.tick.MultiTickScheduler;
import net.minecraft.world.tick.OrderedTick; import net.minecraft.world.tick.OrderedTick;
@@ -74,10 +78,9 @@ public abstract class ChunkRegionMixin {
@Inject(at = @At("RETURN"), @Inject(at = @At("RETURN"),
method = "<init>(Lnet/minecraft/server/world/ServerWorld;Ljava/util/List;Lnet/minecraft/world/chunk/ChunkStatus;I)V") method = "<init>(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/util/collection/BoundedRegionArray;Lnet/minecraft/world/chunk/ChunkGenerationStep;Lnet/minecraft/world/chunk/Chunk;)V")
public void injectConstructor(net.minecraft.server.world.ServerWorld world, List<net.minecraft.world.chunk.Chunk> list, public void injectConstructor(net.minecraft.server.world.ServerWorld world, BoundedRegionArray chunks,
ChunkStatus chunkStatus, int i, ChunkGenerationStep generationStep, Chunk centerPos, CallbackInfo ci) {
CallbackInfo ci) {
this.terra$config = ((ServerWorld) world).getPack(); this.terra$config = ((ServerWorld) world).getPack();
} }
@@ -88,7 +91,7 @@ public abstract class ChunkRegionMixin {
((ChunkRegion) (Object) this).setBlockState(pos, (net.minecraft.block.BlockState) data, physics ? 3 : 1042); ((ChunkRegion) (Object) this).setBlockState(pos, (net.minecraft.block.BlockState) data, physics ? 3 : 1042);
if(physics && ((net.minecraft.block.BlockState) data).getBlock() instanceof FluidBlock) { if(physics && ((net.minecraft.block.BlockState) data).getBlock() instanceof FluidBlock) {
fluidTickScheduler.scheduleTick( fluidTickScheduler.scheduleTick(
OrderedTick.create(((FluidBlock) ((net.minecraft.block.BlockState) data).getBlock()).getFluidState( OrderedTick.create((((FluidBlockInvoker) ((net.minecraft.block.BlockState) data).getBlock())).invokeGetFluidState(
(net.minecraft.block.BlockState) data).getFluid(), pos)); (net.minecraft.block.BlockState) data).getFluid(), pos));
} }
} }
@@ -0,0 +1,14 @@
package com.dfsek.terra.mod.mixin.invoke;
import net.minecraft.block.BlockState;
import net.minecraft.block.FluidBlock;
import net.minecraft.fluid.FluidState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(FluidBlock.class)
public interface FluidBlockInvoker {
@Invoker("getFluidState")
public FluidState invokeGetFluidState(BlockState state);
}
@@ -3,9 +3,12 @@ package com.dfsek.terra.mod.mixin.lifecycle;
import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.ReloadableRegistries;
import net.minecraft.server.DataPackContents; import net.minecraft.server.DataPackContents;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -16,11 +19,15 @@ import com.dfsek.terra.mod.util.TagUtil;
@Mixin(DataPackContents.class) @Mixin(DataPackContents.class)
public class DataPackContentsMixin { public class DataPackContentsMixin {
@Shadow
@Final
private ReloadableRegistries.Lookup reloadableRegistries;
/* /*
* #refresh populates all tags in the registries * #refresh populates all tags in the registries
*/ */
@Inject(method = "refresh(Lnet/minecraft/registry/DynamicRegistryManager;)V", at = @At("RETURN")) @Inject(method = "refresh()V", at = @At("RETURN"))
private void injectReload(DynamicRegistryManager dynamicRegistryManager, CallbackInfo ci) { private void injectReload(CallbackInfo ci) {
DynamicRegistryManager.Immutable dynamicRegistryManager = this.reloadableRegistries.getRegistryManager();
TagUtil.registerWorldPresetTags(dynamicRegistryManager.get(RegistryKeys.WORLD_PRESET)); TagUtil.registerWorldPresetTags(dynamicRegistryManager.get(RegistryKeys.WORLD_PRESET));
Registry<Biome> biomeRegistry = dynamicRegistryManager.get(RegistryKeys.BIOME); Registry<Biome> biomeRegistry = dynamicRegistryManager.get(RegistryKeys.BIOME);
@@ -47,7 +47,7 @@ public class PresetUtil {
platform.multiNoiseBiomeSourceParameterListRegistry(); platform.multiNoiseBiomeSourceParameterListRegistry();
Identifier generatorID = Identifier.of("terra", pack.getID().toLowerCase(Locale.ROOT) + "/" + pack.getNamespace().toLowerCase( Identifier generatorID = Identifier.tryParse("terra:" + pack.getID().toLowerCase(Locale.ROOT) + "/" + pack.getNamespace().toLowerCase(
Locale.ROOT)); Locale.ROOT));
PRESETS.add(generatorID); PRESETS.add(generatorID);
@@ -2,3 +2,4 @@ accessWidener v1 named
accessible class net/minecraft/world/biome/Biome$Weather accessible class net/minecraft/world/biome/Biome$Weather
accessible class net/minecraft/world/gen/WorldPresets$Registrar accessible class net/minecraft/world/gen/WorldPresets$Registrar
accessible field net/minecraft/world/dimension/DimensionOptionsRegistryHolder VANILLA_KEYS Ljava/util/Set; accessible field net/minecraft/world/dimension/DimensionOptionsRegistryHolder VANILLA_KEYS Ljava/util/Set;
accessible class net/minecraft/registry/RegistryLoader$Loader
@@ -2,7 +2,7 @@
"required": true, "required": true,
"minVersion": "0.8", "minVersion": "0.8",
"package": "com.dfsek.terra.mod.mixin", "package": "com.dfsek.terra.mod.mixin",
"compatibilityLevel": "JAVA_17", "compatibilityLevel": "JAVA_21",
"mixins": [ "mixins": [
"access.BiomeAccessor", "access.BiomeAccessor",
"access.MobSpawnerLogicAccessor", "access.MobSpawnerLogicAccessor",
+1 -5
View File
@@ -15,7 +15,7 @@ dependencies {
minecraft("com.mojang:minecraft:${Versions.Mod.minecraft}") minecraft("com.mojang:minecraft:${Versions.Mod.minecraft}")
mappings("net.fabricmc:yarn:${Versions.Mod.yarn}:v2") mappings("net.fabricmc:yarn:${Versions.Mod.yarn}:v2")
modImplementation("cloud.commandframework", "cloud-fabric", Versions.Libraries.cloud) { modImplementation("org.incendo", "cloud-fabric", Versions.Libraries.cloudFabric) {
exclude("net.fabricmc") exclude("net.fabricmc")
exclude("net.fabricmc.fabric-api") exclude("net.fabricmc.fabric-api")
} }
@@ -30,10 +30,6 @@ loom {
} }
tasks { tasks {
compileJava {
options.release.set(17)
}
remapJar { remapJar {
inputFile.set(shadowJar.get().archiveFile) inputFile.set(shadowJar.get().archiveFile)
} }
@@ -1,8 +1,9 @@
package com.dfsek.terra.lifecycle; package com.dfsek.terra.lifecycle;
import cloud.commandframework.execution.CommandExecutionCoordinator;
import cloud.commandframework.fabric.FabricServerCommandManager;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import org.incendo.cloud.SenderMapper;
import org.incendo.cloud.execution.ExecutionCoordinator;
import org.incendo.cloud.fabric.FabricServerCommandManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -17,9 +18,10 @@ public final class LifecycleEntryPoint {
logger.info("Initializing Terra {} mod...", modName); logger.info("Initializing Terra {} mod...", modName);
FabricServerCommandManager<CommandSender> manager = new FabricServerCommandManager<>( FabricServerCommandManager<CommandSender> manager = new FabricServerCommandManager<>(
CommandExecutionCoordinator.simpleCoordinator(), ExecutionCoordinator.simpleCoordinator(),
SenderMapper.create(
serverCommandSource -> (CommandSender) serverCommandSource, serverCommandSource -> (CommandSender) serverCommandSource,
commandSender -> (ServerCommandSource) commandSender commandSender -> (ServerCommandSource) commandSender)
); );
@@ -5,6 +5,7 @@ import ca.solostudios.strata.parser.tokenizer.ParseException;
import ca.solostudios.strata.version.Version; import ca.solostudios.strata.version.Version;
import net.minecraft.MinecraftVersion; import net.minecraft.MinecraftVersion;
import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
@@ -35,7 +36,7 @@ public abstract class LifecyclePlatform extends ModPlatform {
private static final AtomicReference<Registry<DimensionType>> DIMENSIONS = new AtomicReference<>(); private static final AtomicReference<Registry<DimensionType>> DIMENSIONS = new AtomicReference<>();
private static final AtomicReference<Registry<ChunkGeneratorSettings>> SETTINGS = new AtomicReference<>(); private static final AtomicReference<Registry<ChunkGeneratorSettings>> SETTINGS = new AtomicReference<>();
private static final AtomicReference<Registry<MultiNoiseBiomeSourceParameterList>> NOISE = new AtomicReference<>(); private static final AtomicReference<Registry<MultiNoiseBiomeSourceParameterList>> NOISE = new AtomicReference<>();
private static final AtomicReference<Registry<Enchantment>> ENCHANTMENT = new AtomicReference<>();
private static final AtomicReference<DynamicRegistryManager.Immutable> DYNAMIC_REGISTRY_MANAGER = new AtomicReference<>(); private static final AtomicReference<DynamicRegistryManager.Immutable> DYNAMIC_REGISTRY_MANAGER = new AtomicReference<>();
private static MinecraftServer server; private static MinecraftServer server;
@@ -47,11 +48,13 @@ public abstract class LifecyclePlatform extends ModPlatform {
public static void setRegistries(Registry<Biome> biomeRegistry, public static void setRegistries(Registry<Biome> biomeRegistry,
Registry<DimensionType> dimensionTypeRegistry, Registry<DimensionType> dimensionTypeRegistry,
Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry,
Registry<MultiNoiseBiomeSourceParameterList> multiNoiseBiomeSourceParameterListRegistry) { Registry<MultiNoiseBiomeSourceParameterList> multiNoiseBiomeSourceParameterListRegistry,
Registry<Enchantment> enchantmentRegistry) {
BIOMES.set(biomeRegistry); BIOMES.set(biomeRegistry);
DIMENSIONS.set(dimensionTypeRegistry); DIMENSIONS.set(dimensionTypeRegistry);
SETTINGS.set(chunkGeneratorSettingsRegistry); SETTINGS.set(chunkGeneratorSettingsRegistry);
NOISE.set(multiNoiseBiomeSourceParameterListRegistry); NOISE.set(multiNoiseBiomeSourceParameterListRegistry);
ENCHANTMENT.set(enchantmentRegistry);
} }
public static void setDynamicRegistryManager(DynamicRegistryManager.Immutable dynamicRegistryManager) { public static void setDynamicRegistryManager(DynamicRegistryManager.Immutable dynamicRegistryManager) {
@@ -74,7 +77,7 @@ public abstract class LifecyclePlatform extends ModPlatform {
if(server != null) { if(server != null) {
BiomeUtil.registerBiomes(server.getRegistryManager().get(RegistryKeys.BIOME)); BiomeUtil.registerBiomes(server.getRegistryManager().get(RegistryKeys.BIOME));
server.reloadResources(server.getDataPackManager().getNames()).exceptionally(throwable -> { server.reloadResources(server.getDataPackManager().getEnabledIds()).exceptionally(throwable -> {
LOGGER.warn("Failed to execute reload", throwable); LOGGER.warn("Failed to execute reload", throwable);
return null; return null;
}).join(); }).join();
@@ -146,5 +149,10 @@ public abstract class LifecyclePlatform extends ModPlatform {
return NOISE.get(); return NOISE.get();
} }
@Override
public Registry<Enchantment> enchantmentRegistry() {
return ENCHANTMENT.get();
}
protected abstract Collection<BaseAddon> getPlatformMods(); protected abstract Collection<BaseAddon> getPlatformMods();
} }
@@ -1,11 +1,15 @@
package com.dfsek.terra.lifecycle.mixin.lifecycle; package com.dfsek.terra.lifecycle.mixin.lifecycle;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.DynamicRegistryManager.Immutable;
import net.minecraft.registry.MutableRegistry; import net.minecraft.registry.MutableRegistry;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.RegistryLoader; import net.minecraft.registry.RegistryLoader;
import net.minecraft.registry.RegistryLoader.Loader;
import net.minecraft.world.biome.source.MultiNoiseBiomeSourceParameterList; import net.minecraft.world.biome.source.MultiNoiseBiomeSourceParameterList;
import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.WorldPreset; import net.minecraft.world.gen.WorldPreset;
@@ -14,7 +18,9 @@ import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Redirect;
import java.util.List; import java.util.List;
@@ -25,48 +31,62 @@ import com.dfsek.terra.lifecycle.LifecyclePlatform;
import com.dfsek.terra.lifecycle.util.LifecycleUtil; import com.dfsek.terra.lifecycle.util.LifecycleUtil;
import com.dfsek.terra.lifecycle.util.RegistryHack; import com.dfsek.terra.lifecycle.util.RegistryHack;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(RegistryLoader.class) @Mixin(RegistryLoader.class)
public class RegistryLoaderMixin { public class RegistryLoaderMixin {
private static boolean initialized = false;
@Shadow @Shadow
@Final @Final
private static Logger LOGGER; private static Logger LOGGER;
// @Inject(
// method = "load(Lnet/minecraft/registry/RegistryLoader$RegistryLoadable;Lnet/minecraft/registry/DynamicRegistryManager;Ljava/util/List;)Lnet/minecraft/registry/DynamicRegistryManager$Immutable;",
// at = @At(
// value = "INVOKE",
// target = "Ljava/util/List;forEach(Ljava/util/function/Consumer;)V",
// ordinal = 1 // we want right after the first forEach
// )
// )
// private static void grabRegiestry(RegistryLoader.RegistryLoadable loadable, DynamicRegistryManager baseRegistryManager,
// List<RegistryLoader.Entry<?>> entries, CallbackInfoReturnable<Immutable> cir) {
// entries.forEach((loader) -> {
// Registry<?> registry = loader.registry();
// }
@Redirect( @Redirect(
method = "load(Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/registry/DynamicRegistryManager;Ljava/util/List;)" + method = "load(Lnet/minecraft/registry/RegistryLoader$RegistryLoadable;Lnet/minecraft/registry/DynamicRegistryManager;Ljava/util/List;)Lnet/minecraft/registry/DynamicRegistryManager$Immutable;",
"Lnet/minecraft/registry/DynamicRegistryManager$Immutable;",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "Ljava/util/List;forEach(Ljava/util/function/Consumer;)V", target = "Ljava/util/List;forEach(Ljava/util/function/Consumer;)V",
ordinal = 1 // we want right after the first forEach ordinal = 1 // we want right after the first forEach
) )
) )
private static void grabManager(List<Pair<MutableRegistry<?>, Object>> instance, Consumer<Pair<MutableRegistry<?>, Object>> consumer) { private static void grabManager(List<RegistryLoader.Loader<?>> instance, Consumer<? super Loader<?>> consumer) {
instance.forEach(mutableRegistryObjectPair -> LOGGER.debug("{}: {} entries", if (!initialized) {
mutableRegistryObjectPair.getFirst().toString(), extractRegistry(instance, RegistryKeys.BIOME).ifPresent(
mutableRegistryObjectPair.getFirst().size()) biomes -> { // this redirect triggers twice, second time only with dimension registry. don't try extraction second time
); MutableRegistry<DimensionType> dimensionTypes = extractRegistry(instance, RegistryKeys.DIMENSION_TYPE).orElseThrow();
extractRegistry(instance, RegistryKeys.BIOME).ifPresent( MutableRegistry<WorldPreset> worldPresets = extractRegistry(instance, RegistryKeys.WORLD_PRESET).orElseThrow();
biomes -> { // this redirect triggers twice, second time only with dimension registry. don't try extraction second time MutableRegistry<ChunkGeneratorSettings> chunkGeneratorSettings = extractRegistry(instance,
MutableRegistry<DimensionType> dimensionTypes = extractRegistry(instance, RegistryKeys.DIMENSION_TYPE).orElseThrow(); RegistryKeys.CHUNK_GENERATOR_SETTINGS).orElseThrow();
MutableRegistry<WorldPreset> worldPresets = extractRegistry(instance, RegistryKeys.WORLD_PRESET).orElseThrow(); MutableRegistry<MultiNoiseBiomeSourceParameterList> multiNoiseBiomeSourceParameterLists = extractRegistry(instance,
MutableRegistry<ChunkGeneratorSettings> chunkGeneratorSettings = extractRegistry(instance, RegistryKeys.MULTI_NOISE_BIOME_SOURCE_PARAMETER_LIST).orElseThrow();
RegistryKeys.CHUNK_GENERATOR_SETTINGS).orElseThrow(); MutableRegistry<Enchantment> enchantments = extractRegistry(instance, RegistryKeys.ENCHANTMENT).orElseThrow();
MutableRegistry<MultiNoiseBiomeSourceParameterList> multiNoiseBiomeSourceParameterLists = extractRegistry(instance,
RegistryKeys.MULTI_NOISE_BIOME_SOURCE_PARAMETER_LIST).orElseThrow();
LifecyclePlatform.setRegistries(biomes, dimensionTypes, chunkGeneratorSettings, multiNoiseBiomeSourceParameterLists); LifecyclePlatform.setRegistries(biomes, dimensionTypes, chunkGeneratorSettings, multiNoiseBiomeSourceParameterLists, enchantments);
LifecycleUtil.initialize(biomes, worldPresets); LifecycleUtil.initialize(biomes, worldPresets);
}); });
initialized = true;
}
instance.forEach(consumer); instance.forEach(consumer);
} }
@Unique
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static <T> Optional<MutableRegistry<T>> extractRegistry(List<Pair<MutableRegistry<?>, Object>> instance, private static <T> Optional<MutableRegistry<T>> extractRegistry(List<RegistryLoader.Loader<?>> instance,
RegistryKey<Registry<T>> key) { RegistryKey<Registry<T>> key) {
List<? extends MutableRegistry<?>> matches = instance List<? extends MutableRegistry<?>> matches = instance
.stream() .stream().map(RegistryLoader.Loader::registry)
.map(Pair::getFirst)
.filter(r -> r.getKey().equals(key)) .filter(r -> r.getKey().equals(key))
.toList(); .toList();
if(matches.size() > 1) { if(matches.size() > 1) {
@@ -74,7 +94,7 @@ public class RegistryLoaderMixin {
} else if(matches.isEmpty()) { } else if(matches.isEmpty()) {
return Optional.empty(); return Optional.empty();
} }
MutableRegistry<T> registry = (MutableRegistry<T>) matches.get(0); MutableRegistry<T> registry = (MutableRegistry<T>) matches.getFirst();
((RegistryHack) registry).terra_bind(); ((RegistryHack) registry).terra_bind();
return Optional.of(registry); return Optional.of(registry);
} }
@@ -13,18 +13,14 @@ import com.dfsek.terra.mod.util.MinecraftUtil;
@Mixin(SaveLoading.class) @Mixin(SaveLoading.class)
public class SaveLoadingMixin { public class SaveLoadingMixin {
@ModifyArg( @ModifyArg(
method = "method_42097(Lnet/minecraft/registry/DynamicRegistryManager$Immutable;" + method = "load(Lnet/minecraft/server/SaveLoading$ServerConfig;Lnet/minecraft/server/SaveLoading$LoadContextSupplier;Lnet/minecraft/server/SaveLoading$SaveApplierFactory;Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;",
"Lnet/minecraft/server/SaveLoading$SaveApplierFactory;Lnet/minecraft/resource/LifecycledResourceManager;" +
"Lnet/minecraft/registry/CombinedDynamicRegistries;Lnet/minecraft/server/SaveLoading$LoadContext;" +
"Lnet/minecraft/server/DataPackContents;)Ljava/lang/Object;",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "Lnet/minecraft/server/DataPackContents;refresh(Lnet/minecraft/registry/DynamicRegistryManager;)V" target = "Lnet/minecraft/registry/RegistryLoader;loadFromResource(Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/registry/DynamicRegistryManager;Ljava/util/List;)Lnet/minecraft/registry/DynamicRegistryManager$Immutable;" ),
), index = 1
index = 0
) )
private static DynamicRegistryManager grabManager(DynamicRegistryManager in) { private static DynamicRegistryManager grabManager(DynamicRegistryManager registryManager) {
MinecraftUtil.registerFlora(in.get(RegistryKeys.BIOME)); MinecraftUtil.registerFlora(registryManager.get(RegistryKeys.BIOME));
return in; return registryManager;
} }
} }
@@ -58,7 +58,7 @@ public final class BiomeUtil {
net.minecraft.world.biome.Biome minecraftBiome = MinecraftUtil.createBiome(biome, Objects.requireNonNull(registry.get(vanilla)), net.minecraft.world.biome.Biome minecraftBiome = MinecraftUtil.createBiome(biome, Objects.requireNonNull(registry.get(vanilla)),
vanillaBiomeProperties); vanillaBiomeProperties);
Identifier identifier = new Identifier("terra", MinecraftUtil.createBiomeID(pack, id)); Identifier identifier = Identifier.of("terra", MinecraftUtil.createBiomeID(pack, id));
if(registry.containsId(identifier)) { if(registry.containsId(identifier)) {
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(MinecraftUtil.getEntry(registry, identifier) ((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(MinecraftUtil.getEntry(registry, identifier)
@@ -15,7 +15,7 @@ public final class RegistryUtil {
public static void register() { public static void register() {
MinecraftUtil.registerIntProviderTypes(); MinecraftUtil.registerIntProviderTypes();
Registry.register(Registries.CHUNK_GENERATOR, new Identifier("terra:terra"), Codecs.MINECRAFT_CHUNK_GENERATOR_WRAPPER); Registry.register(Registries.CHUNK_GENERATOR, Identifier.of("terra:terra"), Codecs.MINECRAFT_CHUNK_GENERATOR_WRAPPER);
Registry.register(Registries.BIOME_SOURCE, new Identifier("terra:terra"), Codecs.TERRA_BIOME_SOURCE); Registry.register(Registries.BIOME_SOURCE, Identifier.of("terra:terra"), Codecs.TERRA_BIOME_SOURCE);
} }
} }
@@ -2,7 +2,7 @@
"required": true, "required": true,
"minVersion": "0.8", "minVersion": "0.8",
"package": "com.dfsek.terra.lifecycle.mixin", "package": "com.dfsek.terra.lifecycle.mixin",
"compatibilityLevel": "JAVA_17", "compatibilityLevel": "JAVA_21",
"mixins": [ "mixins": [
"NoiseConfigMixin", "NoiseConfigMixin",
"RegistryEntryReferenceInvoker", "RegistryEntryReferenceInvoker",
@@ -2,7 +2,7 @@
"required": true, "required": true,
"minVersion": "0.8", "minVersion": "0.8",
"package": "com.dfsek.terra.quilt.mixin", "package": "com.dfsek.terra.quilt.mixin",
"compatibilityLevel": "JAVA_17", "compatibilityLevel": "JAVA_21",
"mixins": [ "mixins": [
], ],
"client": [ "client": [