0
0
mirror of https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git synced 2024-11-24 19:16:15 +00:00
craftbukkit/nms-patches/net/minecraft/server/level/WorldServer.patch
2024-10-23 02:15:00 +11:00

619 lines
30 KiB
Diff

--- a/net/minecraft/server/level/WorldServer.java
+++ b/net/minecraft/server/level/WorldServer.java
@@ -173,6 +173,23 @@
import net.minecraft.world.ticks.TickListServer;
import org.slf4j.Logger;
+// CraftBukkit start
+import net.minecraft.world.level.biome.WorldChunkManager;
+import net.minecraft.world.level.dimension.WorldDimension;
+import net.minecraft.world.level.levelgen.ChunkGeneratorAbstract;
+import net.minecraft.world.level.levelgen.ChunkProviderFlat;
+import net.minecraft.world.level.storage.WorldDataServer;
+import org.bukkit.Bukkit;
+import org.bukkit.WeatherType;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.generator.CustomWorldChunkManager;
+import org.bukkit.craftbukkit.util.WorldUUID;
+import org.bukkit.event.entity.CreatureSpawnEvent;
+import org.bukkit.event.server.MapInitializeEvent;
+import org.bukkit.event.weather.LightningStrikeEvent;
+import org.bukkit.event.world.TimeSkipEvent;
+// CraftBukkit end
+
public class WorldServer extends World implements ServerEntityGetter, GeneratorAccessSeed {
public static final BlockPosition END_SPAWN_POINT = new BlockPosition(100, 50, 0);
@@ -186,7 +203,7 @@
final List<EntityPlayer> players = Lists.newArrayList();
private final ChunkProviderServer chunkSource;
private final MinecraftServer server;
- public final IWorldDataServer serverLevelData;
+ public final WorldDataServer serverLevelData; // CraftBukkit - type
private int lastSpawnChunkRadius;
final EntityTickList entityTickList = new EntityTickList();
public final PersistentEntitySectionManager<Entity> entityManager;
@@ -213,13 +230,47 @@
private final boolean tickTime;
private final RandomSequences randomSequences;
- public WorldServer(MinecraftServer minecraftserver, Executor executor, Convertable.ConversionSession convertable_conversionsession, IWorldDataServer iworlddataserver, ResourceKey<World> resourcekey, WorldDimension worlddimension, WorldLoadListener worldloadlistener, boolean flag, long i, List<MobSpawner> list, boolean flag1, @Nullable RandomSequences randomsequences) {
- super(iworlddataserver, resourcekey, minecraftserver.registryAccess(), worlddimension.type(), false, flag, i, minecraftserver.getMaxChainedNeighborUpdates());
+ // CraftBukkit start
+ public final Convertable.ConversionSession convertable;
+ public final UUID uuid;
+
+ public Chunk getChunkIfLoaded(int x, int z) {
+ return this.chunkSource.getChunk(x, z, false);
+ }
+
+ @Override
+ public ResourceKey<WorldDimension> getTypeKey() {
+ return convertable.dimensionType;
+ }
+
+ // Add env and gen to constructor, IWorldDataServer -> WorldDataServer
+ public WorldServer(MinecraftServer minecraftserver, Executor executor, Convertable.ConversionSession convertable_conversionsession, WorldDataServer iworlddataserver, ResourceKey<World> resourcekey, WorldDimension worlddimension, WorldLoadListener worldloadlistener, boolean flag, long i, List<MobSpawner> list, boolean flag1, @Nullable RandomSequences randomsequences, org.bukkit.World.Environment env, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider) {
+ super(iworlddataserver, resourcekey, minecraftserver.registryAccess(), worlddimension.type(), false, flag, i, minecraftserver.getMaxChainedNeighborUpdates(), gen, biomeProvider, env);
+ this.pvpMode = minecraftserver.isPvpAllowed();
+ convertable = convertable_conversionsession;
+ uuid = WorldUUID.getUUID(convertable_conversionsession.levelDirectory.path().toFile());
+ // CraftBukkit end
this.tickTime = flag1;
this.server = minecraftserver;
this.customSpawners = list;
this.serverLevelData = iworlddataserver;
ChunkGenerator chunkgenerator = worlddimension.generator();
+ // CraftBukkit start
+ serverLevelData.setWorld(this);
+
+ if (biomeProvider != null) {
+ WorldChunkManager worldChunkManager = new CustomWorldChunkManager(getWorld(), biomeProvider, server.registryAccess().lookupOrThrow(Registries.BIOME));
+ if (chunkgenerator instanceof ChunkGeneratorAbstract cga) {
+ chunkgenerator = new ChunkGeneratorAbstract(worldChunkManager, cga.settings);
+ } else if (chunkgenerator instanceof ChunkProviderFlat cpf) {
+ chunkgenerator = new ChunkProviderFlat(cpf.settings(), worldChunkManager);
+ }
+ }
+
+ if (gen != null) {
+ chunkgenerator = new org.bukkit.craftbukkit.generator.CustomChunkGenerator(this, chunkgenerator, gen);
+ }
+ // CraftBukkit end
boolean flag2 = minecraftserver.forceSynchronousWrites();
DataFixer datafixer = minecraftserver.getFixerUpper();
EntityPersistentStorage<Entity> entitypersistentstorage = new EntityStorage(new SimpleRegionStorage(new RegionStorageInfo(convertable_conversionsession.getLevelId(), resourcekey, "entities"), convertable_conversionsession.getDimensionPath(resourcekey).resolve("entities"), datafixer, flag2, DataFixTypes.ENTITY_CHUNK), this, minecraftserver);
@@ -247,9 +298,9 @@
long l = minecraftserver.getWorldData().worldGenOptions().seed();
this.structureCheck = new StructureCheck(this.chunkSource.chunkScanner(), this.registryAccess(), minecraftserver.getStructureManager(), resourcekey, chunkgenerator, this.chunkSource.randomState(), this, chunkgenerator.getBiomeSource(), l, datafixer);
- this.structureManager = new StructureManager(this, minecraftserver.getWorldData().worldGenOptions(), this.structureCheck);
- if (this.dimension() == World.END && this.dimensionTypeRegistration().is(BuiltinDimensionTypes.END)) {
- this.dragonFight = new EnderDragonBattle(this, l, minecraftserver.getWorldData().endDragonFightData());
+ this.structureManager = new StructureManager(this, this.serverLevelData.worldGenOptions(), structureCheck); // CraftBukkit
+ if ((this.dimension() == World.END && this.dimensionTypeRegistration().is(BuiltinDimensionTypes.END)) || env == org.bukkit.World.Environment.THE_END) { // CraftBukkit - Allow to create EnderDragonBattle in default and custom END
+ this.dragonFight = new EnderDragonBattle(this, this.serverLevelData.worldGenOptions().seed(), this.serverLevelData.endDragonFightData()); // CraftBukkit
} else {
this.dragonFight = null;
}
@@ -259,6 +310,7 @@
this.randomSequences = (RandomSequences) Objects.requireNonNullElseGet(randomsequences, () -> {
return (RandomSequences) this.getDataStorage().computeIfAbsent(RandomSequences.factory(l), "random_sequences");
});
+ this.getCraftServer().addWorld(this.getWorld()); // CraftBukkit
}
/** @deprecated */
@@ -304,12 +356,20 @@
long j;
if (this.sleepStatus.areEnoughSleeping(i) && this.sleepStatus.areEnoughDeepSleeping(i, this.players)) {
+ // CraftBukkit start
+ j = this.levelData.getDayTime() + 24000L;
+ TimeSkipEvent event = new TimeSkipEvent(this.getWorld(), TimeSkipEvent.SkipReason.NIGHT_SKIP, (j - j % 24000L) - this.getDayTime());
if (this.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT)) {
- j = this.levelData.getDayTime() + 24000L;
- this.setDayTime(j - j % 24000L);
+ getCraftServer().getPluginManager().callEvent(event);
+ if (!event.isCancelled()) {
+ this.setDayTime(this.getDayTime() + event.getSkipAmount());
+ }
}
- this.wakeUpAllPlayers();
+ if (!event.isCancelled()) {
+ this.wakeUpAllPlayers();
+ }
+ // CraftBukkit end
if (this.getGameRules().getBoolean(GameRules.RULE_WEATHER_CYCLE) && this.isRaining()) {
this.resetWeatherCycle();
}
@@ -344,7 +404,7 @@
this.handlingTick = false;
gameprofilerfiller.pop();
- boolean flag1 = !this.players.isEmpty() || !this.getForcedChunks().isEmpty();
+ boolean flag1 = true || !this.players.isEmpty() || !this.getForcedChunks().isEmpty(); // CraftBukkit - this prevents entity cleanup, other issues on servers with no players
if (flag1) {
this.resetEmptyTime();
@@ -428,7 +488,7 @@
private void wakeUpAllPlayers() {
this.sleepStatus.removeAllSleepers();
- ((List) this.players.stream().filter(EntityLiving::isSleeping).collect(Collectors.toList())).forEach((entityplayer) -> {
+ (this.players.stream().filter(EntityLiving::isSleeping).collect(Collectors.toList())).forEach((entityplayer) -> { // CraftBukkit - decompile error
entityplayer.stopSleepInBed(false, false);
});
}
@@ -455,7 +515,7 @@
entityhorseskeleton.setTrap(true);
entityhorseskeleton.setAge(0);
entityhorseskeleton.setPos((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ());
- this.addFreshEntity(entityhorseskeleton);
+ this.addFreshEntity(entityhorseskeleton, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.LIGHTNING); // CraftBukkit
}
}
@@ -464,7 +524,7 @@
if (entitylightning != null) {
entitylightning.moveTo(Vec3D.atBottomCenterOf(blockposition));
entitylightning.setVisualOnly(flag1);
- this.addFreshEntity(entitylightning);
+ this.strikeLightning(entitylightning, org.bukkit.event.weather.LightningStrikeEvent.Cause.WEATHER); // CraftBukkit
}
}
}
@@ -520,7 +580,7 @@
BiomeBase biomebase = (BiomeBase) this.getBiome(blockposition1).value();
if (biomebase.shouldFreeze(this, blockposition2)) {
- this.setBlockAndUpdate(blockposition2, Blocks.ICE.defaultBlockState());
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, blockposition2, Blocks.ICE.defaultBlockState(), null); // CraftBukkit
}
if (this.isRaining()) {
@@ -536,10 +596,10 @@
IBlockData iblockdata1 = (IBlockData) iblockdata.setValue(BlockSnow.LAYERS, j + 1);
Block.pushEntitiesUp(iblockdata, iblockdata1, this, blockposition1);
- this.setBlockAndUpdate(blockposition1, iblockdata1);
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, blockposition1, iblockdata1, null); // CraftBukkit
}
} else {
- this.setBlockAndUpdate(blockposition1, Blocks.SNOW.defaultBlockState());
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, blockposition1, Blocks.SNOW.defaultBlockState(), null); // CraftBukkit
}
}
@@ -700,6 +760,7 @@
this.rainLevel = MathHelper.clamp(this.rainLevel, 0.0F, 1.0F);
}
+ /* CraftBukkit start
if (this.oRainLevel != this.rainLevel) {
this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.RAIN_LEVEL_CHANGE, this.rainLevel), this.dimension());
}
@@ -718,15 +779,48 @@
this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.RAIN_LEVEL_CHANGE, this.rainLevel));
this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.THUNDER_LEVEL_CHANGE, this.thunderLevel));
}
+ // */
+ for (int idx = 0; idx < this.players.size(); ++idx) {
+ if (((EntityPlayer) this.players.get(idx)).level() == this) {
+ ((EntityPlayer) this.players.get(idx)).tickWeather();
+ }
+ }
+
+ if (flag != this.isRaining()) {
+ // Only send weather packets to those affected
+ for (int idx = 0; idx < this.players.size(); ++idx) {
+ if (((EntityPlayer) this.players.get(idx)).level() == this) {
+ ((EntityPlayer) this.players.get(idx)).setPlayerWeather((!flag ? WeatherType.DOWNFALL : WeatherType.CLEAR), false);
+ }
+ }
+ }
+ for (int idx = 0; idx < this.players.size(); ++idx) {
+ if (((EntityPlayer) this.players.get(idx)).level() == this) {
+ ((EntityPlayer) this.players.get(idx)).updateWeather(this.oRainLevel, this.rainLevel, this.oThunderLevel, this.thunderLevel);
+ }
+ }
+ // CraftBukkit end
}
@VisibleForTesting
public void resetWeatherCycle() {
- this.serverLevelData.setRainTime(0);
+ // CraftBukkit start
this.serverLevelData.setRaining(false);
- this.serverLevelData.setThunderTime(0);
+ // If we stop due to everyone sleeping we should reset the weather duration to some other random value.
+ // Not that everyone ever manages to get the whole server to sleep at the same time....
+ if (!this.serverLevelData.isRaining()) {
+ this.serverLevelData.setRainTime(0);
+ }
+ // CraftBukkit end
this.serverLevelData.setThundering(false);
+ // CraftBukkit start
+ // If we stop due to everyone sleeping we should reset the weather duration to some other random value.
+ // Not that everyone ever manages to get the whole server to sleep at the same time....
+ if (!this.serverLevelData.isThundering()) {
+ this.serverLevelData.setThunderTime(0);
+ }
+ // CraftBukkit end
}
public void resetEmptyTime() {
@@ -762,6 +856,7 @@
});
gameprofilerfiller.incrementCounter("tickNonPassenger");
entity.tick();
+ entity.postTick(); // CraftBukkit
gameprofilerfiller.pop();
Iterator iterator = entity.getPassengers().iterator();
@@ -785,6 +880,7 @@
});
gameprofilerfiller.incrementCounter("tickPassenger");
entity1.rideTick();
+ entity1.postTick(); // CraftBukkit
gameprofilerfiller.pop();
Iterator iterator = entity1.getPassengers().iterator();
@@ -809,6 +905,7 @@
ChunkProviderServer chunkproviderserver = this.getChunkSource();
if (!flag1) {
+ org.bukkit.Bukkit.getPluginManager().callEvent(new org.bukkit.event.world.WorldSaveEvent(getWorld())); // CraftBukkit
if (iprogressupdate != null) {
iprogressupdate.progressStartNoAbort(IChatBaseComponent.translatable("menu.savingLevel"));
}
@@ -826,11 +923,19 @@
}
}
+
+ // CraftBukkit start - moved from MinecraftServer.saveChunks
+ WorldServer worldserver1 = this;
+
+ serverLevelData.setWorldBorder(worldserver1.getWorldBorder().createSettings());
+ serverLevelData.setCustomBossEvents(this.server.getCustomBossEvents().save(this.registryAccess()));
+ convertable.saveDataTag(this.server.registryAccess(), this.serverLevelData, this.server.getPlayerList().getSingleplayerData());
+ // CraftBukkit end
}
private void saveLevelData(boolean flag) {
if (this.dragonFight != null) {
- this.server.getWorldData().setEndDragonFightData(this.dragonFight.saveData());
+ this.serverLevelData.setEndDragonFightData(this.dragonFight.saveData()); // CraftBukkit
}
WorldPersistentData worldpersistentdata = this.getChunkSource().getDataStorage();
@@ -902,18 +1007,40 @@
@Override
public boolean addFreshEntity(Entity entity) {
- return this.addEntity(entity);
+ // CraftBukkit start
+ return this.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.DEFAULT);
+ }
+
+ @Override
+ public boolean addFreshEntity(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
+ return this.addEntity(entity, reason);
+ // CraftBukkit end
}
public boolean addWithUUID(Entity entity) {
- return this.addEntity(entity);
+ // CraftBukkit start
+ return this.addWithUUID(entity, CreatureSpawnEvent.SpawnReason.DEFAULT);
+ }
+
+ public boolean addWithUUID(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
+ return this.addEntity(entity, reason);
+ // CraftBukkit end
}
public void addDuringTeleport(Entity entity) {
+ // CraftBukkit start
+ // SPIGOT-6415: Don't call spawn event for entities which travel trough worlds,
+ // since it is only an implementation detail, that a new entity is created when
+ // they are traveling between worlds.
+ this.addDuringTeleport(entity, null);
+ }
+
+ public void addDuringTeleport(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
+ // CraftBukkit end
if (entity instanceof EntityPlayer entityplayer) {
this.addPlayer(entityplayer);
} else {
- this.addEntity(entity);
+ this.addEntity(entity, reason); // CraftBukkit
}
}
@@ -938,24 +1065,37 @@
this.entityManager.addNewEntity(entityplayer);
}
- private boolean addEntity(Entity entity) {
+ // CraftBukkit start
+ private boolean addEntity(Entity entity, CreatureSpawnEvent.SpawnReason spawnReason) {
if (entity.isRemoved()) {
- WorldServer.LOGGER.warn("Tried to add entity {} but it was marked as removed already", EntityTypes.getKey(entity.getType()));
+ // WorldServer.LOGGER.warn("Tried to add entity {} but it was marked as removed already", EntityTypes.getKey(entity.getType())); // CraftBukkit
return false;
} else {
+ // SPIGOT-6415: Don't call spawn event when reason is null. For example when an entity teleports to a new world.
+ if (spawnReason != null && !CraftEventFactory.doEntityAddEventCalling(this, entity, spawnReason)) {
+ return false;
+ }
+ // CraftBukkit end
+
return this.entityManager.addNewEntity(entity);
}
}
public boolean tryAddFreshEntityWithPassengers(Entity entity) {
- Stream stream = entity.getSelfAndPassengers().map(Entity::getUUID);
+ // CraftBukkit start
+ return this.tryAddFreshEntityWithPassengers(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
+ }
+
+ public boolean tryAddFreshEntityWithPassengers(Entity entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) {
+ // CraftBukkit end
+ Stream<UUID> stream = entity.getSelfAndPassengers().map(Entity::getUUID); // CraftBukkit - decompile error
PersistentEntitySectionManager persistententitysectionmanager = this.entityManager;
Objects.requireNonNull(this.entityManager);
if (stream.anyMatch(persistententitysectionmanager::isLoaded)) {
return false;
} else {
- this.addFreshEntityWithPassengers(entity);
+ this.addFreshEntityWithPassengers(entity, reason); // CraftBukkit
return true;
}
}
@@ -966,13 +1106,35 @@
}
public void removePlayerImmediately(EntityPlayer entityplayer, Entity.RemovalReason entity_removalreason) {
- entityplayer.remove(entity_removalreason);
+ entityplayer.remove(entity_removalreason, null); // CraftBukkit - add Bukkit remove cause
+ }
+
+ // CraftBukkit start
+ public boolean strikeLightning(Entity entitylightning) {
+ return this.strikeLightning(entitylightning, LightningStrikeEvent.Cause.UNKNOWN);
}
+ public boolean strikeLightning(Entity entitylightning, LightningStrikeEvent.Cause cause) {
+ LightningStrikeEvent lightning = CraftEventFactory.callLightningStrikeEvent((org.bukkit.entity.LightningStrike) entitylightning.getBukkitEntity(), cause);
+
+ if (lightning.isCancelled()) {
+ return false;
+ }
+
+ return this.addFreshEntity(entitylightning);
+ }
+ // CraftBukkit end
+
@Override
public void destroyBlockProgress(int i, BlockPosition blockposition, int j) {
Iterator iterator = this.server.getPlayerList().getPlayers().iterator();
+ // CraftBukkit start
+ EntityHuman entityhuman = null;
+ Entity entity = this.getEntity(i);
+ if (entity instanceof EntityHuman) entityhuman = (EntityHuman) entity;
+ // CraftBukkit end
+
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
@@ -981,6 +1143,12 @@
double d1 = (double) blockposition.getY() - entityplayer.getY();
double d2 = (double) blockposition.getZ() - entityplayer.getZ();
+ // CraftBukkit start
+ if (entityhuman != null && !entityplayer.getBukkitEntity().canSee(entityhuman.getBukkitEntity())) {
+ continue;
+ }
+ // CraftBukkit end
+
if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) {
entityplayer.connection.send(new PacketPlayOutBlockBreakAnimation(i, blockposition, j));
}
@@ -1059,7 +1227,18 @@
Iterator iterator = this.navigatingMobs.iterator();
while (iterator.hasNext()) {
- EntityInsentient entityinsentient = (EntityInsentient) iterator.next();
+ // CraftBukkit start - fix SPIGOT-6362
+ EntityInsentient entityinsentient;
+ try {
+ entityinsentient = (EntityInsentient) iterator.next();
+ } catch (java.util.ConcurrentModificationException ex) {
+ // This can happen because the pathfinder update below may trigger a chunk load, which in turn may cause more navigators to register
+ // In this case we just run the update again across all the iterators as the chunk will then be loaded
+ // As this is a relative edge case it is much faster than copying navigators (on either read or write)
+ sendBlockUpdated(blockposition, iblockdata, iblockdata1, i);
+ return;
+ }
+ // CraftBukkit end
NavigationAbstract navigationabstract = entityinsentient.getNavigation();
if (navigationabstract.shouldRecomputePath(blockposition)) {
@@ -1125,6 +1304,12 @@
@Override
public void explode(@Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, double d0, double d1, double d2, float f, boolean flag, World.a world_a, ParticleParam particleparam, ParticleParam particleparam1, Holder<SoundEffect> holder) {
+ // CraftBukkit start
+ this.explode0(entity, damagesource, explosiondamagecalculator, d0, d1, d2, f, flag, world_a, particleparam, particleparam1, holder);
+ }
+
+ public ServerExplosion explode0(@Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, double d0, double d1, double d2, float f, boolean flag, World.a world_a, ParticleParam particleparam, ParticleParam particleparam1, Holder<SoundEffect> holder) {
+ // CraftBukkit end
Explosion.Effect explosion_effect;
switch (world_a) {
@@ -1143,6 +1328,11 @@
case TRIGGER:
explosion_effect = Explosion.Effect.TRIGGER_BLOCK;
break;
+ // CraftBukkit start - handle custom explosion type
+ case STANDARD:
+ explosion_effect = Explosion.Effect.DESTROY;
+ break;
+ // CraftBukkit end
default:
throw new MatchException((String) null, (Throwable) null);
}
@@ -1152,6 +1342,11 @@
ServerExplosion serverexplosion = new ServerExplosion(this, entity, damagesource, explosiondamagecalculator, vec3d, f, flag, explosion_effect1);
serverexplosion.explode();
+ // CraftBukkit start
+ if (serverexplosion.wasCanceled) {
+ return serverexplosion;
+ }
+ // CraftBukkit end
ParticleParam particleparam2 = serverexplosion.isSmall() ? particleparam : particleparam1;
Iterator iterator = this.players.iterator();
@@ -1165,6 +1360,7 @@
}
}
+ return serverexplosion; // CraftBukkit
}
private Explosion.Effect getDestroyType(GameRules.GameRuleKey<GameRules.GameRuleBoolean> gamerules_gamerulekey) {
@@ -1225,13 +1421,20 @@
}
public <T extends ParticleParam> int sendParticles(T t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6) {
- PacketPlayOutWorldParticles packetplayoutworldparticles = new PacketPlayOutWorldParticles(t0, false, d0, d1, d2, (float) d3, (float) d4, (float) d5, (float) d6, i);
+ // CraftBukkit - visibility api support
+ return sendParticles(null, t0, d0, d1, d2, i, d3, d4, d5, d6, false);
+ }
+
+ public <T extends ParticleParam> int sendParticles(EntityPlayer sender, T t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6, boolean force) {
+ PacketPlayOutWorldParticles packetplayoutworldparticles = new PacketPlayOutWorldParticles(t0, force, d0, d1, d2, (float) d3, (float) d4, (float) d5, (float) d6, i);
+ // CraftBukkit end
int j = 0;
for (int k = 0; k < this.players.size(); ++k) {
EntityPlayer entityplayer = (EntityPlayer) this.players.get(k);
+ if (sender != null && !entityplayer.getBukkitEntity().canSee(sender.getBukkitEntity())) continue; // CraftBukkit
- if (this.sendParticles(entityplayer, false, d0, d1, d2, packetplayoutworldparticles)) {
+ if (this.sendParticles(entityplayer, force, d0, d1, d2, packetplayoutworldparticles)) { // CraftBukkit
++j;
}
}
@@ -1282,7 +1485,7 @@
@Nullable
public BlockPosition findNearestMapStructure(TagKey<Structure> tagkey, BlockPosition blockposition, int i, boolean flag) {
- if (!this.server.getWorldData().worldGenOptions().generateStructures()) {
+ if (!this.serverLevelData.worldGenOptions().generateStructures()) { // CraftBukkit
return null;
} else {
Optional<HolderSet.Named<Structure>> optional = this.registryAccess().lookupOrThrow(Registries.STRUCTURE).get(tagkey);
@@ -1324,11 +1527,22 @@
@Nullable
@Override
public WorldMap getMapData(MapId mapid) {
- return (WorldMap) this.getServer().overworld().getDataStorage().get(WorldMap.factory(), mapid.key());
+ // CraftBukkit start
+ WorldMap worldmap = (WorldMap) this.getServer().overworld().getDataStorage().get(WorldMap.factory(), mapid.key());
+ if (worldmap != null) {
+ worldmap.id = mapid;
+ }
+ return worldmap;
+ // CraftBukkit end
}
@Override
public void setMapData(MapId mapid, WorldMap worldmap) {
+ // CraftBukkit start
+ worldmap.id = mapid;
+ MapInitializeEvent event = new MapInitializeEvent(worldmap.mapView);
+ Bukkit.getServer().getPluginManager().callEvent(event);
+ // CraftBukkit end
this.getServer().overworld().getDataStorage().set(mapid.key(), worldmap);
}
@@ -1639,6 +1853,11 @@
@Override
public void blockUpdated(BlockPosition blockposition, Block block) {
if (!this.isDebug()) {
+ // CraftBukkit start
+ if (populating) {
+ return;
+ }
+ // CraftBukkit end
this.updateNeighborsAt(blockposition, block);
}
@@ -1658,12 +1877,12 @@
}
public boolean isFlat() {
- return this.server.getWorldData().isFlatWorld();
+ return this.serverLevelData.isFlatWorld(); // CraftBukkit
}
@Override
public long getSeed() {
- return this.server.getWorldData().worldGenOptions().seed();
+ return this.serverLevelData.worldGenOptions().seed(); // CraftBukkit
}
@Nullable
@@ -1686,7 +1905,7 @@
private static <T> String getTypeCount(Iterable<T> iterable, Function<T, String> function) {
try {
Object2IntOpenHashMap<String> object2intopenhashmap = new Object2IntOpenHashMap();
- Iterator iterator = iterable.iterator();
+ Iterator<T> iterator = iterable.iterator(); // CraftBukkit - decompile error
while (iterator.hasNext()) {
T t0 = iterator.next();
@@ -1695,7 +1914,7 @@
object2intopenhashmap.addTo(s, 1);
}
- return (String) object2intopenhashmap.object2IntEntrySet().stream().sorted(Comparator.comparing(Entry::getIntValue).reversed()).limit(5L).map((entry) -> {
+ return (String) object2intopenhashmap.object2IntEntrySet().stream().sorted(Comparator.comparing(Entry<String>::getIntValue).reversed()).limit(5L).map((entry) -> { // CraftBukkit - decompile error
String s1 = (String) entry.getKey();
return s1 + ":" + entry.getIntValue();
@@ -1854,6 +2073,8 @@
}
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
+ entity.inWorld = true; // CraftBukkit - Mark entity as in world
+ entity.valid = true; // CraftBukkit
}
public void onTrackingEnd(Entity entity) {
@@ -1885,6 +2106,14 @@
}
entity.updateDynamicGameEventListener(DynamicGameEventListener::remove);
+ // CraftBukkit start
+ entity.valid = false;
+ if (!(entity instanceof EntityPlayer)) {
+ for (EntityPlayer player : players) {
+ player.getBukkitEntity().onEntityRemove(entity);
+ }
+ }
+ // CraftBukkit end
}
public void onSectionChange(Entity entity) {