From 71abdb001078052312fac924569ba305c7fd8d7f Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sun, 30 Jan 2011 20:19:56 +0100 Subject: [PATCH] Optimized blockCache, now only stores blocks asked for By: Erik Broes --- .../org/bukkit/craftbukkit/CraftWorld.java | 20 ++++++++++--------- .../bukkit/craftbukkit/block/CraftBlock.java | 10 +++++++--- 2 files changed, 18 insertions(+), 12 deletions(-) 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 d7d2093cb3..30e91359ca 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -83,20 +83,22 @@ public class CraftWorld implements World { } - public Block updateBlock(int x, int y, int z) { + public void updateBlock(int x, int y, int z, Integer type, Integer data) { BlockCoordinate loc = new BlockCoordinate(x, y, z); - CraftBlock block = (CraftBlock)blockCache.get(loc); - final int type = world.getTypeId(x, y, z); - final byte data = (byte)world.getData(x, y, z); + CraftBlock block = (CraftBlock) blockCache.get(loc); if (block == null) { - block = new CraftBlock(this, x, y, z, type, data); - blockCache.put(loc, block); - } else { - block.update(); + return; } - return block; + if (type == null) { + type = world.getTypeId(x, y, z); + } + if (data == null) { + data = world.getData(x, y, z); + } + + block.update(type, data.byteValue()); } public CraftChunk updateChunk(int x, int z) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java index efe07ef013..16718f8653 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java @@ -346,9 +346,13 @@ public class CraftBlock implements Block { return world.getHandle().p(x, y, z); } - public void update() { - type = world.getHandle().getTypeId(x, y, z); - data = (byte)world.getHandle().getData(x, y, z); + public void update(int type, byte data) { + this.type = type; + this.data = data; light = (byte)world.getHandle().j(x, y, z); } + + public void update() { + this.update( world.getHandle().getTypeId(x, y, z), (byte)world.getHandle().getData(x, y, z)); + } }