Skip to content

Commit

Permalink
Adjust structure placement in GoG skyblock
Browse files Browse the repository at this point in the history
Fixes #4712 using code snippets from Carpet Skyblock Additions that use the original noise generator to emulate the non-skyblock heightmap for placing height-sensitive structures.
  • Loading branch information
TheRealWormbo committed Jul 11, 2024
1 parent 1d4d462 commit beba017
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@
import com.mojang.serialization.codecs.RecordCodecBuilder;

import net.minecraft.core.*;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.WorldGenRegion;
import net.minecraft.world.level.*;
import net.minecraft.world.level.biome.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.*;
import net.minecraft.world.level.levelgen.*;
import net.minecraft.world.level.levelgen.blending.Blender;

import org.jetbrains.annotations.NotNull;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.BiConsumer;
Expand All @@ -48,39 +50,44 @@ private SkyblockChunkGenerator(BiomeSource biomeSource, Holder<NoiseGeneratorSet
super(biomeSource, settings);
}

@NotNull
@Override
protected Codec<? extends ChunkGenerator> codec() {
return CODEC;
}

@Override
public int getBaseHeight(int x, int z, Heightmap.Types heightmapTypes, LevelHeightAccessor levelHeightAccessor, RandomState randomState) {
return levelHeightAccessor.getMinBuildHeight();
}

@Override
public NoiseColumn getBaseColumn(int x, int z, LevelHeightAccessor levelHeightAccessor, RandomState randomState) {
return new NoiseColumn(levelHeightAccessor.getMinBuildHeight(), new BlockState[0]);
}

@Override
public void buildSurface(ChunkAccess chunkAccess, WorldGenerationContext context,
RandomState randomState, StructureManager structureManager, BiomeManager biomeManager,
Registry<Biome> biomes, Blender blender) {}
public void buildSurface(@NotNull ChunkAccess chunkAccess, @NotNull WorldGenerationContext context,
@NotNull RandomState randomState, @NotNull StructureManager structureManager,
@NotNull BiomeManager biomeManager, @NotNull Registry<Biome> biomes, @NotNull Blender blender) {}

@Override
public void applyCarvers(WorldGenRegion worldGenRegion, long seed, RandomState randomState, BiomeManager biomeManager, StructureManager structureManager, ChunkAccess chunkAccess, GenerationStep.Carving carving) {

}
public void applyCarvers(@NotNull WorldGenRegion worldGenRegion, long seed, @NotNull RandomState randomState,
@NotNull BiomeManager biomeManager, @NotNull StructureManager structureManager,
@NotNull ChunkAccess chunkAccess, GenerationStep.@NotNull Carving carving) {}

@Override
public CompletableFuture<ChunkAccess> fillFromNoise(Executor executor, Blender blender, RandomState randomState, StructureManager structureManager, ChunkAccess chunk) {
public @NotNull CompletableFuture<ChunkAccess> fillFromNoise(@NotNull Executor executor, @NotNull Blender blender,
@NotNull RandomState randomState, @NotNull StructureManager structureManager, @NotNull ChunkAccess chunk) {
return CompletableFuture.completedFuture(chunk);
}

@Override
public void spawnOriginalMobs(WorldGenRegion region) {}
public void spawnOriginalMobs(@NotNull WorldGenRegion region) {}

@Override
public void applyBiomeDecoration(WorldGenLevel level, ChunkAccess chunkAccess, StructureManager structureManager) {}
public void applyBiomeDecoration(@NotNull WorldGenLevel level, @NotNull ChunkAccess chunkAccess,
@NotNull StructureManager structureManager) {}

/**
* Calculates the height at a particular location as it would be in a world with the same seed that isn't empty.
* (Based on code from CarpetSkyAdditions.)
*/
public int getBaseHeightInEquivalentNoiseWorld(int x, int z, Heightmap.Types heightmap, WorldGenLevel level) {
RandomState randomState = RandomState.create(
generatorSettings().value(),
level.registryAccess().registryOrThrow(Registries.NOISE).asLookup(),
level.getSeed());
return super.getBaseHeight(x, z, heightmap, level, randomState);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package vazkii.botania.mixin;

import net.minecraft.world.level.LevelHeightAccessor;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.WorldGenerationContext;
import net.minecraft.world.level.levelgen.placement.PlacementContext;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import vazkii.botania.common.world.SkyblockChunkGenerator;

/**
* Based on code from CarpetSkyAdditions. Ensures terrain-sensitive structures generate where they should.
*/
@Mixin(PlacementContext.class)
public class PlacementContextMixin extends WorldGenerationContext {
@Shadow
@Final
private ChunkGenerator generator;

@Shadow
@Final
private WorldGenLevel level;

public PlacementContextMixin(ChunkGenerator generator, LevelHeightAccessor levelHeightAccessor) {
super(generator, levelHeightAccessor);
}

/**
* For Garden of Glass, use generation heightmap instead of empty actual heightmap to place features/structures.
*/
@Inject(method = "getHeight", cancellable = true, at = @At("HEAD"))
private void useGenerationHeightmap(Heightmap.Types heightmap, int x, int z, CallbackInfoReturnable<Integer> cir) {
if (generator instanceof SkyblockChunkGenerator skyblockChunkGenerator) {
cir.setReturnValue(skyblockChunkGenerator.getBaseHeightInEquivalentNoiseWorld(x, z, heightmap, level));
}
}
}
1 change: 1 addition & 0 deletions Xplat/src/main/resources/botania_xplat.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"PistonBaseBlockAccessor",
"PistonBaseBlockMixin",
"PistonStructureResolverMixin",
"PlacementContextMixin",
"PlayerMixin",
"PollinateGoalMixin",
"ProtectionEnchantmentMixin",
Expand Down

0 comments on commit beba017

Please sign in to comment.