Skip to content

Commit

Permalink
new: cache sea level in NoiseChunkGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskarth authored and 2No2Name committed Jan 24, 2021
1 parent ea97a63 commit a55cfd1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ private LithiumConfig() {

this.addMixinRule("gen", true);
this.addMixinRule("gen.biome_noise_cache", true);
this.addMixinRule("gen.cached_generator_settings", true);
this.addMixinRule("gen.chunk_region", true);
this.addMixinRule("gen.fast_island_noise", true);
this.addMixinRule("gen.fast_layer_sampling", true);
Expand Down
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();
}
}
1 change: 1 addition & 0 deletions src/main/resources/lithium.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"gen.biome_noise_cache.InitLayerMixin",
"gen.biome_noise_cache.MergingLayerMixin",
"gen.biome_noise_cache.ParentedLayerMixin",
"gen.cached_generator_settings.NoiseChunkGeneratorMixin",
"gen.chunk_region.ChunkRegionMixin",
"gen.fast_island_noise.NoiseChunkGeneratorMixin",
"gen.fast_island_noise.TheEndBiomeSourceMixin",
Expand Down

0 comments on commit a55cfd1

Please sign in to comment.