diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunk.java index 003ee0f464..1d278fc905 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunk.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunk.java @@ -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 * diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftItemStack.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftItemStack.java new file mode 100644 index 0000000000..ed80091064 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftItemStack.java @@ -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; + } + +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java index 0adf0a180e..7567529e31 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java @@ -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 getContents() { + ArrayList items = new ArrayList(); + for (net.minecraft.server.ItemStack item: minecart.getContents()) { + ItemStack i = null; + if (item != null) { + i = new CraftItemStack( item ); + } + items.add(i); + } + + return items; + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 31b9d0f0e3..74c49a9ec1 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -21,8 +21,8 @@ import org.bukkit.Vector; import org.bukkit.World; public class CraftWorld implements World { - private final Map chunkCache = new HashMap(); - private final Map blockCache = new HashMap(); + private final Map chunkCache = new HashMap(); + private final Map blockCache = new HashMap(); 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; }