-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change: Reorder lightmap handling, fixes MC-169913 (#17)
* Reorder lightmap removal * Add lightmap handling to ProtoChunk
- Loading branch information
Showing
6 changed files
with
187 additions
and
1 deletion.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/main/java/me/jellysquid/mods/phosphor/mixin/chunk/MixinProtoChunk.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,62 @@ | ||
package me.jellysquid.mods.phosphor.mixin.chunk; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.Slice; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.chunk.ChunkSection; | ||
import net.minecraft.world.chunk.ChunkStatus; | ||
import net.minecraft.world.chunk.ProtoChunk; | ||
import net.minecraft.world.chunk.light.LightingProvider; | ||
|
||
@Mixin(ProtoChunk.class) | ||
public abstract class MixinProtoChunk { | ||
@Shadow | ||
public abstract LightingProvider getLightingProvider(); | ||
|
||
@Shadow | ||
public abstract ChunkStatus getStatus(); | ||
|
||
@Unique | ||
private static final ChunkStatus PRE_LIGHT = ChunkStatus.LIGHT.getPrevious(); | ||
|
||
@Inject( | ||
method = "setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Z)Lnet/minecraft/block/BlockState;", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/chunk/ChunkSection;setBlockState(IIILnet/minecraft/block/BlockState;)Lnet/minecraft/block/BlockState;" | ||
), | ||
locals = LocalCapture.CAPTURE_FAILHARD | ||
) | ||
private void addLightmap(final BlockPos pos, final BlockState state, final boolean moved, final CallbackInfoReturnable<BlockState> ci, final int x, final int y, final int z, final ChunkSection section) { | ||
if (this.getStatus().isAtLeast(PRE_LIGHT) && ChunkSection.isEmpty(section)) { | ||
this.getLightingProvider().updateSectionStatus(pos, false); | ||
} | ||
} | ||
|
||
@Inject( | ||
method = "setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Z)Lnet/minecraft/block/BlockState;", | ||
slice = @Slice( | ||
from = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/chunk/ChunkSection;setBlockState(IIILnet/minecraft/block/BlockState;)Lnet/minecraft/block/BlockState;" | ||
) | ||
), | ||
at = @At( | ||
value = "RETURN", | ||
ordinal = 0 | ||
), | ||
locals = LocalCapture.CAPTURE_FAILHARD | ||
) | ||
private void removeLightmap(final BlockPos pos, final BlockState state, final boolean moved, final CallbackInfoReturnable<BlockState> ci, final int x, final int y, final int z, final ChunkSection section) { | ||
if (this.getStatus().isAtLeast(PRE_LIGHT) && ChunkSection.isEmpty(section)) { | ||
this.getLightingProvider().updateSectionStatus(pos, true); | ||
} | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
src/main/java/me/jellysquid/mods/phosphor/mixin/chunk/light/MixinServerLightingProvider.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,58 @@ | ||
package me.jellysquid.mods.phosphor.mixin.chunk.light; | ||
|
||
import java.util.function.IntSupplier; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
import net.minecraft.server.world.ServerLightingProvider; | ||
import net.minecraft.util.Util; | ||
import net.minecraft.util.math.ChunkSectionPos; | ||
import net.minecraft.world.chunk.ChunkProvider; | ||
import net.minecraft.world.chunk.light.LightingProvider; | ||
|
||
@Mixin(ServerLightingProvider.class) | ||
public abstract class MixinServerLightingProvider extends LightingProvider | ||
{ | ||
private MixinServerLightingProvider(final ChunkProvider chunkProvider, final boolean hasBlockLight, final boolean hasSkyLight) { | ||
super(chunkProvider, hasBlockLight, hasSkyLight); | ||
} | ||
|
||
@Shadow | ||
protected abstract void enqueue(int x, int z, IntSupplier completedLevelSupplier, ServerLightingProvider.Stage stage, Runnable task); | ||
|
||
@Shadow | ||
protected abstract void enqueue(int x, int z, ServerLightingProvider.Stage stage, Runnable task); | ||
|
||
/** | ||
* @author PhiPro | ||
* @reason Re-implement | ||
*/ | ||
@Overwrite | ||
public void updateSectionStatus(final ChunkSectionPos pos, final boolean empty) | ||
{ | ||
if (empty) { | ||
// Schedule after light updates have been carried out | ||
this.enqueue(pos.getSectionX(), pos.getSectionZ(), ServerLightingProvider.Stage.POST_UPDATE, Util.debugRunnable(() -> { | ||
super.updateSectionStatus(pos, true); | ||
}, | ||
() -> "updateSectionStatus " + pos + " " + true | ||
)); | ||
} else { | ||
// Schedule before light updates are carried out | ||
this.enqueue(pos.getSectionX(), pos.getSectionZ(), () -> 0, ServerLightingProvider.Stage.PRE_UPDATE, Util.debugRunnable(() -> { | ||
super.updateSectionStatus(pos, false); | ||
}, | ||
() -> "updateSectionStatus " + pos + " " + false | ||
)); | ||
|
||
// Schedule another version in POST_UPDATE to achieve reliable final state | ||
this.enqueue(pos.getSectionX(), pos.getSectionZ(), ServerLightingProvider.Stage.POST_UPDATE, Util.debugRunnable(() -> { | ||
super.updateSectionStatus(pos, false); | ||
}, | ||
() -> "updateSectionStatus " + pos + " " + false | ||
)); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/me/jellysquid/mods/phosphor/mixin/world/MixinWorld.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,48 @@ | ||
package me.jellysquid.mods.phosphor.mixin.world; | ||
|
||
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.Slice; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.WorldAccess; | ||
import net.minecraft.world.chunk.ChunkSection; | ||
import net.minecraft.world.chunk.WorldChunk; | ||
|
||
@Mixin(World.class) | ||
public abstract class MixinWorld implements WorldAccess { | ||
@Inject( | ||
method = "setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;II)Z", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/chunk/WorldChunk;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Z)Lnet/minecraft/block/BlockState;" | ||
), | ||
locals = LocalCapture.CAPTURE_FAILHARD | ||
) | ||
private void addLightmap(final BlockPos pos, final BlockState state, final int flags, final int maxUpdateDepth, final CallbackInfoReturnable<Boolean> ci, final WorldChunk chunk) { | ||
if (ChunkSection.isEmpty(chunk.getSectionArray()[pos.getY() >> 4])) { | ||
this.getChunkManager().getLightingProvider().updateSectionStatus(pos, false); | ||
} | ||
} | ||
|
||
@Inject( | ||
method = "setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;II)Z", | ||
slice = @Slice( | ||
from = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/chunk/WorldChunk;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Z)Lnet/minecraft/block/BlockState;" | ||
) | ||
), | ||
at = @At("RETURN"), | ||
locals = LocalCapture.CAPTURE_FAILHARD | ||
) | ||
private void removeLightmap(final BlockPos pos, final BlockState state, final int flags, final int maxUpdateDepth, final CallbackInfoReturnable<Boolean> ci, final WorldChunk chunk) { | ||
if (ChunkSection.isEmpty(chunk.getSectionArray()[pos.getY() >> 4])) { | ||
this.getChunkManager().getLightingProvider().updateSectionStatus(pos, true); | ||
} | ||
} | ||
} |
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