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

248 Zeilen
10 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/Chunk.java
+++ b/net/minecraft/server/Chunk.java
2018-10-22 21:00:00 +02:00
@@ -22,6 +22,8 @@
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
+
2018-07-15 02:00:00 +02:00
public class Chunk implements IChunkAccess {
2018-08-26 04:00:00 +02:00
private static final Logger d = LogManager.getLogger();
@@ -57,6 +59,35 @@
private final AtomicInteger E;
2018-10-22 21:00:00 +02:00
private final ChunkCoordIntPair F;
+ // CraftBukkit start - Neighbor loaded cache for chunk lighting and entity ticking
+ private int neighbors = 0x1 << 12;
+ public long chunkKey;
+
+ 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
+
2018-07-15 02:00:00 +02:00
public Chunk(World world, int i, int j, BiomeBase[] abiomebase, ChunkConverter chunkconverter, TickList<Block> ticklist, TickList<FluidType> ticklist1, long k) {
this.sections = new ChunkSection[16];
2018-08-26 04:00:00 +02:00
this.g = new boolean[256];
2018-10-22 21:00:00 +02:00
@@ -95,8 +126,16 @@
2018-08-26 04:00:00 +02:00
this.s = ticklist;
this.t = ticklist1;
this.z = k;
+ // CraftBukkit start
2016-02-29 22:32:46 +01:00
+ this.bukkitChunk = new org.bukkit.craftbukkit.CraftChunk(this);
+ this.chunkKey = ChunkCoordIntPair.a(this.locX, this.locZ);
}
+ public org.bukkit.Chunk bukkitChunk;
+ public boolean mustSave;
+ private boolean needsDecoration;
+ // CraftBukkit end
+
2018-07-15 02:00:00 +02:00
public Chunk(World world, ProtoChunk protochunk, int i, int j) {
this(world, i, j, protochunk.getBiomeIndex(), protochunk.v(), protochunk.n(), protochunk.o(), protochunk.m());
2018-10-22 21:00:00 +02:00
@@ -136,14 +175,15 @@
2018-07-15 02:00:00 +02:00
HeightMap.Type heightmap_type = (HeightMap.Type) iterator.next();
if (heightmap_type.c() == HeightMap.Use.LIVE_WORLD) {
- ((HeightMap) this.heightMap.computeIfAbsent(heightmap_type, (heightmap_type) -> {
- return new HeightMap(this, heightmap_type);
+ ((HeightMap) this.heightMap.computeIfAbsent(heightmap_type, (heightmap_type1) -> { // CraftBukkit - decompile error
+ return new HeightMap(this, heightmap_type1); // CraftBukkit - decompile error
})).a(protochunk.b(heightmap_type).b());
}
}
2018-08-26 04:00:00 +02:00
this.x = true;
2018-07-15 02:00:00 +02:00
this.a(ChunkStatus.FULLCHUNK);
+ this.needsDecoration = true; // CraftBukkit
2018-07-15 02:00:00 +02:00
}
public Set<BlockPosition> t() {
2018-10-22 21:00:00 +02:00
@@ -413,8 +453,15 @@
}
}
+ // CraftBukkit start
@Nullable
2018-10-22 21:00:00 +02:00
public IBlockData setType(BlockPosition blockposition, IBlockData iblockdata, boolean flag) {
+ return this.setType(blockposition, iblockdata, flag, true);
+ }
+
+ @Nullable
2018-10-22 21:00:00 +02:00
+ public IBlockData setType(BlockPosition blockposition, IBlockData iblockdata, boolean flag, boolean doPlace) {
+ // CraftBukkit end
int i = blockposition.getX() & 15;
int j = blockposition.getY();
int k = blockposition.getZ() & 15;
2018-10-22 21:00:00 +02:00
@@ -474,7 +521,8 @@
}
}
2018-07-15 02:00:00 +02:00
- if (!this.world.isClientSide) {
+ // 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.isClientSide && doPlace && (!this.world.captureBlockStates || block instanceof BlockTileEntity)) {
2018-07-15 02:00:00 +02:00
iblockdata.onPlace(this.world, blockposition, iblockdata1);
}
2018-10-22 21:00:00 +02:00
@@ -654,7 +702,12 @@
2016-05-10 13:47:39 +02:00
@Nullable
public TileEntity a(BlockPosition blockposition, Chunk.EnumTileEntityState chunk_enumtileentitystate) {
- TileEntity tileentity = (TileEntity) this.tileEntities.get(blockposition);
+ // CraftBukkit start
+ TileEntity tileentity = world.capturedTileEntities.get(blockposition);
+ if (tileentity == null) {
+ tileentity = (TileEntity) this.tileEntities.get(blockposition);
+ }
+ // CraftBukkit end
if (tileentity == null) {
2018-10-22 21:00:00 +02:00
NBTTagCompound nbttagcompound = (NBTTagCompound) this.h.remove(blockposition);
@@ -701,6 +754,13 @@
2018-07-15 02:00:00 +02:00
tileentity.z();
2018-10-22 21:00:00 +02:00
this.tileEntities.put(blockposition.h(), tileentity);
+ // CraftBukkit start
+ } else {
+ System.out.println("Attempted to place a tile entity (" + tileentity + ") at " + tileentity.position.getX() + "," + tileentity.position.getY() + "," + tileentity.position.getZ()
2018-07-15 02:00:00 +02:00
+ + " (" + getType(blockposition) + ") where there was no entity tile!");
+ System.out.println("Chunk coordinates: " + (this.locX * 16) + "," + (this.locZ * 16));
+ new Exception().printStackTrace();
+ // CraftBukkit end
}
}
2018-10-22 21:00:00 +02:00
@@ -733,6 +793,40 @@
2018-08-26 04:00:00 +02:00
}));
2018-07-30 05:09:04 +02:00
}
+ // CraftBukkit start
+ org.bukkit.Server server = this.world.getServer();
+ if (server != null) {
+ /*
+ * If it's a new world, the first few chunks are generated inside
+ * the World constructor. We can't reliably alter that, so we have
+ * no way of creating a CraftWorld/CraftServer at that point.
+ */
+ server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkLoadEvent(this.bukkitChunk, this.needsDecoration));
+
+ if (this.needsDecoration) {
+ BlockSand.instaFall = true;
+ java.util.Random random = new java.util.Random();
+ random.setSeed(world.getSeed());
+ long xRand = random.nextLong() / 2L * 2L + 1L;
+ long zRand = random.nextLong() / 2L * 2L + 1L;
+ random.setSeed((long) locX * xRand + (long) locZ * zRand ^ world.getSeed());
+
+ org.bukkit.World world = this.world.getWorld();
+ if (world != null) {
+ this.world.populating = true;
+ try {
+ for (org.bukkit.generator.BlockPopulator populator : world.getPopulators()) {
+ populator.populate(world, random, bukkitChunk);
+ }
+ } finally {
+ this.world.populating = false;
+ }
+ }
+ BlockSand.instaFall = false;
+ server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkPopulateEvent(bukkitChunk));
+ }
2018-07-30 05:09:04 +02:00
+ }
+ // CraftBukkit end
}
public void removeEntities() {
2018-10-22 21:00:00 +02:00
@@ -749,9 +843,21 @@
2016-06-09 03:43:49 +02:00
int i = aentityslice.length;
2016-06-09 03:43:49 +02:00
for (int j = 0; j < i; ++j) {
- EntitySlice entityslice = aentityslice[j];
+ // CraftBukkit start
2016-06-09 03:43:49 +02:00
+ List<Entity> newList = Lists.newArrayList(aentityslice[j]);
+ java.util.Iterator<Entity> iter = newList.iterator();
+ while (iter.hasNext()) {
+ Entity entity = iter.next();
2018-10-22 21:00:00 +02:00
+
+ // 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();
+ }
+ }
2018-10-22 21:00:00 +02:00
- this.world.b((Collection) entityslice);
2018-08-26 04:00:00 +02:00
+ this.world.b((Collection) newList);
+ // CraftBukkit end
}
}
2018-10-22 21:00:00 +02:00
@@ -813,8 +919,8 @@
2015-02-26 23:41:06 +01:00
while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next();
2018-07-15 02:00:00 +02:00
- if (entity.getBoundingBox().c(axisalignedbb) && (predicate == null || predicate.test(entity))) {
2015-02-26 23:41:06 +01:00
- list.add(entity);
2018-07-15 02:00:00 +02:00
+ if (entity.getBoundingBox().c(axisalignedbb) && (predicate == null || predicate.test((T) entity))) { // CraftBukkit - fix decompile error
2015-02-26 23:41:06 +01:00
+ list.add((T) entity); // Fix decompile error
}
}
}
2018-10-22 21:00:00 +02:00
@@ -1020,13 +1126,13 @@
2018-07-15 02:00:00 +02:00
@Nullable
public LongSet b(String s) {
2018-08-26 04:00:00 +02:00
- return (LongSet) this.q.computeIfAbsent(s, (s) -> {
+ return (LongSet) this.q.computeIfAbsent(s, (s1) -> { // CraftBukkit - decompile error
2018-07-15 02:00:00 +02:00
return new LongOpenHashSet();
});
}
2018-07-15 02:00:00 +02:00
public void a(String s, long i) {
2018-08-26 04:00:00 +02:00
- ((LongSet) this.q.computeIfAbsent(s, (s) -> {
+ ((LongSet) this.q.computeIfAbsent(s, (s1) -> { // CraftBukkit - decompile error
2018-07-15 02:00:00 +02:00
return new LongOpenHashSet();
})).add(i);
}
2018-10-22 21:00:00 +02:00
@@ -1074,14 +1180,14 @@
2018-07-15 02:00:00 +02:00
}
2018-08-26 04:00:00 +02:00
if (this.s instanceof ProtoChunkTickList) {
- ((ProtoChunkTickList) this.s).a(this.world.J(), (blockposition) -> {
2018-07-15 02:00:00 +02:00
- return this.world.getType(blockposition).getBlock();
2018-08-26 04:00:00 +02:00
+ ((ProtoChunkTickList<Block>) this.s).a(this.world.J(), (blockposition1) -> { // CraftBukkit - decompile error
2018-07-15 02:00:00 +02:00
+ return this.world.getType(blockposition1).getBlock();
});
}
2018-08-26 04:00:00 +02:00
if (this.t instanceof ProtoChunkTickList) {
- ((ProtoChunkTickList) this.t).a(this.world.I(), (blockposition) -> {
2018-07-15 02:00:00 +02:00
- return this.world.b(blockposition).c();
2018-08-26 04:00:00 +02:00
+ ((ProtoChunkTickList<FluidType>) this.t).a(this.world.I(), (blockposition1) -> { // CraftBukkit - decompile error
2018-07-15 02:00:00 +02:00
+ return this.world.b(blockposition1).c();
});
}
2016-02-29 22:32:46 +01:00