2010-12-27 03:13:03 +01:00
|
|
|
package org.bukkit.craftbukkit;
|
|
|
|
|
2011-01-15 22:52:43 +01:00
|
|
|
import org.bukkit.craftbukkit.entity.*;
|
|
|
|
import org.bukkit.entity.*;
|
2011-01-26 21:03:54 +01:00
|
|
|
import org.bukkit.entity.Entity;
|
2011-01-17 09:26:47 +01:00
|
|
|
|
2011-01-26 21:03:54 +01:00
|
|
|
import java.util.ArrayList;
|
2010-12-27 03:13:03 +01:00
|
|
|
import java.util.HashMap;
|
2011-01-26 21:03:54 +01:00
|
|
|
import java.util.List;
|
2011-01-03 03:01:17 +01:00
|
|
|
import java.util.Random;
|
2011-01-15 22:52:43 +01:00
|
|
|
import net.minecraft.server.*;
|
2011-02-17 06:25:03 +01:00
|
|
|
|
2011-01-15 22:21:05 +01:00
|
|
|
import org.bukkit.entity.Arrow;
|
2011-01-15 22:36:57 +01:00
|
|
|
import org.bukkit.block.Block;
|
2011-01-15 22:21:05 +01:00
|
|
|
import org.bukkit.entity.Boat;
|
2010-12-27 03:13:03 +01:00
|
|
|
import org.bukkit.Chunk;
|
2011-01-15 22:27:29 +01:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2011-01-15 22:44:22 +01:00
|
|
|
import org.bukkit.util.Vector;
|
2011-01-30 22:53:57 +01:00
|
|
|
import org.bukkit.BlockChangeDelegate;
|
2011-01-02 09:40:27 +01:00
|
|
|
import org.bukkit.Location;
|
2011-01-30 22:53:57 +01:00
|
|
|
import org.bukkit.TreeType;
|
2010-12-27 03:13:03 +01:00
|
|
|
import org.bukkit.World;
|
|
|
|
|
|
|
|
public class CraftWorld implements World {
|
|
|
|
private final WorldServer world;
|
2011-02-06 21:50:57 +01:00
|
|
|
private final Environment environment;
|
2011-02-08 13:03:36 +01:00
|
|
|
private final CraftServer server;
|
2011-02-08 16:22:46 +01:00
|
|
|
private final ChunkProviderServer provider;
|
2011-02-20 17:09:02 +01:00
|
|
|
private HashMap<Integer,CraftChunk> unloadedChunks = new HashMap<Integer, CraftChunk>();
|
2011-02-02 00:32:18 +01:00
|
|
|
|
2011-01-03 03:01:17 +01:00
|
|
|
private static final Random rand = new Random();
|
2010-12-27 03:13:03 +01:00
|
|
|
|
2010-12-30 05:37:32 +01:00
|
|
|
public CraftWorld(WorldServer world) {
|
2010-12-27 03:13:03 +01:00
|
|
|
this.world = world;
|
2011-02-08 13:03:36 +01:00
|
|
|
this.server = world.getServer();
|
2011-02-23 03:37:56 +01:00
|
|
|
this.provider = world.u;
|
2011-02-06 21:50:57 +01:00
|
|
|
|
2011-02-23 03:37:56 +01:00
|
|
|
if (world.m instanceof WorldProviderHell) {
|
2011-02-06 21:50:57 +01:00
|
|
|
environment = Environment.NETHER;
|
|
|
|
} else {
|
|
|
|
environment = Environment.NORMAL;
|
|
|
|
}
|
2011-02-08 13:03:36 +01:00
|
|
|
|
|
|
|
server.addWorld(this);
|
2010-12-27 03:13:03 +01:00
|
|
|
}
|
2011-01-01 14:06:04 +01:00
|
|
|
|
2011-02-20 17:09:02 +01:00
|
|
|
public void preserveChunk( CraftChunk chunk ) {
|
2011-02-20 23:22:28 +01:00
|
|
|
unloadedChunks.put( (chunk.getX() << 16) + chunk.getZ(), chunk );
|
2011-02-20 17:09:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public CraftChunk popPreservedChunk( int x, int z ) {
|
2011-02-20 23:22:28 +01:00
|
|
|
return unloadedChunks.remove( (x << 16) + z );
|
2011-02-20 17:09:02 +01:00
|
|
|
}
|
|
|
|
|
2010-12-27 03:13:03 +01:00
|
|
|
public Block getBlockAt(int x, int y, int z) {
|
2011-02-01 23:49:28 +01:00
|
|
|
return getChunkAt(x >> 4, z >> 4).getBlock(x & 0xF, y & 0x7F, z & 0xF);
|
2010-12-27 03:13:03 +01:00
|
|
|
}
|
2011-01-15 21:01:49 +01:00
|
|
|
|
|
|
|
public int getBlockTypeIdAt(int x, int y, int z) {
|
2011-01-29 22:50:29 +01:00
|
|
|
return world.getTypeId(x, y, z);
|
2011-01-15 21:01:49 +01:00
|
|
|
}
|
|
|
|
|
2011-01-03 22:56:09 +01:00
|
|
|
public int getHighestBlockYAt(int x, int z) {
|
2011-01-10 09:30:34 +01:00
|
|
|
return world.d(x, z);
|
2011-01-03 22:56:09 +01:00
|
|
|
}
|
2011-02-02 00:32:18 +01:00
|
|
|
|
2011-01-16 00:00:01 +01:00
|
|
|
public Location getSpawnLocation() {
|
2011-02-23 03:37:56 +01:00
|
|
|
ChunkCoordinates spawn = world.l();
|
|
|
|
return new Location(this, spawn.a, world.e(spawn.a, spawn.c), spawn.c);
|
2011-01-16 00:00:01 +01:00
|
|
|
}
|
2011-03-01 03:21:27 +01:00
|
|
|
|
|
|
|
public boolean setSpawnLocation(int x, int y, int z) {
|
|
|
|
try {
|
|
|
|
world.q.a(x, y, z);
|
|
|
|
return true;
|
|
|
|
} catch (Exception e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-27 03:13:03 +01:00
|
|
|
public Chunk getChunkAt(int x, int z) {
|
2011-02-08 16:22:46 +01:00
|
|
|
return this.provider.d(x,z).bukkitChunk;
|
2010-12-27 03:13:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public Chunk getChunkAt(Block block) {
|
2011-01-18 12:37:01 +01:00
|
|
|
return getChunkAt(block.getX() >> 4, block.getZ() >> 4);
|
2010-12-27 03:13:03 +01:00
|
|
|
}
|
|
|
|
|
2011-02-01 23:49:28 +01:00
|
|
|
public boolean isChunkLoaded(int x, int z) {
|
2011-02-08 16:22:46 +01:00
|
|
|
return provider.a( x, z );
|
2010-12-27 03:13:03 +01:00
|
|
|
}
|
|
|
|
|
2011-02-04 21:11:57 +01:00
|
|
|
public Chunk[] getLoadedChunks() {
|
2011-02-09 21:00:17 +01:00
|
|
|
Object[] chunks = provider.e.values().toArray();
|
2011-02-08 16:22:46 +01:00
|
|
|
org.bukkit.Chunk[] craftChunks = new CraftChunk[chunks.length];
|
|
|
|
|
|
|
|
for (int i = 0; i < chunks.length; i++) {
|
2011-02-09 21:00:17 +01:00
|
|
|
net.minecraft.server.Chunk chunk = (net.minecraft.server.Chunk)chunks[i];
|
|
|
|
craftChunks[i] = chunk.bukkitChunk;
|
2011-02-08 16:22:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return craftChunks;
|
2011-02-04 21:11:57 +01:00
|
|
|
}
|
|
|
|
|
2011-02-01 23:49:28 +01:00
|
|
|
public void loadChunk(int x, int z) {
|
2011-02-08 15:26:55 +01:00
|
|
|
loadChunk(x, z, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean unloadChunk(int x, int z) {
|
|
|
|
return unloadChunk(x, z, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean unloadChunk(int x, int z, boolean save) {
|
|
|
|
return unloadChunk(x, z, save, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean unloadChunkRequest(int x, int z) {
|
|
|
|
return unloadChunkRequest(x, z, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean unloadChunkRequest(int x, int z, boolean safe) {
|
2011-02-08 16:22:46 +01:00
|
|
|
if (safe && isChunkInUse(x, z)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
provider.c(x, z);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean unloadChunk(int x, int z, boolean save, boolean safe) {
|
|
|
|
if (safe && isChunkInUse(x, z)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
net.minecraft.server.Chunk chunk = provider.b(x, z);
|
|
|
|
|
|
|
|
if (save) {
|
|
|
|
chunk.e();
|
|
|
|
provider.b(chunk);
|
|
|
|
provider.a(chunk);
|
|
|
|
}
|
|
|
|
|
|
|
|
provider.a.remove(x, z);
|
|
|
|
provider.e.remove(x, z);
|
|
|
|
provider.f.remove(chunk);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-02 21:27:44 +01:00
|
|
|
public boolean regenerateChunk(int x, int z) {
|
|
|
|
unloadChunk(x, z, false, false);
|
|
|
|
|
|
|
|
provider.a.remove(x, z);
|
|
|
|
|
|
|
|
net.minecraft.server.Chunk chunk = null;
|
|
|
|
|
2011-03-11 22:25:35 +01:00
|
|
|
if (provider.c == null) {
|
2011-03-02 21:27:44 +01:00
|
|
|
chunk = provider.b;
|
|
|
|
} else {
|
|
|
|
chunk = provider.c.b(x, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
chunkLoadPostProcess(chunk, x, z);
|
|
|
|
|
|
|
|
refreshChunk(x, z);
|
|
|
|
|
|
|
|
return chunk != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean refreshChunk(int x, int z) {
|
2011-03-11 22:25:35 +01:00
|
|
|
if (!isChunkLoaded(x, z)) {
|
2011-03-02 21:27:44 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int px = x<<4;
|
|
|
|
int pz = z<<4;
|
|
|
|
|
|
|
|
// If there are more than 10 updates to a chunk at once, it carries out the update as a cuboid
|
|
|
|
// This flags 16 blocks in a line along the bottom for update and then flags a block at the opposite corner at the top
|
|
|
|
// The cuboid that contains these 17 blocks covers the entire chunk
|
|
|
|
// The server will compress the chunk and send it to all clients
|
|
|
|
|
|
|
|
for(int xx = px; xx < (px + 16); xx++) {
|
|
|
|
world.g(xx, 0, pz);
|
|
|
|
}
|
|
|
|
world.g(px, 127, pz+15);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-08 16:22:46 +01:00
|
|
|
public boolean isChunkInUse(int x, int z) {
|
|
|
|
Player[] players = server.getOnlinePlayers();
|
|
|
|
|
|
|
|
for (Player player : players) {
|
|
|
|
Location loc = player.getLocation();
|
|
|
|
if (loc.getWorld() != provider.g.getWorld()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the chunk is within 256 blocks of a player, refuse to accept the unload request
|
|
|
|
// This is larger than the distance of loaded chunks that actually surround a player
|
|
|
|
// The player is the center of a 21x21 chunk grid, so the edge is 10 chunks (160 blocks) away from the player
|
|
|
|
if (Math.abs(loc.getBlockX() - (x << 4)) <= 256 && Math.abs(loc.getBlockZ() - (z << 4)) <= 256) {
|
2011-03-02 19:50:39 +01:00
|
|
|
return true;
|
2011-02-08 16:22:46 +01:00
|
|
|
}
|
|
|
|
}
|
2011-03-02 19:50:39 +01:00
|
|
|
return false;
|
2011-02-08 16:22:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean loadChunk(int x, int z, boolean generate) {
|
|
|
|
if (generate) {
|
|
|
|
// Use the default variant of loadChunk when generate == true.
|
|
|
|
return provider.d(x, z) != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
provider.a.remove(x, z);
|
|
|
|
net.minecraft.server.Chunk chunk = (net.minecraft.server.Chunk) provider.e.get(x, z);
|
|
|
|
|
|
|
|
if (chunk == null) {
|
|
|
|
chunk = provider.e(x, z);
|
|
|
|
|
2011-03-02 21:27:44 +01:00
|
|
|
chunkLoadPostProcess(chunk, x, z);
|
|
|
|
}
|
|
|
|
return chunk != null;
|
|
|
|
}
|
2011-02-08 16:22:46 +01:00
|
|
|
|
2011-03-02 21:27:44 +01:00
|
|
|
private void chunkLoadPostProcess(net.minecraft.server.Chunk chunk, int x, int z) {
|
|
|
|
if (chunk != null) {
|
|
|
|
provider.e.put(x, z, chunk);
|
|
|
|
provider.f.add(chunk);
|
2011-02-08 16:22:46 +01:00
|
|
|
|
2011-03-02 21:27:44 +01:00
|
|
|
chunk.c();
|
|
|
|
chunk.d();
|
2011-02-08 16:22:46 +01:00
|
|
|
|
2011-03-02 21:27:44 +01:00
|
|
|
if (!chunk.n && provider.a(x + 1, z + 1) && provider.a(x, z + 1) && provider.a(x + 1, z)) {
|
|
|
|
provider.a(provider, x, z);
|
|
|
|
}
|
2011-02-08 16:22:46 +01:00
|
|
|
|
2011-03-02 21:27:44 +01:00
|
|
|
if (provider.a(x - 1, z) && !provider.b(x - 1, z).n && provider.a(x - 1, z + 1) && provider.a(x, z + 1) && provider.a(x - 1, z)) {
|
|
|
|
provider.a(provider, x - 1, z);
|
|
|
|
}
|
2011-02-08 16:22:46 +01:00
|
|
|
|
2011-03-02 21:27:44 +01:00
|
|
|
if (provider.a(x, z - 1) && !provider.b(x, z - 1).n && provider.a(x + 1, z - 1) && provider.a(x, z - 1) && provider.a(x + 1, z)) {
|
|
|
|
provider.a(provider, x, z - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (provider.a(x - 1, z - 1) && !provider.b(x - 1, z - 1).n && provider.a(x - 1, z - 1) && provider.a(x, z - 1) && provider.a(x - 1, z)) {
|
|
|
|
provider.a(provider, x - 1, z - 1);
|
2011-02-08 16:22:46 +01:00
|
|
|
}
|
|
|
|
}
|
2011-01-20 21:57:33 +01:00
|
|
|
}
|
|
|
|
|
2011-02-01 23:49:28 +01:00
|
|
|
public boolean isChunkLoaded(Chunk chunk) {
|
|
|
|
return isChunkLoaded(chunk.getX(), chunk.getZ());
|
2010-12-29 00:52:29 +01:00
|
|
|
}
|
|
|
|
|
2011-02-01 23:49:28 +01:00
|
|
|
public void loadChunk(Chunk chunk) {
|
|
|
|
loadChunk(chunk.getX(), chunk.getZ());
|
|
|
|
((CraftChunk) getChunkAt(chunk.getX(), chunk.getZ())).getHandle().bukkitChunk = chunk;
|
2011-01-04 16:54:41 +01:00
|
|
|
}
|
|
|
|
|
2010-12-29 02:07:57 +01:00
|
|
|
public WorldServer getHandle() {
|
|
|
|
return world;
|
|
|
|
}
|
2011-02-01 23:49:28 +01:00
|
|
|
|
2011-02-22 01:43:12 +01:00
|
|
|
public org.bukkit.entity.Item dropItem(Location loc, ItemStack item) {
|
2011-01-15 20:53:20 +01:00
|
|
|
net.minecraft.server.ItemStack stack = new net.minecraft.server.ItemStack(
|
|
|
|
item.getTypeId(),
|
|
|
|
item.getAmount(),
|
2011-01-31 02:07:38 +01:00
|
|
|
item.getDurability()
|
2011-01-15 20:53:20 +01:00
|
|
|
);
|
|
|
|
EntityItem entity = new EntityItem(world, loc.getX(), loc.getY(), loc.getZ(), stack);
|
2011-01-08 21:48:45 +01:00
|
|
|
entity.c = 10;
|
|
|
|
world.a(entity);
|
2011-01-17 09:26:47 +01:00
|
|
|
//TODO this is inconsistent with how Entity.getBukkitEntity() works.
|
|
|
|
// However, this entity is not at the moment backed by a server entity class so it may be left.
|
2011-02-22 01:43:12 +01:00
|
|
|
return new CraftItem(world.getServer(), entity);
|
2011-01-08 21:48:45 +01:00
|
|
|
}
|
2011-02-02 00:32:18 +01:00
|
|
|
|
2011-02-22 01:43:12 +01:00
|
|
|
public org.bukkit.entity.Item dropItemNaturally(Location loc, ItemStack item) {
|
2011-02-23 03:37:56 +01:00
|
|
|
double xs = world.k.nextFloat() * 0.7F + (1.0F - 0.7F) * 0.5D;
|
|
|
|
double ys = world.k.nextFloat() * 0.7F + (1.0F - 0.7F) * 0.5D;
|
|
|
|
double zs = world.k.nextFloat() * 0.7F + (1.0F - 0.7F) * 0.5D;
|
2011-01-08 21:48:45 +01:00
|
|
|
loc = loc.clone();
|
|
|
|
loc.setX(loc.getX() + xs);
|
2011-01-15 22:45:48 +01:00
|
|
|
loc.setY(loc.getY() + ys);
|
|
|
|
loc.setZ(loc.getZ() + zs);
|
2011-01-08 21:48:45 +01:00
|
|
|
return dropItem(loc, item);
|
|
|
|
}
|
2010-12-29 02:07:57 +01:00
|
|
|
|
2011-01-15 20:53:20 +01:00
|
|
|
public Arrow spawnArrow(Location loc, Vector velocity, float speed, float spread) {
|
2011-01-02 09:40:27 +01:00
|
|
|
EntityArrow arrow = new EntityArrow(world);
|
2011-01-10 23:13:44 +01:00
|
|
|
arrow.c(loc.getX(), loc.getY(), loc.getZ(), 0, 0);
|
2011-01-02 09:40:27 +01:00
|
|
|
world.a(arrow);
|
|
|
|
arrow.a(velocity.getX(), velocity.getY(), velocity.getZ(), speed, spread);
|
2011-01-17 09:26:47 +01:00
|
|
|
return (Arrow) arrow.getBukkitEntity();
|
2011-01-02 09:40:27 +01:00
|
|
|
}
|
2011-02-02 00:32:18 +01:00
|
|
|
|
2011-01-03 06:41:57 +01:00
|
|
|
public Minecart spawnMinecart(Location loc) {
|
|
|
|
EntityMinecart minecart = new EntityMinecart(
|
2011-01-15 20:53:20 +01:00
|
|
|
world,
|
|
|
|
loc.getX(),
|
|
|
|
loc.getY(),
|
|
|
|
loc.getZ(),
|
|
|
|
CraftMinecart.Type.Minecart.getId()
|
|
|
|
);
|
2011-01-03 06:41:57 +01:00
|
|
|
world.a(minecart);
|
2011-01-23 13:23:13 +01:00
|
|
|
return (Minecart) minecart.getBukkitEntity();
|
2011-01-03 06:41:57 +01:00
|
|
|
}
|
2011-02-02 00:32:18 +01:00
|
|
|
|
2011-01-03 06:41:57 +01:00
|
|
|
public StorageMinecart spawnStorageMinecart(Location loc) {
|
|
|
|
EntityMinecart minecart = new EntityMinecart(
|
2011-01-15 20:53:20 +01:00
|
|
|
world,
|
|
|
|
loc.getX(),
|
|
|
|
loc.getY(),
|
|
|
|
loc.getZ(),
|
|
|
|
CraftMinecart.Type.StorageMinecart.getId()
|
|
|
|
);
|
2011-01-03 06:41:57 +01:00
|
|
|
world.a(minecart);
|
2011-01-23 13:23:13 +01:00
|
|
|
return (StorageMinecart) minecart.getBukkitEntity();
|
2011-01-03 06:41:57 +01:00
|
|
|
}
|
2011-02-02 00:32:18 +01:00
|
|
|
|
2011-01-03 06:41:57 +01:00
|
|
|
public PoweredMinecart spawnPoweredMinecart(Location loc) {
|
|
|
|
EntityMinecart minecart = new EntityMinecart(
|
2011-01-15 20:53:20 +01:00
|
|
|
world,
|
|
|
|
loc.getX(),
|
|
|
|
loc.getY(),
|
|
|
|
loc.getZ(),
|
|
|
|
CraftMinecart.Type.PoweredMinecart.getId()
|
|
|
|
);
|
2011-01-03 06:41:57 +01:00
|
|
|
world.a(minecart);
|
2011-01-17 09:26:47 +01:00
|
|
|
return (PoweredMinecart) minecart.getBukkitEntity();
|
2011-01-03 06:41:57 +01:00
|
|
|
}
|
2011-02-02 00:32:18 +01:00
|
|
|
|
2011-01-07 23:01:37 +01:00
|
|
|
public Boat spawnBoat(Location loc) {
|
2011-01-15 20:53:20 +01:00
|
|
|
EntityBoat boat = new EntityBoat(world, loc.getX(), loc.getY(), loc.getZ());
|
2011-01-07 23:01:37 +01:00
|
|
|
world.a(boat);
|
2011-01-17 09:26:47 +01:00
|
|
|
return (Boat) boat.getBukkitEntity();
|
2011-01-07 23:01:37 +01:00
|
|
|
}
|
2011-02-02 00:32:18 +01:00
|
|
|
|
2011-02-17 06:25:03 +01:00
|
|
|
public Creature spawnCreature(Location loc, CreatureType creatureType) {
|
|
|
|
Creature creature;
|
|
|
|
try {
|
|
|
|
EntityCreature entityCreature = (EntityCreature) EntityTypes.a(creatureType.getName(), world);
|
|
|
|
entityCreature.a(loc.getX(), loc.getY(), loc.getZ());
|
|
|
|
creature = (Creature) CraftEntity.getEntity(server, entityCreature);
|
|
|
|
world.a(entityCreature);
|
|
|
|
} catch (Exception e) {
|
|
|
|
// if we fail, for any reason, return null.
|
|
|
|
creature = null;
|
|
|
|
}
|
|
|
|
return creature;
|
|
|
|
}
|
|
|
|
|
2011-01-30 22:53:57 +01:00
|
|
|
public boolean generateTree(Location loc, TreeType type) {
|
|
|
|
return generateTree(loc, type, world);
|
2011-01-03 03:01:17 +01:00
|
|
|
}
|
2011-01-30 22:53:57 +01:00
|
|
|
|
|
|
|
public boolean generateTree(Location loc, TreeType type, BlockChangeDelegate delegate) {
|
|
|
|
switch (type) {
|
|
|
|
case BIG_TREE:
|
2011-02-02 00:32:18 +01:00
|
|
|
return new WorldGenBigTree().generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
2011-01-30 22:53:57 +01:00
|
|
|
case BIRCH:
|
2011-02-02 00:32:18 +01:00
|
|
|
return new WorldGenForest().generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
2011-01-30 22:53:57 +01:00
|
|
|
case REDWOOD:
|
2011-02-02 00:32:18 +01:00
|
|
|
return new WorldGenTaiga2().generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
2011-01-30 22:53:57 +01:00
|
|
|
case TALL_REDWOOD:
|
2011-02-02 00:32:18 +01:00
|
|
|
return new WorldGenTaiga1().generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
2011-01-30 22:53:57 +01:00
|
|
|
case TREE:
|
|
|
|
default:
|
2011-02-02 00:32:18 +01:00
|
|
|
return new WorldGenTrees().generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
2011-01-30 22:53:57 +01:00
|
|
|
}
|
2011-01-03 03:01:17 +01:00
|
|
|
}
|
2011-02-02 00:32:18 +01:00
|
|
|
|
2011-01-08 02:22:17 +01:00
|
|
|
public TileEntity getTileEntityAt(final int x, final int y, final int z) {
|
2011-01-29 22:50:29 +01:00
|
|
|
return world.getTileEntity(x, y, z);
|
2011-01-08 02:22:17 +01:00
|
|
|
}
|
|
|
|
|
2011-01-08 03:29:57 +01:00
|
|
|
public String getName() {
|
2011-02-23 03:37:56 +01:00
|
|
|
return world.q.j;
|
2011-01-08 03:29:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public long getId() {
|
2011-02-23 03:37:56 +01:00
|
|
|
return world.q.b();
|
2011-01-08 03:29:57 +01:00
|
|
|
}
|
|
|
|
|
2010-12-30 21:34:26 +01:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
2011-02-07 02:22:43 +01:00
|
|
|
return "CraftWorld{name=" + getName() + '}';
|
2010-12-30 21:34:26 +01:00
|
|
|
}
|
|
|
|
|
2011-02-01 15:53:39 +01:00
|
|
|
public long getTime() {
|
|
|
|
long time = getFullTime() % 24000;
|
|
|
|
if (time < 0) time += 24000;
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTime(long time) {
|
|
|
|
long margin = (time - getFullTime()) % 24000;
|
|
|
|
if (margin < 0) margin += 24000;
|
|
|
|
setFullTime(getFullTime() + margin);
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getFullTime() {
|
2011-02-23 03:37:56 +01:00
|
|
|
return world.k();
|
2011-02-01 15:53:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setFullTime(long time) {
|
2011-02-23 03:37:56 +01:00
|
|
|
world.a(time);
|
2011-02-01 15:53:39 +01:00
|
|
|
}
|
|
|
|
|
2011-02-06 21:50:57 +01:00
|
|
|
public Environment getEnvironment() {
|
|
|
|
return environment;
|
|
|
|
}
|
|
|
|
|
2011-02-18 17:35:05 +01:00
|
|
|
public Block getBlockAt(Location location) {
|
|
|
|
return getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getBlockTypeIdAt(Location location) {
|
|
|
|
return getBlockTypeIdAt(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getHighestBlockYAt(Location location) {
|
|
|
|
return getHighestBlockYAt(location.getBlockX(), location.getBlockZ());
|
|
|
|
}
|
|
|
|
|
|
|
|
public Chunk getChunkAt(Location location) {
|
|
|
|
return getChunkAt(location.getBlockX() >> 4, location.getBlockZ() >> 4);
|
|
|
|
}
|
|
|
|
|
2010-12-27 03:13:03 +01:00
|
|
|
private final class ChunkCoordinate {
|
|
|
|
public final int x;
|
|
|
|
public final int z;
|
2011-01-01 14:06:04 +01:00
|
|
|
|
2010-12-27 03:13:03 +01:00
|
|
|
public ChunkCoordinate(final int x, final int z) {
|
|
|
|
this.x = x;
|
|
|
|
this.z = z;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (obj == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (getClass() != obj.getClass()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
final ChunkCoordinate other = (ChunkCoordinate) obj;
|
|
|
|
if (this.x != other.x) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (this.z != other.z) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
int hash = 5;
|
|
|
|
hash = 53 * hash + this.x;
|
|
|
|
hash = 53 * hash + this.z;
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-26 21:03:54 +01:00
|
|
|
public List<Entity> getEntities() {
|
|
|
|
List<Entity> list = new ArrayList<Entity>();
|
2011-02-02 00:32:18 +01:00
|
|
|
|
|
|
|
for (Object o: world.b) {
|
2011-01-26 21:03:54 +01:00
|
|
|
if (o instanceof net.minecraft.server.Entity) {
|
2011-02-02 00:32:18 +01:00
|
|
|
net.minecraft.server.Entity mcEnt = (net.minecraft.server.Entity)o;
|
2011-01-26 21:03:54 +01:00
|
|
|
Entity bukkitEntity = mcEnt.getBukkitEntity();
|
|
|
|
|
|
|
|
// Assuming that bukkitEntity isn't null
|
|
|
|
if (bukkitEntity != null) {
|
|
|
|
list.add(bukkitEntity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-02 00:32:18 +01:00
|
|
|
|
2011-01-26 21:03:54 +01:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<LivingEntity> getLivingEntities() {
|
|
|
|
List<LivingEntity> list = new ArrayList<LivingEntity>();
|
2011-02-02 00:32:18 +01:00
|
|
|
|
|
|
|
for (Object o: world.b) {
|
2011-01-26 21:03:54 +01:00
|
|
|
if (o instanceof net.minecraft.server.Entity) {
|
2011-02-02 00:32:18 +01:00
|
|
|
net.minecraft.server.Entity mcEnt = (net.minecraft.server.Entity)o;
|
2011-01-26 21:03:54 +01:00
|
|
|
Entity bukkitEntity = mcEnt.getBukkitEntity();
|
2011-02-02 00:32:18 +01:00
|
|
|
|
2011-01-26 21:03:54 +01:00
|
|
|
// Assuming that bukkitEntity isn't null
|
|
|
|
if (bukkitEntity != null && bukkitEntity instanceof LivingEntity) {
|
|
|
|
list.add((LivingEntity)bukkitEntity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-02 00:32:18 +01:00
|
|
|
|
2011-01-26 21:03:54 +01:00
|
|
|
return list;
|
|
|
|
}
|
2011-02-24 20:37:53 +01:00
|
|
|
|
|
|
|
public List<Player> getPlayers() {
|
|
|
|
List<Player> list = new ArrayList<Player>();
|
|
|
|
|
|
|
|
for (Object o : world.b) {
|
|
|
|
if (o instanceof net.minecraft.server.Entity) {
|
|
|
|
net.minecraft.server.Entity mcEnt = (net.minecraft.server.Entity)o;
|
|
|
|
Entity bukkitEntity = mcEnt.getBukkitEntity();
|
|
|
|
|
|
|
|
if ((bukkitEntity != null) && (bukkitEntity instanceof Player)) {
|
|
|
|
list.add((Player)bukkitEntity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
2011-02-26 03:29:42 +01:00
|
|
|
|
|
|
|
public void save() {
|
|
|
|
// Writes level.dat
|
|
|
|
world.r();
|
|
|
|
|
|
|
|
// Saves all chunks/regions
|
|
|
|
world.o.a(true, null);
|
|
|
|
}
|
2010-12-27 03:13:03 +01:00
|
|
|
}
|