-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix various issues with world generation
- Loading branch information
1 parent
5c857c0
commit 1fad880
Showing
10 changed files
with
265 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
common/src/main/java/io/github/steveplays28/noisium/mixin/world/WorldAccessMixin.java
This file was deleted.
Oops, something went wrong.
98 changes: 98 additions & 0 deletions
98
...c/main/java/io/github/steveplays28/noisium/mixin/world/gen/chunk/ChunkGeneratorMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package io.github.steveplays28.noisium.mixin.world.gen.chunk; | ||
|
||
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.registry.RegistryKeys; | ||
import net.minecraft.registry.entry.RegistryEntry; | ||
import net.minecraft.server.network.DebugInfoSender; | ||
import net.minecraft.structure.StructureStart; | ||
import net.minecraft.util.crash.CrashException; | ||
import net.minecraft.util.crash.CrashReport; | ||
import net.minecraft.util.crash.CrashReportSection; | ||
import net.minecraft.util.math.ChunkPos; | ||
import net.minecraft.util.math.ChunkSectionPos; | ||
import net.minecraft.world.StructureWorldAccess; | ||
import net.minecraft.world.biome.Biome; | ||
import net.minecraft.world.chunk.Chunk; | ||
import net.minecraft.world.chunk.ChunkSection; | ||
import net.minecraft.world.gen.StructureAccessor; | ||
import net.minecraft.world.gen.chunk.ChunkGenerator; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.util.Set; | ||
import java.util.function.Consumer; | ||
import java.util.stream.Stream; | ||
|
||
@Mixin(ChunkGenerator.class) | ||
public class ChunkGeneratorMixin { | ||
@WrapWithCondition(method = "generateFeatures", at = @At(value = "INVOKE", target = "Ljava/util/stream/Stream;forEach(Ljava/util/function/Consumer;)V")) | ||
private static boolean noisium$cancelChunkPosStreamToFixAnInfiniteLoop(Stream<ChunkPos> stream, Consumer<?> consumer) { | ||
return false; | ||
} | ||
|
||
@Inject(method = "generateFeatures", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/ChunkPos;stream(Lnet/minecraft/util/math/ChunkPos;I)Ljava/util/stream/Stream;", shift = At.Shift.BEFORE)) | ||
private void noisium$addChunkSectionBiomeContainersToSet(StructureWorldAccess world, Chunk chunk, StructureAccessor structureAccessor, CallbackInfo ci, @Local Set<RegistryEntry<Biome>> set) { | ||
for (ChunkSection chunkSection : chunk.getSectionArray()) { | ||
chunkSection.getBiomeContainer().forEachValue(set::add); | ||
} | ||
} | ||
|
||
/** | ||
* Replaces {@link ChunkGenerator#addStructureReferences} with a simpler one, that only checks the center chunk, instead of iterating outwards. | ||
* This fixes an infinite loop with {@link io.github.steveplays28.noisium.server.world.NoisiumServerWorldChunkManager}. | ||
*/ | ||
@Inject(method = "addStructureReferences", at = @At(value = "HEAD"), cancellable = true) | ||
public void noisium$replaceAddStructureReferencesToFixAnInfiniteLoop(StructureWorldAccess world, StructureAccessor structureAccessor, Chunk chunk, CallbackInfo ci) { | ||
var chunkPos = chunk.getPos(); | ||
int chunkPosStartX = chunkPos.getStartX(); | ||
int chunkPosStartZ = chunkPos.getStartZ(); | ||
var chunkSectionPos = ChunkSectionPos.from(chunk); | ||
var chunkPosLong = chunkPos.toLong(); | ||
|
||
for (StructureStart structureStart : chunk.getStructureStarts().values()) { | ||
try { | ||
if (structureStart.hasChildren() && structureStart.getBoundingBox().intersectsXZ( | ||
chunkPosStartX, chunkPosStartZ, chunkPosStartX + 15, chunkPosStartZ + 15) | ||
) { | ||
structureAccessor.addStructureReference(chunkSectionPos, structureStart.getStructure(), chunkPosLong, chunk); | ||
DebugInfoSender.sendStructureStart(world, structureStart); | ||
} | ||
} catch (Exception e) { | ||
CrashReport crashReport = CrashReport.create(e, "Generating structure reference"); | ||
CrashReportSection crashReportSection = crashReport.addElement("Structure"); | ||
crashReportSection.add( | ||
"Id", | ||
() -> world.getRegistryManager().getOptional(RegistryKeys.STRUCTURE).map( | ||
structureTypeRegistry -> { | ||
var structureId = structureTypeRegistry.getId(structureStart.getStructure()); | ||
if (structureId == null) { | ||
return "UNKNOWN"; | ||
} | ||
|
||
return structureId.toString(); | ||
} | ||
).orElse("UNKNOWN") | ||
); | ||
crashReportSection.add( | ||
"Name", | ||
() -> { | ||
var structureTypeId = Registries.STRUCTURE_TYPE.getId(structureStart.getStructure().getType()); | ||
if (structureTypeId == null) { | ||
return "UNKNOWN"; | ||
} | ||
|
||
return structureTypeId.toString(); | ||
} | ||
); | ||
crashReportSection.add("Class", () -> structureStart.getStructure().getClass().getCanonicalName()); | ||
throw new CrashException(crashReport); | ||
} | ||
} | ||
|
||
ci.cancel(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...n/java/io/github/steveplays28/noisium/mixin/world/gen/chunk/NoiseChunkGeneratorMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.github.steveplays28.noisium.mixin.world.gen.chunk; | ||
|
||
import net.minecraft.world.gen.chunk.NoiseChunkGenerator; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.Constant; | ||
import org.spongepowered.asm.mixin.injection.ModifyConstant; | ||
|
||
@Mixin(NoiseChunkGenerator.class) | ||
public class NoiseChunkGeneratorMixin { | ||
@ModifyConstant(method = "carve", constant = @Constant(intValue = 8)) | ||
private int noisium$modifyCarvingChunkRadiusPositiveToFixAnInfiniteLoop(int chunkRadius) { | ||
return 0; | ||
} | ||
|
||
@ModifyConstant(method = "carve", constant = @Constant(intValue = -8)) | ||
private int noisium$modifyCarvingChunkRadiusNegativeToFixAnInfiniteLoop(int chunkRadius) { | ||
return 0; | ||
} | ||
} |
Oops, something went wrong.