2021-03-15 23:00:00 +01:00
--- a/net/minecraft/server/level/WorldServer.java
+++ b/net/minecraft/server/level/WorldServer.java
2024-06-13 17:05:00 +02:00
@@ -171,6 +171,23 @@
2022-02-28 16:00:00 +01:00
import net.minecraft.world.ticks.TickListServer;
import org.slf4j.Logger;
2014-11-25 22:32:16 +01:00
+// CraftBukkit start
2022-06-07 18:00:00 +02:00
+import net.minecraft.world.level.biome.WorldChunkManager;
2021-11-23 08:39:43 +01:00
+import net.minecraft.world.level.dimension.WorldDimension;
2022-06-07 18:00:00 +02:00
+import net.minecraft.world.level.levelgen.ChunkGeneratorAbstract;
2022-06-10 03:08:00 +02:00
+import net.minecraft.world.level.levelgen.ChunkProviderFlat;
2021-03-15 23:00:00 +01:00
+import net.minecraft.world.level.storage.WorldDataServer;
2019-04-23 04:00:00 +02:00
+import org.bukkit.Bukkit;
2014-11-25 22:32:16 +01:00
+import org.bukkit.WeatherType;
2019-04-23 04:00:00 +02:00
+import org.bukkit.craftbukkit.event.CraftEventFactory;
2022-06-07 18:00:00 +02:00
+import org.bukkit.craftbukkit.generator.CustomWorldChunkManager;
2020-06-25 02:00:00 +02:00
+import org.bukkit.craftbukkit.util.WorldUUID;
2019-04-23 04:00:00 +02:00
+import org.bukkit.event.entity.CreatureSpawnEvent;
+import org.bukkit.event.server.MapInitializeEvent;
2014-11-25 22:32:16 +01:00
+import org.bukkit.event.weather.LightningStrikeEvent;
2019-12-21 02:06:18 +01:00
+import org.bukkit.event.world.TimeSkipEvent;
2014-11-25 22:32:16 +01:00
+// CraftBukkit end
+
2020-06-25 02:00:00 +02:00
public class WorldServer extends World implements GeneratorAccessSeed {
2021-06-11 07:00:00 +02:00
public static final BlockPosition END_SPAWN_POINT = new BlockPosition(100, 50, 0);
2024-06-13 17:05:00 +02:00
@@ -184,7 +201,7 @@
2021-06-11 07:00:00 +02:00
final List<EntityPlayer> players;
private final ChunkProviderServer chunkSource;
2020-06-25 02:00:00 +02:00
private final MinecraftServer server;
2021-06-11 07:00:00 +02:00
- public final IWorldDataServer serverLevelData;
+ public final WorldDataServer serverLevelData; // CraftBukkit - type
2024-04-23 17:15:00 +02:00
private int lastSpawnChunkRadius;
2021-06-11 07:00:00 +02:00
final EntityTickList entityTickList;
2021-07-06 16:00:00 +02:00
public final PersistentEntitySectionManager<Entity> entityManager;
2024-06-13 17:05:00 +02:00
@@ -211,12 +228,30 @@
2021-06-11 07:00:00 +02:00
private final boolean tickTime;
2023-06-07 17:30:00 +02:00
private final RandomSequences randomSequences;
2020-06-25 02:00:00 +02:00
2023-06-07 17:30:00 +02:00
- 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) {
2023-03-14 17:30:00 +01:00
- IRegistryCustom.Dimension iregistrycustom_dimension = minecraftserver.registryAccess();
2022-12-07 17:00:00 +01:00
- Holder holder = worlddimension.type();
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
2020-06-25 02:00:00 +02:00
+ public final Convertable.ConversionSession convertable;
+ public final UUID uuid;
2023-09-21 18:57:13 +02:00
- Objects.requireNonNull(minecraftserver);
- super(iworlddataserver, resourcekey, iregistrycustom_dimension, holder, minecraftserver::getProfiler, false, flag, i, minecraftserver.getMaxChainedNeighborUpdates());
2020-06-25 02:00:00 +02:00
+ public Chunk getChunkIfLoaded(int x, int z) {
2021-11-21 23:00:00 +01:00
+ return this.chunkSource.getChunk(x, z, false);
2020-06-25 02:00:00 +02:00
+ }
2022-12-16 01:13:10 +01:00
+
2021-11-23 08:39:43 +01:00
+ @Override
+ public ResourceKey<WorldDimension> getTypeKey() {
+ return convertable.dimensionType;
+ }
2023-09-21 18:57:13 +02:00
+
2022-06-07 18:00:00 +02:00
+ // Add env and gen to constructor, IWorldDataServer -> WorldDataServer
2023-06-07 17:30:00 +02:00
+ 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) {
2023-03-14 17:30:00 +01:00
+ // IRegistryCustom.Dimension iregistrycustom_dimension = minecraftserver.registryAccess(); // CraftBukkit - decompile error
2022-12-07 17:00:00 +01:00
+ // Holder holder = worlddimension.type(); // CraftBukkit - decompile error
2023-03-14 17:30:00 +01:00
+
2021-06-11 07:00:00 +02:00
+ // Objects.requireNonNull(minecraftserver); // CraftBukkit - decompile error
2023-03-14 17:30:00 +01:00
+ super(iworlddataserver, resourcekey, minecraftserver.registryAccess(), worlddimension.type(), minecraftserver::getProfiler, false, flag, i, minecraftserver.getMaxChainedNeighborUpdates(), gen, biomeProvider, env);
2021-11-21 23:00:00 +01:00
+ this.pvpMode = minecraftserver.isPvpAllowed();
2020-06-25 02:00:00 +02:00
+ convertable = convertable_conversionsession;
2022-06-07 18:00:00 +02:00
+ uuid = WorldUUID.getUUID(convertable_conversionsession.levelDirectory.path().toFile());
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
this.players = Lists.newArrayList();
this.entityTickList = new EntityTickList();
2021-11-21 23:00:00 +01:00
this.blockTicks = new TickListServer<>(this::isPositionTickingWithEntitiesLoaded, this.getProfilerSupplier());
2024-06-13 17:05:00 +02:00
@@ -231,6 +266,22 @@
2021-06-11 07:00:00 +02:00
this.customSpawners = list;
2022-06-07 18:00:00 +02:00
this.serverLevelData = iworlddataserver;
ChunkGenerator chunkgenerator = worlddimension.generator();
2020-06-25 02:00:00 +02:00
+ // CraftBukkit start
2022-02-14 23:36:00 +01:00
+ serverLevelData.setWorld(this);
2022-06-07 18:00:00 +02:00
+
+ if (biomeProvider != null) {
2022-12-07 17:00:00 +01:00
+ WorldChunkManager worldChunkManager = new CustomWorldChunkManager(getWorld(), biomeProvider, server.registryAccess().registryOrThrow(Registries.BIOME));
2022-06-07 18:00:00 +02:00
+ if (chunkgenerator instanceof ChunkGeneratorAbstract cga) {
2022-12-07 17:00:00 +01:00
+ chunkgenerator = new ChunkGeneratorAbstract(worldChunkManager, cga.settings);
2022-06-10 03:08:00 +02:00
+ } else if (chunkgenerator instanceof ChunkProviderFlat cpf) {
2022-12-07 17:00:00 +01:00
+ chunkgenerator = new ChunkProviderFlat(cpf.settings(), worldChunkManager);
2022-06-07 18:00:00 +02:00
+ }
+ }
+
2020-06-25 02:00:00 +02:00
+ if (gen != null) {
+ chunkgenerator = new org.bukkit.craftbukkit.generator.CustomChunkGenerator(this, chunkgenerator, gen);
+ }
+ // CraftBukkit end
2021-11-21 23:00:00 +01:00
boolean flag2 = minecraftserver.forceSynchronousWrites();
DataFixer datafixer = minecraftserver.getFixerUpper();
2024-04-23 17:15:00 +02:00
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);
2024-06-13 17:05:00 +02:00
@@ -258,9 +309,9 @@
2022-12-07 17:00:00 +01:00
long l = minecraftserver.getWorldData().worldGenOptions().seed();
2021-11-21 23:00:00 +01:00
2022-06-07 18:00:00 +02:00
this.structureCheck = new StructureCheck(this.chunkSource.chunkScanner(), this.registryAccess(), minecraftserver.getStructureManager(), resourcekey, chunkgenerator, this.chunkSource.randomState(), this, chunkgenerator.getBiomeSource(), l, datafixer);
2022-12-07 17:00:00 +01:00
- this.structureManager = new StructureManager(this, minecraftserver.getWorldData().worldGenOptions(), this.structureCheck);
2022-06-18 13:06:59 +02:00
- if (this.dimension() == World.END && this.dimensionTypeRegistration().is(BuiltinDimensionTypes.END)) {
2021-11-21 23:00:00 +01:00
- this.dragonFight = new EnderDragonBattle(this, l, minecraftserver.getWorldData().endDragonFightData());
2022-12-07 17:00:00 +01:00
+ this.structureManager = new StructureManager(this, this.serverLevelData.worldGenOptions(), structureCheck); // CraftBukkit
2022-06-18 13:06:59 +02:00
+ 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
2022-12-07 17:00:00 +01:00
+ this.dragonFight = new EnderDragonBattle(this, this.serverLevelData.worldGenOptions().seed(), this.serverLevelData.endDragonFightData()); // CraftBukkit
2020-06-25 02:00:00 +02:00
} else {
2021-06-11 07:00:00 +02:00
this.dragonFight = null;
2015-03-16 12:32:53 +01:00
}
2024-06-13 17:05:00 +02:00
@@ -270,6 +321,7 @@
2023-09-21 18:40:00 +02:00
this.randomSequences = (RandomSequences) Objects.requireNonNullElseGet(randomsequences, () -> {
return (RandomSequences) this.getDataStorage().computeIfAbsent(RandomSequences.factory(l), "random_sequences");
2023-06-07 17:30:00 +02:00
});
2021-06-11 13:33:49 +02:00
+ this.getCraftServer().addWorld(this.getWorld()); // CraftBukkit
2019-12-21 02:06:18 +01:00
}
2023-06-07 17:30:00 +02:00
/** @deprecated */
2024-06-13 17:05:00 +02:00
@@ -314,12 +366,20 @@
2021-11-21 23:00:00 +01:00
long j;
2019-04-23 04:00:00 +02:00
2021-11-21 23:00:00 +01:00
if (this.sleepStatus.areEnoughSleeping(i) && this.sleepStatus.areEnoughDeepSleeping(i, this.players)) {
2019-12-21 02:06:18 +01:00
+ // CraftBukkit start
2021-11-21 23:00:00 +01:00
+ j = this.levelData.getDayTime() + 24000L;
+ TimeSkipEvent event = new TimeSkipEvent(this.getWorld(), TimeSkipEvent.SkipReason.NIGHT_SKIP, (j - j % 24000L) - this.getDayTime());
2021-06-11 07:00:00 +02:00
if (this.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT)) {
2021-11-21 23:00:00 +01:00
- j = this.levelData.getDayTime() + 24000L;
- this.setDayTime(j - j % 24000L);
2021-06-11 13:33:49 +02:00
+ getCraftServer().getPluginManager().callEvent(event);
2019-12-21 02:06:18 +01:00
+ if (!event.isCancelled()) {
+ this.setDayTime(this.getDayTime() + event.getSkipAmount());
+ }
}
2021-11-21 23:00:00 +01:00
- this.wakeUpAllPlayers();
2019-12-21 02:06:18 +01:00
+ if (!event.isCancelled()) {
2021-11-21 23:00:00 +01:00
+ this.wakeUpAllPlayers();
2019-12-21 02:06:18 +01:00
+ }
+ // CraftBukkit end
2021-11-21 23:00:00 +01:00
if (this.getGameRules().getBoolean(GameRules.RULE_WEATHER_CYCLE) && this.isRaining()) {
this.resetWeatherCycle();
2019-12-21 02:06:18 +01:00
}
2024-06-13 17:05:00 +02:00
@@ -354,7 +414,7 @@
2023-12-05 17:40:00 +01:00
2021-06-11 07:00:00 +02:00
this.handlingTick = false;
2021-11-21 23:00:00 +01:00
gameprofilerfiller.pop();
2023-12-05 17:40:00 +01:00
- 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
2019-04-23 04:00:00 +02:00
2023-12-05 17:40:00 +01:00
if (flag1) {
2019-04-23 04:00:00 +02:00
this.resetEmptyTime();
2024-06-13 17:05:00 +02:00
@@ -370,7 +430,7 @@
2019-04-23 04:00:00 +02:00
2021-11-21 23:00:00 +01:00
this.entityTickList.forEach((entity) -> {
2021-06-11 07:00:00 +02:00
if (!entity.isRemoved()) {
2021-11-21 23:00:00 +01:00
- if (this.shouldDiscardEntity(entity)) {
+ if (false && this.shouldDiscardEntity(entity)) { // CraftBukkit - We prevent spawning in general, so this butchering is not needed
entity.discard();
2023-12-05 17:40:00 +01:00
} else if (!tickratemanager.isEntityFrozen(entity)) {
2021-11-21 23:00:00 +01:00
gameprofilerfiller.push("checkDespawn");
2024-06-13 17:05:00 +02:00
@@ -442,7 +502,7 @@
2019-12-10 23:00:00 +01:00
2021-11-21 23:00:00 +01:00
private void wakeUpAllPlayers() {
this.sleepStatus.removeAllSleepers();
2019-12-10 23:00:00 +01:00
- ((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
2021-11-21 23:00:00 +01:00
entityplayer.stopSleepInBed(false, false);
2019-12-10 23:00:00 +01:00
});
}
2024-06-13 17:05:00 +02:00
@@ -469,7 +529,7 @@
2022-12-07 17:00:00 +01:00
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
}
2019-04-23 04:00:00 +02:00
}
2024-06-13 17:05:00 +02:00
@@ -478,7 +538,7 @@
2022-12-07 17:00:00 +01:00
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
}
2019-04-23 04:00:00 +02:00
}
}
2024-06-13 17:05:00 +02:00
@@ -534,7 +594,7 @@
2023-09-21 18:40:00 +02:00
BiomeBase biomebase = (BiomeBase) this.getBiome(blockposition1).value();
2019-04-23 04:00:00 +02:00
2023-09-21 18:40:00 +02:00
if (biomebase.shouldFreeze(this, blockposition2)) {
- this.setBlockAndUpdate(blockposition2, Blocks.ICE.defaultBlockState());
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, blockposition2, Blocks.ICE.defaultBlockState(), null); // CraftBukkit
}
2019-04-23 04:00:00 +02:00
2023-12-05 17:40:00 +01:00
if (this.isRaining()) {
2024-06-13 17:05:00 +02:00
@@ -550,10 +610,10 @@
2023-09-21 18:40:00 +02:00
IBlockData iblockdata1 = (IBlockData) iblockdata.setValue(BlockSnow.LAYERS, j + 1);
2022-12-07 17:00:00 +01:00
2023-09-21 18:40:00 +02:00
Block.pushEntitiesUp(iblockdata, iblockdata1, this, blockposition1);
- this.setBlockAndUpdate(blockposition1, iblockdata1);
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, blockposition1, iblockdata1, null); // CraftBukkit
2022-12-07 17:00:00 +01:00
}
2023-09-21 18:40:00 +02:00
} else {
- this.setBlockAndUpdate(blockposition1, Blocks.SNOW.defaultBlockState());
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, blockposition1, Blocks.SNOW.defaultBlockState(), null); // CraftBukkit
2021-06-11 07:00:00 +02:00
}
2023-09-21 18:40:00 +02:00
}
2014-11-25 22:32:16 +01:00
2024-06-13 17:05:00 +02:00
@@ -714,6 +774,7 @@
2021-11-21 23:00:00 +01:00
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());
}
2024-06-13 17:05:00 +02:00
@@ -732,15 +793,48 @@
2021-11-21 23:00:00 +01:00
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) {
2023-06-07 17:30:00 +02:00
+ if (((EntityPlayer) this.players.get(idx)).level() == this) {
2021-11-21 23:00:00 +01:00
+ ((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) {
2023-06-07 17:30:00 +02:00
+ if (((EntityPlayer) this.players.get(idx)).level() == this) {
2021-11-21 23:00:00 +01:00
+ ((EntityPlayer) this.players.get(idx)).setPlayerWeather((!flag ? WeatherType.DOWNFALL : WeatherType.CLEAR), false);
+ }
+ }
+ }
+ for (int idx = 0; idx < this.players.size(); ++idx) {
2023-06-07 17:30:00 +02:00
+ if (((EntityPlayer) this.players.get(idx)).level() == this) {
2021-11-21 23:00:00 +01:00
+ ((EntityPlayer) this.players.get(idx)).updateWeather(this.oRainLevel, this.rainLevel, this.oThunderLevel, this.thunderLevel);
+ }
+ }
+ // CraftBukkit end
2014-11-25 22:32:16 +01:00
}
2023-12-05 17:40:00 +01:00
@VisibleForTesting
public void resetWeatherCycle() {
2021-11-21 23:00:00 +01:00
- this.serverLevelData.setRainTime(0);
2018-07-15 02:00:00 +02:00
+ // CraftBukkit start
2021-11-21 23:00:00 +01:00
this.serverLevelData.setRaining(false);
- this.serverLevelData.setThunderTime(0);
2015-01-04 23:50:48 +01:00
+ // 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....
2021-11-21 23:00:00 +01:00
+ if (!this.serverLevelData.isRaining()) {
+ this.serverLevelData.setRainTime(0);
2014-11-25 22:32:16 +01:00
+ }
2015-01-04 23:50:48 +01:00
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
this.serverLevelData.setThundering(false);
2015-01-04 23:50:48 +01:00
+ // 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....
2021-06-11 07:00:00 +02:00
+ if (!this.serverLevelData.isThundering()) {
2021-11-21 23:00:00 +01:00
+ this.serverLevelData.setThunderTime(0);
2014-11-25 22:32:16 +01:00
+ }
+ // CraftBukkit end
}
2019-04-23 04:00:00 +02:00
public void resetEmptyTime() {
2024-06-13 17:05:00 +02:00
@@ -775,6 +869,7 @@
2021-06-11 07:00:00 +02:00
});
2021-11-21 23:00:00 +01:00
gameprofilerfiller.incrementCounter("tickNonPassenger");
2021-06-11 07:00:00 +02:00
entity.tick();
+ entity.postTick(); // CraftBukkit
2021-11-21 23:00:00 +01:00
this.getProfiler().pop();
2021-06-11 07:00:00 +02:00
Iterator iterator = entity.getPassengers().iterator();
2024-06-13 17:05:00 +02:00
@@ -798,6 +893,7 @@
2019-04-23 04:00:00 +02:00
});
2021-11-21 23:00:00 +01:00
gameprofilerfiller.incrementCounter("tickPassenger");
entity1.rideTick();
2021-06-11 07:00:00 +02:00
+ entity1.postTick(); // CraftBukkit
2021-11-21 23:00:00 +01:00
gameprofilerfiller.pop();
2021-06-11 07:00:00 +02:00
Iterator iterator = entity1.getPassengers().iterator();
2014-11-25 22:32:16 +01:00
2024-06-13 17:05:00 +02:00
@@ -822,6 +918,7 @@
2021-11-21 23:00:00 +01:00
ChunkProviderServer chunkproviderserver = this.getChunkSource();
2014-11-25 22:32:16 +01:00
2019-04-23 04:00:00 +02:00
if (!flag1) {
2014-12-03 20:35:33 +01:00
+ org.bukkit.Bukkit.getPluginManager().callEvent(new org.bukkit.event.world.WorldSaveEvent(getWorld())); // CraftBukkit
2014-11-25 22:32:16 +01:00
if (iprogressupdate != null) {
2022-06-07 18:00:00 +02:00
iprogressupdate.progressStartNoAbort(IChatBaseComponent.translatable("menu.savingLevel"));
2014-12-03 20:35:33 +01:00
}
2024-06-13 17:05:00 +02:00
@@ -839,11 +936,19 @@
2021-06-11 07:00:00 +02:00
}
2019-06-25 13:02:13 +02:00
}
+
+ // CraftBukkit start - moved from MinecraftServer.saveChunks
+ WorldServer worldserver1 = this;
+
2021-11-21 23:00:00 +01:00
+ serverLevelData.setWorldBorder(worldserver1.getWorldBorder().createSettings());
2024-04-23 17:15:00 +02:00
+ serverLevelData.setCustomBossEvents(this.server.getCustomBossEvents().save(this.registryAccess()));
2022-12-16 01:13:10 +01:00
+ convertable.saveDataTag(this.server.registryAccess(), this.serverLevelData, this.server.getPlayerList().getSingleplayerData());
2019-06-25 13:02:13 +02:00
+ // CraftBukkit end
}
2021-11-21 23:00:00 +01:00
private void saveLevelData() {
2021-06-11 07:00:00 +02:00
if (this.dragonFight != null) {
2021-11-21 23:00:00 +01:00
- this.server.getWorldData().setEndDragonFightData(this.dragonFight.saveData());
+ this.serverLevelData.setEndDragonFightData(this.dragonFight.saveData()); // CraftBukkit
2020-07-17 00:56:56 +02:00
}
2021-11-21 23:00:00 +01:00
this.getChunkSource().getDataStorage().save();
2024-06-13 17:05:00 +02:00
@@ -908,18 +1013,40 @@
2014-11-25 22:32:16 +01:00
2019-04-23 04:00:00 +02:00
@Override
2021-11-21 23:00:00 +01:00
public boolean addFreshEntity(Entity entity) {
- return this.addEntity(entity);
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
2021-11-21 23:00:00 +01:00
+ return this.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.DEFAULT);
2019-04-23 04:00:00 +02:00
+ }
+
+ @Override
2021-11-21 23:00:00 +01:00
+ public boolean addFreshEntity(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
+ return this.addEntity(entity, reason);
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
2016-10-16 08:20:12 +02:00
}
2021-11-21 23:00:00 +01:00
public boolean addWithUUID(Entity entity) {
- return this.addEntity(entity);
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
2021-11-21 23:00:00 +01:00
+ return this.addWithUUID(entity, CreatureSpawnEvent.SpawnReason.DEFAULT);
2019-04-23 04:00:00 +02:00
+ }
+
2021-11-21 23:00:00 +01:00
+ public boolean addWithUUID(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
+ return this.addEntity(entity, reason);
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
2016-10-16 08:20:12 +02:00
}
2021-11-21 23:00:00 +01:00
public void addDuringTeleport(Entity entity) {
2021-06-11 07:00:00 +02:00
+ // CraftBukkit start
2022-03-12 21:48:22 +01:00
+ // 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);
2021-06-11 07:00:00 +02:00
+ }
+
2021-11-21 23:00:00 +01:00
+ public void addDuringTeleport(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
2021-06-11 07:00:00 +02:00
+ // CraftBukkit end
2024-06-13 17:05:00 +02:00
if (entity instanceof EntityPlayer entityplayer) {
this.addPlayer(entityplayer);
} else {
- this.addEntity(entity);
+ this.addEntity(entity, reason); // CraftBukkit
}
2021-06-11 07:00:00 +02:00
2024-06-13 17:05:00 +02:00
}
@@ -944,24 +1071,37 @@
2021-11-21 23:00:00 +01:00
this.entityManager.addNewEntity(entityplayer);
2019-04-23 04:00:00 +02:00
}
2016-02-29 22:32:46 +01:00
2021-11-21 23:00:00 +01:00
- private boolean addEntity(Entity entity) {
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
2021-11-21 23:00:00 +01:00
+ private boolean addEntity(Entity entity, CreatureSpawnEvent.SpawnReason spawnReason) {
2021-06-11 07:00:00 +02:00
if (entity.isRemoved()) {
2021-11-21 23:00:00 +01:00
- 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
2019-04-23 04:00:00 +02:00
return false;
2016-02-29 22:32:46 +01:00
} else {
2022-03-12 21:48:22 +01:00
+ // 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)) {
2019-04-23 04:00:00 +02:00
+ return false;
+ }
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
+
2021-11-21 23:00:00 +01:00
return this.entityManager.addNewEntity(entity);
2019-04-23 04:00:00 +02:00
}
}
2020-08-11 23:00:00 +02:00
2021-11-21 23:00:00 +01:00
public boolean tryAddFreshEntityWithPassengers(Entity entity) {
- Stream stream = entity.getSelfAndPassengers().map(Entity::getUUID);
2020-08-11 23:00:00 +02:00
+ // CraftBukkit start
2021-11-21 23:00:00 +01:00
+ return this.tryAddFreshEntityWithPassengers(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
2020-08-11 23:00:00 +02:00
+ }
+
2021-11-21 23:00:00 +01:00
+ public boolean tryAddFreshEntityWithPassengers(Entity entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) {
2020-08-11 23:00:00 +02:00
+ // CraftBukkit end
2021-11-21 23:00:00 +01:00
+ Stream<UUID> stream = entity.getSelfAndPassengers().map(Entity::getUUID); // CraftBukkit - decompile error
2021-06-11 07:00:00 +02:00
PersistentEntitySectionManager persistententitysectionmanager = this.entityManager;
Objects.requireNonNull(this.entityManager);
2021-11-21 23:00:00 +01:00
if (stream.anyMatch(persistententitysectionmanager::isLoaded)) {
2020-08-11 23:00:00 +02:00
return false;
} else {
2021-11-21 23:00:00 +01:00
- this.addFreshEntityWithPassengers(entity);
+ this.addFreshEntityWithPassengers(entity, reason); // CraftBukkit
2020-11-17 03:41:47 +01:00
return true;
2020-08-11 23:00:00 +02:00
}
}
2024-06-13 17:05:00 +02:00
@@ -972,13 +1112,35 @@
2014-11-25 22:32:16 +01:00
}
2024-02-21 10:55:34 +01:00
public void removePlayerImmediately(EntityPlayer entityplayer, Entity.RemovalReason entity_removalreason) {
- entityplayer.remove(entity_removalreason);
+ entityplayer.remove(entity_removalreason, null); // CraftBukkit - add Bukkit remove cause
2024-06-13 17:05:00 +02:00
}
2020-06-25 02:00:00 +02:00
+ // CraftBukkit start
+ public boolean strikeLightning(Entity entitylightning) {
+ return this.strikeLightning(entitylightning, LightningStrikeEvent.Cause.UNKNOWN);
2018-09-15 11:16:42 +02:00
+ }
+
2020-06-25 02:00:00 +02:00
+ public boolean strikeLightning(Entity entitylightning, LightningStrikeEvent.Cause cause) {
2021-05-09 08:33:34 +02:00
+ LightningStrikeEvent lightning = CraftEventFactory.callLightningStrikeEvent((org.bukkit.entity.LightningStrike) entitylightning.getBukkitEntity(), cause);
2014-11-25 22:32:16 +01:00
+
+ if (lightning.isCancelled()) {
2020-06-25 02:00:00 +02:00
+ return false;
2014-11-25 22:32:16 +01:00
+ }
2020-06-25 02:00:00 +02:00
+
2021-11-21 23:00:00 +01:00
+ return this.addFreshEntity(entitylightning);
2024-06-13 17:05:00 +02:00
+ }
2020-06-25 02:00:00 +02:00
+ // CraftBukkit end
2024-06-13 17:05:00 +02:00
+
2020-06-25 02:00:00 +02:00
@Override
2021-11-21 23:00:00 +01:00
public void destroyBlockProgress(int i, BlockPosition blockposition, int j) {
2019-04-23 04:00:00 +02:00
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();
2024-06-13 17:05:00 +02:00
@@ -987,6 +1149,12 @@
2021-11-21 23:00:00 +01:00
double d1 = (double) blockposition.getY() - entityplayer.getY();
double d2 = (double) blockposition.getZ() - entityplayer.getZ();
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
2021-11-28 23:18:52 +01:00
+ if (entityhuman != null && !entityplayer.getBukkitEntity().canSee(entityhuman.getBukkitEntity())) {
2019-04-23 04:00:00 +02:00
+ continue;
+ }
+ // CraftBukkit end
+
if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) {
2021-11-21 23:00:00 +01:00
entityplayer.connection.send(new PacketPlayOutBlockBreakAnimation(i, blockposition, j));
2019-04-23 04:00:00 +02:00
}
2024-06-13 17:05:00 +02:00
@@ -1047,7 +1215,18 @@
2021-06-11 07:00:00 +02:00
Iterator iterator = this.navigatingMobs.iterator();
2021-02-14 00:08:27 +01:00
while (iterator.hasNext()) {
2021-06-11 07:00:00 +02:00
- EntityInsentient entityinsentient = (EntityInsentient) iterator.next();
2021-02-14 00:08:27 +01:00
+ // CraftBukkit start - fix SPIGOT-6362
2021-06-11 07:00:00 +02:00
+ EntityInsentient entityinsentient;
2021-02-14 00:08:27 +01:00
+ try {
2021-06-11 07:00:00 +02:00
+ entityinsentient = (EntityInsentient) iterator.next();
2021-02-14 00:08:27 +01:00
+ } 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)
2021-11-21 23:00:00 +01:00
+ sendBlockUpdated(blockposition, iblockdata, iblockdata1, i);
2021-02-14 00:08:27 +01:00
+ return;
+ }
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
NavigationAbstract navigationabstract = entityinsentient.getNavigation();
2021-02-14 00:08:27 +01:00
2021-12-10 14:11:02 +01:00
if (navigationabstract.shouldRecomputePath(blockposition)) {
2024-06-13 17:05:00 +02:00
@@ -1109,6 +1288,11 @@
2019-04-23 04:00:00 +02:00
@Override
2024-04-23 17:15:00 +02:00
public Explosion 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) {
Explosion explosion = this.explode(entity, damagesource, explosiondamagecalculator, d0, d1, d2, f, flag, world_a, false, particleparam, particleparam1, holder);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ if (explosion.wasCanceled) {
+ return explosion;
+ }
2022-12-07 17:00:00 +01:00
+ // CraftBukkit end
if (!explosion.interactsWithBlocks()) {
2021-11-21 23:00:00 +01:00
explosion.clearToBlow();
2024-06-13 17:05:00 +02:00
@@ -1181,13 +1365,20 @@
2014-11-25 22:32:16 +01:00
}
2021-11-21 23:00:00 +01:00
public <T extends ParticleParam> int sendParticles(T t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6) {
2019-12-10 23:00:00 +01:00
- PacketPlayOutWorldParticles packetplayoutworldparticles = new PacketPlayOutWorldParticles(t0, false, d0, d1, d2, (float) d3, (float) d4, (float) d5, (float) d6, i);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit - visibility api support
2018-08-26 10:26:09 +02:00
+ return sendParticles(null, t0, d0, d1, d2, i, d3, d4, d5, d6, false);
2014-11-25 22:32:16 +01:00
+ }
2015-02-26 23:41:06 +01:00
+
2018-08-26 10:26:09 +02:00
+ 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) {
2019-12-10 23:00:00 +01:00
+ PacketPlayOutWorldParticles packetplayoutworldparticles = new PacketPlayOutWorldParticles(t0, force, d0, d1, d2, (float) d3, (float) d4, (float) d5, (float) d6, i);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
2018-07-15 02:00:00 +02:00
int j = 0;
2014-11-25 22:32:16 +01:00
2018-07-15 02:00:00 +02:00
for (int k = 0; k < this.players.size(); ++k) {
EntityPlayer entityplayer = (EntityPlayer) this.players.get(k);
2014-12-28 15:56:18 +01:00
+ if (sender != null && !entityplayer.getBukkitEntity().canSee(sender.getBukkitEntity())) continue; // CraftBukkit
2014-11-25 22:32:16 +01:00
2021-11-21 23:00:00 +01:00
- if (this.sendParticles(entityplayer, false, d0, d1, d2, packetplayoutworldparticles)) {
+ if (this.sendParticles(entityplayer, force, d0, d1, d2, packetplayoutworldparticles)) { // CraftBukkit
2018-07-15 02:00:00 +02:00
++j;
2018-08-26 10:26:09 +02:00
}
}
2024-06-13 17:05:00 +02:00
@@ -1238,7 +1429,7 @@
2020-06-30 02:29:41 +02:00
@Nullable
2022-06-07 18:00:00 +02:00
public BlockPosition findNearestMapStructure(TagKey<Structure> tagkey, BlockPosition blockposition, int i, boolean flag) {
2022-12-07 17:00:00 +01:00
- if (!this.server.getWorldData().worldGenOptions().generateStructures()) {
+ if (!this.serverLevelData.worldGenOptions().generateStructures()) { // CraftBukkit
2022-02-28 16:00:00 +01:00
return null;
} else {
2022-12-07 17:00:00 +01:00
Optional<HolderSet.Named<Structure>> optional = this.registryAccess().registryOrThrow(Registries.STRUCTURE).getTag(tagkey);
2024-06-13 17:05:00 +02:00
@@ -1280,11 +1471,22 @@
2023-12-08 09:20:05 +01:00
@Nullable
@Override
2024-04-23 17:15:00 +02:00
public WorldMap getMapData(MapId mapid) {
- return (WorldMap) this.getServer().overworld().getDataStorage().get(WorldMap.factory(), mapid.key());
2023-12-08 09:20:05 +01:00
+ // CraftBukkit start
2024-04-23 17:15:00 +02:00
+ WorldMap worldmap = (WorldMap) this.getServer().overworld().getDataStorage().get(WorldMap.factory(), mapid.key());
2023-12-08 09:20:05 +01:00
+ if (worldmap != null) {
2024-04-23 17:15:00 +02:00
+ worldmap.id = mapid;
2023-12-08 09:20:05 +01:00
+ }
+ return worldmap;
+ // CraftBukkit end
}
2019-04-23 04:00:00 +02:00
2021-06-11 07:00:00 +02:00
@Override
2024-04-23 17:15:00 +02:00
public void setMapData(MapId mapid, WorldMap worldmap) {
2023-12-08 09:20:05 +01:00
+ // CraftBukkit start
2024-04-23 17:15:00 +02:00
+ worldmap.id = mapid;
2023-12-08 09:20:05 +01:00
+ MapInitializeEvent event = new MapInitializeEvent(worldmap.mapView);
+ Bukkit.getServer().getPluginManager().callEvent(event);
+ // CraftBukkit end
2024-04-23 17:15:00 +02:00
this.getServer().overworld().getDataStorage().set(mapid.key(), worldmap);
2021-03-15 23:00:00 +01:00
}
2024-06-13 17:05:00 +02:00
@@ -1595,6 +1797,11 @@
2020-06-25 02:00:00 +02:00
@Override
2021-11-21 23:00:00 +01:00
public void blockUpdated(BlockPosition blockposition, Block block) {
if (!this.isDebug()) {
2020-06-25 02:00:00 +02:00
+ // CraftBukkit start
+ if (populating) {
+ return;
+ }
+ // CraftBukkit end
2021-11-21 23:00:00 +01:00
this.updateNeighborsAt(blockposition, block);
2020-06-25 02:00:00 +02:00
}
2024-06-13 17:05:00 +02:00
@@ -1614,12 +1821,12 @@
2020-06-25 02:00:00 +02:00
}
2021-11-21 23:00:00 +01:00
public boolean isFlat() {
2022-12-07 17:00:00 +01:00
- return this.server.getWorldData().isFlatWorld();
+ return this.serverLevelData.isFlatWorld(); // CraftBukkit
2020-06-25 02:00:00 +02:00
}
@Override
public long getSeed() {
2022-12-07 17:00:00 +01:00
- return this.server.getWorldData().worldGenOptions().seed();
+ return this.serverLevelData.worldGenOptions().seed(); // CraftBukkit
2020-06-25 02:00:00 +02:00
}
@Nullable
2024-06-13 17:05:00 +02:00
@@ -1642,7 +1849,7 @@
2021-11-21 23:00:00 +01:00
private static <T> String getTypeCount(Iterable<T> iterable, Function<T, String> function) {
2020-11-02 21:00:00 +01:00
try {
2021-06-11 07:00:00 +02:00
Object2IntOpenHashMap<String> object2intopenhashmap = new Object2IntOpenHashMap();
- Iterator iterator = iterable.iterator();
+ Iterator<T> iterator = iterable.iterator(); // CraftBukkit - decompile error
2020-11-02 21:00:00 +01:00
while (iterator.hasNext()) {
T t0 = iterator.next();
2024-06-13 17:05:00 +02:00
@@ -1651,7 +1858,7 @@
2021-06-11 07:00:00 +02:00
object2intopenhashmap.addTo(s, 1);
2020-11-02 21:00:00 +01:00
}
2021-06-11 07:00:00 +02:00
- 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();
2024-06-13 17:05:00 +02:00
@@ -1796,6 +2003,8 @@
2021-06-11 07:00:00 +02:00
}
2022-06-07 18:00:00 +02:00
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
2023-12-06 22:24:27 +01:00
+ entity.inWorld = true; // CraftBukkit - Mark entity as in world
2021-06-11 07:00:00 +02:00
+ entity.valid = true; // CraftBukkit
}
2021-11-21 23:00:00 +01:00
public void onTrackingEnd(Entity entity) {
2024-06-13 17:05:00 +02:00
@@ -1827,6 +2036,14 @@
2021-06-11 07:00:00 +02:00
}
2022-06-07 18:00:00 +02:00
entity.updateDynamicGameEventListener(DynamicGameEventListener::remove);
2021-12-03 22:23:26 +01:00
+ // CraftBukkit start
+ entity.valid = false;
+ if (!(entity instanceof EntityPlayer)) {
+ for (EntityPlayer player : players) {
+ player.getBukkitEntity().onEntityRemove(entity);
+ }
+ }
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
}
2022-06-07 18:00:00 +02:00
public void onSectionChange(Entity entity) {