2021-03-15 23:00:00 +01:00
--- a/net/minecraft/world/level/chunk/Chunk.java
+++ b/net/minecraft/world/level/chunk/Chunk.java
2024-04-23 17:15:00 +02:00
@@ -77,7 +77,7 @@
2023-06-07 17:30:00 +02:00
};
2021-11-21 23:00:00 +01:00
private final Map<BlockPosition, Chunk.d> tickersInLevel;
2020-06-25 02:00:00 +02:00
public boolean loaded;
2021-06-11 07:00:00 +02:00
- public final World level;
+ public final WorldServer level; // CraftBukkit - type
2021-11-21 23:00:00 +01:00
@Nullable
2023-06-07 17:30:00 +02:00
private Supplier<FullChunkStatus> fullStatus;
2021-11-21 23:00:00 +01:00
@Nullable
2024-04-23 17:15:00 +02:00
@@ -93,7 +93,7 @@
2023-06-07 17:30:00 +02:00
public Chunk(World world, ChunkCoordIntPair chunkcoordintpair, ChunkConverter chunkconverter, LevelChunkTicks<Block> levelchunkticks, LevelChunkTicks<FluidType> levelchunkticks1, long i, @Nullable ChunkSection[] achunksection, @Nullable Chunk.c chunk_c, @Nullable BlendingData blendingdata) {
2022-12-07 17:00:00 +01:00
super(chunkcoordintpair, chunkconverter, world, world.registryAccess().registryOrThrow(Registries.BIOME), i, achunksection, blendingdata);
2021-11-21 23:00:00 +01:00
this.tickersInLevel = Maps.newHashMap();
2021-06-11 07:00:00 +02:00
- this.level = world;
+ this.level = (WorldServer) world; // CraftBukkit - type
2022-12-07 17:00:00 +01:00
this.gameEventListenerRegistrySections = new Int2ObjectOpenHashMap();
2021-11-21 23:00:00 +01:00
HeightMap.Type[] aheightmap_type = HeightMap.Type.values();
int j = aheightmap_type.length;
2024-04-23 17:15:00 +02:00
@@ -111,6 +111,11 @@
2021-11-21 23:00:00 +01:00
this.fluidTicks = levelchunkticks1;
2019-05-16 01:11:20 +02:00
}
2023-04-02 05:06:59 +02:00
+ // CraftBukkit start
2019-04-23 04:00:00 +02:00
+ public boolean mustNotSave;
+ public boolean needsDecoration;
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
+
2021-11-21 23:00:00 +01:00
public Chunk(WorldServer worldserver, ProtoChunk protochunk, @Nullable Chunk.c chunk_c) {
this(worldserver, protochunk.getPos(), protochunk.getUpgradeData(), protochunk.unpackBlockTicks(), protochunk.unpackFluidTicks(), protochunk.getInhabitedTime(), protochunk.getSections(), chunk_c, protochunk.getBlendingData());
Iterator iterator = protochunk.getBlockEntities().values().iterator();
2024-04-23 17:15:00 +02:00
@@ -142,6 +147,10 @@
2023-06-07 17:30:00 +02:00
this.skyLightSources = protochunk.skyLightSources;
2021-11-21 23:00:00 +01:00
this.setLightCorrect(protochunk.isLightCorrect());
2021-06-11 07:00:00 +02:00
this.unsaved = true;
2018-10-28 02:30:35 +02:00
+ this.needsDecoration = true; // CraftBukkit
2021-11-28 23:28:19 +01:00
+ // CraftBukkit start
+ this.persistentDataContainer = protochunk.persistentDataContainer; // SPIGOT-6814: copy PDC to account for 1.17 to 1.18 chunk upgrading.
+ // CraftBukkit end
2018-07-15 02:00:00 +02:00
}
2019-04-23 04:00:00 +02:00
@Override
2023-06-07 17:30:00 +02:00
@@ -244,9 +253,16 @@
2018-08-27 10:27:59 +02:00
}
}
+ // CraftBukkit start
@Nullable
2019-04-23 04:00:00 +02:00
@Override
2021-11-21 23:00:00 +01:00
public IBlockData setBlockState(BlockPosition blockposition, IBlockData iblockdata, boolean flag) {
+ return this.setBlockState(blockposition, iblockdata, flag, true);
2018-08-27 10:27:59 +02:00
+ }
+
+ @Nullable
2021-11-21 23:00:00 +01:00
+ public IBlockData setBlockState(BlockPosition blockposition, IBlockData iblockdata, boolean flag, boolean doPlace) {
2018-08-27 10:27:59 +02:00
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
int i = blockposition.getY();
2021-11-21 23:00:00 +01:00
ChunkSection chunksection = this.getSection(this.getSectionIndex(i));
boolean flag1 = chunksection.hasOnlyAir();
2023-06-07 17:30:00 +02:00
@@ -295,7 +311,8 @@
2021-11-21 23:00:00 +01:00
if (!chunksection.getBlockState(j, k, l).is(block)) {
return null;
} else {
- if (!this.level.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.level.isClientSide && doPlace && (!this.level.captureBlockStates || block instanceof net.minecraft.world.level.block.BlockTileEntity)) {
iblockdata.onPlace(this.level, blockposition, iblockdata1, flag);
}
2023-06-07 17:30:00 +02:00
@@ -340,7 +357,12 @@
2015-03-16 10:48:01 +01:00
2016-05-10 13:47:39 +02:00
@Nullable
2021-11-21 23:00:00 +01:00
public TileEntity getBlockEntity(BlockPosition blockposition, Chunk.EnumTileEntityState chunk_enumtileentitystate) {
2021-06-11 07:00:00 +02:00
- TileEntity tileentity = (TileEntity) this.blockEntities.get(blockposition);
2015-03-16 10:48:01 +01:00
+ // CraftBukkit start
2021-06-11 07:00:00 +02:00
+ TileEntity tileentity = level.capturedTileEntities.get(blockposition);
2015-03-16 10:48:01 +01:00
+ if (tileentity == null) {
2021-06-11 07:00:00 +02:00
+ tileentity = (TileEntity) this.blockEntities.get(blockposition);
2015-03-16 10:48:01 +01:00
+ }
+ // CraftBukkit end
if (tileentity == null) {
2021-06-11 07:00:00 +02:00
NBTTagCompound nbttagcompound = (NBTTagCompound) this.pendingBlockEntities.remove(blockposition);
2024-06-13 17:05:00 +02:00
@@ -412,6 +434,7 @@
if (!iblockdata.hasBlockEntity()) {
Chunk.LOGGER.warn("Trying to set block entity {} at position {}, but state {} does not allow it", new Object[]{tileentity, blockposition, iblockdata});
+ new Exception().printStackTrace(); // CraftBukkit
} else {
IBlockData iblockdata1 = tileentity.getBlockState();
2014-11-25 22:32:16 +01:00
2024-06-13 17:05:00 +02:00
@@ -465,6 +488,12 @@
2021-11-21 23:00:00 +01:00
if (this.isInLevel()) {
2021-07-13 11:22:27 +02:00
TileEntity tileentity = (TileEntity) this.blockEntities.remove(blockposition);
+ // CraftBukkit start - SPIGOT-5561: Also remove from pending map
+ if (!pendingBlockEntities.isEmpty()) {
+ pendingBlockEntities.remove(blockposition);
+ }
+ // CraftBukkit end
+
if (tileentity != null) {
2022-06-07 18:00:00 +02:00
World world = this.level;
2024-06-13 17:05:00 +02:00
@@ -518,6 +547,57 @@
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() {
2021-06-11 13:33:49 +02:00
+ org.bukkit.Server server = this.level.getCraftServer();
2018-07-30 05:09:04 +02:00
+ 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.
+ */
2023-04-02 05:06:59 +02:00
+ org.bukkit.Chunk bukkitChunk = new org.bukkit.craftbukkit.CraftChunk(this);
+ server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkLoadEvent(bukkitChunk, this.needsDecoration));
2018-09-27 13:41:24 +02:00
+
+ 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();
2021-06-11 07:00:00 +02:00
+ random.setSeed(level.getSeed());
2018-09-27 13:41:24 +02:00
+ long xRand = random.nextLong() / 2L * 2L + 1L;
+ long zRand = random.nextLong() / 2L * 2L + 1L;
2021-06-11 07:00:00 +02:00
+ random.setSeed((long) this.chunkPos.x * xRand + (long) this.chunkPos.z * zRand ^ level.getSeed());
2018-09-27 13:41:24 +02:00
+
2021-06-11 07:00:00 +02:00
+ org.bukkit.World world = this.level.getWorld();
2018-09-27 13:41:24 +02:00
+ if (world != null) {
2021-06-11 07:00:00 +02:00
+ this.level.populating = true;
2018-09-27 13:41:24 +02:00
+ try {
+ for (org.bukkit.generator.BlockPopulator populator : world.getPopulators()) {
+ populator.populate(world, random, bukkitChunk);
+ }
+ } finally {
2021-06-11 07:00:00 +02:00
+ this.level.populating = false;
2018-09-27 13:41:24 +02:00
+ }
+ }
+ 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() {
2021-06-11 13:33:49 +02:00
+ org.bukkit.Server server = this.level.getCraftServer();
2023-04-02 05:06:59 +02:00
+ org.bukkit.Chunk bukkitChunk = new org.bukkit.craftbukkit.CraftChunk(this);
+ org.bukkit.event.world.ChunkUnloadEvent unloadEvent = new org.bukkit.event.world.ChunkUnloadEvent(bukkitChunk, this.isUnsaved());
2019-05-16 01:11:20 +02:00
+ server.getPluginManager().callEvent(unloadEvent);
+ // note: saving can be prevented, but not forced if no saving is actually required
+ this.mustNotSave = !unloadEvent.isSaveChunk();
+ }
2021-11-21 23:00:00 +01:00
+
+ @Override
+ public boolean isUnsaved() {
+ return super.isUnsaved() && !this.mustNotSave;
+ }
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
2018-10-22 21:00:00 +02:00
+
2021-11-21 23:00:00 +01:00
public boolean isEmpty() {
return false;
2019-04-23 04:00:00 +02:00
}
2024-06-13 17:05:00 +02:00
@@ -713,7 +793,7 @@
2018-07-15 02:00:00 +02:00
2021-11-21 23:00:00 +01:00
private <T extends TileEntity> void updateBlockEntityTicker(T t0) {
IBlockData iblockdata = t0.getBlockState();
- BlockEntityTicker<T> blockentityticker = iblockdata.getTicker(this.level, t0.getType());
+ BlockEntityTicker<T> blockentityticker = iblockdata.getTicker(this.level, (TileEntityTypes<T>) t0.getType()); // CraftBukkit - decompile error
2021-06-11 07:00:00 +02:00
if (blockentityticker == null) {
2021-11-21 23:00:00 +01:00
this.removeBlockEntityTicker(t0.getBlockPos());
2024-06-13 17:05:00 +02:00
@@ -798,7 +878,7 @@
2021-06-11 07:00:00 +02:00
private boolean loggedInvalidBlockState;
2024-04-23 17:15:00 +02:00
a(final TileEntity tileentity, final BlockEntityTicker blockentityticker) {
2021-06-11 07:00:00 +02:00
- this.blockEntity = tileentity;
+ this.blockEntity = (T) tileentity; // CraftBukkit - decompile error
this.ticker = blockentityticker;
2019-05-14 02:00:00 +02:00
}
2021-06-11 07:00:00 +02:00