Created
June 18, 2014 11:18
-
-
Save peter-lawrey/0b4cc132647d00cb20bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java (revision 9f6a0e678ebfed5aa8d636886fae35be1cca092f) | |
+++ src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java (revision ) | |
@@ -118,7 +118,7 @@ | |
for (l = 0; l < achunksection.length; ++l) { | |
if (achunksection[l] != null && (!flag || !achunksection[l].isEmpty()) && (i & 1 << l) != 0) { | |
chunkmap.b |= 1 << l; | |
- if (achunksection[l].getExtendedIdArray() != null) { | |
+ if (achunksection[l].hasExtendedIdArray()) { | |
chunkmap.c |= 1 << l; | |
++k; | |
} | |
@@ -127,10 +127,13 @@ | |
for (l = 0; l < achunksection.length; ++l) { | |
if (achunksection[l] != null && (!flag || !achunksection[l].isEmpty()) && (i & 1 << l) != 0) { | |
+/* | |
byte[] abyte1 = achunksection[l].getIdArray(); | |
System.arraycopy(abyte1, 0, abyte, j, abyte1.length); | |
j += abyte1.length; | |
+*/ | |
+ j += achunksection[l].copyIdTo(abyte, j); | |
} | |
} | |
@@ -138,36 +141,30 @@ | |
for (l = 0; l < achunksection.length; ++l) { | |
if (achunksection[l] != null && (!flag || !achunksection[l].isEmpty()) && (i & 1 << l) != 0) { | |
- nibblearray = achunksection[l].getDataArray(); | |
- System.arraycopy(nibblearray.a, 0, abyte, j, nibblearray.a.length); | |
- j += nibblearray.a.length; | |
+ j += achunksection[l].copyDataArray(abyte, j); | |
} | |
} | |
for (l = 0; l < achunksection.length; ++l) { | |
if (achunksection[l] != null && (!flag || !achunksection[l].isEmpty()) && (i & 1 << l) != 0) { | |
- nibblearray = achunksection[l].getEmittedLightArray(); | |
- System.arraycopy(nibblearray.a, 0, abyte, j, nibblearray.a.length); | |
- j += nibblearray.a.length; | |
+ j += achunksection[l].copyEmittedLightArray(abyte, j); | |
} | |
} | |
if (!chunk.world.worldProvider.g) { | |
for (l = 0; l < achunksection.length; ++l) { | |
if (achunksection[l] != null && (!flag || !achunksection[l].isEmpty()) && (i & 1 << l) != 0) { | |
- nibblearray = achunksection[l].getSkyLightArray(); | |
- System.arraycopy(nibblearray.a, 0, abyte, j, nibblearray.a.length); | |
- j += nibblearray.a.length; | |
+ j += achunksection[l].copySkyLightArray(abyte, j); | |
} | |
} | |
} | |
if (k > 0) { | |
for (l = 0; l < achunksection.length; ++l) { | |
- if (achunksection[l] != null && (!flag || !achunksection[l].isEmpty()) && achunksection[l].getExtendedIdArray() != null && (i & 1 << l) != 0) { | |
- nibblearray = achunksection[l].getExtendedIdArray(); | |
- System.arraycopy(nibblearray.a, 0, abyte, j, nibblearray.a.length); | |
- j += nibblearray.a.length; | |
+ if (achunksection[l] != null && (!flag || !achunksection[l].isEmpty()) && achunksection[l].hasExtendedIdArray() && (i & 1 << l) != 0) { | |
+ byte[] extendedIdArray = achunksection[l].getExtendedIdArrayAsBytes(); | |
+ System.arraycopy(extendedIdArray, 0, abyte, j, extendedIdArray.length); | |
+ j += extendedIdArray.length; | |
} | |
} | |
} | |
Index: src/main/java/net/minecraft/server/NBTTagCompound.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- src/main/java/net/minecraft/server/NBTTagCompound.java (revision 9f6a0e678ebfed5aa8d636886fae35be1cca092f) | |
+++ src/main/java/net/minecraft/server/NBTTagCompound.java (revision ) | |
@@ -6,6 +6,7 @@ | |
import java.io.DataInput; | |
import java.io.DataOutput; | |
import java.io.IOException; | |
+import java.nio.ByteBuffer; | |
import java.util.HashMap; | |
import java.util.Iterator; | |
import java.util.Map; | |
@@ -90,6 +91,10 @@ | |
public void setString(String s, String s1) { | |
this.map.put(s, new NBTTagString(s1)); | |
+ } | |
+ | |
+ public void setByteArray(String s, ByteBuffer abyte) { | |
+ this.map.put(s, new NBTTagByteArray(abyte)); | |
} | |
public void setByteArray(String s, byte[] abyte) { | |
Index: src/main/java/net/minecraft/server/NBTTagByteArray.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- src/main/java/net/minecraft/server/NBTTagByteArray.java (revision 9f6a0e678ebfed5aa8d636886fae35be1cca092f) | |
+++ src/main/java/net/minecraft/server/NBTTagByteArray.java (revision ) | |
@@ -3,56 +3,86 @@ | |
import java.io.DataInput; | |
import java.io.DataOutput; | |
import java.io.IOException; | |
-import java.util.Arrays; | |
+import java.nio.ByteBuffer; | |
public class NBTTagByteArray extends NBTBase { | |
- private byte[] data; | |
+ private ByteBuffer bb; | |
NBTTagByteArray() { | |
} | |
public NBTTagByteArray(byte[] abyte) { | |
- this.data = abyte; | |
+ this.bb = ByteBuffer.allocateDirect(abyte.length); | |
+ this.bb.put(abyte); | |
} | |
+ public NBTTagByteArray(ByteBuffer bb) { | |
+ this.bb = bb; | |
+ } | |
+ | |
void write(DataOutput dataoutput) throws IOException { | |
- dataoutput.writeInt(this.data.length); | |
- dataoutput.write(this.data); | |
+ if (bb.isDirect()) { | |
+ dataoutput.writeInt(this.bb.limit()); | |
+ for (int i = 0; i < this.bb.limit(); i++) | |
+ dataoutput.write(bb.get(i)); | |
+ } else { | |
+ dataoutput.writeInt(this.bb.limit()); | |
+ dataoutput.write(this.bb.array(), 0, this.bb.limit()); | |
- } | |
+ } | |
+ } | |
void load(DataInput datainput, int i, NBTReadLimiter nbtreadlimiter) throws IOException { | |
int j = datainput.readInt(); | |
nbtreadlimiter.a((long) (8 * j)); | |
- this.data = new byte[j]; | |
- datainput.readFully(this.data); | |
+ this.bb = ByteBuffer.allocateDirect(j); | |
+ for (int k = 0; k < j; k++) { | |
+ this.bb.put(datainput.readByte()); | |
- } | |
+ } | |
+ } | |
public byte getTypeId() { | |
return (byte) 7; | |
} | |
public String toString() { | |
- return "[" + this.data.length + " bytes]"; | |
+ return "[" + this.bb.limit() + " bytes]"; | |
} | |
public NBTBase clone() { | |
- byte[] abyte = new byte[this.data.length]; | |
- | |
- System.arraycopy(this.data, 0, abyte, 0, this.data.length); | |
- return new NBTTagByteArray(abyte); | |
+ ByteBuffer bb2 = ByteBuffer.allocateDirect(bb.limit()); | |
+ bb.position(0); | |
+ bb2.put(bb); | |
+ return new NBTTagByteArray(bb2); | |
} | |
public boolean equals(Object object) { | |
- return super.equals(object) ? Arrays.equals(this.data, ((NBTTagByteArray) object).data) : false; | |
+ if (!super.equals(object)) { | |
+ return false; | |
- } | |
+ } | |
+ NBTTagByteArray o = (NBTTagByteArray) object; | |
+ if (bb.limit() != o.bb.limit()) | |
+ return false; | |
+ // todo compare longs | |
+ for (int i = 0; i < bb.limit(); i++) | |
+ if (bb.get(i) != o.bb.get(i)) | |
+ return false; | |
+ return true; | |
+ } | |
public int hashCode() { | |
- return super.hashCode() ^ Arrays.hashCode(this.data); | |
+ int ret = super.hashCode(); | |
+ int h = 0; | |
+ for (int i = 0; i < bb.limit(); i++) | |
+ h = h * 31 + bb.get(i); | |
+ return ret ^ h; | |
} | |
public byte[] c() { | |
- return this.data; | |
+ byte[] bytes = new byte[bb.limit()]; | |
+ bb.position(0); | |
+ bb.get(bytes); | |
+ return bytes; | |
} | |
} | |
Index: src/main/java/net/minecraft/server/MinecraftServer.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- src/main/java/net/minecraft/server/MinecraftServer.java (revision 9f6a0e678ebfed5aa8d636886fae35be1cca092f) | |
+++ src/main/java/net/minecraft/server/MinecraftServer.java (revision ) | |
@@ -296,13 +296,14 @@ | |
long j = ar(); | |
i = 0; | |
- int scale = 2; | |
- for (int k = -192 * scale; k <= 192 * scale && this.isRunning(); k += 16) { | |
- for (int l = -192 * scale; l <= 192 * scale && this.isRunning(); l += 16) { | |
+ int extents = 16 * 25; // 1000 | |
+ int width = extents / 16 * 2 + 1; | |
+ for (int k = -extents; k <= extents && this.isRunning(); k += 16) { | |
+ for (int l = -extents; l <= extents && this.isRunning(); l += 16) { | |
long i1 = ar(); | |
if (i1 - j > 1000L) { | |
- this.a_("Preparing spawn area", i * 100.0 / 625 / scale / scale); | |
+ this.a_("Preparing spawn area", i * 100.0 / width / width); | |
j = i1; | |
} | |
Index: src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java (revision 9f6a0e678ebfed5aa8d636886fae35be1cca092f) | |
+++ src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java (revision ) | |
@@ -1,24 +1,14 @@ | |
package org.bukkit.craftbukkit.generator; | |
-import java.util.List; | |
-import java.util.Random; | |
- | |
-import net.minecraft.server.BiomeBase; | |
-import net.minecraft.server.Chunk; | |
-import net.minecraft.server.ChunkPosition; | |
-import net.minecraft.server.ChunkSection; | |
-import net.minecraft.server.EnumCreatureType; | |
-import net.minecraft.server.IChunkProvider; | |
-import net.minecraft.server.IProgressUpdate; | |
-import net.minecraft.server.World; | |
-import net.minecraft.server.WorldGenStronghold; | |
-import net.minecraft.server.WorldServer; | |
- | |
+import net.minecraft.server.*; | |
import org.bukkit.block.Biome; | |
+import org.bukkit.craftbukkit.block.CraftBlock; | |
import org.bukkit.generator.BlockPopulator; | |
import org.bukkit.generator.ChunkGenerator; | |
-import org.bukkit.craftbukkit.block.CraftBlock; | |
+import java.util.List; | |
+import java.util.Random; | |
+ | |
public class CustomChunkGenerator extends InternalChunkGenerator { | |
private final ChunkGenerator generator; | |
private final WorldServer world; | |
@@ -33,7 +23,7 @@ | |
} | |
public void setBiome(int x, int z, Biome bio) { | |
- biome[(z << 4) | x] = CraftBlock.biomeToBiomeBase(bio); | |
+ biome[(z << 4) | x] = CraftBlock.biomeToBiomeBase(bio); | |
} | |
} | |
@@ -93,8 +83,7 @@ | |
// Build chunk section | |
csect[sec] = new ChunkSection(sec << 4, true, secBlkID, secExtBlkID); | |
} | |
- } | |
- else { // Else check for byte-per-block section data | |
+ } else { // Else check for byte-per-block section data | |
byte[][] btypes = generator.generateBlockSections(this.world.getWorld(), this.random, x, z, biomegrid); | |
if (btypes != null) { | |
@@ -109,8 +98,7 @@ | |
} | |
csect[sec] = new ChunkSection(sec << 4, true, btypes[sec], null); | |
} | |
- } | |
- else { // Else, fall back to pre 1.2 method | |
+ } else { // Else, fall back to pre 1.2 method | |
@SuppressWarnings("deprecation") | |
byte[] types = generator.generate(this.world.getWorld(), this.random, x, z); | |
int ydim = types.length / 256; | |
@@ -124,7 +112,7 @@ | |
// Loop through sections | |
for (int sec = 0; sec < scnt; sec++) { | |
ChunkSection cs = null; // Add sections when needed | |
- byte[] csbytes = null; | |
+// byte[] csbytes = null; | |
for (int cy = 0; cy < 16; cy++) { | |
int cyoff = cy | (sec << 4); | |
@@ -138,9 +126,9 @@ | |
if (blk != 0) { // If non-empty | |
if (cs == null) { // If no section yet, get one | |
cs = csect[sec] = new ChunkSection(sec << 4, true); | |
- csbytes = cs.getIdArray(); | |
+// csbytes = cs.getIdArray(); | |
} | |
- csbytes[(cy << 8) | (cz << 4) | cx] = blk; | |
+ cs.setId((cy << 8) | (cz << 4) | cx, blk); | |
} | |
} | |
} | |
@@ -216,7 +204,8 @@ | |
return "Stronghold".equals(type) && this.strongholdGen != null ? this.strongholdGen.getNearestGeneratedFeature(world, x, y, z) : null; | |
} | |
- public void recreateStructures(int i, int j) {} | |
+ public void recreateStructures(int i, int j) { | |
+ } | |
public int getLoadedChunks() { | |
return 0; | |
@@ -226,5 +215,6 @@ | |
return "CustomChunkGenerator"; | |
} | |
- public void c() {} | |
+ public void c() { | |
+ } | |
} | |
Index: src/main/java/net/minecraft/server/ChunkRegionLoader.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- src/main/java/net/minecraft/server/ChunkRegionLoader.java (revision 9f6a0e678ebfed5aa8d636886fae35be1cca092f) | |
+++ src/main/java/net/minecraft/server/ChunkRegionLoader.java (revision ) | |
@@ -4,6 +4,7 @@ | |
import org.apache.logging.log4j.Logger; | |
import java.io.*; | |
+import java.nio.ByteBuffer; | |
import java.util.*; | |
public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver { | |
@@ -229,16 +230,18 @@ | |
nbttagcompound1 = new NBTTagCompound(); | |
nbttagcompound1.setByte("Y", (byte) (chunksection.getYPosition() >> 4 & 255)); | |
nbttagcompound1.setByteArray("Blocks", chunksection.getIdArray()); | |
- if (chunksection.getExtendedIdArray() != null) { | |
- nbttagcompound1.setByteArray("Add", chunksection.getExtendedIdArray().a); | |
+ ByteBuffer extendedIdArray = chunksection.getExtendedIdArray(); | |
+ if (extendedIdArray != null) { | |
+ nbttagcompound1.setByteArray("Add", extendedIdArray); | |
} | |
- nbttagcompound1.setByteArray("Data", chunksection.getDataArray().a); | |
- nbttagcompound1.setByteArray("BlockLight", chunksection.getEmittedLightArray().a); | |
+ nbttagcompound1.setByteArray("Data", chunksection.getDataArray()); | |
+ ByteBuffer emittedLightArrayAsBytes = chunksection.getEmittedLightArray(); | |
+ nbttagcompound1.setByteArray("BlockLight", emittedLightArrayAsBytes); | |
if (flag) { | |
- nbttagcompound1.setByteArray("SkyLight", chunksection.getSkyLightArray().a); | |
+ nbttagcompound1.setByteArray("SkyLight", chunksection.getSkyLightArray()); | |
} else { | |
- nbttagcompound1.setByteArray("SkyLight", new byte[chunksection.getEmittedLightArray().a.length]); | |
+ nbttagcompound1.setByteArray("SkyLight", new byte[emittedLightArrayAsBytes.limit()]); | |
} | |
nbttaglist.add(nbttagcompound1); | |
@@ -325,13 +328,13 @@ | |
chunksection.setIdArray(nbttagcompound1.getByteArray("Blocks")); | |
if (nbttagcompound1.hasKeyOfType("Add", 7)) { | |
- chunksection.setExtendedIdArray(new NibbleArray(nbttagcompound1.getByteArray("Add"), 4)); | |
+ chunksection.setExtendedIdArray(nbttagcompound1.getByteArray("Add")); | |
} | |
- chunksection.setDataArray(new NibbleArray(nbttagcompound1.getByteArray("Data"), 4)); | |
- chunksection.setEmittedLightArray(new NibbleArray(nbttagcompound1.getByteArray("BlockLight"), 4)); | |
+ chunksection.setDataArray(nbttagcompound1.getByteArray("Data")); | |
+ chunksection.setEmittedLightArray(nbttagcompound1.getByteArray("BlockLight")); | |
if (flag) { | |
- chunksection.setSkyLightArray(new NibbleArray(nbttagcompound1.getByteArray("SkyLight"), 4)); | |
+ chunksection.setSkyLightArray(nbttagcompound1.getByteArray("SkyLight")); | |
} | |
chunksection.recalcBlockCounts(); | |
Index: src/main/java/net/minecraft/server/NibbleArray.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- src/main/java/net/minecraft/server/NibbleArray.java (revision 9f6a0e678ebfed5aa8d636886fae35be1cca092f) | |
+++ src/main/java/net/minecraft/server/NibbleArray.java (revision ) | |
@@ -1,19 +1,22 @@ | |
package net.minecraft.server; | |
+import java.nio.ByteBuffer; | |
+ | |
public class NibbleArray { | |
- public final byte[] a; | |
+ final ByteBuffer a; | |
private final int b; | |
private final int c; | |
public NibbleArray(int i, int j) { | |
- this.a = new byte[i >> 1]; | |
+ this.a = ByteBuffer.allocateDirect(i >> 1); | |
this.b = j; | |
this.c = j + 4; | |
} | |
public NibbleArray(byte[] abyte, int i) { | |
- this.a = abyte; | |
+ this.a = ByteBuffer.allocateDirect(abyte.length); | |
+ this.a.put(abyte); | |
this.b = i; | |
this.c = i + 4; | |
} | |
@@ -23,18 +26,54 @@ | |
int i1 = l >> 1; | |
int j1 = l & 1; | |
- return j1 == 0 ? this.a[i1] & 15 : this.a[i1] >> 4 & 15; | |
+ return j1 == 0 ? this.a.get(i1) & 15 : this.a.get(i1) >> 4 & 15; | |
} | |
- public void a(int i, int j, int k, int l) { | |
+ public void set(int i, int j, int k, int l) { | |
int i1 = j << this.c | k << this.b | i; | |
int j1 = i1 >> 1; | |
int k1 = i1 & 1; | |
if (k1 == 0) { | |
- this.a[j1] = (byte) (this.a[j1] & 240 | l & 15); | |
+ this.a.put(j1, (byte) (this.a.get(j1) & 240 | l & 15)); | |
} else { | |
- this.a[j1] = (byte) (this.a[j1] & 15 | (l & 15) << 4); | |
+ this.a.put(j1, (byte) (this.a.get(j1) & 15 | (l & 15) << 4)); | |
} | |
+ } | |
+ | |
+ public byte get(int i) { | |
+ return this.a.get(i); | |
+ } | |
+ | |
+ public void maskHigh(int off) { | |
+ this.a.put(off, (byte) (this.a.get(off) & 0xF0)); | |
+ } | |
+ | |
+ public void maskLow(int off) { | |
+ this.a.put(off, (byte) (this.a.get(off) & 0x0F)); | |
+ } | |
+ | |
+ public byte[] asBytes() { | |
+ byte[] bytes = new byte[a.limit()]; | |
+ a.position(0); | |
+ a.get(bytes); | |
+ return bytes; | |
+ } | |
+ | |
+ public boolean isEmpty() { | |
+ int i = 0; | |
+ for (; i < a.limit() - 7; i += 8) | |
+ if (a.getLong(i) != 0) | |
+ return false; | |
+ for (; i < a.limit(); i++) | |
+ if (a.get(i) != 0) | |
+ return false; | |
+ return true; | |
+ } | |
+ | |
+ public int copyTo(byte[] bytes, int off) { | |
+ a.position(0); | |
+ a.get(bytes, off, a.remaining()); | |
+ return 0; | |
} | |
} | |
Index: src/main/java/net/minecraft/server/OldChunkLoader.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- src/main/java/net/minecraft/server/OldChunkLoader.java (revision 9f6a0e678ebfed5aa8d636886fae35be1cca092f) | |
+++ src/main/java/net/minecraft/server/OldChunkLoader.java (revision ) | |
@@ -83,9 +83,9 @@ | |
byte b1 = oldchunk.g[j2]; | |
abyte[l1 << 8 | i2 << 4 | k1] = (byte) (b1 & 255); | |
- nibblearray.a(k1, l1, i2, oldchunk.f.a(k1, l1 + (k << 4), i2)); | |
- nibblearray1.a(k1, l1, i2, oldchunk.e.a(k1, l1 + (k << 4), i2)); | |
- nibblearray2.a(k1, l1, i2, oldchunk.d.a(k1, l1 + (k << 4), i2)); | |
+ nibblearray.set(k1, l1, i2, oldchunk.f.a(k1, l1 + (k << 4), i2)); | |
+ nibblearray1.set(k1, l1, i2, oldchunk.e.a(k1, l1 + (k << 4), i2)); | |
+ nibblearray2.set(k1, l1, i2, oldchunk.d.a(k1, l1 + (k << 4), i2)); | |
} | |
} | |
} | |
@@ -94,9 +94,9 @@ | |
nbttagcompound1.setByte("Y", (byte) (k & 255)); | |
nbttagcompound1.setByteArray("Blocks", abyte); | |
- nbttagcompound1.setByteArray("Data", nibblearray.a); | |
- nbttagcompound1.setByteArray("SkyLight", nibblearray1.a); | |
- nbttagcompound1.setByteArray("BlockLight", nibblearray2.a); | |
+ nbttagcompound1.setByteArray("Data", nibblearray.asBytes()); | |
+ nbttagcompound1.setByteArray("SkyLight", nibblearray1.asBytes()); | |
+ nbttagcompound1.setByteArray("BlockLight", nibblearray2.asBytes()); | |
nbttaglist.add(nbttagcompound1); | |
} | |
} | |
Index: src/main/java/org/bukkit/craftbukkit/CraftChunk.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- src/main/java/org/bukkit/craftbukkit/CraftChunk.java (revision 9f6a0e678ebfed5aa8d636886fae35be1cca092f) | |
+++ src/main/java/org/bukkit/craftbukkit/CraftChunk.java (revision ) | |
@@ -1,23 +1,17 @@ | |
package org.bukkit.craftbukkit; | |
-import java.lang.ref.WeakReference; | |
-import java.util.Arrays; | |
- | |
-import net.minecraft.server.BiomeBase; | |
-import net.minecraft.server.ChunkPosition; | |
-import net.minecraft.server.ChunkSection; | |
-import net.minecraft.server.EmptyChunk; | |
-import net.minecraft.server.WorldChunkManager; | |
-import net.minecraft.server.WorldServer; | |
- | |
+import net.minecraft.server.*; | |
import org.bukkit.Chunk; | |
+import org.bukkit.ChunkSnapshot; | |
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.ChunkSnapshot; | |
+import java.lang.ref.WeakReference; | |
+import java.util.Arrays; | |
+ | |
public class CraftChunk implements Chunk { | |
private WeakReference<net.minecraft.server.Chunk> weakChunk; | |
private final WorldServer worldServer; | |
@@ -165,42 +159,17 @@ | |
sectionEmitLights[i] = emptyData; | |
sectionEmpty[i] = true; | |
} else { /* Not empty */ | |
- short[] blockids = new short[4096]; | |
- byte[] baseids = cs[i].getIdArray(); | |
- /* Copy base IDs */ | |
- for (int j = 0; j < 4096; j++) { | |
- blockids[j] = (short) (baseids[j] & 0xFF); | |
- } | |
+ sectionBlockIDs[i] = cs[i].getShortIds(); | |
- if (cs[i].getExtendedIdArray() != null) { /* If we've got extended IDs */ | |
- byte[] extids = cs[i].getExtendedIdArray().a; | |
- | |
- for (int j = 0; j < 2048; j++) { | |
- short b = (short) (extids[j] & 0xFF); | |
- | |
- if (b == 0) { | |
- continue; | |
- } | |
- | |
- blockids[j<<1] |= (b & 0x0F) << 8; | |
- blockids[(j<<1)+1] |= (b & 0xF0) << 4; | |
- } | |
- } | |
- | |
- sectionBlockIDs[i] = blockids; | |
- | |
/* Get block data nibbles */ | |
- sectionBlockData[i] = new byte[2048]; | |
- System.arraycopy(cs[i].getDataArray().a, 0, sectionBlockData[i], 0, 2048); | |
- if (cs[i].getSkyLightArray() == null) { | |
+ sectionBlockData[i] = cs[i].getDataArrayAsBytes(); | |
+ if (cs[i].hasSkyLightArray()) { | |
sectionSkyLights[i] = emptyData; | |
} else { | |
- sectionSkyLights[i] = new byte[2048]; | |
- System.arraycopy(cs[i].getSkyLightArray().a, 0, sectionSkyLights[i], 0, 2048); | |
+ sectionSkyLights[i] = cs[i].getSkyLightArrayAsBytes(); | |
} | |
- sectionEmitLights[i] = new byte[2048]; | |
- System.arraycopy(cs[i].getEmittedLightArray().a, 0, sectionEmitLights[i], 0, 2048); | |
+ sectionEmitLights[i] = cs[i].getEmittedLightArrayAsBytes(); | |
} | |
} | |
Index: src/main/java/net/minecraft/server/ChunkSection.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- src/main/java/net/minecraft/server/ChunkSection.java (revision 9f6a0e678ebfed5aa8d636886fae35be1cca092f) | |
+++ src/main/java/net/minecraft/server/ChunkSection.java (revision ) | |
@@ -1,11 +1,15 @@ | |
package net.minecraft.server; | |
+import java.nio.ByteBuffer; | |
+import java.util.Arrays; | |
+ | |
public class ChunkSection { | |
- private int yPos; | |
+ public static final int SIZE = 4096; | |
+ private final int yPos; | |
private int nonEmptyBlockCount; | |
private int tickingBlockCount; | |
- private byte[] blockIds; | |
+ private ByteBuffer blockIds; | |
private NibbleArray extBlockIds; | |
private NibbleArray blockData; | |
private NibbleArray emittedLight; | |
@@ -13,32 +17,36 @@ | |
public ChunkSection(int i, boolean flag) { | |
this.yPos = i; | |
- this.blockIds = new byte[4096]; | |
- this.blockData = new NibbleArray(this.blockIds.length, 4); | |
- this.emittedLight = new NibbleArray(this.blockIds.length, 4); | |
+ this.blockIds = ByteBuffer.allocateDirect(SIZE); | |
+ ; | |
+ this.blockData = new NibbleArray(SIZE, 4); | |
+ this.emittedLight = new NibbleArray(SIZE, 4); | |
if (flag) { | |
- this.skyLight = new NibbleArray(this.blockIds.length, 4); | |
+ this.skyLight = new NibbleArray(SIZE, 4); | |
} | |
} | |
// CraftBukkit start | |
public ChunkSection(int y, boolean flag, byte[] blkIds, byte[] extBlkIds) { | |
this.yPos = y; | |
- this.blockIds = blkIds; | |
+ this.blockIds = ByteBuffer.allocateDirect(SIZE); | |
+ ; | |
+ this.blockIds.put(blkIds); | |
+ this.blockIds.position(0); | |
if (extBlkIds != null) { | |
this.extBlockIds = new NibbleArray(extBlkIds, 4); | |
} | |
- this.blockData = new NibbleArray(this.blockIds.length, 4); | |
- this.emittedLight = new NibbleArray(this.blockIds.length, 4); | |
+ this.blockData = new NibbleArray(SIZE, 4); | |
+ this.emittedLight = new NibbleArray(SIZE, 4); | |
if (flag) { | |
- this.skyLight = new NibbleArray(this.blockIds.length, 4); | |
+ this.skyLight = new NibbleArray(SIZE, 4); | |
} | |
this.recalcBlockCounts(); | |
} | |
// CraftBukkit end | |
public Block getTypeId(int i, int j, int k) { | |
- int l = this.blockIds[j << 8 | k << 4 | i] & 255; | |
+ int l = getId(i, j, k); | |
if (this.extBlockIds != null) { | |
l |= this.extBlockIds.a(i, j, k) << 8; | |
@@ -47,8 +55,12 @@ | |
return Block.e(l); | |
} | |
+ private short getId(int i, int j, int k) { | |
+ return getId(j << 8 | k << 4 | i); | |
+ } | |
+ | |
public void setTypeId(int i, int j, int k, Block block) { | |
- int l = this.blockIds[j << 8 | k << 4 | i] & 255; | |
+ int l = getId(i, j, k); | |
if (this.extBlockIds != null) { | |
l |= this.extBlockIds.a(i, j, k) << 8; | |
@@ -72,24 +84,28 @@ | |
int i1 = Block.b(block); | |
- this.blockIds[j << 8 | k << 4 | i] = (byte) (i1 & 255); | |
+ setId(i, j, k, i1); | |
if (i1 > 255) { | |
if (this.extBlockIds == null) { | |
- this.extBlockIds = new NibbleArray(this.blockIds.length, 4); | |
+ this.extBlockIds = new NibbleArray(SIZE, 4); | |
} | |
- this.extBlockIds.a(i, j, k, (i1 & 3840) >> 8); | |
+ this.extBlockIds.set(i, j, k, (i1 & 3840) >> 8); | |
} else if (this.extBlockIds != null) { | |
- this.extBlockIds.a(i, j, k, 0); | |
+ this.extBlockIds.set(i, j, k, 0); | |
} | |
} | |
+ private void setId(int i, int j, int k, int i1) { | |
+ setId(j << 8 | k << 4 | i, (byte) i1); | |
+ } | |
+ | |
public int getData(int i, int j, int k) { | |
return this.blockData.a(i, j, k); | |
} | |
public void setData(int i, int j, int k, int l) { | |
- this.blockData.a(i, j, k, l); | |
+ this.blockData.set(i, j, k, l); | |
} | |
public boolean isEmpty() { | |
@@ -105,7 +121,7 @@ | |
} | |
public void setSkyLight(int i, int j, int k, int l) { | |
- this.skyLight.a(i, j, k, l); | |
+ this.skyLight.set(i, j, k, l); | |
} | |
public int getSkyLight(int i, int j, int k) { | |
@@ -113,7 +129,7 @@ | |
} | |
public void setEmittedLight(int i, int j, int k, int l) { | |
- this.emittedLight.a(i, j, k, l); | |
+ this.emittedLight.set(i, j, k, l); | |
} | |
public int getEmittedLight(int i, int j, int k) { | |
@@ -122,15 +138,15 @@ | |
public void recalcBlockCounts() { | |
// CraftBukkit start - Optimize for speed | |
- byte[] blkIds = this.blockIds; | |
+ ByteBuffer blkIds = this.blockIds; | |
int cntNonEmpty = 0; | |
int cntTicking = 0; | |
if (this.extBlockIds == null) { // No extended block IDs? Don't waste time messing with them | |
- for (int off = 0; off < blkIds.length; off++) { | |
- int l = blkIds[off] & 0xFF; | |
+ for (int off = 0; off < blkIds.limit(); off++) { | |
+ int l = getId(off); | |
if (l > 0) { | |
if (Block.e(l) == null) { | |
- blkIds[off] = 0; | |
+ setId(off, (byte) 0); | |
} else { | |
++cntNonEmpty; | |
if (Block.e(l).isTicking()) { | |
@@ -140,14 +156,13 @@ | |
} | |
} | |
} else { | |
- byte[] ext = this.extBlockIds.a; | |
- for (int off = 0, off2 = 0; off < blkIds.length;) { | |
- byte extid = ext[off2]; | |
- int l = (blkIds[off] & 0xFF) | ((extid & 0xF) << 8); // Even data | |
+ for (int off = 0, off2 = 0; off < blkIds.limit(); ) { | |
+ byte extid = this.extBlockIds.get(off2); | |
+ int l = getId(off) | ((extid & 0xF) << 8); // Even data | |
if (l > 0) { | |
if (Block.e(l) == null) { | |
- blkIds[off] = 0; | |
- ext[off2] &= 0xF0; | |
+ setId(off, (byte) 0); | |
+ this.extBlockIds.maskHigh(off2); | |
} else { | |
++cntNonEmpty; | |
if (Block.e(l).isTicking()) { | |
@@ -156,11 +171,11 @@ | |
} | |
} | |
off++; | |
- l = (blkIds[off] & 0xFF) | ((extid & 0xF0) << 4); // Odd data | |
+ l = getId(off) | ((extid & 0xF0) << 4); // Odd data | |
if (l > 0) { | |
if (Block.e(l) == null) { | |
- blkIds[off] = 0; | |
- ext[off2] &= 0x0F; | |
+ setId(off, (byte) 0); | |
+ this.extBlockIds.maskLow(off); | |
} else { | |
++cntNonEmpty; | |
if (Block.e(l).isTicking()) { | |
@@ -176,100 +191,155 @@ | |
this.tickingBlockCount = cntTicking; | |
} | |
- public void old_recalcBlockCounts() { | |
- // CraftBukkit end | |
- this.nonEmptyBlockCount = 0; | |
- this.tickingBlockCount = 0; | |
+ private short getId(int off) { | |
+ return (short) (blockIds.get(off) & 0xFF); | |
+ } | |
- for (int i = 0; i < 16; ++i) { | |
- for (int j = 0; j < 16; ++j) { | |
- for (int k = 0; k < 16; ++k) { | |
- Block block = this.getTypeId(i, j, k); | |
+ public byte[] getIdArrayAsBytes() { | |
+ byte[] bytes = new byte[SIZE]; | |
+ this.blockIds.position(0); | |
+ this.blockIds.get(bytes); | |
+ return bytes; | |
+ } | |
- if (block != Blocks.AIR) { | |
- ++this.nonEmptyBlockCount; | |
- if (block.isTicking()) { | |
- ++this.tickingBlockCount; | |
+ public byte[] getExtendedIdArrayAsBytes() { | |
+ return this.extBlockIds == null ? null : this.extBlockIds.asBytes(); | |
- } | |
+ } | |
+ | |
+ public boolean hasExtendedIdArray() { | |
+ return this.extBlockIds != null; | |
- } | |
+ } | |
+ | |
+ public byte[] getDataArrayAsBytes() { | |
+ return this.blockData.asBytes(); | |
- } | |
+ } | |
+ | |
+ public byte[] getEmittedLightArrayAsBytes() { | |
+ return this.emittedLight.asBytes(); | |
- } | |
+ } | |
+ | |
+ public byte[] getSkyLightArrayAsBytes() { | |
+ return this.skyLight.asBytes(); | |
- } | |
+ } | |
+ | |
+ public void setIdArray(byte[] abyte) { | |
+ this.validateByteArray(abyte); // CraftBukkit - Validate data | |
} | |
- public byte[] getIdArray() { | |
- return this.blockIds; | |
+ public void setExtendedIdArray(byte[] bytes) { | |
+ // CraftBukkit start - Don't hang on to an empty nibble array | |
+ boolean empty = true; | |
+ for (byte b : bytes) | |
+ if (b != 0) { | |
+ empty = false; | |
+ break; | |
- } | |
+ } | |
+ if (empty) | |
+ return; | |
+ // CraftBukkit end | |
- public NibbleArray getExtendedIdArray() { | |
- return this.extBlockIds; | |
+ this.extBlockIds = validateNibbleArray(bytes); // CraftBukkit - Validate data | |
} | |
- public NibbleArray getDataArray() { | |
- return this.blockData; | |
+ public void setDataArray(byte[] bytes) { | |
+ this.blockData = validateNibbleArray(bytes); // CraftBukkit - Validate data | |
} | |
- public NibbleArray getEmittedLightArray() { | |
- return this.emittedLight; | |
+ public void setEmittedLightArray(byte[] bytes) { | |
+ this.emittedLight = validateNibbleArray(bytes); // CraftBukkit - Validate data | |
} | |
- public NibbleArray getSkyLightArray() { | |
- return this.skyLight; | |
+ public void setSkyLightArray(byte[] bytes) { | |
+ this.skyLight = validateNibbleArray(bytes); // CraftBukkit - Validate data | |
} | |
- public void setIdArray(byte[] abyte) { | |
- this.blockIds = this.validateByteArray(abyte); // CraftBukkit - Validate data | |
+ // CraftBukkit start - Validate array lengths | |
+ private static NibbleArray validateNibbleArray(byte[] bytes) { | |
+ if (bytes == null) | |
+ return null; | |
+ if (bytes.length < 2048) { | |
+ bytes = Arrays.copyOf(bytes, 2048); | |
- } | |
+ } | |
- public void setExtendedIdArray(NibbleArray nibblearray) { | |
- // CraftBukkit start - Don't hang on to an empty nibble array | |
- boolean empty = true; | |
- for (int i = 0; i < nibblearray.a.length; i++) { | |
- if (nibblearray.a[i] != 0) { | |
- empty = false; | |
- break; | |
+ return new NibbleArray(bytes, 4); | |
- } | |
+ } | |
+ | |
+ private void validateByteArray(byte[] byteArray) { | |
+ if (byteArray != null) { | |
+ this.blockIds.position(0); | |
+ this.blockIds.put(byteArray); | |
+ while (this.blockIds.remaining() > 0) | |
+ this.blockIds.put((byte) 0); | |
} | |
+ } | |
- if (empty) { | |
- return; | |
+ public int copyIdTo(byte[] bytes, int offset) { | |
+ this.blockIds.position(0); | |
+ this.blockIds.get(bytes, offset, this.blockIds.limit()); | |
+ return blockIds.limit(); | |
- } | |
+ } | |
- // CraftBukkit end | |
- this.extBlockIds = this.validateNibbleArray(nibblearray); // CraftBukkit - Validate data | |
+ public short[] getShortIds() { | |
+ short[] shorts = new short[SIZE]; | |
+ for (int j = 0; j < SIZE; j++) { | |
+ shorts[j] = getId(j); | |
- } | |
+ } | |
- public void setDataArray(NibbleArray nibblearray) { | |
- this.blockData = this.validateNibbleArray(nibblearray); // CraftBukkit - Validate data | |
+ if (this.extBlockIds != null) { /* If we've got extended IDs */ | |
+ | |
+ for (int j = 0; j < 2048; j++) { | |
+ short b = (short) (this.extBlockIds.a.get(j) & 0xFF); | |
+ | |
+ if (b == 0) { | |
+ continue; | |
- } | |
+ } | |
- public void setEmittedLightArray(NibbleArray nibblearray) { | |
- this.emittedLight = this.validateNibbleArray(nibblearray); // CraftBukkit - Validate data | |
+ shorts[j << 1] |= (b & 0x0F) << 8; | |
+ shorts[(j << 1) + 1] |= (b & 0xF0) << 4; | |
- } | |
+ } | |
+ } | |
- public void setSkyLightArray(NibbleArray nibblearray) { | |
- this.skyLight = this.validateNibbleArray(nibblearray); // CraftBukkit - Validate data | |
+ return shorts; | |
} | |
- // CraftBukkit start - Validate array lengths | |
- private NibbleArray validateNibbleArray(NibbleArray nibbleArray) { | |
- if (nibbleArray != null && nibbleArray.a.length < 2048) { | |
- byte[] newArray = new byte[2048]; | |
- System.arraycopy(nibbleArray.a, 0, newArray, 0, ((nibbleArray.a.length > 2048) ? 2048 : nibbleArray.a.length)); | |
- nibbleArray = new NibbleArray(newArray, 4); | |
+ public void setId(int pos, byte val) { | |
+ blockIds.put(pos, val); | |
- } | |
+ } | |
- return nibbleArray; | |
+ public int copyDataArray(byte[] abyte, int j) { | |
+ return blockData.copyTo(abyte, j); | |
} | |
- private byte[] validateByteArray(byte[] byteArray) { | |
- if (byteArray != null && byteArray.length < 4096) { | |
- byte[] newArray = new byte[4096]; | |
- System.arraycopy(byteArray, 0, newArray, 0, byteArray.length); | |
- byteArray = newArray; | |
+ public int copyEmittedLightArray(byte[] abyte, int j) { | |
+ return emittedLight.copyTo(abyte, j); | |
- } | |
+ } | |
- return byteArray; | |
+ public int copySkyLightArray(byte[] abyte, int j) { | |
+ return skyLight.copyTo(abyte, j); | |
+ } | |
+ | |
+ public boolean hasSkyLightArray() { | |
+ return skyLight != null; | |
+ } | |
+ | |
+ public ByteBuffer getIdArray() { | |
+ return blockIds; | |
+ } | |
+ | |
+ public ByteBuffer getExtendedIdArray() { | |
+ return extBlockIds == null ? null : extBlockIds.a; | |
+ } | |
+ | |
+ public ByteBuffer getDataArray() { | |
+ return blockData.a; | |
+ } | |
+ | |
+ public ByteBuffer getEmittedLightArray() { | |
+ return emittedLight.a; | |
+ } | |
+ | |
+ public ByteBuffer getSkyLightArray() { | |
+ return skyLight.a; | |
} | |
// CraftBukkit end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment