2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/Chunk.java
+++ b/net/minecraft/server/Chunk.java
2019-05-16 01:11:20 +02:00
@@ -95,8 +95,19 @@
2019-04-23 04:00:00 +02:00
}
}
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
2016-02-29 22:32:46 +01:00
+ this.bukkitChunk = new org.bukkit.craftbukkit.CraftChunk(this);
2019-05-16 01:11:20 +02:00
}
2019-04-23 04:00:00 +02:00
+ public org.bukkit.Chunk bukkitChunk;
+ public org.bukkit.Chunk getBukkitChunk() {
+ return bukkitChunk;
2019-05-16 01:11:20 +02:00
+ }
+
2019-04-23 04:00:00 +02:00
+ public boolean mustNotSave;
+ public boolean needsDecoration;
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
+
2019-04-23 04:00:00 +02:00
public Chunk(World world, ProtoChunk protochunk) {
this(world, protochunk.getPos(), protochunk.getBiomeIndex(), protochunk.p(), protochunk.n(), protochunk.o(), protochunk.q(), protochunk.getSections(), (Consumer) null);
Iterator iterator = protochunk.y().iterator();
2019-05-16 01:11:20 +02:00
@@ -138,6 +149,7 @@
2018-07-15 02:00:00 +02:00
2019-04-23 04:00:00 +02:00
this.b(protochunk.r());
this.s = true;
2018-10-28 02:30:35 +02:00
+ this.needsDecoration = true; // CraftBukkit
2018-07-15 02:00:00 +02:00
}
2019-04-23 04:00:00 +02:00
@Override
2019-05-16 01:11:20 +02:00
@@ -228,9 +240,16 @@
2018-08-27 10:27:59 +02:00
}
}
+ // CraftBukkit start
@Nullable
2019-04-23 04:00:00 +02:00
@Override
2018-10-22 21:00:00 +02:00
public IBlockData setType(BlockPosition blockposition, IBlockData iblockdata, boolean flag) {
+ return this.setType(blockposition, iblockdata, flag, true);
2018-08-27 10:27:59 +02:00
+ }
+
+ @Nullable
2018-10-22 21:00:00 +02:00
+ public IBlockData setType(BlockPosition blockposition, IBlockData iblockdata, boolean flag, boolean doPlace) {
2018-08-27 10:27:59 +02:00
+ // CraftBukkit end
int i = blockposition.getX() & 15;
int j = blockposition.getY();
int k = blockposition.getZ() & 15;
2019-05-16 01:11:20 +02:00
@@ -282,7 +301,8 @@
2014-11-25 22:32:16 +01:00
}
}
2018-07-15 02:00:00 +02:00
- if (!this.world.isClientSide) {
2014-11-25 22:32:16 +01:00
+ // CraftBukkit - Don't place while processing the BlockPlaceEvent, unless it's a BlockContainer. Prevents blocks such as TNT from activating when cancelled.
2018-08-27 10:27:59 +02:00
+ if (!this.world.isClientSide && doPlace && (!this.world.captureBlockStates || block instanceof BlockTileEntity)) {
2019-04-23 04:00:00 +02:00
iblockdata.onPlace(this.world, blockposition, iblockdata1, flag);
2014-11-25 22:32:16 +01:00
}
2019-05-16 01:11:20 +02:00
@@ -382,7 +402,12 @@
2015-03-16 10:48:01 +01:00
2016-05-10 13:47:39 +02:00
@Nullable
2015-03-16 10:48:01 +01:00
public TileEntity a(BlockPosition blockposition, Chunk.EnumTileEntityState chunk_enumtileentitystate) {
- TileEntity tileentity = (TileEntity) this.tileEntities.get(blockposition);
+ // CraftBukkit start
2018-07-22 11:35:42 +02:00
+ TileEntity tileentity = world.capturedTileEntities.get(blockposition);
2015-03-16 10:48:01 +01:00
+ if (tileentity == null) {
+ tileentity = (TileEntity) this.tileEntities.get(blockposition);
+ }
+ // CraftBukkit end
if (tileentity == null) {
2019-04-23 04:00:00 +02:00
NBTTagCompound nbttagcompound = (NBTTagCompound) this.e.remove(blockposition);
2019-05-16 01:11:20 +02:00
@@ -429,6 +454,13 @@
2019-04-23 04:00:00 +02:00
tileentity1.m();
}
2014-11-25 22:32:16 +01:00
+ // 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!");
2019-04-23 04:00:00 +02:00
+ System.out.println("Chunk coordinates: " + (this.loc.x * 16) + "," + (this.loc.z * 16));
2014-11-25 22:32:16 +01:00
+ new Exception().printStackTrace();
+ // CraftBukkit end
}
}
2019-05-16 01:11:20 +02:00
@@ -457,6 +489,50 @@
2018-12-17 02:30:16 +01:00
2019-04-23 04:00:00 +02:00
}
2018-07-30 05:09:04 +02:00
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
+ public void loadCallback() {
2018-07-30 05:09:04 +02:00
+ 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.
+ */
2018-09-27 13:41:24 +02:00
+ server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkLoadEvent(this.bukkitChunk, this.needsDecoration));
+
+ if (this.needsDecoration) {
2019-05-16 01:11:20 +02:00
+ this.needsDecoration = false;
2018-09-27 13:41:24 +02:00
+ 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;
2019-04-23 04:00:00 +02:00
+ random.setSeed((long) this.loc.x * xRand + (long) this.loc.z * zRand ^ world.getSeed());
2018-09-27 13:41:24 +02:00
+
+ 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;
+ }
+ }
+ server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkPopulateEvent(bukkitChunk));
+ }
2018-07-30 05:09:04 +02:00
+ }
2019-04-23 04:00:00 +02:00
+ }
2019-05-16 01:11:20 +02:00
+
+ public void unloadCallback() {
+ org.bukkit.Server server = this.world.getServer();
+ org.bukkit.event.world.ChunkUnloadEvent unloadEvent = new org.bukkit.event.world.ChunkUnloadEvent(this.bukkitChunk, this.isNeedsSaving());
+ server.getPluginManager().callEvent(unloadEvent);
+ // note: saving can be prevented, but not forced if no saving is actually required
+ this.mustNotSave = !unloadEvent.isSaveChunk();
+ }
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
2018-10-22 21:00:00 +02:00
+
2019-04-23 04:00:00 +02:00
public void markDirty() {
this.s = true;
2014-11-25 22:32:16 +01:00
}
2019-05-16 01:11:20 +02:00
@@ -531,7 +607,7 @@
2019-04-23 04:00:00 +02:00
Iterator iterator = this.entitySlices[k].a(oclass).iterator();
2015-02-26 23:41:06 +01:00
2018-12-25 22:00:00 +01:00
while (iterator.hasNext()) {
- T t0 = (Entity) iterator.next();
+ T t0 = (T) iterator.next(); // CraftBukkit - decompile error
2016-06-22 01:08:09 +02:00
2018-12-25 22:00:00 +01:00
if (t0.getBoundingBox().c(axisalignedbb) && (predicate == null || predicate.test(t0))) {
list.add(t0);
2019-05-16 01:11:20 +02:00
@@ -605,7 +681,7 @@
2018-07-15 02:00:00 +02:00
2019-04-23 04:00:00 +02:00
@Override
public boolean isNeedsSaving() {
- return this.s || this.q && this.world.getTime() != this.lastSaved;
+ return (this.s || this.q && this.world.getTime() != this.lastSaved) && !this.mustNotSave; // CraftBukkit
}
2018-07-15 02:00:00 +02:00
2019-04-23 04:00:00 +02:00
public void d(boolean flag) {
2019-05-16 01:11:20 +02:00
@@ -746,7 +822,7 @@
2019-04-23 04:00:00 +02:00
2019-05-14 02:00:00 +02:00
public void B() {
2019-04-23 04:00:00 +02:00
if (this.o instanceof ProtoChunkTickList) {
2019-05-14 02:00:00 +02:00
- ((ProtoChunkTickList) this.o).a(this.world.getBlockTickList(), (blockposition) -> {
+ ((ProtoChunkTickList<Block>) this.o).a(this.world.getBlockTickList(), (blockposition) -> { // CraftBukkit - decompile error
return this.getType(blockposition).getBlock();
2019-04-23 04:00:00 +02:00
});
2019-05-14 02:00:00 +02:00
this.o = TickListEmpty.a();
2019-05-16 01:11:20 +02:00
@@ -756,7 +832,7 @@
2019-04-23 04:00:00 +02:00
}
if (this.p instanceof ProtoChunkTickList) {
2019-05-14 02:00:00 +02:00
- ((ProtoChunkTickList) this.p).a(this.world.getFluidTickList(), (blockposition) -> {
+ ((ProtoChunkTickList<FluidType>) this.p).a(this.world.getFluidTickList(), (blockposition) -> { // CraftBukkit - decompile error
return this.getFluid(blockposition).getType();
2019-04-23 04:00:00 +02:00
});
2019-05-14 02:00:00 +02:00
this.p = TickListEmpty.a();
2019-05-16 01:11:20 +02:00
@@ -768,12 +844,12 @@
2019-05-14 02:00:00 +02:00
}
public void a(WorldServer worldserver) {
- if (this.o == TickListEmpty.a()) {
+ if (this.o == TickListEmpty.<Block>a()) { // CraftBukkit - decompile error
this.o = new TickListChunk<>(IRegistry.BLOCK::getKey, worldserver.getBlockTickList().a(true, this.loc));
this.setNeedsSaving(true);
}
- if (this.p == TickListEmpty.a()) {
+ if (this.p == TickListEmpty.<FluidType>a()) { // CraftBukkit - decompile error
this.p = new TickListChunk<>(IRegistry.FLUID::getKey, worldserver.getFluidTickList().a(true, this.loc));
this.setNeedsSaving(true);
}