mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 07:48:53 +01:00
214 lines
8.9 KiB
Diff
214 lines
8.9 KiB
Diff
--- a/net/minecraft/server/Chunk.java
|
|
+++ b/net/minecraft/server/Chunk.java
|
|
@@ -31,7 +31,7 @@
|
|
private BiomeStorage d;
|
|
private final Map<BlockPosition, NBTTagCompound> e;
|
|
public boolean loaded;
|
|
- public final World world;
|
|
+ public final WorldServer world; // CraftBukkit - type
|
|
public final Map<HeightMap.Type, HeightMap> heightMap;
|
|
private final ChunkConverter i;
|
|
public final Map<BlockPosition, TileEntity> tileEntities;
|
|
@@ -65,7 +65,7 @@
|
|
this.m = Maps.newHashMap();
|
|
this.n = new ShortList[16];
|
|
this.entitySlices = (EntitySlice[]) (new EntitySlice[16]);
|
|
- this.world = world;
|
|
+ this.world = (WorldServer) world; // CraftBukkit - type
|
|
this.loc = chunkcoordintpair;
|
|
this.i = chunkconverter;
|
|
HeightMap.Type[] aheightmap_type = HeightMap.Type.values();
|
|
@@ -96,8 +96,19 @@
|
|
}
|
|
}
|
|
|
|
+ // CraftBukkit start
|
|
+ this.bukkitChunk = new org.bukkit.craftbukkit.CraftChunk(this);
|
|
}
|
|
|
|
+ public org.bukkit.Chunk bukkitChunk;
|
|
+ public org.bukkit.Chunk getBukkitChunk() {
|
|
+ return bukkitChunk;
|
|
+ }
|
|
+
|
|
+ public boolean mustNotSave;
|
|
+ public boolean needsDecoration;
|
|
+ // CraftBukkit end
|
|
+
|
|
public Chunk(World world, ProtoChunk protochunk) {
|
|
this(world, protochunk.getPos(), protochunk.getBiomeIndex(), protochunk.p(), protochunk.n(), protochunk.o(), protochunk.getInhabitedTime(), protochunk.getSections(), (Consumer) null);
|
|
Iterator iterator = protochunk.y().iterator();
|
|
@@ -139,6 +150,7 @@
|
|
|
|
this.b(protochunk.r());
|
|
this.s = true;
|
|
+ this.needsDecoration = true; // CraftBukkit
|
|
}
|
|
|
|
@Override
|
|
@@ -229,9 +241,16 @@
|
|
}
|
|
}
|
|
|
|
+ // CraftBukkit start
|
|
@Nullable
|
|
@Override
|
|
public IBlockData setType(BlockPosition blockposition, IBlockData iblockdata, boolean flag) {
|
|
+ return this.setType(blockposition, iblockdata, flag, true);
|
|
+ }
|
|
+
|
|
+ @Nullable
|
|
+ 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;
|
|
@@ -283,7 +302,8 @@
|
|
}
|
|
}
|
|
|
|
- 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)) {
|
|
iblockdata.onPlace(this.world, blockposition, iblockdata1, flag);
|
|
}
|
|
|
|
@@ -378,7 +398,12 @@
|
|
|
|
@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) {
|
|
NBTTagCompound nbttagcompound = (NBTTagCompound) this.e.remove(blockposition);
|
|
@@ -424,6 +449,13 @@
|
|
tileentity1.al_();
|
|
}
|
|
|
|
+ // CraftBukkit start
|
|
+ } else {
|
|
+ System.out.println("Attempted to place a tile entity (" + tileentity + ") at " + tileentity.position.getX() + "," + tileentity.position.getY() + "," + tileentity.position.getZ()
|
|
+ + " (" + getType(blockposition) + ") where there was no entity tile!");
|
|
+ System.out.println("Chunk coordinates: " + (this.loc.x * 16) + "," + (this.loc.z * 16));
|
|
+ new Exception().printStackTrace();
|
|
+ // CraftBukkit end
|
|
}
|
|
}
|
|
|
|
@@ -473,6 +505,50 @@
|
|
|
|
}
|
|
|
|
+ // CraftBukkit start
|
|
+ public void loadCallback() {
|
|
+ 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) {
|
|
+ this.needsDecoration = false;
|
|
+ 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) this.loc.x * xRand + (long) this.loc.z * 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;
|
|
+ }
|
|
+ }
|
|
+ server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkPopulateEvent(bukkitChunk));
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ 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();
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
public void markDirty() {
|
|
this.s = true;
|
|
}
|
|
@@ -526,7 +602,7 @@
|
|
Iterator iterator = this.entitySlices[k].a(Entity.class).iterator();
|
|
|
|
while (iterator.hasNext()) {
|
|
- Entity entity = (Entity) iterator.next();
|
|
+ T entity = (T) iterator.next(); // CraftBukkit - decompile error
|
|
|
|
if ((entitytypes == null || entity.getEntityType() == entitytypes) && entity.getBoundingBox().c(axisalignedbb) && predicate.test(entity)) {
|
|
list.add(entity);
|
|
@@ -547,7 +623,7 @@
|
|
Iterator iterator = this.entitySlices[k].a(oclass).iterator();
|
|
|
|
while (iterator.hasNext()) {
|
|
- T t0 = (Entity) iterator.next();
|
|
+ T t0 = (T) iterator.next(); // CraftBukkit - decompile error
|
|
|
|
if (t0.getBoundingBox().c(axisalignedbb) && (predicate == null || predicate.test(t0))) {
|
|
list.add(t0);
|
|
@@ -621,7 +697,7 @@
|
|
|
|
@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
|
|
}
|
|
|
|
public void d(boolean flag) {
|
|
@@ -763,7 +839,7 @@
|
|
|
|
public void B() {
|
|
if (this.o instanceof ProtoChunkTickList) {
|
|
- ((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();
|
|
});
|
|
this.o = TickListEmpty.b();
|
|
@@ -773,7 +849,7 @@
|
|
}
|
|
|
|
if (this.p instanceof ProtoChunkTickList) {
|
|
- ((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();
|
|
});
|
|
this.p = TickListEmpty.b();
|
|
@@ -785,12 +861,12 @@
|
|
}
|
|
|
|
public void a(WorldServer worldserver) {
|
|
- if (this.o == TickListEmpty.b()) {
|
|
+ if (this.o == TickListEmpty.<Block>b()) { // CraftBukkit - decompile error
|
|
this.o = new TickListChunk<>(IRegistry.BLOCK::getKey, worldserver.getBlockTickList().a(this.loc, true, false), worldserver.getTime());
|
|
this.setNeedsSaving(true);
|
|
}
|
|
|
|
- if (this.p == TickListEmpty.b()) {
|
|
+ if (this.p == TickListEmpty.<FluidType>b()) { // CraftBukkit - decompile error
|
|
this.p = new TickListChunk<>(IRegistry.FLUID::getKey, worldserver.getFluidTickList().a(this.loc, true, false), worldserver.getTime());
|
|
this.setNeedsSaving(true);
|
|
}
|