From 39acc5817ef7433062172c541964c814cfdb76f2 Mon Sep 17 00:00:00 2001 From: Tahg Date: Mon, 7 Mar 2011 13:48:35 -0500 Subject: Additional hooks for chunks --- .../java/org/bukkit/craftbukkit/CraftChunk.java | 28 ++++++++++++++++++++++ .../java/org/bukkit/craftbukkit/CraftWorld.java | 1 - 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'src/main/java/org/bukkit') diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java index 24459f06..ba3fb9d4 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java @@ -3,13 +3,16 @@ package org.bukkit.craftbukkit; import java.lang.ref.WeakReference; import java.util.HashMap; +import net.minecraft.server.ChunkPosition; import net.minecraft.server.WorldServer; import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.block.BlockState; import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.entity.Entity; import org.bukkit.craftbukkit.util.SoftMap; public class CraftChunk implements Chunk { @@ -61,5 +64,30 @@ public class CraftChunk implements Chunk { } return block; } + + public Entity[] getEntities() { + int count = 0, index = 0; + net.minecraft.server.Chunk chunk = getHandle(); + for (int i = 0; i < 8; i++) { + count += chunk.m[i].size(); + } + Entity[] entities = new Entity[count]; + for (int i = 0; i < 8; i++) { + for (net.minecraft.server.Entity entity : (net.minecraft.server.Entity[])chunk.m[i].toArray()) { + entities[index++] = entity.getBukkitEntity(); + } + } + return entities; + } + + public BlockState[] getTileEntities() { + int index = 0; + net.minecraft.server.Chunk chunk = getHandle(); + BlockState[] entities = new BlockState[chunk.l.size()]; + for (ChunkPosition position : (ChunkPosition[])chunk.l.keySet().toArray()) { + entities[index++] = worldServer.getWorld().getBlockAt(position.a, position.b, position.c).getState(); + } + return entities; + } } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 18cbe19f..19487365 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -141,7 +141,6 @@ public class CraftWorld implements World { provider.a(chunk); } - provider.a.remove(x, z); provider.a.remove(x, z); provider.e.remove(x, z); provider.f.remove(chunk); -- cgit v1.2.3