Skip to content

Commit

Permalink
1.1 - Release
Browse files Browse the repository at this point in the history
- added more documentation
- fixed entity spawning
- added mod description
- removed client class
- credit to important people c:
- changed mod id to save compat with "cave biomes" by supercoder79
  • Loading branch information
ItsBlackGear committed Jun 14, 2021
1 parent 0d606e5 commit 59f85f5
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 92 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ minecraft_version=1.17
yarn_mappings=1.17+build.6
loader_version=0.11.3
# Mod Properties
mod_version=1.0
mod_version=1.1
maven_group=com.alphastudios
archives_base_name=cavebiomesapi-1.17
archives_base_name=cavebiomeapi-1.17
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.34.10+1.17
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
//<>

/**
* Hello, this API allows the developers to generate their own cave biomes in the world. if you're looking for the API:
* Hello, this API allows the developers to generate their own cave biomes in the world.
* Special Thanks go to TelepathicGrunt, CorgiTaco and LudoCrypt who contributed with a lot of code and knowledge.
*
* @see CaveBiomeAPI
* @apiNote the API by itself it's in the {@link CaveBiomeAPI} class.
*/
public class CavesAPI implements ModInitializer {
public static final String MOD_ID = "cavebiomes";
public static final Logger LOGGER = LogManager.getLogger();
public static final String MOD_ID = "cavebiomeapi";

@Override
public void onInitialize() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeKeys;
import net.minecraft.world.biome.source.MultiNoiseBiomeSource;
import net.minecraft.world.dimension.DimensionType;

//<>

/**
* Special Thanks to TelepathicGrunt and LudoCrypt!
*/
public class CaveBiomeAPI {
private static MultiNoiseBiomeSource caveBiomeSource;

Expand All @@ -24,7 +26,7 @@ public class CaveBiomeAPI {
*
* @param seed the biome provider seed
*
* @see com.alphastudios.cavebiomeapi.mixin.VanillaLayeredBiomeSourceMixin#initialize(long, boolean, boolean, Registry, CallbackInfo)
* @see com.alphastudios.cavebiomeapi.mixin.VanillaLayeredBiomeSourceMixin#cba$initialize(long, boolean, boolean, Registry, CallbackInfo)
*/
public static void initializeCaveBiomes(Registry<Biome> biomeRegistry, long seed) {
caveBiomeSource = CaveLayer.create(biomeRegistry, seed);
Expand All @@ -36,68 +38,50 @@ public static void initializeCaveBiomes(Registry<Biome> biomeRegistry, long seed
* @implNote we don't make cave biomes spawn at y0 because otherwise entities and structures don't spawn.
*
* @param surfaceBiomes the generated surface biomes
* @param biomeRegistry the biome registry given in the biome provider
* @param x the {@link net.minecraft.world.biome.source.BiomeSource#getBiomeForNoiseGen(int, int, int)} x value
* @param y the {@link net.minecraft.world.biome.source.BiomeSource#getBiomeForNoiseGen(int, int, int)} y value
* @param z the {@link net.minecraft.world.biome.source.BiomeSource#getBiomeForNoiseGen(int, int, int)} z value
*
* @return the CaveBiomes injected into the biomeProvider
* @see com.alphastudios.cavebiomeapi.mixin.VanillaLayeredBiomeSourceMixin#getBiomeForNoiseGen(int, int, int)
*/
public static Biome injectCaveBiomes(Biome surfaceBiomes, Registry<Biome> biomeRegistry, int x, int y, int z) {
public static Biome injectCaveBiomes(Biome surfaceBiomes, int x, int y, int z) {
if (y <= 12) {
return sample(biomeRegistry, x, z);
return caveBiomeSource.getBiomeForNoiseGen(x, 0, z);
}
return surfaceBiomes;
}

/**
* Don't use the vanilla layer method of func_242936_a.
* It's bugged and checks the wrong registry first to resolve the biome id which can lead to crashes.
*
* @param dynamicBiomeRegistry - the registry vanilla should've grabbed the biome from first
* @param x - position on x axis in world
* @param z - position on z axis in world
*
* @return the dynamicregistry instance of the biome if done properly
*/
public static Biome sample(Registry<Biome> dynamicBiomeRegistry, int x, int z) {
return caveBiomeSource.getBiomeForNoiseGen(x, 0, z);
}

/**
* Injects a CaveBiome into the biomeLayer
* Injects a CaveBiome into the biomeSource
*
* @see #addDefaultCaves()
*
* @param biome the biome for injection
* @param noise the mixed noise point used for generation
*/
public static void addCaveBiome(Biome biome, Biome.MixedNoisePoint noise) {
if (biome == null || BuiltinRegistries.BIOME.getKey(biome).isEmpty()) {
public static void addCaveBiome(RegistryKey<Biome> biome, Biome.MixedNoisePoint noise) {
if (biome == null) {
throw new NullPointerException("CaveBiomeAPI's addCaveBiome method must take a registered biome. Null or unregistered biomes will be rejected.");
}
// Store the key as we will get the correct biome instance when the biome source is created.
addCaveBiome(BuiltinRegistries.BIOME.getKey(biome).get(), noise);
CaveLayer.addCaveBiome(biome, noise);
}

/**
* Injects a CaveBiome into the biomeLayer
*
* @see #addDefaultCaves()
* Injects a CaveBiome into the biomeSource
*
* @param biome the biome for injection
* @param noise the mixed noise point used for generation
*/
public static void addCaveBiome(RegistryKey<Biome> biome, Biome.MixedNoisePoint noise) {
if (biome == null) {
public static void addCaveBiome(Biome biome, Biome.MixedNoisePoint noise) {
if (biome == null || BuiltinRegistries.BIOME.getKey(biome).isEmpty()) {
throw new NullPointerException("CaveBiomeAPI's addCaveBiome method must take a registered biome. Null or unregistered biomes will be rejected.");
}
// Store the key as we will get the correct biome instance when the biome source is created.
CaveLayer.addCaveBiome(biome, noise);
addCaveBiome(BuiltinRegistries.BIOME.getKey(biome).get(), noise);
}

/**
* Injects the selected CaveBiomes into the biomeLayer
* Example of injection for Cave Biomes into the biomeSource
*
* @see #addCaveBiome(Biome, Biome.MixedNoisePoint)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

//<>

/**
* @author LudoCrypt
*/
public class CaveLayer {
public static final Map<RegistryKey<Biome>, Biome.MixedNoisePoint> CAVE_BIOMES = new HashMap<>();
public static final List<Biome> CAVE_BIOME_LIST = new ArrayList<>();
Expand All @@ -43,4 +46,4 @@ public static void addCaveBiome(RegistryKey<Biome> biome, Biome.MixedNoisePoint
});
return MultiNoiseBiomeSourceAccessor.createMultiNoiseBiomeSource(long_, biomes, Optional.of(Pair.of(registry, preset)));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@

//<>

/**
* @author TelepathicGrunt
*/
public class FeatureGenerationHelper {
/**
* Will not spawn any structure and instead, only features.
*/
public static void generateOnlyFeatures(Biome biome, StructureAccessor accessor, ChunkGenerator generator, ChunkRegion region, long seed, ChunkRandom rand, BlockPos pos) {
public static void generateOnlyFeatures(Biome biome, ChunkGenerator generator, ChunkRegion region, long seed, ChunkRandom rand, BlockPos pos) {
List<List<Supplier<ConfiguredFeature<?, ?>>>> list = biome.getGenerationSettings().getFeatures();
for (int generationStageIndex = 0; generationStageIndex < GenerationStep.Feature.values().length; ++generationStageIndex) {
int featureIndex = 1001; // offset index by 1001 so decorators for features do not exactly line up with features on surface biomes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

/**
* @author TelepathicGrunt
*/
@Mixin(BiomeAccess.class)
public class BiomeAccessMixin {
@Final
@Shadow
static int CHUNK_CENTER_OFFSET;

@Redirect(method = "getBiomeForNoiseGen(Lnet/minecraft/util/math/ChunkPos;)Lnet/minecraft/world/biome/Biome;",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/biome/source/BiomeAccess$Storage;getBiomeForNoiseGen(Lnet/minecraft/util/math/ChunkPos;)Lnet/minecraft/world/biome/Biome;"))
private Biome generateUndergroundFeatures(BiomeAccess.Storage storage, ChunkPos chunkPos) {
Biome biome = storage.getBiomeForNoiseGen(chunkPos.getStartX() + CHUNK_CENTER_OFFSET, 64, chunkPos.getStartZ() + CHUNK_CENTER_OFFSET);
return biome;
@Redirect(method = "getBiomeForNoiseGen(Lnet/minecraft/util/math/ChunkPos;)Lnet/minecraft/world/biome/Biome;", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/biome/source/BiomeAccess$Storage;getBiomeForNoiseGen(Lnet/minecraft/util/math/ChunkPos;)Lnet/minecraft/world/biome/Biome;"))
private Biome cba$generateUndergroundFeatures(BiomeAccess.Storage storage, ChunkPos chunkPos) {
return storage.getBiomeForNoiseGen(chunkPos.getStartX() + CHUNK_CENTER_OFFSET, 64, chunkPos.getStartZ() + CHUNK_CENTER_OFFSET);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@

//<>

/**
* Special thanks to TelepathicGrunt that helped to fix not one but almost every issue with this code on it's experimental stage.
*/
@Mixin(ChunkGenerator.class)
public class ChunkGeneratorMixin {
@Shadow @Final protected BiomeSource populationSource;

@Redirect(method = "generateFeatures", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/biome/source/BiomeSource;getBiomeForNoiseGen(Lnet/minecraft/util/math/ChunkPos;)Lnet/minecraft/world/biome/Biome;"))
private Biome generateSurfaceFeatures(BiomeSource source, ChunkPos chunkPos) {
private Biome cba$generateSurfaceFeatures(BiomeSource source, ChunkPos chunkPos) {
return source.getBiomeForNoiseGen(BiomeCoords.fromChunk(chunkPos.x) + BiomeCoords.fromBlock(8), 64, BiomeCoords.fromChunk(chunkPos.z) + BiomeCoords.fromBlock(8));
}

@Inject(method = "generateFeatures", at = @At("RETURN"), cancellable = true)
private void generateUndergroundFeatures(ChunkRegion region, StructureAccessor accessor, CallbackInfo ci) {
private void cba$generateUndergroundFeatures(ChunkRegion region, StructureAccessor accessor, CallbackInfo ci) {
ChunkPos chunkPos = region.getCenterPos();
int x = chunkPos.getStartX();
int z = chunkPos.getStartZ();
Expand All @@ -45,18 +48,19 @@ private void generateUndergroundFeatures(ChunkRegion region, StructureAccessor a
long seed = chunkRandom.setPopulationSeed(region.getSeed(), x, z);

try {
FeatureGenerationHelper.generateOnlyFeatures(biome, accessor, (ChunkGenerator)(Object)this, region, seed, chunkRandom, pos);
FeatureGenerationHelper.generateOnlyFeatures(biome, (ChunkGenerator)(Object)this, region, seed, chunkRandom, pos);
} catch (Exception exception) {
CrashReport crashReport = CrashReport.create(exception, "Biome decoration");
crashReport.addElement("Generation").add("CenterX", chunkPos.x).add("CenterZ", chunkPos.z).add("Seed", seed).add("Biome", biome);
throw new CrashException(crashReport);
}
}


@Redirect(method = "setStructureStarts(Lnet/minecraft/util/registry/DynamicRegistryManager;Lnet/minecraft/world/gen/StructureAccessor;Lnet/minecraft/world/chunk/Chunk;Lnet/minecraft/structure/StructureManager;J)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/biome/source/BiomeSource;getBiomeForNoiseGen(Lnet/minecraft/util/math/ChunkPos;)Lnet/minecraft/world/biome/Biome;"))
private Biome setStructureStarts(BiomeSource source, ChunkPos chunkPos) {
/**
* @author TelepathicGrunt
*/
@Redirect(method = "setStructureStarts(Lnet/minecraft/util/registry/DynamicRegistryManager;Lnet/minecraft/world/gen/StructureAccessor;Lnet/minecraft/world/chunk/Chunk;Lnet/minecraft/structure/StructureManager;J)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/biome/source/BiomeSource;getBiomeForNoiseGen(Lnet/minecraft/util/math/ChunkPos;)Lnet/minecraft/world/biome/Biome;"))
private Biome cba$setStructureStarts(BiomeSource source, ChunkPos chunkPos) {
return source.getBiomeForNoiseGen(BiomeCoords.fromChunk(chunkPos.x) + BiomeCoords.fromBlock(8), 64, BiomeCoords.fromChunk(chunkPos.z) + BiomeCoords.fromBlock(8));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public class HorizontalVoronoiBiomeAccessTypeMixin {
/**
* @author CorgiTaco
* @reason by default it locates the biome on a 2D map, this method modifies that and allows the BiomeAccessType to return the Y Axis as well.
*/
@Overwrite
public Biome getBiome(long seed, int x, int y, int z, BiomeAccess.Storage storage) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.source.MultiNoiseBiomeSource;

/**
* @author LudoCrypt
*/
@Mixin(MultiNoiseBiomeSource.class)
public interface MultiNoiseBiomeSourceAccessor {
@Invoker("<init>")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.alphastudios.cavebiomeapi.mixin;

import net.minecraft.util.math.BlockPos;
import net.minecraft.world.gen.chunk.NoiseChunkGenerator;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

//<>

/**
* @author TelepathicGrunt
*/
@Mixin(NoiseChunkGenerator.class)
public class NoiseChunkGeneratorMixin {
@ModifyArg(method = "populateEntities(Lnet/minecraft/world/ChunkRegion;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/ChunkRegion;getBiome(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/world/biome/Biome;"))
public BlockPos cba$populateSurfaceEntities(BlockPos pos) {
return new BlockPos(pos.getX(), 64, pos.getZ());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ public class VanillaLayeredBiomeSourceMixin {
@Shadow @Final private Registry<Biome> biomeRegistry;

@Inject(method = "<init>", at = @At("RETURN"))
public void initialize(long seed, boolean legacyBiomeInitLayer, boolean largeBiomes, Registry<Biome> biomeRegistry, CallbackInfo ci) {
public void cba$initialize(long seed, boolean legacyBiomeInitLayer, boolean largeBiomes, Registry<Biome> biomeRegistry, CallbackInfo ci) {
CaveBiomeAPI.initializeCaveBiomes(biomeRegistry, seed);
}

/**
* @author BlackGear27
* @reason collecting the surface biomes and injecting them along the underground biomes.
*/
@Overwrite
public Biome getBiomeForNoiseGen(int x, int y, int z) {
Biome surfaceBiome = this.biomeSampler.sample(this.biomeRegistry, x, z);
return CaveBiomeAPI.injectCaveBiomes(surfaceBiome, this.biomeRegistry, x, y, z);
return CaveBiomeAPI.injectCaveBiomes(surfaceBiome, x, y, z);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@

//<>

/**
* @author TelepathicGrunt
*/
@Mixin(OceanMonumentFeature.class)
public class OceanMonumentFeatureMixin {
@Redirect(method = "shouldStartAt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/biome/source/BiomeSource;getBiomesInArea(IIII)Ljava/util/Set;"))
private Set<Biome> getSurfaceBiomes(BiomeSource source, int x, int y, int z, int radius) {
private Set<Biome> cba$getSurfaceBiomes(BiomeSource source, int x, int y, int z, int radius) {
Set<Biome> biomeSet = source.getBiomesInArea(x, y, z, radius);
biomeSet.removeIf(CaveLayer.CAVE_BIOME_LIST::contains);
return biomeSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@

//<>

/**
* @author TelepathicGrunt
*/
@Mixin(WoodlandMansionFeature.class)
public class WoodlandMansionFeatureMixin {
@Redirect(method = "shouldStartAt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/biome/source/BiomeSource;getBiomesInArea(IIII)Ljava/util/Set;"))
private Set<Biome> getSurfaceBiomes(BiomeSource source, int x, int y, int z, int radius) {
private Set<Biome> cba$getSurfaceBiomes(BiomeSource source, int x, int y, int z, int radius) {
Set<Biome> biomeSet = source.getBiomesInArea(x, y, z, radius);
biomeSet.removeIf(CaveLayer.CAVE_BIOME_LIST::contains);
return biomeSet;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/cavebiomeapi.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"BiomeAccessMixin",
"ChunkGeneratorMixin",
"HorizontalVoronoiBiomeAccessTypeMixin",
"LayerAccessor",
"MultiNoiseBiomeSourceAccessor",
"NoiseChunkGeneratorMixin",
"VanillaLayeredBiomeSourceMixin",
"structure.OceanMonumentFeatureMixin",
"structure.WoodlandMansionFeatureMixin"
Expand Down
Loading

0 comments on commit 59f85f5

Please sign in to comment.