Biome clean up & fixes

Change BiomeType to an interface.
Do not longer use invalid biomes of Bukkit Biome enum.
Add a common unknown biome type.
Dieser Commit ist enthalten in:
aumgn 2012-04-10 13:09:47 +02:00
Ursprung 2ed92dafad
Commit e86dc2c90b
6 geänderte Dateien mit 79 neuen und 56 gelöschten Zeilen

Datei anzeigen

@ -1,43 +1,17 @@
package com.sk89q.worldedit;
public class BiomeType {
public interface BiomeType {
private String name;
public BiomeType(String name) {
this.name = name;
}
public static final BiomeType UNKNOWN = new BiomeType() {
public String getName() {
return "Unknown";
}
};
/**
* Get the name of the player.
* Get the name of this biome type.
*
* @return String
*/
public String getName() {
return name;
}
/**
* Gets the hash code.
*
* @return hash code
*/
@Override
public int hashCode() {
return name.hashCode();
}
/**
* Returns true if equal.
*
* @param other
* @return whether the other object is equivalent
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof BiomeType) {
return ((BiomeType) obj).name.equals(name);
}
return false;
}
public String getName();
}

Datei anzeigen

@ -0,0 +1,49 @@
package com.sk89q.worldedit.bukkit;
import java.util.Locale;
import org.bukkit.block.Biome;
import com.sk89q.worldedit.BiomeType;
public enum BukkitBiomeType implements BiomeType {
SWAMPLAND(Biome.SWAMPLAND),
FOREST(Biome.FOREST),
TAIGA(Biome.TAIGA),
DESERT(Biome.DESERT),
PLAINS(Biome.PLAINS),
HELL(Biome.HELL),
SKY(Biome.SKY),
RIVER(Biome.RIVER),
EXTREME_HILLS(Biome.EXTREME_HILLS),
OCEAN(Biome.OCEAN),
FROZEN_OCEAN(Biome.FROZEN_OCEAN),
FROZEN_RIVER(Biome.FROZEN_RIVER),
ICE_PLAINS(Biome.ICE_PLAINS),
ICE_MOUNTAINS(Biome.ICE_MOUNTAINS),
MUSHROOM_ISLAND(Biome.MUSHROOM_ISLAND),
MUSHROOM_SHORE(Biome.MUSHROOM_SHORE),
BEACH(Biome.BEACH),
DESERT_HILLS(Biome.DESERT_HILLS),
FOREST_HILLS(Biome.FOREST_HILLS),
TAIGA_HILLS(Biome.TAIGA_HILLS),
SMALL_MOUNTAINS(Biome.SMALL_MOUNTAINS),
JUNGLE(Biome.JUNGLE),
JUNGLE_HILLS(Biome.JUNGLE_HILLS);
private Biome bukkitBiome;
private BukkitBiomeType(Biome biome) {
this.bukkitBiome = biome;
}
@Override
public String getName() {
return name().toLowerCase(Locale.ENGLISH);
}
public Biome getBukkitBiome() {
return bukkitBiome;
}
}

Datei anzeigen

@ -1,11 +1,9 @@
package com.sk89q.worldedit.bukkit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import org.bukkit.block.Biome;
import com.sk89q.worldedit.BiomeType;
import com.sk89q.worldedit.BiomeTypes;
import com.sk89q.worldedit.UnknownBiomeTypeException;
@ -18,7 +16,7 @@ public class BukkitBiomeTypes implements BiomeTypes {
@Override
public boolean has(String name) {
try {
Biome.valueOf(name.toUpperCase(Locale.ENGLISH));
BukkitBiomeType.valueOf(name.toUpperCase(Locale.ENGLISH));
return true;
} catch (IllegalArgumentException exc) {
return false;
@ -28,8 +26,7 @@ public class BukkitBiomeTypes implements BiomeTypes {
@Override
public BiomeType get(String name) throws UnknownBiomeTypeException {
try {
Biome biome = Biome.valueOf(name.toUpperCase(Locale.ENGLISH));
return new BiomeType(biome.name());
return BukkitBiomeType.valueOf(name.toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException exc) {
throw new UnknownBiomeTypeException(name);
}
@ -37,11 +34,7 @@ public class BukkitBiomeTypes implements BiomeTypes {
@Override
public List<BiomeType> all() {
List<BiomeType> biomes = new ArrayList<BiomeType>();
for (Biome biome : Biome.values()) {
biomes.add(new BiomeType(biome.name()));
}
return biomes;
return Arrays.<BiomeType>asList(BukkitBiomeType.values());
}
}

Datei anzeigen

@ -214,18 +214,20 @@ public class BukkitWorld extends LocalWorld {
*/
public BiomeType getBiome(Vector2D pt) {
Biome bukkitBiome = world.getBiome(pt.getBlockX(), pt.getBlockZ());
return new BiomeType(bukkitBiome.name());
try {
return BukkitBiomeType.valueOf(bukkitBiome.name());
} catch (IllegalArgumentException exc) {
return BiomeType.UNKNOWN;
}
}
@Override
public void setBiome(Vector2D pt, BiomeType biome) {
Biome bukkitBiome;
try {
bukkitBiome = Biome.valueOf(biome.getName().toUpperCase());
} catch (IllegalArgumentException e) {
return;
if (biome instanceof BukkitBiomeType) {
Biome bukkitBiome;
bukkitBiome = ((BukkitBiomeType) biome).getBukkitBiome();
world.setBiome(pt.getBlockX(), pt.getBlockZ(), bukkitBiome);
}
world.setBiome(pt.getBlockX(), pt.getBlockZ(), bukkitBiome);
}
/**

Datei anzeigen

@ -23,14 +23,18 @@ import org.spout.api.generator.biome.BiomeType;
/**
* @author zml2008
*/
public class SpoutBiomeType extends com.sk89q.worldedit.BiomeType {
public class SpoutBiomeType implements com.sk89q.worldedit.BiomeType {
private final BiomeType type;
public SpoutBiomeType(BiomeType type) {
super(type.getName().toLowerCase().replace(" ", ""));
this.type = type;
}
@Override
public String getName() {
return type.getName().toLowerCase().replace(" ", "");
}
public BiomeType getSpoutBiome() {
return type;
}

Datei anzeigen

@ -206,11 +206,12 @@ public class SpoutWorld extends LocalWorld {
BiomeGenerator gen = (BiomeGenerator) world.getGenerator();
return new SpoutBiomeType(gen.getBiome(pt.getBlockX(), pt.getBlockZ(), world.getSeed()));
}
return new BiomeType("Unknown");
return BiomeType.UNKNOWN;
}
public void setBiome(Vector2D pt, BiomeType biome) {
if (world.getGenerator() instanceof BiomeGenerator) {
if (biome instanceof SpoutBiomeType &&
world.getGenerator() instanceof BiomeGenerator) {
BiomeGenerator gen = (BiomeGenerator) world.getGenerator();
gen.setBiome(new Vector3(pt.getBlockX(), 0, pt.getBlockZ()), ((SpoutBiomeType) biome).getSpoutBiome());
}