Improved Spout biome handling and add LocalWorld method for setting biome

This commit is contained in:
zml2008 2012-03-20 22:45:48 -07:00
parent a8eeacccd4
commit 0702a0f0ac
8 changed files with 89 additions and 14 deletions

View File

@ -105,11 +105,18 @@ public abstract class LocalWorld {
/**
* Get biome type
*
* @param pt
* @return
* @param pt The (x, z) location to check the biome at
* @return The biome type at the location
*/
public abstract BiomeType getBiome(Vector2D pt);
/**
* Set the biome type
* @param pt The (x, z) location to set the biome at
* @param biome The biome type to set to
*/
public abstract void setBiome(Vector2D pt, BiomeType biome);
/**
* set block type & data
* @param pt

View File

@ -208,6 +208,17 @@ public class BukkitWorld extends LocalWorld {
return new BiomeType(bukkitBiome.name());
}
@Override
public void setBiome(Vector2D pt, BiomeType biome) {
Biome bukkitBiome;
try {
bukkitBiome = Biome.valueOf(biome.getName().toUpperCase());
} catch (IllegalArgumentException e) {
return;
}
world.setBiome(pt.getBlockX(), pt.getBlockZ(), bukkitBiome);
}
/**
* Regenerate an area.
*

View File

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

View File

@ -1,26 +1,43 @@
package com.sk89q.worldedit.spout;
import java.util.Collections;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.sk89q.worldedit.BiomeType;
import com.sk89q.worldedit.BiomeTypes;
import com.sk89q.worldedit.UnknownBiomeTypeException;
import org.spout.api.generator.biome.BiomeGenerator;
import org.spout.api.generator.biome.BiomeType;
public class SpoutBiomeTypes implements BiomeTypes {
private final Map<String, SpoutBiomeType> types = new HashMap<String, SpoutBiomeType>();
@Override
public boolean has(String name) {
return false;
return types.containsKey(name.toLowerCase());
}
@Override
public BiomeType get(String name) throws UnknownBiomeTypeException {
throw new UnknownBiomeTypeException(name);
public SpoutBiomeType get(String name) throws UnknownBiomeTypeException {
if (!has(name)) {
throw new UnknownBiomeTypeException(name);
} else {
return types.get(name.toLowerCase());
}
}
public void registerBiomeTypes(BiomeGenerator generator) {
for (BiomeType type : generator.getBiomes()) {
final SpoutBiomeType weType = new SpoutBiomeType(type);
if (!types.containsKey(weType.getName())) {
types.put(weType.getName(), weType);
}
}
}
@Override
public List<BiomeType> all() {
return Collections.<BiomeType>emptyList();
public List<com.sk89q.worldedit.BiomeType> all() {
return new ArrayList<com.sk89q.worldedit.BiomeType>(types.values());
}
}

View File

@ -68,7 +68,7 @@ public class SpoutServerInterface extends ServerInterface {
}
@Override
public BiomeTypes getBiomes() {
public SpoutBiomeTypes getBiomes() {
return biomes;
}

View File

@ -33,6 +33,7 @@ import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.TreeGenerator;
import org.spout.api.entity.Entity;
import org.spout.api.generator.biome.BiomeGenerator;
import org.spout.api.geo.World;
import org.spout.api.geo.cuboid.Chunk;
import org.spout.api.inventory.ItemStack;
@ -83,7 +84,7 @@ public class SpoutWorld extends LocalWorld {
*/
@Override
public boolean setBlockType(Vector pt, int type) {
return world.setBlockId(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), (short)type, WorldEditPlugin.getInstance());
return world.setBlockId(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), (short) type, WorldEditPlugin.getInstance());
}
/**
@ -185,9 +186,20 @@ public class SpoutWorld extends LocalWorld {
* @return
*/
public BiomeType getBiome(Vector2D pt) {
if (world.getGenerator() instanceof BiomeGenerator) {
BiomeGenerator gen = (BiomeGenerator) world.getGenerator();
return new SpoutBiomeType(gen.getBiome(pt.getBlockX(), pt.getBlockZ(), world.getSeed()));
}
return new BiomeType("Unknown");
}
public void setBiome(Vector2D pt, BiomeType biome) {
if (world.getGenerator() instanceof BiomeGenerator) {
BiomeGenerator gen = (BiomeGenerator) world.getGenerator();
gen.setBiome(new Vector3(pt.getBlockX(), 0, pt.getBlockZ()), ((SpoutBiomeType) biome).getSpoutBiome());
}
}
/**
* Regenerate an area.
*

View File

@ -34,6 +34,8 @@ import org.spout.api.event.player.PlayerInteractEvent.Action;
import org.spout.api.event.player.PlayerJoinEvent;
import org.spout.api.event.player.PlayerLeaveEvent;
import org.spout.api.event.server.PreCommandEvent;
import org.spout.api.event.world.WorldLoadEvent;
import org.spout.api.generator.biome.BiomeGenerator;
import org.spout.api.geo.discrete.Point;
import java.util.regex.Matcher;
@ -180,4 +182,11 @@ public class WorldEditPlayerListener implements Listener {
}
}
@EventHandler
public void onWorldLoad(WorldLoadEvent event) {
if (event.getWorld().getGenerator() instanceof BiomeGenerator) {
plugin.getServerInterface().getBiomes().registerBiomeTypes((BiomeGenerator) event.getWorld().getGenerator());
}
}
}

View File

@ -55,7 +55,7 @@ public class WorldEditPlugin extends CommonPlugin implements Named {
/**
* The server interface that all server-related API goes through.
*/
private ServerInterface server;
private SpoutServerInterface server;
/**
* Main WorldEdit instance.
*/
@ -283,7 +283,7 @@ public class WorldEditPlugin extends CommonPlugin implements Named {
*
* @return
*/
public ServerInterface getServerInterface() {
public SpoutServerInterface getServerInterface() {
return server;
}