Merge remote branch 'upstream/master'

By: durron597 <martin.jared@gmail.com>
This commit is contained in:
CraftBukkit/Spigot 2011-01-05 04:54:39 -05:00
commit 0be5b28936
4 changed files with 123 additions and 8 deletions

View file

@ -2,16 +2,28 @@
package org.bukkit.craftbukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
public class CraftChunk implements Chunk {
private final CraftWorld world;
private final int x;
private final int z;
protected CraftChunk(final int x, final int z) {
protected CraftChunk(final CraftWorld world, final int x, final int z) {
this.world = world;
this.x = x;
this.z = z;
}
/**
* Gets the world containing this chunk
*
* @return World
*/
public World getWorld() {
return world;
}
/**
* Gets the X-coordinate of this chunk
*

View file

@ -0,0 +1,61 @@
package org.bukkit.craftbukkit;
import org.bukkit.ItemStack;
import org.bukkit.Material;
public class CraftItemStack extends ItemStack {
protected net.minecraft.server.ItemStack item;
public CraftItemStack(net.minecraft.server.ItemStack item) {
super(item.c, item.a);
this.item = item;
}
/*
* Unsure if we have to syn before each of these calls the values in 'item'
* are all public.
*/
@Override
public Material getType() {
super.setTypeID(item.c); // sync, needed?
return super.getType();
}
@Override
public int getTypeID() {
super.setTypeID(item.c); // sync, needed?
return item.c;
}
@Override
public void setTypeID(int type) {
super.setTypeID(item.c);
item.c = type;
}
@Override
public int getAmount() {
super.setAmount(item.a); // sync, needed?
return item.a;
}
@Override
public void setAmount(int amount) {
super.setAmount(amount);
item.a = amount;
}
@Override
public void setDamage(final byte damage) {
super.setDamage(damage);
item.d = damage;
}
@Override
public byte getDamage() {
super.setDamage((byte) item.d); // sync, needed?
return (byte) item.d;
}
}

View file

@ -1,6 +1,11 @@
package org.bukkit.craftbukkit;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.server.EntityMinecart;
import org.bukkit.ItemStack;
import org.bukkit.StorageMinecart;
/**
@ -8,10 +13,33 @@ import org.bukkit.StorageMinecart;
*
* @author sk89q
*/
public class CraftStorageMinecart extends CraftMinecart
implements StorageMinecart {
public class CraftStorageMinecart extends CraftMinecart implements StorageMinecart {
public CraftStorageMinecart(CraftServer server, EntityMinecart entity) {
super(server, entity);
}
public int getSize() {
return minecart.c();
}
public String getName() {
return minecart.b();
}
public ItemStack getItem(int index) {
return new CraftItemStack(minecart.a(index));
}
public List<ItemStack> getContents() {
ArrayList<ItemStack> items = new ArrayList<ItemStack>();
for (net.minecraft.server.ItemStack item: minecart.getContents()) {
ItemStack i = null;
if (item != null) {
i = new CraftItemStack( item );
}
items.add(i);
}
return items;
}
}

View file

@ -21,8 +21,8 @@ import org.bukkit.Vector;
import org.bukkit.World;
public class CraftWorld implements World {
private final Map<ChunkCoordinate, Chunk> chunkCache = new HashMap<ChunkCoordinate, Chunk>();
private final Map<BlockCoordinate, Block> blockCache = new HashMap<BlockCoordinate, Block>();
private final Map<ChunkCoordinate, CraftChunk> chunkCache = new HashMap<ChunkCoordinate, CraftChunk>();
private final Map<BlockCoordinate, CraftBlock> blockCache = new HashMap<BlockCoordinate, CraftBlock>();
private final WorldServer world;
private static final Random rand = new Random();
@ -33,7 +33,7 @@ public class CraftWorld implements World {
public Block getBlockAt(int x, int y, int z) {
BlockCoordinate loc = new BlockCoordinate(x, y, z);
Block block = blockCache.get(loc);
CraftBlock block = blockCache.get(loc);
if (block == null) {
block = new CraftBlock(this, x, y, z, world.a(x, y, z), (byte)world.b(x, y, z));
@ -49,10 +49,10 @@ public class CraftWorld implements World {
public Chunk getChunkAt(int x, int z) {
ChunkCoordinate loc = new ChunkCoordinate(x, z);
Chunk chunk = chunkCache.get(loc);
CraftChunk chunk = chunkCache.get(loc);
if (chunk == null) {
chunk = new CraftChunk(x, z);
chunk = new CraftChunk(this, x, z);
chunkCache.put(loc, chunk);
}
@ -84,6 +84,20 @@ public class CraftWorld implements World {
return block;
}
public CraftChunk updateChunk(int x, int z) {
ChunkCoordinate loc = new ChunkCoordinate(x, z);
CraftChunk chunk = chunkCache.get(loc);
if (chunk == null) {
chunk = new CraftChunk(this, x, z);
chunkCache.put(loc, chunk);
} else {
// TODO: Chunk stuff
}
return chunk;
}
public WorldServer getHandle() {
return world;
}