mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-08-29 21:30:43 +00:00
API stuff
This commit is contained in:
@@ -0,0 +1,39 @@
|
|||||||
|
package com.dfsek.terra.api.bukkit;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.generic.world.BiomeGrid;
|
||||||
|
import org.bukkit.block.Biome;
|
||||||
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class BukkitBiomeGrid implements BiomeGrid {
|
||||||
|
private final ChunkGenerator.BiomeGrid delegate;
|
||||||
|
|
||||||
|
public BukkitBiomeGrid(ChunkGenerator.BiomeGrid biomeGrid) {
|
||||||
|
this.delegate = biomeGrid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChunkGenerator.BiomeGrid getHandle() {
|
||||||
|
return delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Biome getBiome(int x, int z) {
|
||||||
|
return delegate.getBiome(x, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Biome getBiome(int x, int y, int z) {
|
||||||
|
return delegate.getBiome(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBiome(int x, int z, @NotNull Biome bio) {
|
||||||
|
delegate.setBiome(x, z, bio);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBiome(int x, int y, int z, @NotNull Biome bio) {
|
||||||
|
delegate.setBiome(x, y, z, bio);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.dfsek.terra.api.bukkit;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.generic.BlockData;
|
||||||
|
|
||||||
|
public class BukkitBlockData implements BlockData {
|
||||||
|
private final org.bukkit.block.data.BlockData delegate;
|
||||||
|
|
||||||
|
public BukkitBlockData(org.bukkit.block.data.BlockData delegate) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.bukkit.block.data.BlockData getHandle() {
|
||||||
|
return delegate;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,4 +13,9 @@ public class BukkitWorld implements World {
|
|||||||
public long getSeed() {
|
public long getSeed() {
|
||||||
return delegate.getSeed();
|
return delegate.getSeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.bukkit.World getHandle() {
|
||||||
|
return delegate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.dfsek.terra.api.bukkit.generator;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.bukkit.BukkitBiomeGrid;
|
||||||
|
import com.dfsek.terra.api.bukkit.BukkitBlockData;
|
||||||
|
import com.dfsek.terra.api.bukkit.BukkitWorld;
|
||||||
|
import com.dfsek.terra.api.generic.BlockData;
|
||||||
|
import com.dfsek.terra.api.generic.generator.BlockPopulator;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public abstract class BukkitChunkGenerator extends ChunkGenerator implements com.dfsek.terra.api.generic.generator.ChunkGenerator {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChunkGenerator.@NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int x, int z, @NotNull BiomeGrid biome) {
|
||||||
|
BukkitChunkData data = new BukkitChunkData(createChunkData(((BukkitWorld) world).getHandle()));
|
||||||
|
generateChunkData(new BukkitWorld(world), random, x, z, new BukkitBiomeGrid(biome), data);
|
||||||
|
return data.getHandle();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BlockPopulator> getDefaultPopulators(com.dfsek.terra.api.generic.world.World world) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class BukkitChunkData implements com.dfsek.terra.api.generic.generator.ChunkGenerator.ChunkData {
|
||||||
|
|
||||||
|
private final ChunkGenerator.ChunkData delegate;
|
||||||
|
|
||||||
|
public BukkitChunkData(ChunkGenerator.ChunkData delegate) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChunkGenerator.ChunkData getHandle() {
|
||||||
|
return delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxHeight() {
|
||||||
|
return delegate.getMaxHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBlock(int x, int y, int z, @NotNull BlockData blockData) {
|
||||||
|
delegate.setBlock(x, y, z, ((BukkitBlockData) blockData).getHandle());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull BlockData getBlockData(int x, int y, int z) {
|
||||||
|
return new BukkitBlockData(delegate.getBlockData(x, y, z));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.dfsek.terra.api.generic;
|
||||||
|
|
||||||
|
public interface BlockData {
|
||||||
|
Object getHandle();
|
||||||
|
}
|
||||||
@@ -5,6 +5,6 @@ import com.dfsek.terra.api.generic.world.World;
|
|||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public abstract class BlockPopulator {
|
public interface BlockPopulator {
|
||||||
public abstract void populate(World world, Random random, Chunk chunk);
|
void populate(World world, Random random, Chunk chunk);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,64 @@
|
|||||||
package com.dfsek.terra.api.generic.generator;
|
package com.dfsek.terra.api.generic.generator;
|
||||||
|
|
||||||
import java.util.Collections;
|
import com.dfsek.terra.api.generic.BlockData;
|
||||||
|
import com.dfsek.terra.api.generic.world.BiomeGrid;
|
||||||
|
import com.dfsek.terra.api.generic.world.World;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public abstract class ChunkGenerator {
|
public interface ChunkGenerator {
|
||||||
public boolean isParallelCapable() {
|
boolean isParallelCapable();
|
||||||
return false;
|
|
||||||
}
|
|
||||||
public boolean shouldGenerateCaves() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
public boolean shouldGenerateDecorations() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
public boolean shouldGenerateMobs() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean shouldGenerateStructures() {
|
boolean shouldGenerateCaves();
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<BlockPopulator> getDefaultPopulators() {
|
boolean shouldGenerateDecorations();
|
||||||
return Collections.emptyList();
|
|
||||||
|
boolean shouldGenerateMobs();
|
||||||
|
|
||||||
|
boolean shouldGenerateStructures();
|
||||||
|
|
||||||
|
void generateChunkData(@NotNull World world, @NotNull Random random, int x, int z, @NotNull BiomeGrid biome, ChunkData data);
|
||||||
|
|
||||||
|
List<BlockPopulator> getDefaultPopulators(World world);
|
||||||
|
|
||||||
|
interface ChunkData {
|
||||||
|
Object getHandle();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the maximum height for the chunk.
|
||||||
|
* <p>
|
||||||
|
* Setting blocks at or above this height will do nothing.
|
||||||
|
*
|
||||||
|
* @return the maximum height
|
||||||
|
*/
|
||||||
|
int getMaxHeight();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the block at x,y,z in the chunk data to material.
|
||||||
|
* <p>
|
||||||
|
* Setting blocks outside the chunk's bounds does nothing.
|
||||||
|
*
|
||||||
|
* @param x the x location in the chunk from 0-15 inclusive
|
||||||
|
* @param y the y location in the chunk from 0 (inclusive) - maxHeight (exclusive)
|
||||||
|
* @param z the z location in the chunk from 0-15 inclusive
|
||||||
|
* @param blockData the type to set the block to
|
||||||
|
*/
|
||||||
|
void setBlock(int x, int y, int z, @NotNull BlockData blockData);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the type and data of the block at x, y, z.
|
||||||
|
* <p>
|
||||||
|
* Getting blocks outside the chunk's bounds returns air.
|
||||||
|
*
|
||||||
|
* @param x the x location in the chunk from 0-15 inclusive
|
||||||
|
* @param y the y location in the chunk from 0 (inclusive) - maxHeight (exclusive)
|
||||||
|
* @param z the z location in the chunk from 0-15 inclusive
|
||||||
|
* @return the data of the block or the BlockData for air if x, y or z are outside the chunk's bounds
|
||||||
|
*/
|
||||||
|
@NotNull BlockData getBlockData(int x, int y, int z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.dfsek.terra.api.generic.world;
|
||||||
|
|
||||||
|
import org.bukkit.block.Biome;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public interface BiomeGrid {
|
||||||
|
Object getHandle();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get biome at x, z within chunk being generated
|
||||||
|
*
|
||||||
|
* @param x - 0-15
|
||||||
|
* @param z - 0-15
|
||||||
|
* @return Biome value
|
||||||
|
* @deprecated biomes are now 3-dimensional
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
Biome getBiome(int x, int z);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get biome at x, z within chunk being generated
|
||||||
|
*
|
||||||
|
* @param x - 0-15
|
||||||
|
* @param y - 0-255
|
||||||
|
* @param z - 0-15
|
||||||
|
* @return Biome value
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
Biome getBiome(int x, int y, int z);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set biome at x, z within chunk being generated
|
||||||
|
*
|
||||||
|
* @param x - 0-15
|
||||||
|
* @param z - 0-15
|
||||||
|
* @param bio - Biome value
|
||||||
|
* @deprecated biomes are now 3-dimensional
|
||||||
|
*/
|
||||||
|
void setBiome(int x, int z, @NotNull Biome bio);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set biome at x, z within chunk being generated
|
||||||
|
*
|
||||||
|
* @param x - 0-15
|
||||||
|
* @param y - 0-255
|
||||||
|
* @param z - 0-15
|
||||||
|
* @param bio - Biome value
|
||||||
|
*/
|
||||||
|
void setBiome(int x, int y, int z, @NotNull Biome bio);
|
||||||
|
}
|
||||||
@@ -2,4 +2,6 @@ package com.dfsek.terra.api.generic.world;
|
|||||||
|
|
||||||
public interface World {
|
public interface World {
|
||||||
long getSeed();
|
long getSeed();
|
||||||
|
|
||||||
|
Object getHandle();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user