3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-23 23:00:08 +01:00
Paper/nms-patches/Chunk.patch

155 Zeilen
6.5 KiB
Diff

2015-02-26 23:41:06 +01:00
--- /home/matt/mc-dev-private//net/minecraft/server/Chunk.java 2015-02-26 22:40:22.311608142 +0000
+++ src/main/java/net/minecraft/server/Chunk.java 2015-02-26 22:40:22.315608142 +0000
@@ -14,6 +14,9 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2015-02-26 23:41:06 +01:00
+import com.google.common.collect.Lists; // CraftBukkit
+import org.bukkit.Bukkit; // CraftBukkit
+
public class Chunk {
private static final Logger c = LogManager.getLogger();
2015-02-26 23:41:06 +01:00
@@ -22,13 +25,13 @@
private final int[] f;
private final boolean[] g;
private boolean h;
2015-02-26 23:41:06 +01:00
- private final World world;
- private final int[] heightMap;
2015-02-26 23:41:06 +01:00
+ public final World world; // CraftBukkit - public
+ public final int[] heightMap; // CraftBukkit - public
public final int locX;
public final int locZ;
private boolean k;
2015-02-26 23:41:06 +01:00
- private final Map<BlockPosition, TileEntity> tileEntities;
- private final EntitySlice<Entity>[] entitySlices;
+ public final Map<BlockPosition, TileEntity> tileEntities;
+ public final EntitySlice<Entity>[] entitySlices; // CraftBukkit - public
private boolean done;
private boolean lit;
private boolean p;
@@ -40,6 +43,34 @@
private int v;
2015-02-26 23:41:06 +01:00
private ConcurrentLinkedQueue<BlockPosition> 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;
2015-02-26 23:41:06 +01:00
@@ -529,7 +569,8 @@
}
}
2015-02-26 23:41:06 +01:00
- if (!this.world.isClientSide && block1 != block) {
+ // CraftBukkit - Don't place while processing the BlockPlaceEvent, unless it's a BlockContainer. Prevents blocks such as TNT from activating when cancelled.
2015-02-26 23:41:06 +01:00
+ if (!this.world.isClientSide && block1 != block && (!this.world.captureBlockStates || block instanceof BlockContainer)) {
block.onPlace(this.world, blockposition, iblockdata);
}
2015-02-26 23:41:06 +01:00
@@ -610,7 +651,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();
}
2015-02-26 23:41:06 +01:00
@@ -697,6 +742,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
}
}
2015-02-26 23:41:06 +01:00
@@ -740,7 +792,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
}
}
2015-02-26 23:41:06 +01:00
@@ -798,8 +864,8 @@
while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next();
- if (entity.getBoundingBox().b(axisalignedbb) && (predicate == null || predicate.apply(entity))) {
- list.add(entity);
+ if (entity.getBoundingBox().b(axisalignedbb) && (predicate == null || predicate.apply((T) entity))) { // CraftBukkit - fix decompile error
+ list.add((T) entity); // Fix decompile error
}
}
}