summaryrefslogtreecommitdiffstats
path: root/nms-patches/Chunk.patch
blob: fcb476013df8fc158f6d164c202b810e67088e2b (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
141
--- ../work/decompile-8eb82bde/net/minecraft/server/Chunk.java	2014-12-21 17:32:05.580576417 +0000
+++ src/main/java/net/minecraft/server/Chunk.java	2014-12-21 17:32:05.580576417 +0000
@@ -1,6 +1,7 @@
 package net.minecraft.server;
 
 import com.google.common.base.Predicate;
+import com.google.common.collect.Lists; // CraftBukkit
 import com.google.common.collect.Maps;
 import com.google.common.collect.Queues;
 import java.util.Arrays;
@@ -14,6 +15,8 @@
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
+import org.bukkit.Bukkit; // CraftBukkit
+
 public class Chunk {
 
     private static final Logger c = LogManager.getLogger();
@@ -23,7 +26,7 @@
     private final boolean[] g;
     private boolean h;
     public final World world;
-    private final int[] heightMap;
+    public final int[] heightMap; // CraftBukkit - make public
     public final int locX;
     public final int locZ;
     private boolean k;
@@ -40,6 +43,34 @@
     private int v;
     private ConcurrentLinkedQueue w;
 
+    // CraftBukkit start - Neighbor loaded cache for chunk lighting and entity ticking
+    private int neighbors = 0x1 << 12;
+
+    public boolean areNeighborsLoaded(final int radius) {
+        switch (radius) {
+            case 2:
+                return this.neighbors == Integer.MAX_VALUE >> 6;
+            case 1:
+                final int mask =
+                        //       x        z   offset          x        z   offset          x         z   offset
+                        (0x1 << (1 * 5 +  1 + 12)) | (0x1 << (0 * 5 +  1 + 12)) | (0x1 << (-1 * 5 +  1 + 12)) |
+                        (0x1 << (1 * 5 +  0 + 12)) | (0x1 << (0 * 5 +  0 + 12)) | (0x1 << (-1 * 5 +  0 + 12)) |
+                        (0x1 << (1 * 5 + -1 + 12)) | (0x1 << (0 * 5 + -1 + 12)) | (0x1 << (-1 * 5 + -1 + 12));
+                return (this.neighbors & mask) == mask;
+            default:
+                throw new UnsupportedOperationException(String.valueOf(radius));
+        }
+    }
+
+    public void setNeighborLoaded(final int x, final int z) {
+        this.neighbors |= 0x1 << (x * 5 + 12 + z);
+    }
+
+    public void setNeighborUnloaded(final int x, final int z) {
+        this.neighbors &= ~(0x1 << (x * 5 + 12 + z));
+    }
+    // CraftBukkit end
+
     public Chunk(World world, int i, int j) {
         this.sections = new ChunkSection[16];
         this.e = new byte[256];
@@ -60,8 +91,17 @@
 
         Arrays.fill(this.f, -999);
         Arrays.fill(this.e, (byte) -1);
+
+        // CraftBukkit start
+        if (!(this instanceof EmptyChunk)) {
+            this.bukkitChunk = new org.bukkit.craftbukkit.CraftChunk(this);
+        }
     }
 
+    public org.bukkit.Chunk bukkitChunk;
+    public boolean mustSave;
+    // CraftBukkit end
+
     public Chunk(World world, ChunkSnapshot chunksnapshot, int i, int j) {
         this(world, i, j);
         short short0 = 256;
@@ -505,7 +545,8 @@
                     }
                 }
 
-                if (!this.world.isStatic && block1 != block) {
+                // CraftBukkit - Don't place while processing the BlockPlaceEvent, unless it's a BlockContainer. Prevents blocks such as TNT from activating when cancelled.
+                if (!this.world.isStatic && block1 != block  && (!this.world.captureBlockStates || block instanceof BlockContainer)) {
                     block.onPlace(this.world, blockposition, iblockdata);
                 }
 
@@ -586,7 +627,11 @@
         int j = MathHelper.floor(entity.locZ / 16.0D);
 
         if (i != this.locX || j != this.locZ) {
-            Chunk.c.warn("Wrong location! (" + i + ", " + j + ") should be (" + this.locX + ", " + this.locZ + "), " + entity, new Object[] { entity});
+            // CraftBukkit start
+            Bukkit.getLogger().warning("Wrong location for " + entity + " in world '" + world.getWorld().getName() + "'!");
+            // Chunk.c.warn("Wrong location! (" + i + ", " + j + ") should be (" + this.locX + ", " + this.locZ + "), " + entity, new Object[] { entity});
+            Bukkit.getLogger().warning("Entity is at " + entity.locX + "," + entity.locZ + " (chunk " + i + "," + j + ") but was stored in chunk " + this.locX + "," + this.locZ);
+            // CraftBukkit end
             entity.die();
         }
 
@@ -673,6 +718,13 @@
 
             tileentity.D();
             this.tileEntities.put(blockposition, tileentity);
+            // CraftBukkit start
+        } else {
+            System.out.println("Attempted to place a tile entity (" + tileentity + ") at " + tileentity.position.getX() + "," + tileentity.position.getY() + "," + tileentity.position.getZ()
+                + " (" + org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(getType(blockposition)) + ") where there was no entity tile!");
+            System.out.println("Chunk coordinates: " + (this.locX * 16) + "," + (this.locZ * 16));
+            new Exception().printStackTrace();
+            // CraftBukkit end
         }
     }
 
@@ -716,7 +768,21 @@
         }
 
         for (int i = 0; i < this.entitySlices.length; ++i) {
-            this.world.c((Collection) this.entitySlices[i]);
+            // CraftBukkit start
+            List<Entity> newList = Lists.newArrayList(this.entitySlices[i]);
+            java.util.Iterator<Entity> iter = newList.iterator();
+            while (iter.hasNext()) {
+                Entity entity = iter.next();
+
+                // Do not pass along players, as doing so can get them stuck outside of time.
+                // (which for example disables inventory icon updates and prevents block breaking)
+                if (entity instanceof EntityPlayer) {
+                    iter.remove();
+                }
+            }
+
+            this.world.c((Collection) newList);
+            // CraftBukkit end
         }
 
     }