aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0061-ChunkMap-caching.patch
blob: 1f93ece43bdec195866e80809bd5401152ae9b9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
From 915587ce38bd3ddc6843111678206ccc2bce8e25 Mon Sep 17 00:00:00 2001
From: Iceee <andrew@opticgaming.tv>
Date: Wed, 15 Jul 2015 02:41:12 -0700
Subject: [PATCH] ChunkMap caching


diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index 5a3b22a..7efacfa 100644
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -50,6 +50,49 @@ public class Chunk {
     public long lightUpdateTime;
     // PaperSpigot end
 
+    // PaperSpigot start - ChunkMap caching
+    private PacketPlayOutMapChunk.ChunkMap chunkMap;
+    private int emptySectionBits;
+
+    public PacketPlayOutMapChunk.ChunkMap getChunkMap(boolean groundUpContinuous, int primaryBitMask) {
+        if (!world.paperSpigotConfig.cacheChunkMaps || !groundUpContinuous || (primaryBitMask != 0 && primaryBitMask != '\uffff')) {
+            return PacketPlayOutMapChunk.a(this, groundUpContinuous, !world.worldProvider.o(), primaryBitMask);
+        }
+
+        if (primaryBitMask == 0) {
+            PacketPlayOutMapChunk.ChunkMap chunkMap = new PacketPlayOutMapChunk.ChunkMap();
+            chunkMap.a = new byte[0];
+            return chunkMap;
+        }
+
+        boolean isDirty = false;
+        for (int i = 0; i < sections.length; ++i) {
+            ChunkSection section = sections[i];
+            if (section == null) {
+                if ((emptySectionBits & (1 << i)) == 0) {
+                    isDirty = true;
+                    emptySectionBits |= (1 << i);
+                }
+            } else {
+                if ((emptySectionBits & (1 << i)) == 1) {
+                    isDirty = true;
+                    emptySectionBits &= ~(1 << i);
+                    section.isDirty = false;
+                } else if (section.isDirty) {
+                    isDirty = true;
+                    section.isDirty = false;
+                }
+            }
+        }
+
+        if (isDirty || chunkMap == null) {
+            chunkMap = PacketPlayOutMapChunk.a(this, true, !world.worldProvider.o(), '\uffff');
+        }
+
+        return chunkMap;
+    }
+    // PaperSpigot end
+
     // CraftBukkit start - Neighbor loaded cache for chunk lighting and entity ticking
     private int neighbors = 0x1 << 12;
 
diff --git a/src/main/java/net/minecraft/server/ChunkSection.java b/src/main/java/net/minecraft/server/ChunkSection.java
index f734ab0..907c57b 100644
--- a/src/main/java/net/minecraft/server/ChunkSection.java
+++ b/src/main/java/net/minecraft/server/ChunkSection.java
@@ -8,6 +8,7 @@ public class ChunkSection {
     private char[] blockIds;
     private NibbleArray emittedLight;
     private NibbleArray skyLight;
+    boolean isDirty; // PaperSpigot
 
     public ChunkSection(int i, boolean flag) {
         this.yPos = i;
@@ -57,6 +58,7 @@ public class ChunkSection {
         }
 
         this.blockIds[j << 8 | k << 4 | i] = (char) Block.d.b(iblockdata);
+        isDirty = true; // PaperSpigot
     }
 
     public Block b(int i, int j, int k) {
@@ -83,6 +85,7 @@ public class ChunkSection {
 
     public void a(int i, int j, int k, int l) {
         this.skyLight.a(i, j, k, l);
+        isDirty = true; // PaperSpigot
     }
 
     public int d(int i, int j, int k) {
@@ -91,6 +94,7 @@ public class ChunkSection {
 
     public void b(int i, int j, int k, int l) {
         this.emittedLight.a(i, j, k, l);
+        isDirty = true; // PaperSpigot
     }
 
     public int e(int i, int j, int k) {
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
index 58c0275..a0021fb 100644
--- a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
+++ b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
@@ -18,7 +18,7 @@ public class PacketPlayOutMapChunk implements Packet<PacketListenerPlayOut> {
         this.a = chunk.locX;
         this.b = chunk.locZ;
         this.d = flag;
-        this.c = a(chunk, flag, !chunk.getWorld().worldProvider.o(), i);
+        this.c = chunk.getChunkMap(flag, i); // PaperSpigot
         chunk.world.spigotConfig.antiXrayInstance.obfuscateSync(chunk.locX, chunk.locZ, c.b, c.a, chunk.world);
     }
 
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutMapChunkBulk.java b/src/main/java/net/minecraft/server/PacketPlayOutMapChunkBulk.java
index 10c0e34..00c0538 100644
--- a/src/main/java/net/minecraft/server/PacketPlayOutMapChunkBulk.java
+++ b/src/main/java/net/minecraft/server/PacketPlayOutMapChunkBulk.java
@@ -23,7 +23,7 @@ public class PacketPlayOutMapChunkBulk implements Packet<PacketListenerPlayOut>
 
         for (int j = 0; j < i; ++j) {
             Chunk chunk = (Chunk) list.get(j);
-            PacketPlayOutMapChunk.ChunkMap packetplayoutmapchunk_chunkmap = PacketPlayOutMapChunk.a(chunk, true, this.d, '\uffff');
+            PacketPlayOutMapChunk.ChunkMap packetplayoutmapchunk_chunkmap = chunk.getChunkMap(true, '\uffff'); // PaperSpigot
 
             this.a[j] = chunk.locX;
             this.b[j] = chunk.locZ;
diff --git a/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java b/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
index 8247aef..54f432d 100644
--- a/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
+++ b/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
@@ -358,4 +358,10 @@ public class PaperSpigotWorldConfig
     {
         mobSpawnerTickRate = getInt( "mob-spawner-tick-rate", 1 );
     }
+
+    public boolean cacheChunkMaps;
+    private void cacheChunkMaps()
+    {
+        cacheChunkMaps = getBoolean( "cache-chunk-maps", false );
+    }
 }
-- 
2.7.0