Paper/src/main/java/org/bukkit/craftbukkit/CraftChunk.java

56 Zeilen
1.3 KiB
Java

2010-12-27 03:13:03 +01:00
package org.bukkit.craftbukkit;
2011-02-01 23:49:28 +01:00
import java.util.HashMap;
import net.minecraft.server.WorldServer;
2010-12-27 03:13:03 +01:00
import org.bukkit.Chunk;
2011-01-04 15:17:05 +01:00
import org.bukkit.World;
2011-02-01 23:49:28 +01:00
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.block.CraftBlock;
2010-12-27 03:13:03 +01:00
public class CraftChunk implements Chunk {
private net.minecraft.server.Chunk chunk;
2011-02-01 23:49:28 +01:00
private final HashMap<Integer, Block> cache = new HashMap<Integer, Block>();
public CraftChunk(net.minecraft.server.Chunk chunk) {
this.chunk = chunk;
2010-12-27 03:13:03 +01:00
}
2011-01-04 15:17:05 +01:00
public World getWorld() {
2011-02-01 23:49:28 +01:00
return ((WorldServer) chunk.d).getWorld();
}
public net.minecraft.server.Chunk getHandle() {
return chunk;
2011-01-04 15:17:05 +01:00
}
2010-12-27 03:13:03 +01:00
public int getX() {
2011-02-01 23:49:28 +01:00
return chunk.j;
2010-12-27 03:13:03 +01:00
}
public int getZ() {
2011-02-01 23:49:28 +01:00
return chunk.k;
2010-12-27 03:13:03 +01:00
}
2010-12-29 01:29:18 +01:00
@Override
public String toString() {
2011-02-01 23:49:28 +01:00
return "CraftChunk{" + "x=" + getX() + "z=" + getZ() + '}';
}
public Block getBlock(int x, int y, int z) {
int pos = (x & 0xF) << 11 | (z & 0xF) << 7 | (y & 0x7F);
Block block = this.cache.get( pos );
if (block == null) {
block = new CraftBlock( this, (getX() << 4) | (x & 0xF), y & 0x7F, (getZ() << 4) | (z & 0xF) );
this.cache.put( pos, block );
}
return block;
2010-12-29 01:29:18 +01:00
}
public void breakLink() {
this.chunk = null;
}
2010-12-27 03:13:03 +01:00
}