2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/World.java
+++ b/net/minecraft/server/World.java
2016-02-29 22:32:46 +01:00
@@ -13,6 +13,21 @@
2014-11-25 22:32:16 +01:00
import java.util.UUID;
2016-05-10 13:47:39 +02:00
import javax.annotation.Nullable;
2014-11-25 22:32:16 +01:00
+// CraftBukkit start
2015-03-16 10:48:01 +01:00
+import com.google.common.collect.Maps;
+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;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
2016-02-29 22:32:46 +01:00
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
2014-11-25 22:32:16 +01:00
+import org.bukkit.event.block.BlockCanBuildEvent;
+import org.bukkit.event.block.BlockPhysicsEvent;
+import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
2016-02-29 22:32:46 +01:00
+import org.bukkit.generator.ChunkGenerator;
2014-11-25 22:32:16 +01:00
+// CraftBukkit end
+
public abstract class World implements IBlockAccess {
2015-02-26 23:41:06 +01:00
private int a = 63;
2017-07-28 09:23:39 +02:00
@@ -58,7 +73,52 @@
2017-05-14 04:00:00 +02:00
private final WorldBorder P;
int[] J;
2014-11-25 22:32:16 +01:00
- protected World(IDataManager idatamanager, WorldData worlddata, WorldProvider worldprovider, MethodProfiler methodprofiler, boolean flag) {
+ // CraftBukkit start Added the following
+ private final CraftWorld world;
+ public boolean pvpMode;
+ public boolean keepSpawnInMemory = true;
+ public ChunkGenerator generator;
+
+ public boolean captureBlockStates = false;
+ public boolean captureTreeGeneration = false;
2014-11-29 19:08:50 +01:00
+ public ArrayList<BlockState> capturedBlockStates= new ArrayList<BlockState>(){
+ @Override
+ public boolean add( BlockState blockState ) {
+ Iterator<BlockState> blockStateIterator = this.iterator();
+ while( blockStateIterator.hasNext() ) {
+ BlockState blockState1 = blockStateIterator.next();
+ if ( blockState1.getLocation().equals( blockState.getLocation() ) ) {
2014-11-29 22:17:57 +01:00
+ return false;
2014-11-29 19:08:50 +01:00
+ }
+ }
+
+ return super.add( blockState );
+ }
+ };
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;
+ private int tickPosition;
+
+ public CraftWorld getWorld() {
+ return this.world;
+ }
+
+ public CraftServer getServer() {
+ return (CraftServer) Bukkit.getServer();
+ }
+
+ public Chunk getChunkIfLoaded(int x, int z) {
2016-05-22 05:57:44 +02:00
+ return ((ChunkProviderServer) this.chunkProvider).getChunkIfLoaded(x, z);
2014-11-25 22:32:16 +01:00
+ }
+
+ protected World(IDataManager idatamanager, WorldData worlddata, WorldProvider worldprovider, MethodProfiler methodprofiler, boolean flag, 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
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
this.u = Lists.newArrayList(new IWorldAccess[] { this.t});
2017-05-14 04:00:00 +02:00
this.N = Calendar.getInstance();
2016-02-29 22:32:46 +01:00
this.scoreboard = new Scoreboard();
2017-07-28 09:23:39 +02:00
@@ -71,6 +131,36 @@
2014-11-25 22:32:16 +01:00
this.worldProvider = worldprovider;
2015-02-26 23:41:06 +01:00
this.isClientSide = flag;
2017-05-14 04:00:00 +02:00
this.P = worldprovider.getWorldBorder();
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
+ this.getServer().addWorld(this.world);
+ // CraftBukkit end
2014-11-25 22:32:16 +01:00
}
public World b() {
2017-07-28 09:23:39 +02:00
@@ -208,6 +298,27 @@
2014-11-25 22:32:16 +01:00
}
public boolean setTypeAndData(BlockPosition blockposition, IBlockData iblockdata, int i) {
+ // CraftBukkit start - tree generation
+ if (this.captureTreeGeneration) {
+ BlockState blockstate = null;
+ Iterator<BlockState> it = capturedBlockStates.iterator();
+ while (it.hasNext()) {
+ BlockState previous = it.next();
+ if (previous.getX() == blockposition.getX() && previous.getY() == blockposition.getY() && previous.getZ() == blockposition.getZ()) {
+ blockstate = previous;
+ it.remove();
+ break;
+ }
+ }
+ if (blockstate == null) {
+ blockstate = org.bukkit.craftbukkit.block.CraftBlockState.getBlockState(this, blockposition.getX(), blockposition.getY(), blockposition.getZ(), i);
+ }
+ blockstate.setTypeId(CraftMagicNumbers.getId(iblockdata.getBlock()));
+ blockstate.setRawData((byte) iblockdata.getBlock().toLegacyData(iblockdata));
+ this.capturedBlockStates.add(blockstate);
+ return true;
+ }
+ // CraftBukkit end
2016-05-10 13:47:39 +02:00
if (this.E(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) {
2017-07-28 09:23:39 +02:00
@@ -215,9 +326,23 @@
2014-11-25 22:32:16 +01:00
} else {
Chunk chunk = this.getChunkAtWorldCoords(blockposition);
Block block = iblockdata.getBlock();
2015-02-26 23:41:06 +01:00
+
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - capture blockstates
+ BlockState blockstate = null;
+ if (this.captureBlockStates) {
+ blockstate = org.bukkit.craftbukkit.block.CraftBlockState.getBlockState(this, blockposition.getX(), blockposition.getY(), blockposition.getZ(), i);
+ this.capturedBlockStates.add(blockstate);
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
2014-11-25 22:32:16 +01:00
IBlockData iblockdata1 = chunk.a(blockposition, iblockdata);
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 {
2016-02-29 22:32:46 +01:00
if (iblockdata.c() != iblockdata1.c() || iblockdata.d() != iblockdata1.d()) {
2017-07-28 09:23:39 +02:00
@@ -226,6 +351,7 @@
2014-11-25 22:32:16 +01:00
this.methodProfiler.b();
}
+ /*
2015-02-26 23:41:06 +01:00
if ((i & 2) != 0 && (!this.isClientSide || (i & 4) == 0) && chunk.isReady()) {
2016-02-29 22:32:46 +01:00
this.notify(blockposition, iblockdata1, iblockdata, i);
2014-11-25 22:32:16 +01:00
}
2017-07-28 09:23:39 +02:00
@@ -238,12 +364,37 @@
2016-11-17 02:41:03 +01:00
} else if (!this.isClientSide && (i & 16) == 0) {
this.c(blockposition, block);
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
2016-02-29 22:32:46 +01:00
+ notifyAndUpdatePhysics(blockposition, chunk, iblockdata1, iblockdata, 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
+ public void notifyAndUpdatePhysics(BlockPosition blockposition, Chunk chunk, IBlockData oldBlock, IBlockData newBlock, int i) {
+ if ((i & 2) != 0 && (!this.isClientSide || (i & 4) == 0) && (chunk == null || chunk.isReady())) { // allow chunk to be null here as chunk.isReady() is false when we send our notification during block placement
+ this.notify(blockposition, oldBlock, newBlock, i);
2014-11-25 22:32:16 +01:00
+ }
+
2016-11-17 02:41:03 +01:00
+ if (!this.isClientSide && (i & 1) != 0) {
+ this.update(blockposition, oldBlock.getBlock(), true);
2017-05-19 13:00:13 +02:00
+ if (newBlock.n()) {
2016-02-29 22:32:46 +01:00
+ this.updateAdjacentComparators(blockposition, newBlock.getBlock());
2014-11-25 22:32:16 +01:00
+ }
2016-11-17 02:41:03 +01:00
+ } else if (!this.isClientSide && (i & 16) == 0) {
+ this.c(blockposition, newBlock.getBlock());
2014-11-25 22:32:16 +01:00
+ }
+ }
+ // CraftBukkit end
+
public boolean setAir(BlockPosition blockposition) {
return this.setTypeAndData(blockposition, Blocks.AIR.getBlockData(), 3);
}
2017-07-28 09:23:39 +02:00
@@ -277,6 +428,11 @@
2014-11-25 22:32:16 +01:00
2016-11-17 02:41:03 +01:00
public void update(BlockPosition blockposition, Block block, boolean flag) {
2014-11-25 22:32:16 +01:00
if (this.worldData.getType() != WorldType.DEBUG_ALL_BLOCK_STATES) {
+ // CraftBukkit start
+ if (populating) {
+ return;
+ }
+ // CraftBukkit end
2016-11-17 02:41:03 +01:00
this.applyPhysics(blockposition, block, flag);
2014-11-25 22:32:16 +01:00
}
2017-07-28 09:23:39 +02:00
@@ -365,6 +521,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) {
+ BlockPhysicsEvent event = new BlockPhysicsEvent(world.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()), CraftMagicNumbers.getId(block));
+ this.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+ }
+ // CraftBukkit end
2016-11-17 02:41:03 +01:00
iblockdata.doPhysics(this, blockposition, block, blockposition1);
2014-11-25 22:32:16 +01:00
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Exception while updating neighbours");
2017-07-28 09:23:39 +02:00
@@ -582,6 +749,17 @@
2014-11-25 22:32:16 +01:00
}
public IBlockData getType(BlockPosition blockposition) {
+ // CraftBukkit start - tree generation
+ if (captureTreeGeneration) {
+ Iterator<BlockState> it = capturedBlockStates.iterator();
+ while (it.hasNext()) {
+ BlockState previous = it.next();
+ if (previous.getX() == blockposition.getX() && previous.getY() == blockposition.getY() && previous.getZ() == blockposition.getZ()) {
+ return CraftMagicNumbers.getBlock(previous.getTypeId()).fromLegacyData(previous.getRawData());
+ }
+ }
+ }
+ // CraftBukkit end
2016-05-10 13:47:39 +02:00
if (this.E(blockposition)) {
2014-11-25 22:32:16 +01:00
return Blocks.AIR.getBlockData();
} else {
2017-07-28 09:23:39 +02:00
@@ -787,6 +965,13 @@
2014-11-25 22:32:16 +01:00
}
public boolean addEntity(Entity entity) {
+ // CraftBukkit start - Used for entities other than creatures
+ return addEntity(entity, SpawnReason.DEFAULT);
+ }
+
+ public boolean addEntity(Entity entity, SpawnReason spawnReason) { // Changed signature, added SpawnReason
+ if (entity == null) return false;
+ // CraftBukkit end
int i = MathHelper.floor(entity.locX / 16.0D);
int j = MathHelper.floor(entity.locZ / 16.0D);
boolean flag = entity.attachedToPlayer;
2017-07-28 09:23:39 +02:00
@@ -795,6 +980,37 @@
2014-11-25 22:32:16 +01:00
flag = true;
}
+ // CraftBukkit start
+ org.bukkit.event.Cancellable event = null;
+ if (entity instanceof EntityLiving && !(entity instanceof EntityPlayer)) {
+ boolean isAnimal = entity instanceof EntityAnimal || entity instanceof EntityWaterAnimal || entity instanceof EntityGolem;
+ boolean isMonster = entity instanceof EntityMonster || entity instanceof EntityGhast || entity instanceof EntitySlime;
2016-12-17 04:26:09 +01:00
+ boolean isNpc = entity instanceof NPC;
2014-11-25 22:32:16 +01:00
+
+ if (spawnReason != SpawnReason.CUSTOM) {
2016-12-17 04:26:09 +01:00
+ if (isAnimal && !allowAnimals || isMonster && !allowMonsters || isNpc && !getServer().getServer().getSpawnNPCs()) {
2014-11-25 22:32:16 +01:00
+ entity.dead = true;
+ return false;
+ }
+ }
+
+ event = CraftEventFactory.callCreatureSpawnEvent((EntityLiving) entity, spawnReason);
+ } else if (entity instanceof EntityItem) {
+ event = CraftEventFactory.callItemSpawnEvent((EntityItem) entity);
+ } else if (entity.getBukkitEntity() instanceof org.bukkit.entity.Projectile) {
+ // Not all projectiles extend EntityProjectile, so check for Bukkit interface instead
+ event = CraftEventFactory.callProjectileLaunchEvent(entity);
2017-03-15 10:48:47 +01:00
+ } else if (entity.getBukkitEntity() instanceof org.bukkit.entity.Vehicle){
+ event = CraftEventFactory.callVehicleCreateEvent(entity);
2014-11-25 22:32:16 +01:00
+ }
+
+ if (event != null && (event.isCancelled() || entity.dead)) {
+ entity.dead = true;
+ return false;
+ }
+ // CraftBukkit end
+
2016-02-29 22:32:46 +01:00
+
if (!flag && !this.isChunkLoaded(i, j, false)) {
2014-11-25 22:32:16 +01:00
return false;
} else {
2017-07-28 09:23:39 +02:00
@@ -817,6 +1033,7 @@
2014-11-25 22:32:16 +01:00
((IWorldAccess) this.u.get(i)).a(entity);
}
+ entity.valid = true; // CraftBukkit
}
2016-02-29 22:32:46 +01:00
protected void c(Entity entity) {
2017-07-28 09:23:39 +02:00
@@ -824,6 +1041,7 @@
2016-03-29 02:19:29 +02:00
((IWorldAccess) this.u.get(i)).b(entity);
}
+ entity.valid = false; // CraftBukkit
}
public void kill(Entity entity) {
2017-07-28 09:23:39 +02:00
@@ -859,7 +1077,15 @@
2014-11-25 22:32:16 +01:00
this.getChunkAt(i, j).b(entity);
}
- this.entityList.remove(entity);
+ // CraftBukkit start - Decrement loop variable field if we've already ticked this entity
+ int index = this.entityList.indexOf(entity);
+ if (index != -1) {
+ if (index <= this.tickPosition) {
+ this.tickPosition--;
+ }
+ this.entityList.remove(index);
+ }
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
this.c(entity);
2014-11-25 22:32:16 +01:00
}
2017-07-28 09:23:39 +02:00
@@ -976,7 +1202,7 @@
2016-12-20 21:00:00 +01:00
}
public boolean a(AxisAlignedBB axisalignedbb) {
- return this.a((Entity) null, axisalignedbb, true, Lists.newArrayList());
+ return this.a((Entity) null, axisalignedbb, true, Lists.<AxisAlignedBB>newArrayList()); // CraftBukkit - decompile error
}
public int a(float f) {
2017-07-28 09:23:39 +02:00
@@ -1046,6 +1272,11 @@
2014-11-25 22:32:16 +01:00
2016-02-29 22:32:46 +01:00
for (i = 0; i < this.j.size(); ++i) {
entity = (Entity) this.j.get(i);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - Fixed an NPE
+ if (entity == null) {
+ continue;
+ }
+ // CraftBukkit end
try {
++entity.ticksLived;
2017-07-28 09:23:39 +02:00
@@ -1094,8 +1325,10 @@
2016-02-29 22:32:46 +01:00
CrashReportSystemDetails crashreportsystemdetails1;
CrashReport crashreport1;
2014-11-25 22:32:16 +01:00
- for (i = 0; i < this.entityList.size(); ++i) {
- entity = (Entity) this.entityList.get(i);
+ // CraftBukkit start - Use field for loop variable
+ for (this.tickPosition = 0; this.tickPosition < this.entityList.size(); ++this.tickPosition) {
+ entity = (Entity) this.entityList.get(this.tickPosition);
+ // CraftBukkit end
2017-06-08 10:00:00 +02:00
Entity entity1 = entity.bJ();
2016-02-29 22:32:46 +01:00
if (entity1 != null) {
2017-07-28 09:23:39 +02:00
@@ -1128,7 +1361,7 @@
2016-02-29 22:32:46 +01:00
this.getChunkAt(j, l).b(entity);
2014-11-25 22:32:16 +01:00
}
- this.entityList.remove(i--);
+ this.entityList.remove(this.tickPosition--); // CraftBukkit - Use field for loop variable
2016-02-29 22:32:46 +01:00
this.c(entity);
2014-11-25 22:32:16 +01:00
}
2017-07-28 09:23:39 +02:00
@@ -1137,6 +1370,13 @@
2014-11-25 22:32:16 +01:00
this.methodProfiler.c("blockEntities");
2017-05-14 04:00:00 +02:00
this.O = true;
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - From below, clean up tile entities before ticking them
2016-02-29 22:32:46 +01:00
+ if (!this.tileEntityListUnload.isEmpty()) {
+ this.tileEntityListTick.removeAll(this.tileEntityListUnload);
+ this.tileEntityList.removeAll(this.tileEntityListUnload);
+ this.tileEntityListUnload.clear();
2014-11-25 22:32:16 +01:00
+ }
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
Iterator iterator = this.tileEntityListTick.iterator();
2014-11-25 22:32:16 +01:00
while (iterator.hasNext()) {
2017-07-28 09:23:39 +02:00
@@ -1147,7 +1387,7 @@
2016-03-12 10:43:04 +01:00
2017-05-14 04:00:00 +02:00
if (this.isLoaded(blockposition) && this.P.a(blockposition)) {
2016-03-12 10:43:04 +01:00
try {
- this.methodProfiler.a(tileentity.getClass().getSimpleName());
2017-01-19 02:42:35 +01:00
+ this.methodProfiler.a("ticking"/*tileentity.getClass().getSimpleName()*/); // CraftBukkit: SPIGOT-1900
2017-05-14 04:00:00 +02:00
((ITickable) tileentity).e();
2016-03-12 10:43:04 +01:00
this.methodProfiler.b();
} catch (Throwable throwable2) {
2017-07-28 09:23:39 +02:00
@@ -1169,11 +1409,13 @@
2014-11-25 22:32:16 +01:00
}
2017-05-14 04:00:00 +02:00
this.O = false;
2014-11-25 22:32:16 +01:00
+ /* CraftBukkit start - Moved up
2016-02-29 22:32:46 +01:00
if (!this.tileEntityListUnload.isEmpty()) {
this.tileEntityListTick.removeAll(this.tileEntityListUnload);
this.tileEntityList.removeAll(this.tileEntityListUnload);
this.tileEntityListUnload.clear();
2014-11-25 22:32:16 +01:00
}
2015-02-26 23:41:06 +01:00
+ // CraftBukkit end */
2014-11-25 22:32:16 +01:00
this.methodProfiler.c("pendingBlockEntities");
2015-02-26 23:41:06 +01:00
if (!this.b.isEmpty()) {
2017-07-28 09:23:39 +02:00
@@ -1181,9 +1423,11 @@
2016-02-29 22:32:46 +01:00
TileEntity tileentity1 = (TileEntity) this.b.get(i1);
2014-11-25 22:32:16 +01:00
2016-11-17 02:41:03 +01:00
if (!tileentity1.y()) {
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());
2017-07-28 09:23:39 +02:00
@@ -1191,6 +1435,12 @@
2016-03-25 04:04:27 +01:00
chunk.a(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
}
}
}
2017-07-28 09:23:39 +02:00
@@ -1244,15 +1494,13 @@
2017-05-30 13:25:59 +02:00
int i;
int j;
- if (!(entity instanceof EntityHuman)) {
- i = MathHelper.floor(entity.locX);
- j = MathHelper.floor(entity.locZ);
- boolean flag1 = true;
-
- if (flag && !this.isAreaLoaded(i - 32, 0, j - 32, i + 32, 0, j + 32, true)) {
- return;
- }
2017-05-20 03:27:48 +02:00
+ // CraftBukkit start - check if chunks are loaded as done in previous versions
2017-05-30 13:25:59 +02:00
+ // TODO: Go back to Vanilla behaviour when comfortable
2017-05-20 03:27:48 +02:00
+ Chunk startingChunk = this.getChunkIfLoaded(MathHelper.floor(entity.locX) >> 4, MathHelper.floor(entity.locZ) >> 4);
+ if (flag && !(startingChunk != null && startingChunk.areNeighborsLoaded(2))) {
+ return;
2017-05-30 13:25:59 +02:00
}
2017-05-20 03:27:48 +02:00
+ // CraftBukkit end
2017-05-30 13:25:59 +02:00
2017-05-20 03:27:48 +02:00
entity.M = entity.locX;
entity.N = entity.locY;
2017-07-28 09:23:39 +02:00
@@ -1265,6 +1513,7 @@
2017-06-08 10:00:00 +02:00
entity.aE();
2017-05-19 13:00:13 +02:00
} else {
entity.B_();
+ entity.postTick(); // CraftBukkit
2017-03-20 05:41:15 +01:00
}
2017-05-19 13:00:13 +02:00
}
2017-03-20 05:41:15 +01:00
2017-07-28 09:23:39 +02:00
@@ -1556,11 +1805,18 @@
2015-03-16 10:48:01 +01:00
}
}
+ public Map<BlockPosition, TileEntity> capturedTileEntities = Maps.newHashMap();
2016-05-10 13:47:39 +02:00
@Nullable
2015-03-16 10:48:01 +01:00
public TileEntity getTileEntity(BlockPosition blockposition) {
2016-05-10 13:47:39 +02:00
if (this.E(blockposition)) {
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;
2017-05-14 04:00:00 +02:00
if (this.O) {
2017-07-28 09:23:39 +02:00
@@ -1595,6 +1851,14 @@
2016-05-10 13:47:39 +02:00
public void setTileEntity(BlockPosition blockposition, @Nullable TileEntity tileentity) {
if (!this.E(blockposition)) {
2016-11-17 02:41:03 +01:00
if (tileentity != null && !tileentity.y()) {
2015-03-16 10:48:01 +01:00
+ // CraftBukkit start
+ if (captureBlockStates) {
2015-03-16 16:55:10 +01:00
+ tileentity.a(this);
2016-06-09 03:43:49 +02:00
+ tileentity.setPosition(blockposition);
2015-03-16 10:48:01 +01:00
+ capturedTileEntities.put(blockposition, tileentity);
+ return;
+ }
+ // CraftBukkit end
2017-05-14 04:00:00 +02:00
if (this.O) {
2016-06-09 03:43:49 +02:00
tileentity.setPosition(blockposition);
2016-05-10 13:47:39 +02:00
Iterator iterator = this.b.iterator();
2017-07-28 09:23:39 +02:00
@@ -1754,6 +2018,14 @@
2014-12-02 16:13:07 +01:00
}
2016-02-29 22:32:46 +01:00
this.o = MathHelper.a(this.o, 0.0F, 1.0F);
2015-02-26 23:41:06 +01:00
+
+ // CraftBukkit start
2014-12-02 16:13:07 +01:00
+ for (int idx = 0; idx < this.players.size(); ++idx) {
+ if (((EntityPlayer) this.players.get(idx)).world == this) {
+ ((EntityPlayer) this.players.get(idx)).tickWeather();
+ }
+ }
2015-02-26 23:41:06 +01:00
+ // CraftBukkit end
2014-12-02 16:13:07 +01:00
}
}
2014-11-25 22:32:16 +01:00
}
2017-07-28 09:23:39 +02:00
@@ -1891,7 +2163,10 @@
2014-11-25 22:32:16 +01:00
}
public boolean c(EnumSkyBlock enumskyblock, BlockPosition blockposition) {
- if (!this.areChunksLoaded(blockposition, 17, false)) {
+ // CraftBukkit start - Use neighbor cache instead of looking up
+ Chunk chunk = this.getChunkIfLoaded(blockposition.getX() >> 4, blockposition.getZ() >> 4);
+ if (chunk == null || !chunk.areNeighborsLoaded(1) /*!this.areChunksLoaded(blockposition, 17, false)*/) {
+ // CraftBukkit end
return false;
} else {
int i = 0;
2017-07-28 09:23:39 +02:00
@@ -2058,7 +2333,7 @@
2015-02-26 23:41:06 +01:00
while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next();
2014-11-25 22:32:16 +01:00
2015-02-26 23:41:06 +01:00
- if (oclass.isAssignableFrom(entity.getClass()) && predicate.apply(entity)) {
2016-02-29 22:32:46 +01:00
+ if (oclass.isAssignableFrom(entity.getClass()) && predicate.apply((T) entity)) {
2015-02-26 23:41:06 +01:00
arraylist.add(entity);
}
}
2017-07-28 09:23:39 +02:00
@@ -2073,7 +2348,7 @@
2014-11-25 22:32:16 +01:00
while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next();
2015-02-26 23:41:06 +01:00
- if (oclass.isAssignableFrom(entity.getClass()) && predicate.apply(entity)) {
+ if (oclass.isAssignableFrom(entity.getClass()) && predicate.apply((T) entity)) { // CraftBukkit - fix decompile error
arraylist.add(entity);
}
}
2017-07-28 09:23:39 +02:00
@@ -2122,7 +2397,7 @@
2015-02-26 23:41:06 +01:00
}
}
- return entity;
+ return (T) entity; // CraftBukkit fix decompile error
}
2016-05-10 13:47:39 +02:00
@Nullable
2017-07-28 09:23:39 +02:00
@@ -2143,8 +2418,17 @@
2015-02-26 23:41:06 +01:00
while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next();
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - Split out persistent check, don't apply it to special persistent mobs
+ if (entity instanceof EntityInsentient) {
+ EntityInsentient entityinsentient = (EntityInsentient) entity;
+ if (entityinsentient.isTypeNotPersistent() && entityinsentient.isPersistent()) {
+ continue;
+ }
+ }
2017-05-14 04:00:00 +02:00
- if ((!(entity instanceof EntityInsentient) || !((EntityInsentient) entity).isPersistent()) && oclass.isAssignableFrom(entity.getClass())) {
2014-11-25 22:32:16 +01:00
+ if (oclass.isAssignableFrom(entity.getClass())) {
+ // if ((!(entity instanceof EntityInsentient) || !((EntityInsentient) entity).isPersistent()) && oclass.isAssignableFrom(entity.getClass())) {
+ // CraftBukkit end
++i;
}
}
2017-07-28 09:23:39 +02:00
@@ -2153,12 +2437,18 @@
2014-11-25 22:32:16 +01:00
}
2016-02-29 22:32:46 +01:00
public void a(Collection<Entity> collection) {
2014-11-25 22:32:16 +01:00
- this.entityList.addAll(collection);
+ // CraftBukkit start
+ // this.entityList.addAll(collection);
Iterator iterator = collection.iterator();
while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next();
2015-02-26 23:41:06 +01:00
2014-11-25 22:32:16 +01:00
+ if (entity == null) {
+ continue;
+ }
+ this.entityList.add(entity);
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
this.b(entity);
2014-11-25 22:32:16 +01:00
}
2017-07-28 09:23:39 +02:00
@@ -2172,7 +2462,13 @@
2016-02-29 22:32:46 +01:00
IBlockData iblockdata = this.getType(blockposition);
2017-05-19 13:00:13 +02:00
AxisAlignedBB axisalignedbb = flag ? null : block.getBlockData().d(this, blockposition);
2014-11-25 22:32:16 +01:00
2016-11-17 02:41:03 +01:00
- return axisalignedbb != Block.k && !this.a(axisalignedbb.a(blockposition), entity) ? false : (iblockdata.getMaterial() == Material.ORIENTABLE && block == Blocks.ANVIL ? true : iblockdata.getMaterial().isReplaceable() && block.canPlace(this, blockposition, enumdirection));
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - store default return
2016-11-17 02:41:03 +01:00
+ boolean defaultReturn = axisalignedbb != Block.k && !this.a(axisalignedbb.a(blockposition), entity) ? false : (iblockdata.getMaterial() == Material.ORIENTABLE && block == Blocks.ANVIL ? true : iblockdata.getMaterial().isReplaceable() && block.canPlace(this, blockposition, enumdirection));
2014-11-25 22:32:16 +01:00
+ BlockCanBuildEvent event = new BlockCanBuildEvent(this.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()), CraftMagicNumbers.getId(block), defaultReturn);
+ this.getServer().getPluginManager().callEvent(event);
+
+ return event.isBuildable();
+ // CraftBukkit end
}
2017-05-14 04:00:00 +02:00
public int getSeaLevel() {
2017-07-28 09:23:39 +02:00
@@ -2282,6 +2578,11 @@
2014-11-25 22:32:16 +01:00
for (int i = 0; i < this.players.size(); ++i) {
EntityHuman entityhuman1 = (EntityHuman) this.players.get(i);
+ // CraftBukkit start - Fixed an NPE
+ if (entityhuman1 == null || entityhuman1.dead) {
+ continue;
+ }
+ // CraftBukkit end
2016-11-17 02:41:03 +01:00
if (predicate.apply(entityhuman1)) {
double d5 = entityhuman1.d(d0, d1, d2);
2017-07-28 09:23:39 +02:00
@@ -2450,6 +2751,16 @@
2014-11-25 22:32:16 +01:00
public void everyoneSleeping() {}
+ // CraftBukkit start
+ // Calls the method that checks to see if players are sleeping
+ // Called by CraftPlayer.setPermanentSleeping()
+ public void checkSleepStatus() {
2015-02-26 23:41:06 +01:00
+ if (!this.isClientSide) {
2014-11-25 22:32:16 +01:00
+ this.everyoneSleeping();
+ }
+ }
+ // CraftBukkit end
+
public float h(float f) {
2016-02-29 22:32:46 +01:00
return (this.p + (this.q - this.p) * f) * this.j(f);
2014-11-25 22:32:16 +01:00
}
2017-07-28 09:23:39 +02:00
@@ -2667,7 +2978,7 @@
2014-11-25 22:32:16 +01:00
int l = j * 16 + 8 - blockposition.getZ();
2016-06-09 03:43:49 +02:00
boolean flag = true;
2014-11-25 22:32:16 +01:00
2016-06-09 03:43:49 +02:00
- return k >= -128 && k <= 128 && l >= -128 && l <= 128;
+ return k >= -128 && k <= 128 && l >= -128 && l <= 128 && this.keepSpawnInMemory; // CraftBukkit - Added 'this.keepSpawnInMemory'
2014-11-25 22:32:16 +01:00
}
2016-02-29 22:32:46 +01:00
public void a(Packet<?> packet) {