Skip to content

Commit

Permalink
Config option to fix end island generation at far distances
Browse files Browse the repository at this point in the history
  • Loading branch information
Spottedleaf committed Aug 31, 2024
1 parent bc3743c commit 37ca0e7
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,9 @@ public long configAutoSaveInterval() {
public int configMaxAutoSavePerTick() {
return ConfigHolder.getConfig().chunkSaving.maxAutoSaveChunksPerTick;
}

@Override
public boolean configFixMC159283() {
return ConfigHolder.getConfig().bugFixes.fixMC159283;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,9 @@ public long configAutoSaveInterval() {
public int configMaxAutoSavePerTick() {
return ConfigHolder.getConfig().chunkSaving.maxAutoSaveChunksPerTick;
}

@Override
public boolean configFixMC159283() {
return ConfigHolder.getConfig().bugFixes.fixMC159283;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public <T extends Entity> void addToGetEntities(final Level world, final EntityT

public int configMaxAutoSavePerTick();

public boolean configFixMC159283();

public static final class Holder {
private Holder() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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 <a href="https://bugs.mojang.com/browse/MC-159283">MC-159283</a> 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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
34 changes: 18 additions & 16 deletions src/main/resources/assets/moonrise/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -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"
}
"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"
}
4 changes: 4 additions & 0 deletions src/main/resources/moonrise.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/main/resources/moonrise.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"collisions.VoxelShapeMixin",
"command.CommandsMixin",
"config.MinecraftServerMixin",
"end_island.DensityFunctions$EndIslandDensityFunctionMixin",
"entity_tracker.ChunkMapMixin",
"entity_tracker.EntityMixin",
"entity_tracker.TrackedEntityMixin",
Expand Down

0 comments on commit 37ca0e7

Please sign in to comment.