From a52f5ef52057b56024e294194a558f7103eabc15 Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Thu, 10 Feb 2011 11:56:30 +0000 Subject: [PATCH] Threadsafe World.c(int i, int j) --- src/main/java/net/minecraft/server/World.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java index be0b8e221a..9a1c5a2837 100644 --- a/src/main/java/net/minecraft/server/World.java +++ b/src/main/java/net/minecraft/server/World.java @@ -286,13 +286,18 @@ public class World implements IBlockAccess { Chunk lastChunkAccessed; int lastXAccessed = Integer.MIN_VALUE; int lastZAccessed = Integer.MIN_VALUE; + final Object chunkLock = new Object(); public Chunk c(int i, int j) { - if(lastChunkAccessed == null || lastXAccessed != i || lastZAccessed != j) { - lastXAccessed = i; - lastZAccessed = j; - lastChunkAccessed = this.G.b(i, j); + Chunk result = null; + synchronized (chunkLock) { + if (lastChunkAccessed == null || lastXAccessed != i || lastZAccessed != j) { + lastXAccessed = i; + lastZAccessed = j; + lastChunkAccessed = this.G.b(i, j); + } + result = lastChunkAccessed; } - return lastChunkAccessed; + return result; } // CraftBukkit end