-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: cache sea level in NoiseChunkGenerator
- Loading branch information
Showing
3 changed files
with
39 additions
and
0 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
37 changes: 37 additions & 0 deletions
37
...jellysquid/mods/lithium/mixin/gen/cached_generator_settings/NoiseChunkGeneratorMixin.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,37 @@ | ||
package me.jellysquid.mods.lithium.mixin.gen.cached_generator_settings; | ||
|
||
import net.minecraft.world.biome.source.BiomeSource; | ||
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings; | ||
import net.minecraft.world.gen.chunk.NoiseChunkGenerator; | ||
import org.spongepowered.asm.mixin.*; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.util.function.Supplier; | ||
|
||
@Mixin(NoiseChunkGenerator.class) | ||
public class NoiseChunkGeneratorMixin { | ||
private int cachedSeaLevel; | ||
|
||
/** | ||
* Use cached sea level instead of retrieving from the registry every time. | ||
* This method is called for every block in the chunk so this will save a lot of registry lookups. | ||
* | ||
* @author SuperCoder79 | ||
*/ | ||
@Overwrite | ||
public int getSeaLevel() { | ||
return this.cachedSeaLevel; | ||
} | ||
|
||
/** | ||
* Initialize the cache early in the ctor to avoid potential future problems with uninitialized usages | ||
*/ | ||
@Inject(method = "<init>(Lnet/minecraft/world/biome/source/BiomeSource;Lnet/minecraft/world/biome/source/BiomeSource;JLjava/util/function/Supplier;)V", | ||
at = @At(value = "INVOKE", shift = At.Shift.BEFORE, | ||
target = "Lnet/minecraft/world/gen/chunk/ChunkGeneratorSettings;getGenerationShapeConfig()Lnet/minecraft/world/gen/chunk/GenerationShapeConfig;")) | ||
private void hookConstructor(BiomeSource populationSource, BiomeSource biomeSource, long seed, Supplier<ChunkGeneratorSettings> settings, CallbackInfo ci) { | ||
this.cachedSeaLevel = settings.get().getSeaLevel(); | ||
} | ||
} |
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