Skip to content

Commit

Permalink
chore: when updating chunk section status, use callback
Browse files Browse the repository at this point in the history
This was added somewhere between 1.21.2 and 1.21.3, a missed update during snapshots.
Being that this callback is only used for Clients, this has no real effect on the server
code where transactions are being executed.
  • Loading branch information
gabizou committed Jan 12, 2025
1 parent 45235f6 commit 6fd4332
Showing 1 changed file with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package org.spongepowered.common.event.tracking.context.transaction.effect;

import net.minecraft.core.SectionPos;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.LevelChunkSection;
import org.spongepowered.common.event.tracking.context.transaction.pipeline.BlockPipeline;
Expand All @@ -35,6 +36,7 @@ public final class UpdateChunkLightManagerEffect implements ProcessingSideEffect
private static final class Holder {
static final UpdateChunkLightManagerEffect INSTANCE = new UpdateChunkLightManagerEffect();
}

private UpdateChunkLightManagerEffect() {
}

Expand All @@ -43,15 +45,32 @@ public static UpdateChunkLightManagerEffect getInstance() {
}

@Override
public EffectResult processSideEffect(final BlockPipeline pipeline, final PipelineCursor oldState, final BlockState newState,
final SpongeBlockChangeFlag flag,
final int limit
public EffectResult processSideEffect(
final BlockPipeline pipeline, final PipelineCursor oldState, final BlockState newState,
final SpongeBlockChangeFlag flag, final int limit
) {
/*
Continuing from LevelChunk.setBlockState
boolean $$11 = $$4.hasOnlyAir();
if ($$5 != $$11) {
this.level.getChunkSource().getLightEngine().updateSectionStatus($$0, $$11);
this.level.getChunkSource().onSectionEmptinessChanged(this.chunkPos.x, SectionPos.blockToSectionCoord($$3), this.chunkPos.z, $$11);
}
*/
final var chunk = pipeline.getAffectedChunk();
final var blockY = oldState.pos().getY();
final LevelChunkSection chunkSection = pipeline.getAffectedSection();
final boolean wasEmpty = pipeline.wasEmpty();
final boolean isStillEmpty = chunkSection.hasOnlyAir();
if (wasEmpty != isStillEmpty) {
pipeline.getServerWorld().getChunkSource().getLightEngine().updateSectionStatus(oldState.pos(), isStillEmpty);
final var source = pipeline.getServerWorld().getChunkSource();
source.getLightEngine().updateSectionStatus(oldState.pos(), isStillEmpty);
final var sectionPos = SectionPos.blockToSectionCoord(blockY);
final var chunkX = chunk.getPos().x;
final var chunkZ = chunk.getPos().z;
source.onSectionEmptinessChanged(chunkX, sectionPos, chunkZ, isStillEmpty);
}
return EffectResult.NULL_PASS;
}
Expand Down

0 comments on commit 6fd4332

Please sign in to comment.