From 7fe69638c5744e927b69528b6a02c9b403d27062 Mon Sep 17 00:00:00 2001 From: Awakened Redstone <40528665+Awakened-Redstone@users.noreply.github.com> Date: Sun, 12 May 2024 06:44:05 -0300 Subject: [PATCH] chore: Port to 1.20.5/1.20.6 (#44) * chore: Port to 1.20.5 and probably break something important * chore: Fix logger message * chore: Fix logger message Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> * chore: Fix commented line Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> * chore: Undo static removal Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> * chore: Uncomment and port recipe manager Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> * chore: Remove try catch Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> * chore: Better handle test command errors Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> * chore: Use overworld dimension to get proper world height Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> * chore: Use 1.20.5 Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> * chore: Remove unused imports Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> * chore: Sort actions the same order as on SimpleRegistry#add and remove from entryToRawId Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> * fix: Don't remove the value twice Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> * chore: Cleanup code Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> * chore: Finally get this mixin to work, mod compat unknown Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> * chore: Remove comment Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> * chore: Remove polymer-reg-sync-manipulator No difference was noticed with and without it Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> * chore: Use fabric-api for an easier to understand mod resolution error Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> * chore: Bump mod version Bump the mod version as the PR has a small behavior change (RuntimeWorldConfig.java:78) Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> * fix: Require MC 1.20.5+ Oops, I forgot about this Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> * chore: Java 21 I missed some stuff Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> * chore: 1.20.6 Update to 1.20.6, bumping mc ver as modders should use it over 1.20.5, not bumping required mc ver for compatibility Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> * fix SAVE_PROPERTIES_PREDICATE dimension option encoding of runtime worlds --------- Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> Co-authored-by: LCLP --- .github/workflows/build.yml | 2 +- .github/workflows/release.yml | 2 +- build.gradle | 10 +-- gradle.properties | 10 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 0 .../nucleoid/fantasy/RuntimeWorldConfig.java | 5 +- .../nucleoid/fantasy/RuntimeWorldManager.java | 5 +- .../mixin/ServerChunkManagerMixin.java | 2 +- .../fantasy/mixin/ServerWorldMixin.java | 2 + .../mixin/ThreadedAnvilChunkStorageMixin.java | 2 - .../mixin/registry/DimensionOptionsMixin.java | 6 +- .../DimensionOptionsRegistryHolderMixin.java | 20 ----- .../mixin/registry/SimpleRegistryMixin.java | 47 ++++++----- .../mixin/registry/WorldGenSettingsMixin.java | 21 +++++ .../fantasy/util/FilteredRegistry.java | 17 ++-- .../fantasy/util/VoidChunkGenerator.java | 21 +++-- src/main/resources/fabric.mod.json | 8 +- src/main/resources/fantasy.mixins.json | 6 +- .../nucleoid/fantasy/test/CustomWorld.java | 5 +- .../fantasy/test/FantasyInitializer.java | 84 ++++++++++++------- 21 files changed, 151 insertions(+), 126 deletions(-) mode change 100644 => 100755 gradlew delete mode 100644 src/main/java/xyz/nucleoid/fantasy/mixin/registry/DimensionOptionsRegistryHolderMixin.java create mode 100644 src/main/java/xyz/nucleoid/fantasy/mixin/registry/WorldGenSettingsMixin.java diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 70db019..071a47d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,7 +22,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v1 with: - java-version: 17 + java-version: 21 - name: Grant execute permission for gradlew run: chmod +x gradlew diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9d3f8a6..af082f0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,7 +24,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v1 with: - java-version: 17 + java-version: 21 - name: Grant execute permission for gradlew run: chmod +x gradlew diff --git a/build.gradle b/build.gradle index fa06c3b..6e5fb6d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,10 @@ plugins { - id 'fabric-loom' version '1.4.+' + id 'fabric-loom' version '1.6.+' id 'maven-publish' } -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 +sourceCompatibility = JavaVersion.VERSION_21 +targetCompatibility = JavaVersion.VERSION_21 archivesBaseName = project.archives_base_name version = project.mod_version + "+" + project.minecraft_version @@ -47,8 +47,6 @@ dependencies { modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - modLocalRuntime "eu.pb4:polymer-reg-sync-manipulator:0.7.0+1.20.3-rc1" - testmodImplementation sourceSets.main.output } @@ -62,7 +60,7 @@ processResources { tasks.withType(JavaCompile).configureEach { it.options.encoding = "UTF-8" - it.options.release = 17 + it.options.release = 21 } java { diff --git a/gradle.properties b/gradle.properties index 4a5a17a..6971fcf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,14 +3,14 @@ org.gradle.jvmargs=-Xmx2G # Fabric Properties -minecraft_version=1.20.4 -yarn_mappings=1.20.4+build.1 -loader_version=0.15.0 +minecraft_version=1.20.6 +yarn_mappings=1.20.6+build.1 +loader_version=0.15.10 # Mod Properties -mod_version=0.5.0 +mod_version=0.5.1 maven_group=xyz.nucleoid archives_base_name=fantasy # Dependencies -fabric_version=0.91.1+1.20.4 +fabric_version=0.97.8+1.20.6 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3fa8f86..b82aa23 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldConfig.java b/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldConfig.java index 069a0bc..4307b25 100644 --- a/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldConfig.java +++ b/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldConfig.java @@ -72,9 +72,10 @@ public RuntimeWorldConfig setGenerator(ChunkGenerator generator) { this.generator = generator; return this; } - + public RuntimeWorldConfig setShouldTickTime(boolean shouldTickTime) { this.shouldTickTime = shouldTickTime; + this.gameRules.set(GameRules.DO_DAYLIGHT_CYCLE, shouldTickTime); return this; } @@ -167,7 +168,7 @@ public ChunkGenerator getGenerator() { public RuntimeWorld.Constructor getWorldConstructor() { return this.worldConstructor; } - + public boolean shouldTickTime() { return this.shouldTickTime; } diff --git a/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldManager.java b/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldManager.java index 293bff0..59f99b6 100644 --- a/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldManager.java +++ b/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldManager.java @@ -1,16 +1,15 @@ package xyz.nucleoid.fantasy; -import com.mojang.serialization.Lifecycle; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents; import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.SimpleRegistry; +import net.minecraft.registry.entry.RegistryEntryInfo; import net.minecraft.server.MinecraftServer; import net.minecraft.server.world.ServerWorld; import net.minecraft.text.Text; import net.minecraft.util.ProgressListener; -import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.dimension.DimensionOptions; import net.minecraft.world.level.storage.LevelStorage; @@ -43,7 +42,7 @@ RuntimeWorld add(RegistryKey worldKey, RuntimeWorldConfig config, Runtime var key = RegistryKey.of(RegistryKeys.DIMENSION, worldKey.getValue()); if(!dimensionsRegistry.contains(key)) { - dimensionsRegistry.add(key, options, Lifecycle.stable()); + dimensionsRegistry.add(key, options, RegistryEntryInfo.DEFAULT); } ((RemoveFromRegistry) dimensionsRegistry).fantasy$setFrozen(isFrozen); diff --git a/src/main/java/xyz/nucleoid/fantasy/mixin/ServerChunkManagerMixin.java b/src/main/java/xyz/nucleoid/fantasy/mixin/ServerChunkManagerMixin.java index a4379f7..2cdc559 100644 --- a/src/main/java/xyz/nucleoid/fantasy/mixin/ServerChunkManagerMixin.java +++ b/src/main/java/xyz/nucleoid/fantasy/mixin/ServerChunkManagerMixin.java @@ -14,7 +14,7 @@ public class ServerChunkManagerMixin { @Shadow @Final - private ServerWorld world; + ServerWorld world; @Inject(method = "executeQueuedTasks", at = @At("HEAD"), cancellable = true) private void executeQueuedTasks(CallbackInfoReturnable ci) { diff --git a/src/main/java/xyz/nucleoid/fantasy/mixin/ServerWorldMixin.java b/src/main/java/xyz/nucleoid/fantasy/mixin/ServerWorldMixin.java index 26a8fae..6ec4fe3 100644 --- a/src/main/java/xyz/nucleoid/fantasy/mixin/ServerWorldMixin.java +++ b/src/main/java/xyz/nucleoid/fantasy/mixin/ServerWorldMixin.java @@ -19,6 +19,7 @@ @Mixin(ServerWorld.class) public abstract class ServerWorldMixin implements FantasyWorldAccess { + @Unique private static final int TICK_TIMEOUT = 20 * 15; @Unique @@ -53,6 +54,7 @@ private void tick(BooleanSupplier shouldKeepTicking, CallbackInfo ci) { return shouldTick || this.fantasy$tickTimeout > 0; } + @Unique private boolean isWorldEmpty() { return this.getPlayers().isEmpty() && this.getChunkManager().getLoadedChunkCount() <= 0; } diff --git a/src/main/java/xyz/nucleoid/fantasy/mixin/ThreadedAnvilChunkStorageMixin.java b/src/main/java/xyz/nucleoid/fantasy/mixin/ThreadedAnvilChunkStorageMixin.java index b350f45..ef000a1 100644 --- a/src/main/java/xyz/nucleoid/fantasy/mixin/ThreadedAnvilChunkStorageMixin.java +++ b/src/main/java/xyz/nucleoid/fantasy/mixin/ThreadedAnvilChunkStorageMixin.java @@ -5,7 +5,6 @@ import net.minecraft.server.world.ThreadedAnvilChunkStorage; import net.minecraft.world.gen.chunk.ChunkGenerator; import net.minecraft.world.gen.chunk.ChunkGeneratorSettings; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -14,7 +13,6 @@ @Mixin(ThreadedAnvilChunkStorage.class) public class ThreadedAnvilChunkStorageMixin { @Shadow - @Final private ChunkGenerator chunkGenerator; @WrapOperation(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/gen/chunk/ChunkGeneratorSettings;createMissingSettings()Lnet/minecraft/world/gen/chunk/ChunkGeneratorSettings;")) diff --git a/src/main/java/xyz/nucleoid/fantasy/mixin/registry/DimensionOptionsMixin.java b/src/main/java/xyz/nucleoid/fantasy/mixin/registry/DimensionOptionsMixin.java index 93c5001..d34dfee 100644 --- a/src/main/java/xyz/nucleoid/fantasy/mixin/registry/DimensionOptionsMixin.java +++ b/src/main/java/xyz/nucleoid/fantasy/mixin/registry/DimensionOptionsMixin.java @@ -7,10 +7,8 @@ @Mixin(DimensionOptions.class) public class DimensionOptionsMixin implements FantasyDimensionOptions { - @Unique - private boolean fantasy$save = true; - @Unique - private boolean fantasy$saveProperties = true; + @Unique private boolean fantasy$save = true; + @Unique private boolean fantasy$saveProperties = true; @Override public void fantasy$setSave(boolean value) { diff --git a/src/main/java/xyz/nucleoid/fantasy/mixin/registry/DimensionOptionsRegistryHolderMixin.java b/src/main/java/xyz/nucleoid/fantasy/mixin/registry/DimensionOptionsRegistryHolderMixin.java deleted file mode 100644 index 116aa1a..0000000 --- a/src/main/java/xyz/nucleoid/fantasy/mixin/registry/DimensionOptionsRegistryHolderMixin.java +++ /dev/null @@ -1,20 +0,0 @@ -package xyz.nucleoid.fantasy.mixin.registry; - -import net.minecraft.registry.Registry; -import net.minecraft.world.dimension.DimensionOptions; -import net.minecraft.world.dimension.DimensionOptionsRegistryHolder; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArg; -import xyz.nucleoid.fantasy.FantasyDimensionOptions; -import xyz.nucleoid.fantasy.util.FilteredRegistry; - -import java.util.function.Function; - -@Mixin(DimensionOptionsRegistryHolder.class) -public class DimensionOptionsRegistryHolderMixin { - @ModifyArg(method = "method_45516", at = @At(value = "INVOKE", target = "Lcom/mojang/serialization/MapCodec;forGetter(Ljava/util/function/Function;)Lcom/mojang/serialization/codecs/RecordCodecBuilder;")) - private static Function> fantasy$swapRegistryGetter(Function> getter) { - return (x) -> new FilteredRegistry<>(getter.apply(x), FantasyDimensionOptions.SAVE_PROPERTIES_PREDICATE); - } -} diff --git a/src/main/java/xyz/nucleoid/fantasy/mixin/registry/SimpleRegistryMixin.java b/src/main/java/xyz/nucleoid/fantasy/mixin/registry/SimpleRegistryMixin.java index b3fe3ce..61ec656 100644 --- a/src/main/java/xyz/nucleoid/fantasy/mixin/registry/SimpleRegistryMixin.java +++ b/src/main/java/xyz/nucleoid/fantasy/mixin/registry/SimpleRegistryMixin.java @@ -1,43 +1,44 @@ package xyz.nucleoid.fantasy.mixin.registry; -import com.mojang.serialization.Lifecycle; +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import com.mojang.logging.LogUtils; import it.unimi.dsi.fastutil.objects.ObjectList; import it.unimi.dsi.fastutil.objects.Reference2IntMap; +import net.minecraft.registry.MutableRegistry; +import net.minecraft.registry.Registry; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.SimpleRegistry; import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.registry.entry.RegistryEntryInfo; +import net.minecraft.registry.entry.RegistryEntryOwner; import net.minecraft.util.Identifier; -import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; import xyz.nucleoid.fantasy.RemoveFromRegistry; -import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; +import java.util.UUID; +import java.util.stream.Stream; @Mixin(SimpleRegistry.class) -public abstract class SimpleRegistryMixin implements RemoveFromRegistry { +public abstract class SimpleRegistryMixin implements RemoveFromRegistry, MutableRegistry { + @Unique private static final Logger fantasy$LOGGER = LogUtils.getLogger(); @Shadow @Final private Map> valueToEntry; - @Shadow @Final private Map> idToEntry; - @Shadow @Final private Map, RegistryEntry.Reference> keyToEntry; - - @Shadow @Final private Map entryToLifecycle; - + @Shadow @Final private Map, RegistryEntryInfo> keyToEntryInfo; @Shadow @Final private ObjectList> rawIdToEntry; - @Shadow @Final private Reference2IntMap entryToRawId; - - @Shadow public abstract Optional> getEntry(int rawId); - + @Shadow @Final RegistryKey> key; @Shadow private boolean frozen; - @Shadow @Nullable private List> cachedEntries; - @Override public boolean fantasy$remove(T entry) { var registryEntry = this.valueToEntry.get(entry); @@ -47,18 +48,15 @@ public abstract class SimpleRegistryMixin implements RemoveFromRegistry { } try { - this.rawIdToEntry.set(rawId, null); - this.idToEntry.remove(registryEntry.registryKey().getValue()); this.keyToEntry.remove(registryEntry.registryKey()); - this.entryToLifecycle.remove(entry); + this.idToEntry.remove(registryEntry.registryKey().getValue()); this.valueToEntry.remove(entry); - if (this.cachedEntries != null) { - this.cachedEntries.remove(registryEntry); - } + this.rawIdToEntry.set(rawId, null); + this.keyToEntryInfo.remove(this.key); return true; } catch (Throwable e) { - e.printStackTrace(); + fantasy$LOGGER.error("Could not remove entry", e); return false; } } @@ -78,4 +76,9 @@ public abstract class SimpleRegistryMixin implements RemoveFromRegistry { public boolean fantasy$isFrozen() { return this.frozen; } + + @ModifyReturnValue(method = "streamEntries", at = @At("RETURN")) + public Stream> fixEntryStream(Stream> original) { + return original.filter(Objects::nonNull); + } } diff --git a/src/main/java/xyz/nucleoid/fantasy/mixin/registry/WorldGenSettingsMixin.java b/src/main/java/xyz/nucleoid/fantasy/mixin/registry/WorldGenSettingsMixin.java new file mode 100644 index 0000000..6bfd865 --- /dev/null +++ b/src/main/java/xyz/nucleoid/fantasy/mixin/registry/WorldGenSettingsMixin.java @@ -0,0 +1,21 @@ +package xyz.nucleoid.fantasy.mixin.registry; + +import com.google.common.collect.Maps; +import net.minecraft.world.dimension.DimensionOptionsRegistryHolder; +import net.minecraft.world.level.WorldGenSettings; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArg; +import xyz.nucleoid.fantasy.FantasyDimensionOptions; + +@Mixin(WorldGenSettings.class) +public class WorldGenSettingsMixin { + + @ModifyArg(method = "encode(Lcom/mojang/serialization/DynamicOps;Lnet/minecraft/world/gen/GeneratorOptions;Lnet/minecraft/world/dimension/DimensionOptionsRegistryHolder;)Lcom/mojang/serialization/DataResult;", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/WorldGenSettings;(Lnet/minecraft/world/gen/GeneratorOptions;Lnet/minecraft/world/dimension/DimensionOptionsRegistryHolder;)V"), index = 1) + private static DimensionOptionsRegistryHolder fantasy$wrapWorldGenSettings(DimensionOptionsRegistryHolder original) { + var dimensions = original.dimensions(); + var saveDimensions = Maps.filterEntries(dimensions, entry -> FantasyDimensionOptions.SAVE_PROPERTIES_PREDICATE.test(entry.getValue())); + + return new DimensionOptionsRegistryHolder(saveDimensions); + } +} diff --git a/src/main/java/xyz/nucleoid/fantasy/util/FilteredRegistry.java b/src/main/java/xyz/nucleoid/fantasy/util/FilteredRegistry.java index a11325d..c748efa 100644 --- a/src/main/java/xyz/nucleoid/fantasy/util/FilteredRegistry.java +++ b/src/main/java/xyz/nucleoid/fantasy/util/FilteredRegistry.java @@ -34,17 +34,17 @@ public Registry getSource() { @Nullable @Override public Identifier getId(T value) { - return check.test(value) ? this.source.getId(value) : null; + return this.check.test(value) ? this.source.getId(value) : null; } @Override public Optional> getKey(T entry) { - return check.test(entry) ? this.source.getKey(entry) : Optional.empty(); + return this.check.test(entry) ? this.source.getKey(entry) : Optional.empty(); } @Override public int getRawId(@Nullable T value) { - return check.test(value) ? this.source.getRawId(value) : -1; + return this.check.test(value) ? this.source.getRawId(value) : -1; } @Nullable @@ -67,12 +67,7 @@ public T get(@Nullable RegistryKey key) { @Nullable @Override public T get(@Nullable Identifier id) { - return this.get(id); - } - - @Override - public Lifecycle getEntryLifecycle(T entry) { - return this.source.getEntryLifecycle(entry); + return this.source.get(id); } @Override @@ -82,7 +77,7 @@ public Lifecycle getLifecycle() { @Override public Set getIds() { - return this.getIds(); + return this.source.getIds(); } @Override @@ -174,6 +169,6 @@ public void populateTags(Map, List>> tagEntries) { @NotNull @Override public Iterator iterator() { - return Iterators.filter(this.source.iterator(), e -> this.check.test(e)); + return Iterators.filter(this.source.iterator(), this.check::test); } } diff --git a/src/main/java/xyz/nucleoid/fantasy/util/VoidChunkGenerator.java b/src/main/java/xyz/nucleoid/fantasy/util/VoidChunkGenerator.java index fe916ad..458bef7 100644 --- a/src/main/java/xyz/nucleoid/fantasy/util/VoidChunkGenerator.java +++ b/src/main/java/xyz/nucleoid/fantasy/util/VoidChunkGenerator.java @@ -1,7 +1,9 @@ package xyz.nucleoid.fantasy.util; +import com.mojang.datafixers.kinds.Applicative; import com.mojang.datafixers.util.Pair; import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.block.BlockState; import net.minecraft.entity.SpawnGroup; @@ -46,11 +48,9 @@ import java.util.stream.Stream; public class VoidChunkGenerator extends ChunkGenerator { - public static final Codec CODEC = RecordCodecBuilder.create(instance -> { - return instance.group( - Biome.REGISTRY_CODEC.stable().fieldOf("biome").forGetter(g -> g.biome) - ).apply(instance, instance.stable(VoidChunkGenerator::new)); - }); + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Biome.REGISTRY_CODEC.stable().fieldOf("biome").forGetter(VoidChunkGenerator::getBiome) + ).apply(instance, instance.stable(VoidChunkGenerator::new))); private static final VerticalBlockSample EMPTY_SAMPLE = new VerticalBlockSample(0, new BlockState[0]); @@ -82,12 +82,12 @@ public double maxValue() { @Override public CodecHolder getCodecHolder() { - return CodecHolder.of(Codec.unit(this)); + return CodecHolder.of(MapCodec.unit(this)); } }; public static final MultiNoiseUtil.MultiNoiseSampler EMPTY_SAMPLER = new MultiNoiseUtil.MultiNoiseSampler(ZERO_DENSITY_FUNCTION, ZERO_DENSITY_FUNCTION, ZERO_DENSITY_FUNCTION, ZERO_DENSITY_FUNCTION, ZERO_DENSITY_FUNCTION, ZERO_DENSITY_FUNCTION, Collections.emptyList()); - + public VoidChunkGenerator(RegistryEntry biome) { super(new FixedBiomeSource(biome)); this.biome = biome; @@ -115,10 +115,13 @@ public VoidChunkGenerator(MinecraftServer server, Identifier biome) { this(server.getRegistryManager().get(RegistryKeys.BIOME), RegistryKey.of(RegistryKeys.BIOME, biome)); } @Override - protected Codec getCodec() { + protected MapCodec getCodec() { return CODEC; } - + + protected RegistryEntry getBiome() { + return this.biome; + } @Override public void carve(ChunkRegion chunkRegion, long seed, NoiseConfig noiseConfig, BiomeAccess world, StructureAccessor structureAccessor, Chunk chunk, GenerationStep.Carver carverStep) { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 31b39e4..b1dbc36 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -19,9 +19,9 @@ } }, "depends": { - "fabricloader": ">=0.14.23", - "minecraft": ">=1.20.3-", - "fabric-lifecycle-events-v1": "*", - "java": ">=17" + "fabricloader": ">=0.15.10", + "minecraft": ">=1.20.5-", + "fabric-api": "*", + "java": ">=21" } } diff --git a/src/main/resources/fantasy.mixins.json b/src/main/resources/fantasy.mixins.json index 8d1c304..890ca99 100644 --- a/src/main/resources/fantasy.mixins.json +++ b/src/main/resources/fantasy.mixins.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8", "package": "xyz.nucleoid.fantasy.mixin", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "mixins": [ "MinecraftServerAccess", "MinecraftServerMixin", @@ -10,8 +10,8 @@ "ServerWorldMixin", "ThreadedAnvilChunkStorageMixin", "registry.DimensionOptionsMixin", - "registry.DimensionOptionsRegistryHolderMixin", - "registry.SimpleRegistryMixin" + "registry.SimpleRegistryMixin", + "registry.WorldGenSettingsMixin" ], "injectors": { "defaultRequire": 1 diff --git a/src/testmod/java/xyz/nucleoid/fantasy/test/CustomWorld.java b/src/testmod/java/xyz/nucleoid/fantasy/test/CustomWorld.java index 88fbdb0..c122f63 100644 --- a/src/testmod/java/xyz/nucleoid/fantasy/test/CustomWorld.java +++ b/src/testmod/java/xyz/nucleoid/fantasy/test/CustomWorld.java @@ -11,10 +11,11 @@ public class CustomWorld extends RuntimeWorld { private long dynSeed; - private static final RecipeManager RECIPE_MANAGER = new RecipeManager(); + private final RecipeManager recipeManager; protected CustomWorld(MinecraftServer server, RegistryKey registryKey, RuntimeWorldConfig config, Style style) { super(server, registryKey, config, style); + this.recipeManager = new RecipeManager(server.getRegistryManager()); } @@ -26,7 +27,7 @@ public void tick(BooleanSupplier shouldKeepTicking) { @Override public RecipeManager getRecipeManager() { - return RECIPE_MANAGER; + return this.recipeManager; } @Override diff --git a/src/testmod/java/xyz/nucleoid/fantasy/test/FantasyInitializer.java b/src/testmod/java/xyz/nucleoid/fantasy/test/FantasyInitializer.java index 71cefb4..3714715 100644 --- a/src/testmod/java/xyz/nucleoid/fantasy/test/FantasyInitializer.java +++ b/src/testmod/java/xyz/nucleoid/fantasy/test/FantasyInitializer.java @@ -1,16 +1,19 @@ package xyz.nucleoid.fantasy.test; +import com.mojang.logging.LogUtils; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.dimension.v1.FabricDimensions; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.minecraft.command.argument.IdentifierArgumentType; import net.minecraft.registry.RegistryKeys; +import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.math.Vec3d; import net.minecraft.util.profiler.Profiler; import net.minecraft.world.TeleportTarget; +import org.slf4j.Logger; import xyz.nucleoid.fantasy.Fantasy; import xyz.nucleoid.fantasy.RuntimeWorldConfig; import xyz.nucleoid.fantasy.RuntimeWorldHandle; @@ -23,6 +26,7 @@ import static net.minecraft.server.command.CommandManager.literal; public final class FantasyInitializer implements ModInitializer { + private static final Logger LOGGER = LogUtils.getLogger(); private HashMap worlds = new HashMap<>(); @Override @@ -41,62 +45,84 @@ public void onInitialize() { dispatcher.register(literal("fantasy_open").then( argument("name", IdentifierArgumentType.identifier()) .executes((context -> { + ServerCommandSource source = context.getSource(); try { - var t = System.currentTimeMillis(); + + var ref = new Object() { + long t = System.currentTimeMillis(); + }; + var id = IdentifierArgumentType.getIdentifier(context, "name"); - var x = Fantasy.get(context.getSource().getServer()).getOrOpenPersistentWorld( + var x = Fantasy.get(source.getServer()).getOrOpenPersistentWorld( id, new RuntimeWorldConfig() - .setGenerator(context.getSource().getServer().getOverworld().getChunkManager().getChunkGenerator()) + .setGenerator(source.getServer().getOverworld().getChunkManager().getChunkGenerator()) + .setDimensionType(source.getServer().getOverworld().getDimensionEntry()) .setSeed(id.hashCode()) ); - { - var text = Text.literal("WorldCreate: " + (System.currentTimeMillis() - t)); - context.getSource().sendFeedback(() -> text, false); + + source.sendFeedback(() -> Text.literal("WorldCreate: " + (System.currentTimeMillis() - ref.t)), false); + + this.worlds.put(id, x); + + ref.t = System.currentTimeMillis(); + if (source.getEntity() != null) { + FabricDimensions.teleport(source.getEntity(), x.asWorld(), new TeleportTarget(new Vec3d(0, 100, 0), Vec3d.ZERO, 0, 0)); } - worlds.put(id, x); - - t = System.currentTimeMillis(); - FabricDimensions.teleport(context.getSource().getEntity(), x.asWorld(), new TeleportTarget(new Vec3d(0, 100 ,0) , Vec3d.ZERO, 0, 0)); - { - var text = Text.literal("Teleport: " + (System.currentTimeMillis() - t)); - context.getSource().sendFeedback(() -> text, false); - } } catch (Throwable e) { - e.printStackTrace(); - } - return 0; + source.sendFeedback(() -> Text.literal("Teleport: " + (System.currentTimeMillis() - ref.t)), false); + return 1; + } catch (Throwable e) { + LOGGER.error("Failed to open world", e); + source.sendError(Text.literal("Failed to open world")); + return 0; + } })) )); dispatcher.register(literal("fantasy_delete").then( argument("name", IdentifierArgumentType.identifier()) - .executes((context -> { + .executes(context -> { + ServerCommandSource source = context.getSource(); try { var id = IdentifierArgumentType.getIdentifier(context, "name"); - worlds.get(id).delete(); - worlds.remove(id); + if (this.worlds.get(id) == null) { + source.sendError(Text.literal("This world does not exist")); + return 0; + } + this.worlds.get(id).delete(); + this.worlds.remove(id); + + source.sendFeedback(() -> Text.literal("World \"" + id + "\" deleted"), true); } catch (Throwable e) { - e.printStackTrace(); + LOGGER.error("Failed to delete world", e); + source.sendError(Text.literal("Failed to delete world")); } - return 0; - })) + return 1; + }) )); dispatcher.register(literal("fantasy_unload").then( argument("name", IdentifierArgumentType.identifier()) - .executes((context -> { + .executes(context -> { + ServerCommandSource source = context.getSource(); try { var id = IdentifierArgumentType.getIdentifier(context, "name"); - worlds.get(id).unload(); - worlds.remove(id); + if (this.worlds.get(id) == null) { + source.sendError(Text.literal("This world does not exist")); + return 0; + } + this.worlds.get(id).unload(); + this.worlds.remove(id); + source.sendFeedback(() -> Text.literal("World \"" + id + "\" unloaded"), true); } catch (Throwable e) { - e.printStackTrace(); + LOGGER.error("Failed to unload world", e); + source.sendError(Text.literal("Failed to unload world")); } - return 0; - })) + return 1; + }) )); })); }