Initialise default nibble arrays in ChunkAccess directly

When ChunkAccess was converted to an abstract class some versions
ago, the code to initialise nibble arrays should have been moved.
However, the code was not moved and so now mods constructing their
own implementations of ChunkAccess would not have the nibble arrays
initialised.

Fixes https://github.com/PaperMC/Starlight/issues/186
This commit is contained in:
Spottedleaf
2023-10-16 15:51:31 -07:00
parent 28b19199ce
commit a5038c0856
3 changed files with 16 additions and 49 deletions

View File

@@ -2,7 +2,15 @@ package ca.spottedleaf.moonrise.mixin.starlight.chunk;
import ca.spottedleaf.moonrise.patches.starlight.chunk.StarlightChunk;
import ca.spottedleaf.moonrise.patches.starlight.light.SWMRNibbleArray;
import ca.spottedleaf.moonrise.patches.starlight.light.StarLightEngine;
import net.minecraft.core.Registry;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.LevelHeightAccessor;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ImposterProtoChunk;
import net.minecraft.world.level.chunk.LevelChunkSection;
import net.minecraft.world.level.chunk.UpgradeData;
import net.minecraft.world.level.levelgen.blending.BlendingData;
import net.minecraft.world.level.lighting.ChunkSkyLightSources;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@@ -72,7 +80,7 @@ public abstract class ChunkAccessMixin implements StarlightChunk {
}
/**
* @reason Remove unused skylight sources
* @reason Remove unused skylight sources, and initialise nibble arrays.
* @author Spottedleaf
*/
@Inject(
@@ -81,8 +89,14 @@ public abstract class ChunkAccessMixin implements StarlightChunk {
value = "RETURN"
)
)
private void nullSources(final CallbackInfo ci) {
private void nullSources(ChunkPos chunkPos, UpgradeData upgradeData, LevelHeightAccessor levelHeightAccessor,
Registry registry, long l, LevelChunkSection[] levelChunkSections, BlendingData blendingData,
CallbackInfo ci) {
this.skyLightSources = null;
if (!((Object)this instanceof ImposterProtoChunk)) {
this.setBlockNibbles(StarLightEngine.getFilledEmptyLight(levelHeightAccessor));
this.setSkyNibbles(StarLightEngine.getFilledEmptyLight(levelHeightAccessor));
}
}
/**

View File

@@ -1,18 +1,11 @@
package ca.spottedleaf.moonrise.mixin.starlight.chunk;
import ca.spottedleaf.moonrise.patches.starlight.chunk.StarlightChunk;
import ca.spottedleaf.moonrise.patches.starlight.light.StarLightEngine;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.LevelChunkSection;
import net.minecraft.world.level.chunk.ProtoChunk;
import net.minecraft.world.level.chunk.UpgradeData;
import net.minecraft.world.level.levelgen.blending.BlendingData;
import net.minecraft.world.level.lighting.ChunkSkyLightSources;
import net.minecraft.world.ticks.LevelChunkTicks;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@@ -37,19 +30,6 @@ public abstract class LevelChunkMixin implements StarlightChunk {
this.setBlockEmptinessMap(((StarlightChunk)protoChunk).getBlockEmptinessMap());
}
/**
* Initialises the nibble arrays to default values.
* TODO since this is a constructor inject, check for new constructors on update.
*/
@Inject(
method = "<init>(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/level/ChunkPos;Lnet/minecraft/world/level/chunk/UpgradeData;Lnet/minecraft/world/ticks/LevelChunkTicks;Lnet/minecraft/world/ticks/LevelChunkTicks;J[Lnet/minecraft/world/level/chunk/LevelChunkSection;Lnet/minecraft/world/level/chunk/LevelChunk$PostLoadProcessor;Lnet/minecraft/world/level/levelgen/blending/BlendingData;)V",
at = @At("TAIL")
)
public void onConstruct(Level level, ChunkPos chunkPos, UpgradeData upgradeData, LevelChunkTicks levelChunkTicks, LevelChunkTicks levelChunkTicks2, long l, LevelChunkSection[] levelChunkSections, LevelChunk.PostLoadProcessor postLoadProcessor, BlendingData blendingData, CallbackInfo ci) {
this.setBlockNibbles(StarLightEngine.getFilledEmptyLight(level));
this.setSkyNibbles(StarLightEngine.getFilledEmptyLight(level));
}
/**
* @reason Remove unused skylight sources
* @author Spottedleaf

View File

@@ -1,43 +1,16 @@
package ca.spottedleaf.moonrise.mixin.starlight.chunk;
import ca.spottedleaf.moonrise.patches.starlight.chunk.StarlightChunk;
import ca.spottedleaf.moonrise.patches.starlight.light.StarLightEngine;
import net.minecraft.core.Registry;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.LevelHeightAccessor;
import net.minecraft.world.level.chunk.ImposterProtoChunk;
import net.minecraft.world.level.chunk.LevelChunkSection;
import net.minecraft.world.level.chunk.ProtoChunk;
import net.minecraft.world.level.chunk.UpgradeData;
import net.minecraft.world.level.levelgen.blending.BlendingData;
import net.minecraft.world.level.lighting.ChunkSkyLightSources;
import net.minecraft.world.ticks.ProtoChunkTicks;
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ProtoChunk.class)
public abstract class ProtoChunkMixin implements StarlightChunk {
/**
* Initialises the nibble arrays to default values.
* TODO since this is a constructor inject, check for new constructors on update.
*/
@Inject(
method = "<init>(Lnet/minecraft/world/level/ChunkPos;Lnet/minecraft/world/level/chunk/UpgradeData;[Lnet/minecraft/world/level/chunk/LevelChunkSection;Lnet/minecraft/world/ticks/ProtoChunkTicks;Lnet/minecraft/world/ticks/ProtoChunkTicks;Lnet/minecraft/world/level/LevelHeightAccessor;Lnet/minecraft/core/Registry;Lnet/minecraft/world/level/levelgen/blending/BlendingData;)V",
at = @At("TAIL")
)
public void onConstruct(ChunkPos chunkPos, UpgradeData upgradeData, LevelChunkSection[] levelChunkSections, ProtoChunkTicks protoChunkTicks, ProtoChunkTicks protoChunkTicks2, LevelHeightAccessor levelHeightAccessor, Registry registry, BlendingData blendingData, CallbackInfo ci) {
if ((Object)this instanceof ImposterProtoChunk) {
return;
}
this.setBlockNibbles(StarLightEngine.getFilledEmptyLight(levelHeightAccessor));
this.setSkyNibbles(StarLightEngine.getFilledEmptyLight(levelHeightAccessor));
}
/**
* @reason Remove unused skylight sources
* @author Spottedleaf