下面列出了怎么用org.bukkit.block.Biome的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public ChunkData generateChunkData(World world, Random random, int cx, int cz, BiomeGrid biomeGrid) {
final ChunkData chunkData = createChunkData(world);
Biome biome;
final Config config = IridiumSkyblock.getConfiguration();
final String worldName = world.getName();
if (worldName.equals(config.worldName))
biome = config.defaultBiome.parseBiome();
else if (worldName.equals(config.netherWorldName))
biome = config.defaultNetherBiome.parseBiome();
else
return chunkData;
for (int x = 0; x <= 15; x++) {
for (int z = 0; z <= 15; z++) {
biomeGrid.setBiome(x, z, biome);
}
}
return chunkData;
}
@Test
public void testOilResource() {
NamespacedKey key = new NamespacedKey(plugin, "oil");
GEOResource resource = testResource(key, "Oil", SlimefunItems.OIL_BUCKET, false, 8);
Assertions.assertEquals(0, resource.getDefaultSupply(Environment.NETHER, Biome.NETHER_WASTES));
Assertions.assertNotEquals(0, resource.getDefaultSupply(Environment.NORMAL, Biome.BEACH));
Assertions.assertTrue(resource.getDefaultSupply(Environment.NORMAL, Biome.DESERT) > 10);
Assertions.assertTrue(resource.getDefaultSupply(Environment.NORMAL, Biome.MOUNTAINS) > 10);
Assertions.assertTrue(resource.getDefaultSupply(Environment.NORMAL, Biome.ICE_SPIKES) > 10);
Assertions.assertTrue(resource.getDefaultSupply(Environment.NORMAL, Biome.BADLANDS) > 10);
Assertions.assertTrue(resource.getDefaultSupply(Environment.NORMAL, Biome.OCEAN) > 10);
Assertions.assertTrue(resource.getDefaultSupply(Environment.NORMAL, Biome.SWAMP) > 10);
Assertions.assertEquals(10, resource.getDefaultSupply(Environment.NORMAL, Biome.SUNFLOWER_PLAINS));
}
public static void register() {
setValidBiome(CustomMobType.YOBO, CustomMobLevel.LESSER, Biome.PLAINS);
setValidBiome(CustomMobType.YOBO, CustomMobLevel.LESSER, Biome.FOREST);
setValidBiome(CustomMobType.YOBO, CustomMobLevel.LESSER, Biome.BIRCH_FOREST);
setValidBiome(CustomMobType.YOBO, CustomMobLevel.LESSER, Biome.BIRCH_FOREST_HILLS);
setValidBiome(CustomMobType.YOBO, CustomMobLevel.GREATER, Biome.SUNFLOWER_PLAINS);
setValidBiome(CustomMobType.YOBO, CustomMobLevel.GREATER, Biome.FLOWER_FOREST);
setValidBiome(CustomMobType.YOBO, CustomMobLevel.GREATER, Biome.BIRCH_FOREST_HILLS_MOUNTAINS);
setValidBiome(CustomMobType.YOBO, CustomMobLevel.GREATER, Biome.BIRCH_FOREST_MOUNTAINS);
setValidBiome(CustomMobType.YOBO, CustomMobLevel.GREATER, Biome.FOREST_HILLS);
setValidBiome(CustomMobType.YOBO, CustomMobLevel.ELITE, Biome.EXTREME_HILLS);
setValidBiome(CustomMobType.YOBO, CustomMobLevel.ELITE, Biome.EXTREME_HILLS_PLUS);
setValidBiome(CustomMobType.YOBO, CustomMobLevel.ELITE, Biome.ROOFED_FOREST);
setValidBiome(CustomMobType.YOBO, CustomMobLevel.ELITE, Biome.ROOFED_FOREST_MOUNTAINS);
setValidBiome(CustomMobType.YOBO, CustomMobLevel.BRUTAL, Biome.MEGA_SPRUCE_TAIGA_HILLS);
setValidBiome(CustomMobType.YOBO, CustomMobLevel.BRUTAL, Biome.EXTREME_HILLS_MOUNTAINS);
setValidBiome(CustomMobType.YOBO, CustomMobLevel.BRUTAL, Biome.EXTREME_HILLS_PLUS_MOUNTAINS);
}
@Override
public void populate(World world, Random random, Chunk chunk){
for (int x = 1; x < 15; x++) {
for (int z = 1; z < 15; z++) {
Block block = chunk.getBlock(x, 1, z);
Biome replacementBiome = getReplacementBiome(block.getBiome());
if (UhcCore.getVersion() < 16){
if (replacementBiome != null) {
block.setBiome(replacementBiome);
}
}else {
for (int y = 0; y < 200; y++) {
block = chunk.getBlock(x, y, z);
if (replacementBiome != null) {
block.setBiome(replacementBiome);
}
}
}
}
}
}
private Biome getReplacementBiome(Biome biome){
switch (biome){
case OCEAN:
case FROZEN_OCEAN:
case WARM_OCEAN:
case LUKEWARM_OCEAN:
case COLD_OCEAN:
return Biome.PLAINS;
case DEEP_OCEAN:
case DEEP_FROZEN_OCEAN:
case DEEP_WARM_OCEAN:
case DEEP_LUKEWARM_OCEAN:
case DEEP_COLD_OCEAN:
return Biome.FOREST;
}
return null;
}
public double getSolidBlock(int x, int z, String w, Player p) {
int y = 0;
World world = Bukkit.getWorld(w);
if (world.getBiome(x, z).equals(Biome.valueOf(nether))) {
return getSolidBlockNether(x,z,p);
} else {
if(wild.getConfig().getBoolean("Worlds."+w+".InvertY",false))
return invertSearch(x,z,w);
/*for (int i = world.getMaxHeight(); i >= 0; i--) {
y = i;
if (!world.getBlockAt(x, y, z).isEmpty()) {
return y+ 4.5;
}
}*/
return Bukkit.getWorld(w).getHighestBlockAt(x,z).getRelative(BlockFace.DOWN).getY()+5;
}
}
/**
* @return the biome
*/
public Biome getBiome() {
if (biome == null) {
biome = center.getBlock().getBiome();
}
return biome;
}
@Override
public ChunkGenerator getChunkGenerator() {
return new ChunkGenerator() {
@Override
public final ChunkGenerator.ChunkData generateChunkData(final World world, final Random random, final int x, final int z, final ChunkGenerator.BiomeGrid chunkGererator) {
final ChunkGenerator.ChunkData chunkData = this.createChunkData(world);
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
chunkGererator.setBiome(i, j, Biome.VOID);
}
}
return chunkData;
}
};
}
@Override
public ChunkGenerator getChunkGenerator() {
return new ChunkGenerator() {
@Override
public final ChunkGenerator.ChunkData generateChunkData(final World world, final Random random, final int x, final int z, final ChunkGenerator.BiomeGrid chunkGererator) {
final ChunkGenerator.ChunkData chunkData = this.createChunkData(world);
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
chunkGererator.setBiome(i, j, Biome.VOID);
}
}
return chunkData;
}
};
}
@Override
public boolean setBiome(Vector2D position, BaseBiome biome) {
BukkitImplAdapter adapter = BukkitQueue_0.getAdapter();
if (adapter != null) {
Biome bukkitBiome = adapter.getBiome(biome.getId());
getWorld().setBiome(position.getBlockX(), position.getBlockZ(), bukkitBiome);
return true;
} else {
return false;
}
}
public void setBiome(int x, int z, Biome bio) {
net.minecraft.world.biome.Biome bb = CraftBlock.biomeToBiomeBase(bio);
if (this.world.isBlockLoaded(new BlockPos(x, 0, z))) {
net.minecraft.world.chunk.Chunk chunk = this.world.getChunkFromBlockCoords(new BlockPos(x, 0, z));
if (chunk != null) {
byte[] biomevals = chunk.getBiomeArray();
biomevals[((z & 0xF) << 4) | (x & 0xF)] = (byte) net.minecraft.world.biome.Biome.REGISTRY.getIDForObject(bb);
chunk.markDirty(); // SPIGOT-2890
}
}
}
@Override
public ChunkGenerator getChunkGenerator() {
return new ChunkGenerator() {
@Override
public final ChunkGenerator.ChunkData generateChunkData(final World world, final Random random, final int x, final int z, final ChunkGenerator.BiomeGrid chunkGererator) {
final ChunkGenerator.ChunkData chunkData = this.createChunkData(world);
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
chunkGererator.setBiome(i, j, Biome.THE_VOID);
}
}
return chunkData;
}
};
}
public static @Nullable Biome parse(final String name) {
if (!mapFor19) return util.parse(name);
To19Mapping mapping = BiomeHook.getUtil().parse(name);
if (mapping == null) return util.parse(name); // Should not happen - incomplete maps are a mess to work with for programmer
return mapping.getHandle();
}
@Override
public int getDefaultSupply(Environment environment, Biome biome) {
if (environment != Environment.NORMAL) {
return 0;
}
switch (biome) {
case SNOWY_BEACH:
case STONE_SHORE:
case BEACH:
case DESERT_LAKES:
case RIVER:
case ICE_SPIKES:
case FROZEN_RIVER:
return 40;
case DEEP_OCEAN:
case OCEAN:
case COLD_OCEAN:
case DEEP_COLD_OCEAN:
case DEEP_FROZEN_OCEAN:
case DEEP_LUKEWARM_OCEAN:
case DEEP_WARM_OCEAN:
case FROZEN_OCEAN:
case LUKEWARM_OCEAN:
case WARM_OCEAN:
return 60;
case SWAMP:
case SWAMP_HILLS:
return 20;
default:
return 6;
}
}
@Override
protected Biome[] get(final Event e, final Location[] source) {
return get(source, new Converter<Location, Biome>() {
@SuppressWarnings("null")
@Override
public Biome convert(final Location l) {
return l.getWorld().getBiome(l.getBlockX(), l.getBlockZ());
}
});
}
@Override
@Nullable
public Class<?>[] acceptChange(final ChangeMode mode) {
if (mode == ChangeMode.SET)
return new Class[] {Biome.class};
return super.acceptChange(mode);
}
private boolean isAcceptableBiome(final Biome biome) {
return (biome == Biome.FOREST) || (biome == Biome.BIRCH_FOREST)
|| (biome == Biome.SWAMP) || (biome == Biome.JUNGLE)
|| (biome == Biome.DARK_FOREST) || (biome == Biome.DARK_FOREST_HILLS)
|| (biome == Biome.MOUNTAINS) || (biome == Biome.TAIGA)
|| (biome == Biome.SAVANNA);
}
@Override
public byte[] getBiomeArray() {
if (!hasBiomes) return null;
BukkitImplAdapter adapter = getParent().getAdapter();
byte[] biomes = new byte[256];
int index = 0;
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++, index++) {
Biome biome = snapshot.getBiome(x, z);
biomes[index] = (byte) adapter.getBiomeId(biome);
}
}
return biomes;
}
DefaultBiomeGrid(Environment env) {
switch (env) {
case THE_END:
defaultBiome = Biome.THE_END;
break;
case NETHER:
defaultBiome = Biome.NETHER;
break;
default:
defaultBiome = Biome.OCEAN;
break;
}
}
public List<Biome> getBlacklistedBiomes() {
// Temporary fix. -- Should be enough though.
return super.getConfig().getStringList("Blacklisted_Biomes").stream()
.map(String::toUpperCase)
.map(Biome::valueOf)
.collect(Collectors.toList());
}
@Test
public void testSaltResource() {
NamespacedKey key = new NamespacedKey(plugin, "salt");
GEOResource resource = testResource(key, "Salt", SlimefunItems.SALT, true, 18);
Assertions.assertEquals(0, resource.getDefaultSupply(Environment.NETHER, Biome.NETHER_WASTES));
Assertions.assertEquals(0, resource.getDefaultSupply(Environment.THE_END, Biome.THE_END));
Assertions.assertNotEquals(0, resource.getDefaultSupply(Environment.NORMAL, Biome.MOUNTAINS));
Assertions.assertTrue(resource.getDefaultSupply(Environment.NORMAL, Biome.BEACH) > 10);
Assertions.assertTrue(resource.getDefaultSupply(Environment.NORMAL, Biome.OCEAN) > 10);
Assertions.assertTrue(resource.getDefaultSupply(Environment.NORMAL, Biome.SWAMP) > 10);
}
public boolean inNether(Location loc, Player target) {
if (loc.getWorld().getBiome(loc.getBlockX(), loc.getBlockZ()) == Biome.valueOf(nether) || target.getWorld().getName().equals("DIM-1")) {
inNether = true;
} else {
inNether = false;
}
return inNether;
}
public GEOResourceGenerationEvent(World world, Biome biome, int x, int z, GEOResource resource, int value) {
this.world = world;
this.biome = biome;
this.resource = resource;
this.x = x;
this.z = z;
this.value = value;
}
/**
* Sets all blocks in an island to a specified biome type
*
* @param islandLoc - island location
* @param biomeType - biome type
* @return true if the setting was successful
*/
public boolean setIslandBiome(Location islandLoc, Biome biomeType) {
Island island = plugin.getGrid().getIslandAt(islandLoc);
if (island != null) {
new SetBiome(plugin, island, biomeType, null);
return true;
}
return false;
}
public void setBiome(int x, int z, Biome bio) {
net.minecraft.world.biome.BiomeGenBase bb = CraftBlock.biomeToBiomeBase(bio);
if (this.world.blockExists(x, 0, z)) {
net.minecraft.world.chunk.Chunk chunk = this.world.getChunkFromBlockCoords(x, z);
if (chunk != null) {
byte[] biomevals = chunk.getBiomeArray();
biomevals[((z & 0xF) << 4) | (x & 0xF)] = (byte)bb.biomeID;
}
}
}
@Override
public int getDefaultSupply(Environment envionment, Biome biome) {
if (envionment == Environment.NORMAL) {
return 5;
}
return 0;
}
public static Biome biomeBaseToBiome(BiomeGenBase base) {
if (base == null) {
return null;
}
return BIOME_MAPPING[base.biomeID];
}
public static void setValidBiome(CustomMobType type, CustomMobLevel level, Biome biome) {
LinkedList<TypeLevel> mobs = biomes.get(biome);
if (mobs == null) {
mobs = new LinkedList<TypeLevel>();
}
mobs.add(new TypeLevel(type, level));
biomes.put(biome.name(), mobs);
}
/**
* @return the biome
*/
public Biome getBiome() {
return biome;
}
protected void register(Biome from, Biome to, ProtocolVersion... versions) {
for (ProtocolVersion version : versions) {
getTable(version).setRemap(MaterialAPI.getBiomeNetworkId(from), MaterialAPI.getBiomeNetworkId(to));
}
}