SPIGOT-4900: Rearchitect multiworld support for better compat with new villager AI

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2019-05-12 11:15:48 +10:00
parent 8b207fdf78
commit b407bebd8d
22 changed files with 208 additions and 227 deletions

View File

@@ -22,13 +22,12 @@
public class WorldServer extends World {
private static final Logger LOGGER = LogManager.getLogger();
@@ -56,12 +71,31 @@
@@ -56,12 +71,29 @@
@Nullable
private final MobSpawnerTrader mobSpawnerTrader;
- public WorldServer(MinecraftServer minecraftserver, Executor executor, WorldNBTStorage worldnbtstorage, WorldData worlddata, DimensionManager dimensionmanager, GameProfilerFiller gameprofilerfiller, WorldLoadListener worldloadlistener) {
+ // CraftBukkit start
+ public final DimensionManager dimension;
+ private int tickPosition;
+
+ // Add env and gen to constructor
@@ -50,22 +49,23 @@
- }, gameprofilerfiller, false);
+ // CraftBukkit end
+ }, gameprofilerfiller, false, gen, env);
+ this.dimension = dimensionmanager;
+ this.pvpMode = minecraftserver.getPVP();
+ worlddata.world = this;
+ // CraftBukkit end
this.nextTickListBlock = new TickListServer<>(this, (block) -> {
return block == null || block.getBlockData().isAir();
}, IRegistry.BLOCK::getKey, IRegistry.BLOCK::get, this::b);
@@ -85,6 +119,7 @@
@@ -84,7 +116,8 @@
this.getWorldData().setGameType(minecraftserver.getGamemode());
}
this.mobSpawnerTrader = this.worldProvider.getDimensionManager() == DimensionManager.OVERWORLD ? new MobSpawnerTrader(this) : null;
- this.mobSpawnerTrader = this.worldProvider.getDimensionManager() == DimensionManager.OVERWORLD ? new MobSpawnerTrader(this) : null;
+ this.mobSpawnerTrader = this.worldProvider.getDimensionManager().getType() == DimensionManager.OVERWORLD ? new MobSpawnerTrader(this) : null; // CraftBukkit - getType()
+ this.getServer().addWorld(this.getWorld()); // CraftBukkit
}
public void doTick(BooleanSupplier booleansupplier) {
@@ -161,6 +196,7 @@
@@ -161,6 +194,7 @@
this.m = MathHelper.a(this.m, 0.0F, 1.0F);
}
@@ -73,7 +73,7 @@
if (this.l != this.m) {
this.server.getPlayerList().a((Packet) (new PacketPlayOutGameStateChange(7, this.m)), this.worldProvider.getDimensionManager());
}
@@ -179,13 +215,34 @@
@@ -179,13 +213,34 @@
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(7, this.m));
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(8, this.o));
}
@@ -109,7 +109,7 @@
})) {
this.D = false;
if (this.getGameRules().getBoolean("doDaylightCycle")) {
@@ -226,7 +283,7 @@
@@ -226,7 +281,7 @@
this.ae();
this.ticking = false;
gameprofilerfiller.exitEnter("entities");
@@ -118,7 +118,7 @@
if (flag3) {
this.resetEmptyTime();
@@ -240,6 +297,11 @@
@@ -240,6 +295,11 @@
for (i = 0; i < this.globalEntityList.size(); ++i) {
entity = (Entity) this.globalEntityList.get(i);
@@ -130,7 +130,7 @@
this.a((entity1) -> {
++entity1.ticksLived;
entity1.tick();
@@ -258,6 +320,7 @@
@@ -258,6 +318,7 @@
Entity entity1 = (Entity) entry.getValue();
Entity entity2 = entity1.getVehicle();
@@ -138,7 +138,7 @@
if (!this.server.getSpawnAnimals() && (entity1 instanceof EntityAnimal || entity1 instanceof EntityWaterAnimal)) {
entity1.die();
}
@@ -265,6 +328,7 @@
@@ -265,6 +326,7 @@
if (!this.server.getSpawnNPCs() && entity1 instanceof NPC) {
entity1.die();
}
@@ -146,7 +146,7 @@
if (entity2 != null) {
if (!entity2.dead && entity2.w(entity1)) {
@@ -325,10 +389,10 @@
@@ -325,10 +387,10 @@
entityhorseskeleton.r(true);
entityhorseskeleton.setAgeRaw(0);
entityhorseskeleton.setPosition((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ());
@@ -159,7 +159,7 @@
}
}
@@ -339,11 +403,11 @@
@@ -339,11 +401,11 @@
BiomeBase biomebase = this.getBiome(blockposition);
if (biomebase.a((IWorldReader) this, blockposition1)) {
@@ -173,7 +173,7 @@
}
if (flag && this.getBiome(blockposition1).b() == BiomeBase.Precipitation.RAIN) {
@@ -390,7 +454,7 @@
@@ -390,7 +452,7 @@
protected BlockPosition a(BlockPosition blockposition) {
BlockPosition blockposition1 = this.getHighestBlockYAt(HeightMap.Type.MOTION_BLOCKING, blockposition);
AxisAlignedBB axisalignedbb = (new AxisAlignedBB(blockposition1, new BlockPosition(blockposition1.getX(), this.getHeight(), blockposition1.getZ()))).g(3.0D);
@@ -182,7 +182,7 @@
return entityliving != null && entityliving.isAlive() && this.f(entityliving.getChunkCoordinates());
});
@@ -419,7 +483,7 @@
@@ -419,7 +481,7 @@
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
@@ -191,7 +191,7 @@
++i;
} else if (entityplayer.isSleeping()) {
++j;
@@ -437,10 +501,22 @@
@@ -437,10 +499,22 @@
}
private void clearWeather() {
@@ -216,7 +216,7 @@
}
public void resetEmptyTime() {
@@ -478,6 +554,7 @@
@@ -478,6 +552,7 @@
return IRegistry.ENTITY_TYPE.getKey(entity.getEntityType()).toString();
});
entity.tick();
@@ -224,7 +224,7 @@
this.getMethodProfiler().exit();
}
@@ -563,6 +640,22 @@
@@ -563,6 +638,22 @@
BlockPosition blockposition = worldchunkmanager.a(0, 0, 256, list, random);
ChunkCoordIntPair chunkcoordintpair = blockposition == null ? new ChunkCoordIntPair(0, 0) : new ChunkCoordIntPair(blockposition);
@@ -247,7 +247,7 @@
if (blockposition == null) {
WorldServer.LOGGER.warn("Unable to find spawn biome");
}
@@ -638,6 +731,7 @@
@@ -638,6 +729,7 @@
ChunkProviderServer chunkproviderserver = this.getChunkProvider();
if (!flag1) {
@@ -255,7 +255,7 @@
if (iprogressupdate != null) {
iprogressupdate.a(new ChatMessage("menu.savingLevel", new Object[0]));
}
@@ -716,8 +810,16 @@
@@ -716,8 +808,16 @@
while (objectiterator.hasNext()) {
Entity entity = (Entity) objectiterator.next();
@@ -273,7 +273,7 @@
EnumCreatureType enumcreaturetype = entity.getEntityType().d();
if (enumcreaturetype != EnumCreatureType.MISC) {
@@ -733,11 +835,24 @@
@@ -733,11 +833,24 @@
@Override
public boolean addEntity(Entity entity) {
@@ -300,7 +300,7 @@
}
public void addEntityTeleport(Entity entity) {
@@ -787,13 +902,18 @@
@@ -787,13 +900,18 @@
this.registerEntity(entityplayer);
}
@@ -321,7 +321,7 @@
IChunkAccess ichunkaccess = this.getChunkAt(MathHelper.floor(entity.locX / 16.0D), MathHelper.floor(entity.locZ / 16.0D), ChunkStatus.FULL, entity.attachedToPlayer);
if (!(ichunkaccess instanceof Chunk)) {
@@ -821,7 +941,7 @@
@@ -821,7 +939,7 @@
if (entity1 == null) {
return false;
} else {
@@ -330,7 +330,7 @@
return true;
}
}
@@ -876,6 +996,7 @@
@@ -876,6 +994,7 @@
this.I.remove(((EntityInsentient) entity).getNavigation());
}
@@ -338,7 +338,7 @@
}
private void registerEntity(Entity entity) {
@@ -899,6 +1020,7 @@
@@ -899,6 +1018,7 @@
if (entity instanceof EntityInsentient) {
this.I.add(((EntityInsentient) entity).getNavigation());
}
@@ -346,7 +346,7 @@
}
}
@@ -929,6 +1051,18 @@
@@ -929,6 +1049,18 @@
}
public void strikeLightning(EntityLightning entitylightning) {
@@ -365,7 +365,7 @@
this.globalEntityList.add(entitylightning);
this.server.getPlayerList().sendPacketNearby((EntityHuman) null, entitylightning.locX, entitylightning.locY, entitylightning.locZ, 512.0D, this.worldProvider.getDimensionManager(), new PacketPlayOutSpawnEntityWeather(entitylightning));
}
@@ -937,6 +1071,12 @@
@@ -937,6 +1069,12 @@
public void a(int i, BlockPosition blockposition, int j) {
Iterator iterator = this.server.getPlayerList().getPlayers().iterator();
@@ -378,7 +378,7 @@
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
@@ -945,6 +1085,12 @@
@@ -945,6 +1083,12 @@
double d1 = (double) blockposition.getY() - entityplayer.locY;
double d2 = (double) blockposition.getZ() - entityplayer.locZ;
@@ -391,34 +391,7 @@
if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) {
entityplayer.playerConnection.sendPacket(new PacketPlayOutBlockBreakAnimation(i, blockposition, j));
}
@@ -955,12 +1101,14 @@
@Override
public void a(@Nullable EntityHuman entityhuman, double d0, double d1, double d2, SoundEffect soundeffect, SoundCategory soundcategory, float f, float f1) {
- this.server.getPlayerList().sendPacketNearby(entityhuman, d0, d1, d2, f > 1.0F ? (double) (16.0F * f) : 16.0D, this.worldProvider.getDimensionManager(), new PacketPlayOutNamedSoundEffect(soundeffect, soundcategory, d0, d1, d2, f, f1));
+ // CraftBukkit - this.dimension
+ this.server.getPlayerList().sendPacketNearby(entityhuman, d0, d1, d2, f > 1.0F ? (double) (16.0F * f) : 16.0D, this.dimension, new PacketPlayOutNamedSoundEffect(soundeffect, soundcategory, d0, d1, d2, f, f1));
}
@Override
public void a(@Nullable EntityHuman entityhuman, Entity entity, SoundEffect soundeffect, SoundCategory soundcategory, float f, float f1) {
- this.server.getPlayerList().sendPacketNearby(entityhuman, entity.locX, entity.locY, entity.locZ, f > 1.0F ? (double) (16.0F * f) : 16.0D, this.worldProvider.getDimensionManager(), new PacketPlayOutEntitySound(soundeffect, soundcategory, entity, f, f1));
+ // CraftBukkit - this.dimension
+ this.server.getPlayerList().sendPacketNearby(entityhuman, entity.locX, entity.locY, entity.locZ, f > 1.0F ? (double) (16.0F * f) : 16.0D, this.dimension, new PacketPlayOutEntitySound(soundeffect, soundcategory, entity, f, f1));
}
@Override
@@ -970,7 +1118,8 @@
@Override
public void a(@Nullable EntityHuman entityhuman, int i, BlockPosition blockposition, int j) {
- this.server.getPlayerList().sendPacketNearby(entityhuman, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), 64.0D, this.worldProvider.getDimensionManager(), new PacketPlayOutWorldEvent(i, blockposition, j, false));
+ // CraftBukkit - this.dimension
+ this.server.getPlayerList().sendPacketNearby(entityhuman, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), 64.0D, this.dimension, new PacketPlayOutWorldEvent(i, blockposition, j, false));
}
@Override
@@ -1005,6 +1154,14 @@
@@ -1005,6 +1149,14 @@
@Override
public Explosion createExplosion(@Nullable Entity entity, DamageSource damagesource, double d0, double d1, double d2, float f, boolean flag, Explosion.Effect explosion_effect) {
@@ -433,7 +406,7 @@
Explosion explosion = new Explosion(this, entity, d0, d1, d2, f, flag, explosion_effect);
if (damagesource != null) {
@@ -1013,6 +1170,8 @@
@@ -1013,6 +1165,8 @@
explosion.a();
explosion.a(false);
@@ -442,17 +415,7 @@
if (explosion_effect == Explosion.Effect.NONE) {
explosion.clearBlocks();
}
@@ -1040,7 +1199,8 @@
BlockActionData blockactiondata = (BlockActionData) this.J.removeFirst();
if (this.a(blockactiondata)) {
- this.server.getPlayerList().sendPacketNearby((EntityHuman) null, (double) blockactiondata.a().getX(), (double) blockactiondata.a().getY(), (double) blockactiondata.a().getZ(), 64.0D, this.worldProvider.getDimensionManager(), new PacketPlayOutBlockAction(blockactiondata.a(), blockactiondata.b(), blockactiondata.c(), blockactiondata.d()));
+ // CraftBukkit - this.worldProvider.dimension -> this.dimension
+ this.server.getPlayerList().sendPacketNearby((EntityHuman) null, (double) blockactiondata.a().getX(), (double) blockactiondata.a().getY(), (double) blockactiondata.a().getZ(), 64.0D, dimension, new PacketPlayOutBlockAction(blockactiondata.a(), blockactiondata.b(), blockactiondata.c(), blockactiondata.d()));
}
}
@@ -1083,13 +1243,20 @@
@@ -1083,13 +1237,20 @@
}
public <T extends ParticleParam> int a(T t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6) {
@@ -475,7 +438,7 @@
++j;
}
}
@@ -1172,7 +1339,13 @@
@@ -1172,7 +1333,13 @@
@Override
public WorldMap a(String s) {
return (WorldMap) this.getMinecraftServer().getWorldServer(DimensionManager.OVERWORLD).getWorldPersistentData().b(() -> {