2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/World.java
+++ b/net/minecraft/server/World.java
2019-04-23 04:00:00 +02:00
@@ -14,6 +14,22 @@
2018-07-15 02:00:00 +02:00
import org.apache.logging.log4j.Logger;
2019-04-23 04:00:00 +02:00
import org.apache.logging.log4j.util.Supplier;
2014-11-25 22:32:16 +01:00
+// CraftBukkit start
2015-03-16 10:48:01 +01:00
+import com.google.common.collect.Maps;
2018-12-25 22:00:00 +01:00
+import java.util.ArrayList;
2015-03-16 10:48:01 +01:00
+import java.util.Map;
2014-11-25 22:32:16 +01:00
+import org.bukkit.Bukkit;
+import org.bukkit.block.BlockState;
+import org.bukkit.craftbukkit.CraftServer;
+import org.bukkit.craftbukkit.CraftWorld;
2018-07-15 02:00:00 +02:00
+import org.bukkit.craftbukkit.block.CraftBlockState;
+import org.bukkit.craftbukkit.block.data.CraftBlockData;
2014-11-25 22:32:16 +01:00
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.block.BlockPhysicsEvent;
+import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
2019-04-23 04:00:00 +02:00
+import org.bukkit.event.weather.LightningStrikeEvent;
2014-11-25 22:32:16 +01:00
+// CraftBukkit end
+
2019-04-23 04:00:00 +02:00
public abstract class World implements IIBlockAccess, GeneratorAccess, AutoCloseable {
2014-11-25 22:32:16 +01:00
2018-07-15 02:00:00 +02:00
protected static final Logger e = LogManager.getLogger();
2019-04-23 04:00:00 +02:00
@@ -41,14 +57,87 @@
protected boolean tickingTileEntities;
private final WorldBorder worldBorder;
2014-11-25 22:32:16 +01:00
2019-04-23 04:00:00 +02:00
- protected World(WorldData worlddata, DimensionManager dimensionmanager, BiFunction<World, WorldProvider, IChunkProvider> bifunction, GameProfilerFiller gameprofilerfiller, boolean flag) {
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start Added the following
+ 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;
2018-07-15 02:00:00 +02:00
+ public ArrayList<CraftBlockState> capturedBlockStates = new ArrayList<CraftBlockState>() {
2014-11-29 19:08:50 +01:00
+ @Override
2018-07-15 02:00:00 +02:00
+ public boolean add(CraftBlockState blockState) {
+ Iterator<CraftBlockState> blockStateIterator = this.iterator();
+ while (blockStateIterator.hasNext()) {
2014-11-29 19:08:50 +01:00
+ BlockState blockState1 = blockStateIterator.next();
2018-07-15 02:00:00 +02:00
+ if (blockState1.getLocation().equals(blockState.getLocation())) {
2014-11-29 22:17:57 +01:00
+ return false;
2014-11-29 19:08:50 +01:00
+ }
+ }
+
2018-07-15 02:00:00 +02:00
+ return super.add(blockState);
2014-11-29 19:08:50 +01:00
+ }
+ };
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;
+ public boolean populating;
+
+ public CraftWorld getWorld() {
+ return this.world;
+ }
+
+ public CraftServer getServer() {
+ return (CraftServer) Bukkit.getServer();
+ }
+
+ public Chunk getChunkIfLoaded(int x, int z) {
2019-04-23 04:00:00 +02:00
+ return ((ChunkProviderServer) this.chunkProvider).getChunkAt(x, z, false);
2014-11-25 22:32:16 +01:00
+ }
+
2019-04-23 04:00:00 +02:00
+ protected World(WorldData worlddata, DimensionManager dimensionmanager, BiFunction<World, WorldProvider, IChunkProvider> bifunction, GameProfilerFiller gameprofilerfiller, boolean flag, 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
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
this.methodProfiler = gameprofilerfiller;
this.worldData = worlddata;
- this.worldProvider = dimensionmanager.getWorldProvider(this);
+ this.worldProvider = DimensionManager.a(env.getId()).getWorldProvider(this); // CraftBukkit
this.chunkProvider = (IChunkProvider) bifunction.apply(this, this.worldProvider);
2015-02-26 23:41:06 +01:00
this.isClientSide = flag;
2019-04-23 04:00:00 +02:00
this.worldBorder = this.worldProvider.getWorldBorder();
this.c = Thread.currentThread();
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) {
+ 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
2014-11-25 22:32:16 +01:00
}
2019-04-23 04:00:00 +02:00
@Override
@@ -119,6 +208,26 @@
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 boolean setTypeAndData(BlockPosition blockposition, IBlockData iblockdata, int i) {
+ // CraftBukkit start - tree generation
+ if (this.captureTreeGeneration) {
2018-07-15 02:00:00 +02:00
+ CraftBlockState blockstate = null;
+ Iterator<CraftBlockState> it = capturedBlockStates.iterator();
2014-11-25 22:32:16 +01:00
+ while (it.hasNext()) {
2018-07-15 02:00:00 +02:00
+ CraftBlockState previous = it.next();
2018-12-22 01:32:11 +01:00
+ if (previous.getPosition().equals(blockposition)) {
2014-11-25 22:32:16 +01:00
+ blockstate = previous;
+ it.remove();
+ break;
+ }
+ }
+ if (blockstate == null) {
2018-07-15 02:00:00 +02:00
+ blockstate = org.bukkit.craftbukkit.block.CraftBlockState.getBlockState(this, blockposition, i);
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
+ this.capturedBlockStates.add(blockstate);
+ return true;
+ }
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
if (isInsideWorld(blockposition)) {
2014-11-25 22:32:16 +01:00
return false;
2015-02-26 23:41:06 +01:00
} else if (!this.isClientSide && this.worldData.getType() == WorldType.DEBUG_ALL_BLOCK_STATES) {
2019-04-23 04:00:00 +02:00
@@ -126,9 +235,23 @@
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
2018-07-15 02:00:00 +02:00
+ CraftBlockState blockstate = null;
2014-11-25 22:32:16 +01:00
+ if (this.captureBlockStates) {
2018-07-15 02:00:00 +02:00
+ blockstate = org.bukkit.craftbukkit.block.CraftBlockState.getBlockState(this, blockposition, i);
2014-11-25 22:32:16 +01:00
+ this.capturedBlockStates.add(blockstate);
+ }
+ // 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) {
+ // CraftBukkit start - remove blockstate if failed
2014-11-29 22:17:57 +01:00
+ if (this.captureBlockStates) {
2014-11-25 22:32:16 +01:00
+ this.capturedBlockStates.remove(blockstate);
+ }
+ // CraftBukkit end
return false;
} else {
2018-07-15 02:00:00 +02:00
IBlockData iblockdata2 = this.getType(blockposition);
2019-04-23 04:00:00 +02:00
@@ -139,6 +262,7 @@
2018-12-13 01:00:00 +01:00
this.methodProfiler.exit();
2014-11-25 22:32:16 +01:00
}
+ /*
2018-07-15 02:00:00 +02:00
if (iblockdata2 == iblockdata) {
if (iblockdata1 != iblockdata2) {
2019-04-23 04:00:00 +02:00
this.m(blockposition);
@@ -165,12 +289,65 @@
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
2018-07-15 02:00:00 +02:00
+ notifyAndUpdatePhysics(blockposition, chunk, iblockdata1, iblockdata, iblockdata2, i);
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
2018-07-15 02:00:00 +02:00
+ public void notifyAndUpdatePhysics(BlockPosition blockposition, Chunk chunk, IBlockData oldBlock, IBlockData newBlock, IBlockData actualBlock, int i) {
+ IBlockData iblockdata = newBlock;
+ IBlockData iblockdata1 = oldBlock;
+ IBlockData iblockdata2 = actualBlock;
+ if (iblockdata2 == iblockdata) {
+ if (iblockdata1 != iblockdata2) {
2019-04-23 04:00:00 +02:00
+ this.m(blockposition);
2018-07-15 02:00:00 +02:00
+ }
2014-11-25 22:32:16 +01:00
+
2019-04-23 04:00:00 +02:00
+ if ((i & 2) != 0 && (!this.isClientSide || (i & 4) == 0) && (this.isClientSide || chunk == null || (chunk.getState() != null && chunk.getState().a(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);
+ }
+
+ if (!this.isClientSide && (i & 1) != 0) {
+ this.update(blockposition, iblockdata1.getBlock());
+ if (iblockdata.isComplexRedstone()) {
+ this.updateAdjacentComparators(blockposition, newBlock.getBlock());
+ }
+ }
+
+ if ((i & 16) == 0) {
+ int j = i & -2;
+
2018-07-29 01:37:16 +02:00
+ // CraftBukkit start
+ iblockdata1.b(this, blockposition, j); // 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
2019-04-23 04:00:00 +02:00
+ iblockdata.a(this, blockposition, j);
2018-07-15 02:00:00 +02:00
+ iblockdata.b(this, blockposition, j);
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
@@ -209,6 +386,11 @@
@Override
2018-07-15 02:00:00 +02:00
public void update(BlockPosition blockposition, Block block) {
2014-11-25 22:32:16 +01:00
if (this.worldData.getType() != WorldType.DEBUG_ALL_BLOCK_STATES) {
+ // CraftBukkit start
+ if (populating) {
+ return;
+ }
+ // CraftBukkit end
2018-07-15 02:00:00 +02:00
this.applyPhysics(blockposition, block);
2014-11-25 22:32:16 +01:00
}
2019-04-23 04:00:00 +02:00
@@ -257,6 +439,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");
2019-04-23 04:00:00 +02:00
@@ -316,6 +509,17 @@
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) {
2018-07-15 02:00:00 +02:00
+ Iterator<CraftBlockState> it = capturedBlockStates.iterator();
2014-11-25 22:32:16 +01:00
+ while (it.hasNext()) {
2018-07-15 02:00:00 +02:00
+ CraftBlockState previous = it.next();
2018-12-22 01:32:11 +01:00
+ if (previous.getPosition().equals(blockposition)) {
2018-07-15 02:00:00 +02:00
+ return previous.getHandle();
2014-11-25 22:32:16 +01:00
+ }
+ }
+ }
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
if (isInsideWorld(blockposition)) {
2018-07-15 02:00:00 +02:00
return Blocks.VOID_AIR.getBlockData();
2014-11-25 22:32:16 +01:00
} else {
2019-04-23 04:00:00 +02:00
@@ -454,9 +658,11 @@
TileEntity tileentity1 = (TileEntity) this.tileEntityListPending.get(i);
2014-11-25 22:32:16 +01:00
2019-04-23 04:00:00 +02:00
if (!tileentity1.isRemoved()) {
2014-11-25 22:32:16 +01:00
+ /* CraftBukkit start - Order matters, moved down
2016-02-29 22:32:46 +01:00
if (!this.tileEntityList.contains(tileentity1)) {
2014-11-25 22:32:16 +01:00
this.a(tileentity1);
}
+ // CraftBukkit end */
if (this.isLoaded(tileentity1.getPosition())) {
2016-02-29 22:32:46 +01:00
Chunk chunk = this.getChunkAtWorldCoords(tileentity1.getPosition());
2019-04-23 04:00:00 +02:00
@@ -464,6 +670,12 @@
2016-03-25 04:04:27 +01:00
2019-04-23 04:00:00 +02:00
chunk.setTileEntity(tileentity1.getPosition(), tileentity1);
2016-03-25 04:04:27 +01:00
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
}
}
}
2019-04-23 04:00:00 +02:00
@@ -626,6 +838,7 @@
2015-03-16 10:48:01 +01:00
}
}
+ public Map<BlockPosition, TileEntity> capturedTileEntities = Maps.newHashMap();
2016-05-10 13:47:39 +02:00
@Nullable
2019-04-23 04:00:00 +02:00
@Override
2015-03-16 10:48:01 +01:00
public TileEntity getTileEntity(BlockPosition blockposition) {
2019-04-23 04:00:00 +02:00
@@ -634,6 +847,12 @@
} else if (!this.isClientSide && Thread.currentThread() != this.c) {
2015-03-16 10:48:01 +01:00
return null;
} else {
+ // CraftBukkit start
2015-03-22 20:21:34 +01:00
+ if (capturedTileEntities.containsKey(blockposition)) {
2015-03-16 10:48:01 +01:00
+ return capturedTileEntities.get(blockposition);
+ }
+ // CraftBukkit end
+
TileEntity tileentity = null;
2019-04-23 04:00:00 +02:00
if (this.tickingTileEntities) {
@@ -668,6 +887,14 @@
2016-05-10 13:47:39 +02:00
public void setTileEntity(BlockPosition blockposition, @Nullable TileEntity tileentity) {
2019-04-23 04:00:00 +02:00
if (!isInsideWorld(blockposition)) {
if (tileentity != null && !tileentity.isRemoved()) {
2018-07-15 02:00:00 +02:00
+ // CraftBukkit start
+ if (captureBlockStates) {
+ tileentity.setWorld(this);
+ tileentity.setPosition(blockposition);
+ capturedTileEntities.put(blockposition, tileentity);
+ return;
+ }
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
if (this.tickingTileEntities) {
2016-06-09 03:43:49 +02:00
tileentity.setPosition(blockposition);
2019-04-23 04:00:00 +02:00
Iterator iterator = this.tileEntityListPending.iterator();