From 28b19199ce07dc14899f9a50ee70d997ba933181 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Mon, 16 Oct 2023 14:10:07 -0700 Subject: [PATCH] Fix mushrooms not generating in swamps During feature generation, light data is not initialised and will always return 15 in Starlight. Vanilla can possibly return 0 if partially initialised, which allows some mushroom blocks to generate. In general, the brightness value from the light engine should not be used until the chunk is ready. To emulate Vanilla behavior better, we return 0 as the brightness during world gen unless the target chunk is finished lighting. The regular light retrieval outside of WorldGenRegion remains the same, as behaviorally chunks not lit should be at max skylight and zero block light. Fixes https://github.com/PaperMC/Starlight/issues/193 --- .../starlight/world/WorldGenRegionMixin.java | 46 +++++++++++++++++++ src/main/resources/moonrise.mixins.json | 1 + 2 files changed, 47 insertions(+) create mode 100644 src/main/java/ca/spottedleaf/moonrise/mixin/starlight/world/WorldGenRegionMixin.java diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/starlight/world/WorldGenRegionMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/starlight/world/WorldGenRegionMixin.java new file mode 100644 index 0000000..11c53b3 --- /dev/null +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/starlight/world/WorldGenRegionMixin.java @@ -0,0 +1,46 @@ +package ca.spottedleaf.moonrise.mixin.starlight.world; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.WorldGenRegion; +import net.minecraft.world.level.LightLayer; +import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.chunk.ChunkAccess; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(WorldGenRegion.class) +public abstract class WorldGenRegionMixin implements WorldGenLevel { + + @Shadow + public abstract ChunkAccess getChunk(int i, int j); + + /** + * @reason During feature generation, light data is not initialised and will always return 15 in Starlight. Vanilla + * can possibly return 0 if partially initialised, which allows some mushroom blocks to generate. + * In general, the brightness value from the light engine should not be used until the chunk is ready. To emulate + * Vanilla behavior better, we return 0 as the brightness during world gen unless the target chunk is finished + * lighting. + * @author Spottedleaf + */ + @Override + public int getBrightness(final LightLayer lightLayer, final BlockPos blockPos) { + final ChunkAccess chunk = this.getChunk(blockPos.getX() >> 4, blockPos.getZ() >> 4); + if (!chunk.isLightCorrect()) { + return 0; + } + return this.getLightEngine().getLayerListener(lightLayer).getLightValue(blockPos); + } + + /** + * @reason See above + * @author Spottedleaf + */ + @Override + public int getRawBrightness(final BlockPos blockPos, final int subtract) { + final ChunkAccess chunk = this.getChunk(blockPos.getX() >> 4, blockPos.getZ() >> 4); + if (!chunk.isLightCorrect()) { + return 0; + } + return this.getLightEngine().getRawBrightness(blockPos, subtract); + } +} diff --git a/src/main/resources/moonrise.mixins.json b/src/main/resources/moonrise.mixins.json index f52a9cd..0f83592 100644 --- a/src/main/resources/moonrise.mixins.json +++ b/src/main/resources/moonrise.mixins.json @@ -58,6 +58,7 @@ "starlight.world.ChunkSerializerMixin", "starlight.world.LevelMixin", "starlight.world.ServerWorldMixin", + "starlight.world.WorldGenRegionMixin", "util_thread_counts.UtilMixin", "util_threading_detector.ThreadingDetectorMixin", "util_time_source.UtilMixin"