Skip to content
This repository was archived by the owner on Oct 6, 2024. It is now read-only.

Commit

Permalink
Update to latest Spigot
Browse files Browse the repository at this point in the history
The BaseChunkGenerator.getBiomesForChunk method is now deprecated, use getBlocksForChunk().getBiome instead. This was necessary because Bukkit deprecated the BiomeGrid.

Now that Bukkit has an actually good world generator api, most of WorldGeneratorApi is no longer necessary. 😃 I'll have a look at what needs to remain, and what parts of the API can be removed in the future.
  • Loading branch information
rutgerkok committed Aug 26, 2021
1 parent eb616a1 commit 4a1aaf6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.core.Registry;
import net.minecraft.world.level.chunk.ChunkBiomeContainer;

@Deprecated
public final class BiomeGridImpl implements BiomeGrid {
private final ChunkBiomeContainer biomeStorage;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock;
import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData;
import org.bukkit.generator.ChunkGenerator.ChunkData;

import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Registry;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ChunkBiomeContainer;

public final class ChunkDataImpl implements ChunkData {
private final ChunkAccess internal;
Expand All @@ -23,6 +27,13 @@ public final class ChunkDataImpl implements ChunkData {
this.zOffset = internal.getPos().z * 16;
}

@Override
public org.bukkit.block.Biome getBiome(int x, int y, int z) {
ChunkBiomeContainer biomeStorage = getHandle().getBiomes();
return CraftBlock.biomeBaseToBiome((Registry<Biome>) biomeStorage.biomeRegistry,
biomeStorage.getNoiseBiome(x >> 2, y >> 2, z >> 2));
}

@Override
public BlockData getBlockData(int x, int y, int z) {
reusableBlockPos.set(xOffset + x, y, zOffset + z);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public DummyBukkitChunkGenerator(WorldGeneratorApi impl, WorldRef worldRef) {
}

@Override
@Deprecated
public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) {
throw new UnsupportedOperationException("This is a dummy class, used"
+ " because a custom world generator was registered. However,"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.concurrent.Executor;
import java.util.stream.IntStream;

import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import org.bukkit.generator.ChunkGenerator.ChunkData;

import com.mojang.serialization.Codec;
Expand Down Expand Up @@ -66,9 +65,11 @@ public static class GeneratingChunkImpl implements GeneratingChunk {
private final int chunkZ;
private final ChunkDataImpl blocks;
private final BiomeGenerator biomeGenerator;
@Deprecated
private final BiomeGridImpl biomeGrid;
public final ChunkAccess internal;

@SuppressWarnings("deprecation")
GeneratingChunkImpl(ChunkAccess internal, BiomeGenerator biomeGenerator) {
this.internal = Objects.requireNonNull(internal, "internal");
this.chunkX = internal.getPos().x;
Expand All @@ -85,7 +86,8 @@ public BiomeGenerator getBiomeGenerator() {
}

@Override
public BiomeGrid getBiomesForChunk() {
@Deprecated
public org.bukkit.generator.ChunkGenerator.BiomeGrid getBiomesForChunk() {
return biomeGrid;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package nl.rutgerkok.worldgeneratorapi;

import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import org.bukkit.generator.ChunkGenerator.ChunkData;

import nl.rutgerkok.worldgeneratorapi.property.PropertyRegistry;
Expand Down Expand Up @@ -28,14 +27,17 @@ interface GeneratingChunk {
BiomeGenerator getBiomeGenerator();

/**
* The biome grid. Represents the biomes of this chunk. Can be modified.
* (Although if you want to change biome generation, it is better to register
* your own {@link BiomeGenerator} instead.)
* The biome grid. Represents the biomes of this chunk.
*
* @return The biome grid for the chunk.
* @since 0.1
* @deprecated Bukkit deprecated this class. Access stored biomes through
* {@link #getBlocksForChunk()} instead, using
* {@link ChunkData#getBiome(int, int, int)}. (If that method
* doesn't exist, update your Bukkit API.)
*/
BiomeGrid getBiomesForChunk();
@Deprecated
org.bukkit.generator.ChunkGenerator.BiomeGrid getBiomesForChunk();

/**
* The blocks of the chunk. You should fill the chunk with water and its base
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.bukkit.World;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import org.bukkit.plugin.Plugin;

import nl.rutgerkok.worldgeneratorapi.decoration.WorldDecorator;
Expand Down Expand Up @@ -45,9 +44,7 @@ public interface WorldGenerator {

/**
* Gets the biome generator currently in use. This method will return a valid
* biome generator for both vanilla and custom worlds. Note that modifications
* to the biomes made in later stages of world generation (using for example
* {@link BiomeGrid}) will not show up in this biome generator.
* biome generator for both vanilla and custom worlds.
*
* @return The biome generator.
* @since 0.1
Expand Down

0 comments on commit 4a1aaf6

Please sign in to comment.