forked from Johni0702/bobby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bypass lighting engine for fake chunks
The vanilla lighting engine has horrible bulk chunk load/unload performance, but we do not even need it because we do not need to update any light in any of the fake chunks, so this commit completely bypasses it for fake chunks. Thereby massively reducing main thread load on fake chunk load/unload. Also fixes any lighting issues present in the current implementation (cause we no longer do any lighting updates!).
- Loading branch information
Showing
7 changed files
with
103 additions
and
61 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
8 changes: 8 additions & 0 deletions
8
src/main/java/de/johni0702/minecraft/bobby/ext/ChunkLightProviderExt.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,8 @@ | ||
package de.johni0702.minecraft.bobby.ext; | ||
|
||
import net.minecraft.world.chunk.ChunkNibbleArray; | ||
|
||
public interface ChunkLightProviderExt { | ||
void bobby_addSectionData(long pos, ChunkNibbleArray data); | ||
void bobby_removeSectionData(long pos); | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/de/johni0702/minecraft/bobby/mixin/ChunkLightProviderMixin.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,49 @@ | ||
package de.johni0702.minecraft.bobby.mixin; | ||
|
||
import de.johni0702.minecraft.bobby.ext.ChunkLightProviderExt; | ||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap; | ||
import it.unimi.dsi.fastutil.longs.Long2ObjectMaps; | ||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.ChunkSectionPos; | ||
import net.minecraft.world.chunk.ChunkNibbleArray; | ||
import net.minecraft.world.chunk.light.ChunkLightProvider; | ||
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.CallbackInfoReturnable; | ||
|
||
@Mixin(ChunkLightProvider.class) | ||
public abstract class ChunkLightProviderMixin implements ChunkLightProviderExt { | ||
private final Long2ObjectMap<ChunkNibbleArray> bobbySectionData = Long2ObjectMaps.synchronize(new Long2ObjectOpenHashMap<>()); | ||
|
||
@Override | ||
public void bobby_addSectionData(long pos, ChunkNibbleArray data) { | ||
this.bobbySectionData.put(pos, data); | ||
} | ||
|
||
@Override | ||
public void bobby_removeSectionData(long pos) { | ||
this.bobbySectionData.remove(pos); | ||
} | ||
|
||
@Inject(method = "getLightSection", at = @At("HEAD"), cancellable = true) | ||
private void bobby_getLightSection(ChunkSectionPos pos, CallbackInfoReturnable<ChunkNibbleArray> ci) { | ||
ChunkNibbleArray data = this.bobbySectionData.get(pos.asLong()); | ||
if (data != null) { | ||
ci.setReturnValue(data); | ||
} | ||
} | ||
|
||
@Inject(method = "getLightLevel", at = @At("HEAD"), cancellable = true) | ||
private void bobby_getLightSection(BlockPos blockPos, CallbackInfoReturnable<Integer> ci) { | ||
ChunkNibbleArray data = this.bobbySectionData.get(ChunkSectionPos.from(blockPos).asLong()); | ||
if (data != null) { | ||
ci.setReturnValue(data.get( | ||
ChunkSectionPos.getLocalCoord(blockPos.getX()), | ||
ChunkSectionPos.getLocalCoord(blockPos.getY()), | ||
ChunkSectionPos.getLocalCoord(blockPos.getZ()) | ||
)); | ||
} | ||
} | ||
} |
25 changes: 0 additions & 25 deletions
25
src/main/java/de/johni0702/minecraft/bobby/mixin/ClientPlayNetworkHandlerMixin.java
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
src/main/java/de/johni0702/minecraft/bobby/mixin/LightingProviderAccessor.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,17 @@ | ||
package de.johni0702.minecraft.bobby.mixin; | ||
|
||
import net.minecraft.world.chunk.light.ChunkLightProvider; | ||
import net.minecraft.world.chunk.light.LightingProvider; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(LightingProvider.class) | ||
public interface LightingProviderAccessor { | ||
@Accessor | ||
@Nullable | ||
ChunkLightProvider<?, ?> getBlockLightProvider(); | ||
@Accessor | ||
@Nullable | ||
ChunkLightProvider<?, ?> getSkyLightProvider(); | ||
} |
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