2021-03-15 23:00:00 +01:00
--- a/net/minecraft/world/level/World.java
+++ b/net/minecraft/world/level/World.java
2021-06-11 07:00:00 +02:00
@@ -67,6 +67,28 @@
2020-06-25 02:00:00 +02:00
import org.apache.logging.log4j.LogManager;
2018-07-15 02:00:00 +02:00
import org.apache.logging.log4j.Logger;
2014-11-25 22:32:16 +01:00
+// CraftBukkit start
2020-01-27 23:48:28 +01:00
+import java.util.HashMap;
2015-03-16 10:48:01 +01:00
+import java.util.Map;
2021-06-11 07:00:00 +02:00
+import net.minecraft.network.protocol.game.ClientboundSetBorderCenterPacket;
+import net.minecraft.network.protocol.game.ClientboundSetBorderLerpSizePacket;
+import net.minecraft.network.protocol.game.ClientboundSetBorderSizePacket;
+import net.minecraft.network.protocol.game.ClientboundSetBorderWarningDelayPacket;
+import net.minecraft.network.protocol.game.ClientboundSetBorderWarningDistancePacket;
2021-03-15 23:00:00 +01:00
+import net.minecraft.server.level.WorldServer;
+import net.minecraft.world.entity.item.EntityItem;
+import net.minecraft.world.level.border.IWorldBorderListener;
2014-11-25 22:32:16 +01:00
+import org.bukkit.Bukkit;
2021-06-11 07:00:00 +02:00
+import org.bukkit.Location;
2014-11-25 22:32:16 +01:00
+import org.bukkit.craftbukkit.CraftServer;
+import org.bukkit.craftbukkit.CraftWorld;
2020-01-27 23:48:28 +01:00
+import org.bukkit.craftbukkit.block.CapturedBlockState;
2018-07-15 02:00:00 +02:00
+import org.bukkit.craftbukkit.block.data.CraftBlockData;
2021-06-11 07:00:00 +02:00
+import org.bukkit.craftbukkit.util.CraftNamespacedKey;
2014-11-25 22:32:16 +01:00
+import org.bukkit.event.block.BlockPhysicsEvent;
2021-06-11 07:00:00 +02:00
+import org.bukkit.event.world.GenericGameEvent;
2014-11-25 22:32:16 +01:00
+// CraftBukkit end
+
2019-12-10 23:00:00 +01:00
public abstract class World implements GeneratorAccess, AutoCloseable {
2014-11-25 22:32:16 +01:00
2019-04-25 04:00:00 +02:00
protected static final Logger LOGGER = LogManager.getLogger();
2021-06-11 07:00:00 +02:00
@@ -103,7 +125,49 @@
2020-08-11 23:00:00 +02:00
private final BiomeManager biomeManager;
2021-06-11 07:00:00 +02:00
private final ResourceKey<World> dimension;
2014-11-25 22:32:16 +01:00
2020-08-11 23:00:00 +02:00
- protected World(WorldDataMutable worlddatamutable, ResourceKey<World> resourcekey, final DimensionManager dimensionmanager, Supplier<GameProfilerFiller> supplier, boolean flag, boolean flag1, long i) {
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start Added the following
2020-08-11 23:00:00 +02:00
+ private final ResourceKey<DimensionManager> typeKey;
2014-11-25 22:32:16 +01:00
+ private final CraftWorld world;
+ public boolean pvpMode;
+ public boolean keepSpawnInMemory = true;
2019-04-23 04:00:00 +02:00
+ public org.bukkit.generator.ChunkGenerator generator;
2014-11-25 22:32:16 +01:00
+
+ public boolean captureBlockStates = false;
+ public boolean captureTreeGeneration = false;
2020-08-28 10:32:44 +02:00
+ public Map<BlockPosition, CapturedBlockState> capturedBlockStates = new java.util.LinkedHashMap<>();
2020-01-27 23:48:28 +01:00
+ public Map<BlockPosition, TileEntity> capturedTileEntities = new HashMap<>();
2017-07-28 09:23:39 +02:00
+ public List<EntityItem> captureDrops;
2014-11-25 22:32:16 +01:00
+ public long ticksPerAnimalSpawns;
+ public long ticksPerMonsterSpawns;
2020-03-07 18:30:21 +01:00
+ public long ticksPerWaterSpawns;
2020-06-26 10:39:42 +02:00
+ public long ticksPerWaterAmbientSpawns;
2020-03-07 18:30:21 +01:00
+ public long ticksPerAmbientSpawns;
2014-11-25 22:32:16 +01:00
+ public boolean populating;
+
+ public CraftWorld getWorld() {
+ return this.world;
+ }
+
+ public CraftServer getServer() {
+ return (CraftServer) Bukkit.getServer();
+ }
+
2020-08-11 23:00:00 +02:00
+ public ResourceKey<DimensionManager> getTypeKey() {
+ return typeKey;
+ }
+
+ protected World(WorldDataMutable worlddatamutable, ResourceKey<World> resourcekey, final DimensionManager dimensionmanager, Supplier<GameProfilerFiller> supplier, boolean flag, boolean flag1, long i, org.bukkit.generator.ChunkGenerator gen, org.bukkit.World.Environment env) {
2014-11-25 22:32:16 +01:00
+ this.generator = gen;
+ this.world = new CraftWorld((WorldServer) this, gen, env);
+ this.ticksPerAnimalSpawns = this.getServer().getTicksPerAnimalSpawns(); // CraftBukkit
+ this.ticksPerMonsterSpawns = this.getServer().getTicksPerMonsterSpawns(); // CraftBukkit
2020-03-07 18:30:21 +01:00
+ this.ticksPerWaterSpawns = this.getServer().getTicksPerWaterSpawns(); // CraftBukkit
2020-06-26 10:39:42 +02:00
+ this.ticksPerWaterAmbientSpawns = this.getServer().getTicksPerWaterAmbientSpawns(); // CraftBukkit
2020-03-07 18:30:21 +01:00
+ this.ticksPerAmbientSpawns = this.getServer().getTicksPerAmbientSpawns(); // CraftBukkit
2021-06-11 07:00:00 +02:00
+ this.typeKey = (ResourceKey) this.getServer().getHandle().getServer().registryHolder.d(IRegistry.DIMENSION_TYPE_REGISTRY).c(dimensionmanager).orElseThrow(() -> {
2020-08-11 23:00:00 +02:00
+ return new IllegalStateException("Unregistered dimension type: " + dimensionmanager);
+ });
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
this.profiler = supplier;
this.levelData = worlddatamutable;
this.dimensionType = dimensionmanager;
@@ -113,12 +177,12 @@
2020-06-25 02:00:00 +02:00
this.worldBorder = new WorldBorder() {
@Override
public double getCenterX() {
2020-08-11 23:00:00 +02:00
- return super.getCenterX() / dimensionmanager.getCoordinateScale();
2020-06-25 02:00:00 +02:00
+ return super.getCenterX(); // CraftBukkit
}
@Override
public double getCenterZ() {
2020-08-11 23:00:00 +02:00
- return super.getCenterZ() / dimensionmanager.getCoordinateScale();
2020-06-25 02:00:00 +02:00
+ return super.getCenterZ(); // CraftBukkit
}
};
} else {
2021-06-11 07:00:00 +02:00
@@ -128,6 +192,35 @@
this.thread = Thread.currentThread();
2020-06-25 02:00:00 +02:00
this.biomeManager = new BiomeManager(this, i, dimensionmanager.getGenLayerZoomer());
2021-06-11 07:00:00 +02:00
this.isDebug = flag1;
2016-03-01 01:20:42 +01:00
+ // CraftBukkit start
2016-03-06 02:13:07 +01:00
+ getWorldBorder().world = (WorldServer) this;
+ // From PlayerList.setPlayerFileData
+ getWorldBorder().a(new IWorldBorderListener() {
+ public void a(WorldBorder worldborder, double d0) {
2021-06-11 07:00:00 +02:00
+ getServer().getHandle().sendAll(new ClientboundSetBorderSizePacket(worldborder), worldborder.world);
2016-03-06 02:13:07 +01:00
+ }
+
+ public void a(WorldBorder worldborder, double d0, double d1, long i) {
2021-06-11 07:00:00 +02:00
+ getServer().getHandle().sendAll(new ClientboundSetBorderLerpSizePacket(worldborder), worldborder.world);
2016-03-06 02:13:07 +01:00
+ }
+
+ public void a(WorldBorder worldborder, double d0, double d1) {
2021-06-11 07:00:00 +02:00
+ getServer().getHandle().sendAll(new ClientboundSetBorderCenterPacket(worldborder), worldborder.world);
2016-03-06 02:13:07 +01:00
+ }
+
+ public void a(WorldBorder worldborder, int i) {
2021-06-11 07:00:00 +02:00
+ getServer().getHandle().sendAll(new ClientboundSetBorderWarningDelayPacket(worldborder), worldborder.world);
2016-03-06 02:13:07 +01:00
+ }
+
+ public void b(WorldBorder worldborder, int i) {
2021-06-11 07:00:00 +02:00
+ getServer().getHandle().sendAll(new ClientboundSetBorderWarningDistancePacket(worldborder), worldborder.world);
2016-03-06 02:13:07 +01:00
+ }
+
+ public void b(WorldBorder worldborder, double d0) {}
+
+ public void c(WorldBorder worldborder, double d0) {}
+ });
2016-03-01 01:20:42 +01:00
+ // CraftBukkit end
2014-11-25 22:32:16 +01:00
}
2019-04-23 04:00:00 +02:00
@Override
2021-06-11 07:00:00 +02:00
@@ -185,6 +278,17 @@
2014-11-25 22:32:16 +01:00
2019-04-23 04:00:00 +02:00
@Override
2020-06-25 02:00:00 +02:00
public boolean a(BlockPosition blockposition, IBlockData iblockdata, int i, int j) {
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - tree generation
+ if (this.captureTreeGeneration) {
2020-01-27 23:48:28 +01:00
+ CapturedBlockState blockstate = capturedBlockStates.get(blockposition);
2014-11-25 22:32:16 +01:00
+ if (blockstate == null) {
2020-01-27 23:48:28 +01:00
+ blockstate = CapturedBlockState.getTreeBlockState(this, blockposition, i);
+ this.capturedBlockStates.put(blockposition.immutableCopy(), blockstate);
2014-11-25 22:32:16 +01:00
+ }
2018-07-15 02:00:00 +02:00
+ blockstate.setData(iblockdata);
2014-11-25 22:32:16 +01:00
+ return true;
+ }
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
if (this.isOutsideWorld(blockposition)) {
2014-11-25 22:32:16 +01:00
return false;
2020-06-25 02:00:00 +02:00
} else if (!this.isClientSide && this.isDebugWorld()) {
2021-06-11 07:00:00 +02:00
@@ -192,9 +296,24 @@
2014-11-25 22:32:16 +01:00
} else {
Chunk chunk = this.getChunkAtWorldCoords(blockposition);
Block block = iblockdata.getBlock();
2018-10-22 21:00:00 +02:00
- IBlockData iblockdata1 = chunk.setType(blockposition, iblockdata, (i & 64) != 0);
2015-02-26 23:41:06 +01:00
+
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - capture blockstates
2020-04-05 09:19:03 +02:00
+ boolean captured = false;
2020-01-27 23:48:28 +01:00
+ if (this.captureBlockStates && !this.capturedBlockStates.containsKey(blockposition)) {
+ CapturedBlockState blockstate = CapturedBlockState.getBlockState(this, blockposition, i);
+ this.capturedBlockStates.put(blockposition.immutableCopy(), blockstate);
2020-04-05 09:19:03 +02:00
+ captured = true;
2014-11-25 22:32:16 +01:00
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
2018-10-22 21:00:00 +02:00
+ IBlockData iblockdata1 = chunk.setType(blockposition, iblockdata, (i & 64) != 0, (i & 1024) == 0); // CraftBukkit custom NO_PLACE flag
2014-11-25 22:32:16 +01:00
if (iblockdata1 == null) {
2020-04-05 09:19:03 +02:00
+ // CraftBukkit start - remove blockstate if failed (or the same)
+ if (this.captureBlockStates && captured) {
2020-01-27 23:48:28 +01:00
+ this.capturedBlockStates.remove(blockposition);
2014-11-25 22:32:16 +01:00
+ }
+ // CraftBukkit end
return false;
} else {
2018-07-15 02:00:00 +02:00
IBlockData iblockdata2 = this.getType(blockposition);
2021-06-11 07:00:00 +02:00
@@ -205,6 +324,7 @@
2020-06-25 02:00:00 +02:00
this.getMethodProfiler().exit();
2014-11-25 22:32:16 +01:00
}
+ /*
2018-07-15 02:00:00 +02:00
if (iblockdata2 == iblockdata) {
if (iblockdata1 != iblockdata2) {
2019-07-20 01:00:00 +02:00
this.b(blockposition, iblockdata1, iblockdata2);
2021-06-11 07:00:00 +02:00
@@ -231,12 +351,65 @@
2019-04-23 04:00:00 +02:00
this.a(blockposition, iblockdata1, iblockdata2);
2014-11-25 22:32:16 +01:00
}
+ */
+
+ // CraftBukkit start
+ if (!this.captureBlockStates) { // Don't notify clients or update physics while capturing blockstates
+ // Modularize client and physic updates
2020-07-07 01:35:47 +02:00
+ notifyAndUpdatePhysics(blockposition, chunk, iblockdata1, iblockdata, iblockdata2, i, j);
2014-11-25 22:32:16 +01:00
+ }
+ // CraftBukkit end
return true;
}
}
}
2016-11-17 02:41:03 +01:00
+ // CraftBukkit start - Split off from above in order to directly send client and physic updates
2020-07-07 01:35:47 +02:00
+ public void notifyAndUpdatePhysics(BlockPosition blockposition, Chunk chunk, IBlockData oldBlock, IBlockData newBlock, IBlockData actualBlock, int i, int j) {
2018-07-15 02:00:00 +02:00
+ IBlockData iblockdata = newBlock;
+ IBlockData iblockdata1 = oldBlock;
+ IBlockData iblockdata2 = actualBlock;
+ if (iblockdata2 == iblockdata) {
+ if (iblockdata1 != iblockdata2) {
2019-07-20 01:00:00 +02:00
+ this.b(blockposition, iblockdata1, iblockdata2);
2018-07-15 02:00:00 +02:00
+ }
2014-11-25 22:32:16 +01:00
+
2019-05-27 22:30:00 +02:00
+ if ((i & 2) != 0 && (!this.isClientSide || (i & 4) == 0) && (this.isClientSide || chunk == null || (chunk.getState() != null && chunk.getState().isAtLeast(PlayerChunk.State.TICKING)))) { // allow chunk to be null here as chunk.isReady() is false when we send our notification during block placement
2018-07-15 02:00:00 +02:00
+ this.notify(blockposition, iblockdata1, iblockdata, i);
+ }
+
2020-07-07 01:35:47 +02:00
+ if ((i & 1) != 0) {
2018-07-15 02:00:00 +02:00
+ this.update(blockposition, iblockdata1.getBlock());
2020-07-07 01:35:47 +02:00
+ if (!this.isClientSide && iblockdata.isComplexRedstone()) {
2018-07-15 02:00:00 +02:00
+ this.updateAdjacentComparators(blockposition, newBlock.getBlock());
+ }
+ }
+
2020-07-07 01:35:47 +02:00
+ if ((i & 16) == 0 && j > 0) {
+ int k = i & -34;
2018-07-15 02:00:00 +02:00
+
2018-07-29 01:37:16 +02:00
+ // CraftBukkit start
2020-07-07 01:35:47 +02:00
+ iblockdata1.b(this, blockposition, k, j - 1); // Don't call an event for the old block to limit event spam
2018-07-29 01:37:16 +02:00
+ CraftWorld world = ((WorldServer) this).getWorld();
+ if (world != null) {
+ BlockPhysicsEvent event = new BlockPhysicsEvent(world.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()), CraftBlockData.fromData(iblockdata));
+ this.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+ }
+ // CraftBukkit end
2020-07-07 01:35:47 +02:00
+ iblockdata.a((GeneratorAccess) this, blockposition, k, j - 1);
+ iblockdata.b(this, blockposition, k, j - 1);
2014-11-25 22:32:16 +01:00
+ }
2019-04-23 04:00:00 +02:00
+
+ this.a(blockposition, iblockdata1, iblockdata2);
2014-11-25 22:32:16 +01:00
+ }
+ }
+ // CraftBukkit end
+
2019-04-23 04:00:00 +02:00
public void a(BlockPosition blockposition, IBlockData iblockdata, IBlockData iblockdata1) {}
2014-11-25 22:32:16 +01:00
2019-04-23 04:00:00 +02:00
@Override
2021-06-11 07:00:00 +02:00
@@ -326,6 +499,17 @@
2014-11-25 22:32:16 +01:00
IBlockData iblockdata = this.getType(blockposition);
try {
+ // CraftBukkit start
+ CraftWorld world = ((WorldServer) this).getWorld();
+ if (world != null) {
2019-02-25 04:50:05 +01:00
+ BlockPhysicsEvent event = new BlockPhysicsEvent(world.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()), CraftBlockData.fromData(iblockdata), world.getBlockAt(blockposition1.getX(), blockposition1.getY(), blockposition1.getZ()));
2014-11-25 22:32:16 +01:00
+ this.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+ }
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
iblockdata.doPhysics(this, blockposition, block, blockposition1, false);
2014-11-25 22:32:16 +01:00
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Exception while updating neighbours");
2021-06-11 07:00:00 +02:00
@@ -368,6 +552,14 @@
2014-11-25 22:32:16 +01:00
2019-04-23 04:00:00 +02:00
@Override
2014-11-25 22:32:16 +01:00
public IBlockData getType(BlockPosition blockposition) {
+ // CraftBukkit start - tree generation
+ if (captureTreeGeneration) {
2020-01-27 23:48:28 +01:00
+ CapturedBlockState previous = capturedBlockStates.get(blockposition);
+ if (previous != null) {
+ return previous.getHandle();
2014-11-25 22:32:16 +01:00
+ }
+ }
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
if (this.isOutsideWorld(blockposition)) {
2018-07-15 02:00:00 +02:00
return Blocks.VOID_AIR.getBlockData();
2014-11-25 22:32:16 +01:00
} else {
2021-06-11 07:00:00 +02:00
@@ -484,7 +676,17 @@
2015-03-16 10:48:01 +01:00
2016-05-10 13:47:39 +02:00
@Nullable
2019-04-23 04:00:00 +02:00
@Override
2019-12-23 01:59:51 +01:00
+ // CraftBukkit start
2015-03-16 10:48:01 +01:00
public TileEntity getTileEntity(BlockPosition blockposition) {
2019-12-23 01:59:51 +01:00
+ return getTileEntity(blockposition, true);
+ }
+
+ @Nullable
2021-03-15 23:00:00 +01:00
+ public TileEntity getTileEntity(BlockPosition blockposition, boolean validate) {
2021-06-11 07:00:00 +02:00
+ if (capturedTileEntities.containsKey(blockposition)) {
+ return capturedTileEntities.get(blockposition);
+ }
2019-12-23 01:59:51 +01:00
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
return this.isOutsideWorld(blockposition) ? null : (!this.isClientSide && Thread.currentThread() != this.thread ? null : this.getChunkAtWorldCoords(blockposition).a(blockposition, Chunk.EnumTileEntityState.IMMEDIATE));
}
@@ -492,6 +694,12 @@
BlockPosition blockposition = tileentity.getPosition();
if (!this.isOutsideWorld(blockposition)) {
2015-03-16 10:48:01 +01:00
+ // CraftBukkit start
2021-06-11 07:00:00 +02:00
+ if (captureBlockStates) {
+ capturedTileEntities.put(blockposition.immutableCopy(), tileentity);
+ return;
2015-03-16 10:48:01 +01:00
+ }
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
this.getChunkAtWorldCoords(blockposition).b(tileentity);
}
2019-12-23 01:59:51 +01:00
}
2021-06-11 07:00:00 +02:00
@@ -595,7 +803,7 @@
for (int j = 0; j < i; ++j) {
EntityComplexPart entitycomplexpart = aentitycomplexpart[j];
- T t0 = (Entity) entitytypetest.a((Object) entitycomplexpart);
+ T t0 = entitytypetest.a(entitycomplexpart);
2019-12-23 01:59:51 +01:00
2021-06-11 07:00:00 +02:00
if (t0 != null && predicate.test(t0)) {
list.add(t0);
@@ -921,6 +1129,14 @@
public abstract LevelEntityGetter<Entity> getEntities();
2019-12-23 01:59:51 +01:00
2021-06-11 07:00:00 +02:00
protected void a(@Nullable Entity entity, GameEvent gameevent, BlockPosition blockposition, int i) {
+ // CraftBukkit start
+ GenericGameEvent event = new GenericGameEvent(org.bukkit.GameEvent.getByKey(CraftNamespacedKey.fromMinecraft(IRegistry.GAME_EVENT.getKey(gameevent))), new Location(this.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ()), (entity == null) ? null : entity.getBukkitEntity(), i);
+ getServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return;
+ }
+ i = event.getRadius();
+ // CraftBukkit end
int j = SectionPosition.a(blockposition.getX() - i);
int k = SectionPosition.a(blockposition.getZ() - i);
int l = SectionPosition.a(blockposition.getX() + i);