diff --git a/fabric/src/main/java/ca/spottedleaf/moonrise/fabric/FabricHooks.java b/fabric/src/main/java/ca/spottedleaf/moonrise/fabric/FabricHooks.java index 99220340..fa6c818d 100644 --- a/fabric/src/main/java/ca/spottedleaf/moonrise/fabric/FabricHooks.java +++ b/fabric/src/main/java/ca/spottedleaf/moonrise/fabric/FabricHooks.java @@ -168,4 +168,9 @@ public long configAutoSaveInterval() { public int configMaxAutoSavePerTick() { return ConfigHolder.getConfig().chunkSaving.maxAutoSaveChunksPerTick; } + + @Override + public boolean configFixMC159283() { + return ConfigHolder.getConfig().bugFixes.fixMC159283; + } } diff --git a/neoforge/src/main/java/ca/spottedleaf/moonrise/neoforge/NeoForgeHooks.java b/neoforge/src/main/java/ca/spottedleaf/moonrise/neoforge/NeoForgeHooks.java index cc6fd38b..67f8d160 100644 --- a/neoforge/src/main/java/ca/spottedleaf/moonrise/neoforge/NeoForgeHooks.java +++ b/neoforge/src/main/java/ca/spottedleaf/moonrise/neoforge/NeoForgeHooks.java @@ -201,4 +201,9 @@ public long configAutoSaveInterval() { public int configMaxAutoSavePerTick() { return ConfigHolder.getConfig().chunkSaving.maxAutoSaveChunksPerTick; } + + @Override + public boolean configFixMC159283() { + return ConfigHolder.getConfig().bugFixes.fixMC159283; + } } diff --git a/src/main/java/ca/spottedleaf/moonrise/common/PlatformHooks.java b/src/main/java/ca/spottedleaf/moonrise/common/PlatformHooks.java index e98eaddf..2389c6cb 100644 --- a/src/main/java/ca/spottedleaf/moonrise/common/PlatformHooks.java +++ b/src/main/java/ca/spottedleaf/moonrise/common/PlatformHooks.java @@ -86,6 +86,8 @@ public void addToGetEntities(final Level world, final EntityT public int configMaxAutoSavePerTick(); + public boolean configFixMC159283(); + public static final class Holder { private Holder() { } diff --git a/src/main/java/ca/spottedleaf/moonrise/common/config/moonrise/MoonriseConfig.java b/src/main/java/ca/spottedleaf/moonrise/common/config/moonrise/MoonriseConfig.java index 22147327..183e5095 100644 --- a/src/main/java/ca/spottedleaf/moonrise/common/config/moonrise/MoonriseConfig.java +++ b/src/main/java/ca/spottedleaf/moonrise/common/config/moonrise/MoonriseConfig.java @@ -232,5 +232,23 @@ public static final class BugFixes { section = BUG_FIX_SECTION ) public boolean fixMC224294 = true; + + @Serializable( + serializedKey = "fix-MC-159283", + comment = """ + Fixes https://bugs.mojang.com/browse/MC-159283. This fixes a bug resulting in the end islands + not properly generating at far enough distances in the end. Note that toggling this config option + will not affect already generated areas. + This configuration has two options: + true -> Fixes the end islands generation. This is different from Vanilla behavior. + false -> Does not fix the end islands generation. This is the same behavior as Vanilla. + """ + ) + @ClothConfig( + tooltip = "tooltip.moonrise.fixMC159283", + fieldKeyName = "option.moonrise.fixMC159283", + section = BUG_FIX_SECTION + ) + public boolean fixMC159283 = false; } } diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/end_island/DensityFunctions$EndIslandDensityFunctionMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/end_island/DensityFunctions$EndIslandDensityFunctionMixin.java new file mode 100644 index 00000000..a9ec01b6 --- /dev/null +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/end_island/DensityFunctions$EndIslandDensityFunctionMixin.java @@ -0,0 +1,35 @@ +package ca.spottedleaf.moonrise.mixin.end_island; + +import ca.spottedleaf.moonrise.common.PlatformHooks; +import com.llamalad7.mixinextras.sugar.Local; +import net.minecraft.world.level.levelgen.DensityFunctions; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(DensityFunctions.EndIslandDensityFunction.class) +abstract class DensityFunctions$EndIslandDensityFunctionMixin { + + /** + * @reason Fix MC-159283 by avoiding overflow in the distance calculation. + * See the bug report for the issue description. + * @author Spottedleaf + */ + @Redirect( + method = "getHeightValue", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/util/Mth;sqrt(F)F", + ordinal = 0 + ) + ) + private static float fixMC159283(final float input, + @Local(ordinal = 0, argsOnly = true) final int x, + @Local(ordinal = 1, argsOnly = true) final int z) { + if (PlatformHooks.get().configFixMC159283()) { + return (float)Math.sqrt((double)((long)x * (long)x + (long)z * (long)z)); + } else { + return (float)Math.sqrt((double)(float)(x * x + z * z)); + } + } +} diff --git a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/NewChunkHolder.java b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/NewChunkHolder.java index 7a5f3be6..39449c4e 100644 --- a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/NewChunkHolder.java +++ b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/NewChunkHolder.java @@ -840,10 +840,10 @@ UnloadState unloadStage1() { // chunk state this.currentChunk = null; this.currentGenStatus = null; - this.lastChunkCompletion = null; for (int i = 0; i < this.chunkCompletions.length; ++i) { - CHUNK_COMPLETION_ARRAY_HANDLE.setVolatile(this.chunkCompletions, i, (ChunkCompletion)null); + CHUNK_COMPLETION_ARRAY_HANDLE.setRelease(this.chunkCompletions, i, (ChunkCompletion)null); } + this.lastChunkCompletion = null; // entity chunk state this.entityChunk = null; this.pendingEntityChunk = null; diff --git a/src/main/resources/assets/moonrise/lang/en_us.json b/src/main/resources/assets/moonrise/lang/en_us.json index 12cc4c18..eec313d3 100644 --- a/src/main/resources/assets/moonrise/lang/en_us.json +++ b/src/main/resources/assets/moonrise/lang/en_us.json @@ -1,17 +1,19 @@ { - "title.moonrise.config": "Moonrise Config", - "category.moonrise.bugfixes": "Bug Fixes", - "tooltip.moonrise.fixMC224294": "Fixes lava being double ticked during random block ticking.", - "option.moonrise.fixMC224294": "Fix MC-224294", - "category.moonrise.chunksystem": "Chunk System", - "tooltip.moonrise.populatorparallelism": "Allows populators to run in parallel. May set to true if any worldgen affecting mods are safe to run populators in parallel.", - "option.moonrise.populatorparallelism": "World Generation Populator Parallelism", - "tooltip.moonrise.iothreads": "Set the number of I/O threads for RegionFile operations. Only increase if I/O is a confirmed bottleneck and you are on SSDs.", - "option.moonrise.iothreads": "RegionFile I/O Threads", - "tooltip.moonrise.workerthreads": "Sets the number of threads to use for chunk generation,loading and clientside chunk rendering.", - "option.moonrise.workerthreads": "Chunk Generation / Rendering Worker Threads", - "tooltip.moonrise.genrate": "Sets the maximum number of chunks to generate per second.", - "option.moonrise.genrate": "Maximum Chunk Generate Rate", - "tooltip.moonrise.loadrate": "Sets the maximum number of chunks to load per second.", - "option.moonrise.loadrate": "Maximum Chunk Load Rate" -} \ No newline at end of file + "title.moonrise.config": "Moonrise Config", + "category.moonrise.bugfixes": "Bug Fixes", + "tooltip.moonrise.fixMC224294": "Fixes lava being double ticked during random block ticking.", + "option.moonrise.fixMC224294": "Fix MC-224294", + "category.moonrise.chunksystem": "Chunk System", + "tooltip.moonrise.populatorparallelism": "Allows populators to run in parallel. May set to true if any worldgen affecting mods are safe to run populators in parallel.", + "option.moonrise.populatorparallelism": "World Generation Populator Parallelism", + "tooltip.moonrise.iothreads": "Set the number of I/O threads for RegionFile operations. Only increase if I/O is a confirmed bottleneck and you are on SSDs.", + "option.moonrise.iothreads": "RegionFile I/O Threads", + "tooltip.moonrise.workerthreads": "Sets the number of threads to use for chunk generation,loading and clientside chunk rendering.", + "option.moonrise.workerthreads": "Chunk Generation / Rendering Worker Threads", + "tooltip.moonrise.genrate": "Sets the maximum number of chunks to generate per second.", + "option.moonrise.genrate": "Maximum Chunk Generate Rate", + "tooltip.moonrise.loadrate": "Sets the maximum number of chunks to load per second.", + "option.moonrise.loadrate": "Maximum Chunk Load Rate", + "tooltip.moonrise.fixMC159283": "Fixes end islands not generating far away in the end. Does not affect already generated areas.", + "option.moonrise.fixMC159283": "Fix MC-159283" +} diff --git a/src/main/resources/moonrise.accesswidener b/src/main/resources/moonrise.accesswidener index e5f0e764..a4a93326 100644 --- a/src/main/resources/moonrise.accesswidener +++ b/src/main/resources/moonrise.accesswidener @@ -289,3 +289,7 @@ accessible method net/minecraft/world/level/chunk/storage/RegionFile write (Lnet # RegionFile$ChunkBuffer accessible class net/minecraft/world/level/chunk/storage/RegionFile$ChunkBuffer + + +# DensityFunctions$EndIslandDensityFunction +accessible class net/minecraft/world/level/levelgen/DensityFunctions$EndIslandDensityFunction diff --git a/src/main/resources/moonrise.mixins.json b/src/main/resources/moonrise.mixins.json index da29746c..6d6d77a8 100644 --- a/src/main/resources/moonrise.mixins.json +++ b/src/main/resources/moonrise.mixins.json @@ -76,6 +76,7 @@ "collisions.VoxelShapeMixin", "command.CommandsMixin", "config.MinecraftServerMixin", + "end_island.DensityFunctions$EndIslandDensityFunctionMixin", "entity_tracker.ChunkMapMixin", "entity_tracker.EntityMixin", "entity_tracker.TrackedEntityMixin",