Paper/nms-patches/World.patch

348 lines
16 KiB
Diff
Raw Normal View History

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/World.java
+++ b/net/minecraft/server/World.java
@@ -14,6 +14,17 @@
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;
+// CraftBukkit start
+import java.util.HashMap;
+import java.util.Map;
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.CraftServer;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.block.CapturedBlockState;
2018-07-15 02:00:00 +02:00
+import org.bukkit.craftbukkit.block.data.CraftBlockData;
+import org.bukkit.event.block.BlockPhysicsEvent;
+// CraftBukkit end
+
2019-12-10 23:00:00 +01:00
public abstract class World implements GeneratorAccess, AutoCloseable {
2019-04-25 04:00:00 +02:00
protected static final Logger LOGGER = LogManager.getLogger();
2020-08-11 23:00:00 +02:00
@@ -45,7 +56,49 @@
private final BiomeManager biomeManager;
2020-06-25 02:00:00 +02:00
private final ResourceKey<World> dimensionKey;
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) {
+ // CraftBukkit start Added the following
2020-08-11 23:00:00 +02:00
+ private final ResourceKey<DimensionManager> typeKey;
+ 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;
+
+ public boolean captureBlockStates = false;
+ public boolean captureTreeGeneration = false;
+ public Map<BlockPosition, CapturedBlockState> capturedBlockStates = new HashMap<>();
+ public Map<BlockPosition, TileEntity> capturedTileEntities = new HashMap<>();
+ public List<EntityItem> captureDrops;
+ public long ticksPerAnimalSpawns;
+ public long ticksPerMonsterSpawns;
+ public long ticksPerWaterSpawns;
+ public long ticksPerWaterAmbientSpawns;
+ public long ticksPerAmbientSpawns;
+ 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) {
+ this.generator = gen;
+ this.world = new CraftWorld((WorldServer) this, gen, env);
+ this.ticksPerAnimalSpawns = this.getServer().getTicksPerAnimalSpawns(); // CraftBukkit
+ this.ticksPerMonsterSpawns = this.getServer().getTicksPerMonsterSpawns(); // CraftBukkit
+ this.ticksPerWaterSpawns = this.getServer().getTicksPerWaterSpawns(); // CraftBukkit
+ this.ticksPerWaterAmbientSpawns = this.getServer().getTicksPerWaterAmbientSpawns(); // CraftBukkit
+ this.ticksPerAmbientSpawns = this.getServer().getTicksPerAmbientSpawns(); // CraftBukkit
2020-08-11 23:00:00 +02:00
+ this.typeKey = (ResourceKey) this.getServer().getHandle().getServer().f.a().c(dimensionmanager).orElseThrow(() -> {
+ return new IllegalStateException("Unregistered dimension type: " + dimensionmanager);
+ });
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
this.methodProfiler = supplier;
this.worldData = worlddatamutable;
this.x = dimensionmanager;
2020-08-11 23:00:00 +02:00
@@ -55,12 +108,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 {
2020-08-11 23:00:00 +02:00
@@ -70,6 +123,35 @@
2019-05-14 02:00:00 +02:00
this.serverThread = Thread.currentThread();
2020-06-25 02:00:00 +02:00
this.biomeManager = new BiomeManager(this, i, dimensionmanager.getGenLayerZoomer());
this.debugWorld = flag1;
2016-03-01 01:20:42 +01:00
+ // CraftBukkit start
+ getWorldBorder().world = (WorldServer) this;
+ // From PlayerList.setPlayerFileData
+ getWorldBorder().a(new IWorldBorderListener() {
+ public void a(WorldBorder worldborder, double d0) {
+ getServer().getHandle().sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.SET_SIZE), worldborder.world);
+ }
+
+ public void a(WorldBorder worldborder, double d0, double d1, long i) {
+ getServer().getHandle().sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.LERP_SIZE), worldborder.world);
+ }
+
+ public void a(WorldBorder worldborder, double d0, double d1) {
+ getServer().getHandle().sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.SET_CENTER), worldborder.world);
+ }
+
+ public void a(WorldBorder worldborder, int i) {
+ getServer().getHandle().sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.SET_WARNING_TIME), worldborder.world);
+ }
+
+ public void b(WorldBorder worldborder, int i) {
+ getServer().getHandle().sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.SET_WARNING_BLOCKS), worldborder.world);
+ }
+
+ public void b(WorldBorder worldborder, double d0) {}
+
+ public void c(WorldBorder worldborder, double d0) {}
+ });
2016-03-01 01:20:42 +01:00
+ // CraftBukkit end
}
2019-04-23 04:00:00 +02:00
@Override
2020-08-11 23:00:00 +02:00
@@ -133,6 +215,17 @@
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) {
+ // CraftBukkit start - tree generation
+ if (this.captureTreeGeneration) {
+ CapturedBlockState blockstate = capturedBlockStates.get(blockposition);
+ if (blockstate == null) {
+ blockstate = CapturedBlockState.getTreeBlockState(this, blockposition, i);
+ this.capturedBlockStates.put(blockposition.immutableCopy(), blockstate);
+ }
2018-07-15 02:00:00 +02:00
+ blockstate.setData(iblockdata);
+ return true;
+ }
+ // CraftBukkit end
2019-05-14 02:00:00 +02:00
if (isOutsideWorld(blockposition)) {
return false;
2020-06-25 02:00:00 +02:00
} else if (!this.isClientSide && this.isDebugWorld()) {
2020-08-11 23:00:00 +02:00
@@ -140,9 +233,24 @@
} 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
+
+ // CraftBukkit start - capture blockstates
+ boolean captured = false;
+ if (this.captureBlockStates && !this.capturedBlockStates.containsKey(blockposition)) {
+ CapturedBlockState blockstate = CapturedBlockState.getBlockState(this, blockposition, i);
+ this.capturedBlockStates.put(blockposition.immutableCopy(), blockstate);
+ captured = true;
+ }
+ // 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
if (iblockdata1 == null) {
+ // CraftBukkit start - remove blockstate if failed (or the same)
+ if (this.captureBlockStates && captured) {
+ this.capturedBlockStates.remove(blockposition);
+ }
+ // CraftBukkit end
return false;
} else {
2018-07-15 02:00:00 +02:00
IBlockData iblockdata2 = this.getType(blockposition);
2020-08-11 23:00:00 +02:00
@@ -153,6 +261,7 @@
2020-06-25 02:00:00 +02:00
this.getMethodProfiler().exit();
}
+ /*
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);
2020-08-11 23:00:00 +02:00
@@ -179,12 +288,65 @@
2019-04-23 04:00:00 +02:00
this.a(blockposition, iblockdata1, iblockdata2);
}
+ */
+
+ // 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);
+ }
+ // 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
+ }
+
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
+
+ // 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
+ 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);
+ }
2019-04-23 04:00:00 +02:00
+
+ this.a(blockposition, iblockdata1, iblockdata2);
+ }
+ }
+ // CraftBukkit end
+
2019-04-23 04:00:00 +02:00
public void a(BlockPosition blockposition, IBlockData iblockdata, IBlockData iblockdata1) {}
2019-04-23 04:00:00 +02:00
@Override
2020-08-11 23:00:00 +02:00
@@ -266,6 +428,17 @@
IBlockData iblockdata = this.getType(blockposition);
try {
+ // CraftBukkit start
+ CraftWorld world = ((WorldServer) this).getWorld();
+ if (world != null) {
+ BlockPhysicsEvent event = new BlockPhysicsEvent(world.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()), CraftBlockData.fromData(iblockdata), world.getBlockAt(blockposition1.getX(), blockposition1.getY(), blockposition1.getZ()));
+ 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);
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Exception while updating neighbours");
2020-08-11 23:00:00 +02:00
@@ -308,6 +481,14 @@
2019-04-23 04:00:00 +02:00
@Override
public IBlockData getType(BlockPosition blockposition) {
+ // CraftBukkit start - tree generation
+ if (captureTreeGeneration) {
+ CapturedBlockState previous = capturedBlockStates.get(blockposition);
+ if (previous != null) {
+ return previous.getHandle();
+ }
+ }
+ // CraftBukkit end
2019-05-14 02:00:00 +02:00
if (isOutsideWorld(blockposition)) {
2018-07-15 02:00:00 +02:00
return Blocks.VOID_AIR.getBlockData();
} else {
2020-08-11 23:00:00 +02:00
@@ -455,9 +636,11 @@
2019-04-23 04:00:00 +02:00
TileEntity tileentity1 = (TileEntity) this.tileEntityListPending.get(i);
2019-04-23 04:00:00 +02:00
if (!tileentity1.isRemoved()) {
+ /* CraftBukkit start - Order matters, moved down
2016-02-29 22:32:46 +01:00
if (!this.tileEntityList.contains(tileentity1)) {
this.a(tileentity1);
}
+ // CraftBukkit end */
if (this.isLoaded(tileentity1.getPosition())) {
2016-02-29 22:32:46 +01:00
Chunk chunk = this.getChunkAtWorldCoords(tileentity1.getPosition());
2020-08-11 23:00:00 +02:00
@@ -465,6 +648,12 @@
2019-04-23 04:00:00 +02:00
chunk.setTileEntity(tileentity1.getPosition(), tileentity1);
this.notify(tileentity1.getPosition(), iblockdata, iblockdata, 3);
+ // CraftBukkit start
+ // From above, don't screw this up - SPIGOT-1746
+ if (!this.tileEntityList.contains(tileentity1)) {
+ this.a(tileentity1);
+ }
+ // CraftBukkit end
}
}
}
2020-08-11 23:00:00 +02:00
@@ -505,12 +694,25 @@
2016-05-10 13:47:39 +02:00
@Nullable
2019-04-23 04:00:00 +02:00
@Override
+ // CraftBukkit start
public TileEntity getTileEntity(BlockPosition blockposition) {
+ return getTileEntity(blockposition, true);
+ }
+
+ @Nullable
+ protected TileEntity getTileEntity(BlockPosition blockposition, boolean validate) {
+ // CraftBukkit end
if (isOutsideWorld(blockposition)) {
return null;
2019-05-14 02:00:00 +02:00
} else if (!this.isClientSide && Thread.currentThread() != this.serverThread) {
return null;
} else {
+ // CraftBukkit start
+ if (capturedTileEntities.containsKey(blockposition)) {
+ return capturedTileEntities.get(blockposition);
+ }
+ // CraftBukkit end
+
TileEntity tileentity = null;
2019-04-23 04:00:00 +02:00
if (this.tickingTileEntities) {
2020-08-11 23:00:00 +02:00
@@ -545,6 +747,13 @@
2016-05-10 13:47:39 +02:00
public void setTileEntity(BlockPosition blockposition, @Nullable TileEntity tileentity) {
2019-05-14 02:00:00 +02:00
if (!isOutsideWorld(blockposition)) {
2019-04-23 04:00:00 +02:00
if (tileentity != null && !tileentity.isRemoved()) {
2018-07-15 02:00:00 +02:00
+ // CraftBukkit start
+ if (captureBlockStates) {
2019-12-10 23:00:00 +01:00
+ tileentity.setLocation(this, blockposition);
+ capturedTileEntities.put(blockposition.immutableCopy(), tileentity);
2018-07-15 02:00:00 +02:00
+ return;
+ }
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
if (this.tickingTileEntities) {
2019-12-10 23:00:00 +01:00
tileentity.setLocation(this, blockposition);
2019-04-23 04:00:00 +02:00
Iterator iterator = this.tileEntityListPending.iterator();
2020-08-11 23:00:00 +02:00
@@ -569,7 +778,7 @@
}
public void removeTileEntity(BlockPosition blockposition) {
- TileEntity tileentity = this.getTileEntity(blockposition);
+ TileEntity tileentity = this.getTileEntity(blockposition, false); // CraftBukkit
if (tileentity != null && this.tickingTileEntities) {
2020-08-11 23:00:00 +02:00
tileentity.al_();