2021-03-15 23:00:00 +01:00
--- a/net/minecraft/server/level/WorldServer.java
+++ b/net/minecraft/server/level/WorldServer.java
2022-06-07 18:00:00 +02:00
@@ -152,6 +152,25 @@
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;
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;
2022-06-07 18:00:00 +02:00
+import org.bukkit.Location;
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;
+import org.bukkit.craftbukkit.util.CraftNamespacedKey;
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;
2022-06-07 18:00:00 +02:00
+import org.bukkit.event.world.GenericGameEvent;
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);
2022-06-07 18:00:00 +02:00
@@ -169,7 +188,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
final EntityTickList entityTickList;
2021-07-06 16:00:00 +02:00
public final PersistentEntitySectionManager<Entity> entityManager;
2021-06-11 07:00:00 +02:00
public boolean noSave;
2022-06-07 18:00:00 +02:00
@@ -193,11 +212,28 @@
2021-11-21 23:00:00 +01:00
private final StructureCheck structureCheck;
2021-06-11 07:00:00 +02:00
private final boolean tickTime;
2020-06-25 02:00:00 +02:00
2022-06-07 18:00: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) {
- Holder holder = worlddimension.typeHolder();
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;
2014-11-25 22:32:16 +01:00
+
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
+ }
2019-04-23 04:00:00 +02:00
+
2021-11-23 08:39:43 +01:00
+ @Override
+ public ResourceKey<WorldDimension> getTypeKey() {
+ return convertable.dimensionType;
+ }
2022-06-07 18:00:00 +02:00
- Objects.requireNonNull(minecraftserver);
- super(iworlddataserver, resourcekey, holder, minecraftserver::getProfiler, false, flag, i, minecraftserver.getMaxChainedNeighborUpdates());
+ // 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, org.bukkit.World.Environment env, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider) {
+ // Holder holder = worlddimension.typeHolder(); // CraftBukkit - decompile error
2021-06-11 07:00:00 +02:00
+ // Objects.requireNonNull(minecraftserver); // CraftBukkit - decompile error
2022-06-07 18:00:00 +02:00
+ super(iworlddataserver, resourcekey, worlddimension.typeHolder(), 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());
2022-06-07 18:00:00 +02:00
@@ -212,6 +248,20 @@
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) {
+ WorldChunkManager worldChunkManager = new CustomWorldChunkManager(getWorld(), biomeProvider, server.registryHolder.registryOrThrow(IRegistry.BIOME_REGISTRY));
+ if (chunkgenerator instanceof ChunkGeneratorAbstract cga) {
+ chunkgenerator = new ChunkGeneratorAbstract(cga.structureSets, cga.noises, worldChunkManager, cga.settings);
+ }
+ }
+
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();
2022-06-07 18:00:00 +02:00
EntityPersistentStorage<Entity> entitypersistentstorage = new EntityStorage(this, convertable_conversionsession.getDimensionPath(resourcekey).resolve("entities"), datafixer, flag2, minecraftserver);
@@ -243,14 +293,15 @@
2021-11-21 23:00:00 +01:00
long l = minecraftserver.getWorldData().worldGenSettings().seed();
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);
- this.structureManager = new StructureManager(this, minecraftserver.getWorldData().worldGenSettings(), this.structureCheck);
+ this.structureManager = new StructureManager(this, this.serverLevelData.worldGenSettings(), structureCheck); // CraftBukkit
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());
+ this.dragonFight = new EnderDragonBattle(this, this.serverLevelData.worldGenSettings().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
}
2021-06-11 07:00:00 +02:00
this.sleepStatus = new SleepStatus();
2021-06-11 13:33:49 +02:00
+ this.getCraftServer().addWorld(this.getWorld()); // CraftBukkit
2019-12-21 02:06:18 +01:00
}
2021-11-21 23:00:00 +01:00
public void setWeatherParameters(int i, int j, boolean flag, boolean flag1) {
2022-06-07 18:00:00 +02:00
@@ -282,12 +333,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
}
2022-06-07 18:00:00 +02:00
@@ -313,7 +372,7 @@
2021-11-21 23:00:00 +01:00
this.runBlockEvents();
2021-06-11 07:00:00 +02:00
this.handlingTick = false;
2021-11-21 23:00:00 +01:00
gameprofilerfiller.pop();
- boolean flag = !this.players.isEmpty() || !this.getForcedChunks().isEmpty();
+ boolean flag = 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
2021-11-21 23:00:00 +01:00
if (flag) {
2019-04-23 04:00:00 +02:00
this.resetEmptyTime();
2022-06-07 18:00:00 +02:00
@@ -329,7 +388,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();
2021-06-11 07:00:00 +02:00
} else {
2021-11-21 23:00:00 +01:00
gameprofilerfiller.push("checkDespawn");
2022-06-07 18:00:00 +02:00
@@ -403,7 +462,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
});
}
2022-06-07 18:00:00 +02:00
@@ -430,14 +489,14 @@
2021-11-21 23: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
}
2021-11-21 23:00:00 +01:00
EntityLightning entitylightning = (EntityLightning) EntityTypes.LIGHTNING_BOLT.create(this);
2020-06-25 02:00:00 +02:00
2021-11-21 23:00:00 +01:00
entitylightning.moveTo(Vec3D.atBottomCenterOf(blockposition));
entitylightning.setVisualOnly(flag1);
- this.addFreshEntity(entitylightning);
2020-06-25 02:00:00 +02:00
+ this.strikeLightning(entitylightning, org.bukkit.event.weather.LightningStrikeEvent.Cause.WEATHER); // CraftBukkit
2019-04-23 04:00:00 +02:00
}
}
2022-06-07 18:00:00 +02:00
@@ -448,12 +507,12 @@
2022-02-28 16:00:00 +01:00
BiomeBase biomebase = (BiomeBase) this.getBiome(blockposition).value();
2019-04-23 04:00:00 +02:00
2021-11-21 23:00:00 +01:00
if (biomebase.shouldFreeze(this, blockposition1)) {
- this.setBlockAndUpdate(blockposition1, Blocks.ICE.defaultBlockState());
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, blockposition1, Blocks.ICE.defaultBlockState(), null); // CraftBukkit
2019-04-23 04:00:00 +02:00
}
2021-06-11 07:00:00 +02:00
if (flag) {
2021-11-21 23:00:00 +01:00
if (biomebase.shouldSnow(this, blockposition)) {
- this.setBlockAndUpdate(blockposition, Blocks.SNOW.defaultBlockState());
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this, blockposition, Blocks.SNOW.defaultBlockState(), null); // CraftBukkit
2021-06-11 07:00:00 +02:00
}
2014-11-25 22:32:16 +01:00
2021-11-21 23:00:00 +01:00
IBlockData iblockdata = this.getBlockState(blockposition1);
2022-06-07 18:00:00 +02:00
@@ -649,6 +708,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());
}
2022-06-07 18:00:00 +02:00
@@ -667,14 +727,47 @@
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) {
+ 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
2014-11-25 22:32:16 +01:00
}
2021-11-21 23:00:00 +01:00
private void resetWeatherCycle() {
- 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() {
2022-06-07 18:00:00 +02:00
@@ -709,6 +802,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();
2022-06-07 18:00:00 +02:00
@@ -732,6 +826,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
2022-06-07 18:00:00 +02:00
@@ -756,6 +851,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
}
2022-06-07 18:00:00 +02:00
@@ -773,11 +869,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());
+ serverLevelData.setCustomBossEvents(this.server.getCustomBossEvents().save());
+ convertable.saveDataTag(this.server.registryHolder, 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();
2022-06-07 18:00:00 +02:00
@@ -823,15 +927,37 @@
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) {
- this.addEntity(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) {
+ this.addEntity(entity, reason);
2021-06-11 07:00:00 +02:00
+ // CraftBukkit end
}
2021-11-21 23:00:00 +01:00
public void addDuringCommandTeleport(EntityPlayer entityplayer) {
2022-06-07 18:00:00 +02:00
@@ -862,24 +988,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
}
}
2022-06-07 18:00:00 +02:00
@@ -893,10 +1032,32 @@
2021-11-21 23:00:00 +01:00
entityplayer.remove(entity_removalreason);
2014-11-25 22:32:16 +01: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);
2020-06-25 02:00:00 +02:00
+ }
+ // CraftBukkit end
+
@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();
2022-06-07 18:00:00 +02:00
@@ -905,6 +1066,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
}
2022-06-07 18:00:00 +02:00
@@ -941,6 +1108,14 @@
public void gameEvent(GameEvent gameevent, Vec3D vec3d, GameEvent.a gameevent_a) {
int i = gameevent.getNotificationRadius();
BlockPosition blockposition = new BlockPosition(vec3d);
+ // CraftBukkit start
+ GenericGameEvent event = new GenericGameEvent(org.bukkit.GameEvent.getByKey(CraftNamespacedKey.fromMinecraft(IRegistry.GAME_EVENT.getKey(gameevent))), new Location(this.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ()), (gameevent_a.sourceEntity() == null) ? null : gameevent_a.sourceEntity().getBukkitEntity(), i, !Bukkit.isPrimaryThread());
+ getCraftServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return;
+ }
+ i = event.getRadius();
+ // CraftBukkit end
int j = SectionPosition.blockToSectionCoord(blockposition.getX() - i);
int k = SectionPosition.blockToSectionCoord(blockposition.getY() - i);
int l = SectionPosition.blockToSectionCoord(blockposition.getZ() - i);
@@ -1013,7 +1188,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)) {
2022-06-07 18:00:00 +02:00
@@ -1069,10 +1255,20 @@
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 Explosion explode(@Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, double d0, double d1, double d2, float f, boolean flag, Explosion.Effect explosion_effect) {
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
2021-11-21 23:00:00 +01:00
+ Explosion explosion = super.explode(entity, damagesource, explosiondamagecalculator, d0, d1, d2, f, flag, explosion_effect);
2014-11-25 22:32:16 +01:00
+
+ if (explosion.wasCanceled) {
+ return explosion;
+ }
2015-02-26 23:41:06 +01:00
+
2014-11-25 22:32:16 +01:00
+ /* Remove
2020-06-25 02:00:00 +02:00
Explosion explosion = new Explosion(this, entity, damagesource, explosiondamagecalculator, d0, d1, d2, f, flag, explosion_effect);
2018-07-15 02:00:00 +02:00
2021-11-21 23:00:00 +01:00
explosion.explode();
explosion.finalizeExplosion(false);
2014-11-25 22:32:16 +01:00
+ */
+ // CraftBukkit end - TODO: Check if explosions are still properly implemented
2019-04-23 04:00:00 +02:00
if (explosion_effect == Explosion.Effect.NONE) {
2021-11-21 23:00:00 +01:00
explosion.clearToBlow();
2014-11-25 22:32:16 +01:00
}
2022-06-07 18:00:00 +02:00
@@ -1144,13 +1340,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
}
}
2022-06-07 18:00:00 +02:00
@@ -1201,7 +1404,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) {
- if (!this.server.getWorldData().worldGenSettings().generateStructures()) {
+ if (!this.serverLevelData.worldGenSettings().generateStructures()) { // CraftBukkit
2022-02-28 16:00:00 +01:00
return null;
} else {
2022-06-07 18:00:00 +02:00
Optional<HolderSet.Named<Structure>> optional = this.registryAccess().registryOrThrow(IRegistry.STRUCTURE_REGISTRY).getTag(tagkey);
@@ -1243,11 +1446,21 @@
2021-06-11 07:00:00 +02:00
@Nullable
2019-04-23 04:00:00 +02:00
@Override
2021-11-21 23:00:00 +01:00
public WorldMap getMapData(String s) {
- return (WorldMap) this.getServer().overworld().getDataStorage().get(WorldMap::load, s);
+ // CraftBukkit start
+ return (WorldMap) this.getServer().overworld().getDataStorage().get((nbttagcompound) -> {
2019-04-23 04:00:00 +02:00
+ // We only get here when the data file exists, but is not a valid map
2021-11-21 23:00:00 +01:00
+ WorldMap newMap = WorldMap.load(nbttagcompound);
2021-06-11 07:00:00 +02:00
+ newMap.id = s;
2019-04-23 04:00:00 +02:00
+ MapInitializeEvent event = new MapInitializeEvent(newMap.mapView);
+ Bukkit.getServer().getPluginManager().callEvent(event);
+ return newMap;
2021-06-11 07:00:00 +02:00
+ }, s);
2021-11-21 23:00:00 +01:00
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
}
2021-06-11 07:00:00 +02:00
@Override
2021-11-21 23:00:00 +01:00
public void setMapData(String s, WorldMap worldmap) {
2021-06-11 07:00:00 +02:00
+ worldmap.id = s; // CraftBukkit
2021-11-21 23:00:00 +01:00
this.getServer().overworld().getDataStorage().set(s, worldmap);
2021-03-15 23:00:00 +01:00
}
2022-06-07 18:00:00 +02:00
@@ -1545,6 +1758,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
}
2022-06-07 18:00:00 +02:00
@@ -1564,12 +1782,12 @@
2020-06-25 02:00:00 +02:00
}
2021-11-21 23:00:00 +01:00
public boolean isFlat() {
- return this.server.getWorldData().worldGenSettings().isFlatWorld();
+ return this.serverLevelData.worldGenSettings().isFlatWorld(); // CraftBukkit
2020-06-25 02:00:00 +02:00
}
@Override
public long getSeed() {
2021-11-21 23:00:00 +01:00
- return this.server.getWorldData().worldGenSettings().seed();
+ return this.serverLevelData.worldGenSettings().seed(); // CraftBukkit
2020-06-25 02:00:00 +02:00
}
@Nullable
2022-06-07 18:00:00 +02:00
@@ -1592,7 +1810,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();
2022-06-07 18:00:00 +02:00
@@ -1601,7 +1819,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();
2022-06-07 18:00:00 +02:00
@@ -1612,17 +1830,33 @@
2020-06-25 02:00:00 +02:00
}
2021-11-21 23:00:00 +01:00
public static void makeObsidianPlatform(WorldServer worldserver) {
2020-06-25 02:00:00 +02:00
+ // CraftBukkit start
2021-11-21 23:00:00 +01:00
+ WorldServer.makeObsidianPlatform(worldserver, null);
2020-06-25 02:00:00 +02:00
+ }
+
2021-11-21 23:00:00 +01:00
+ public static void makeObsidianPlatform(WorldServer worldserver, Entity entity) {
2020-06-25 02:00:00 +02:00
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
BlockPosition blockposition = WorldServer.END_SPAWN_POINT;
2020-06-25 02:00:00 +02:00
int i = blockposition.getX();
int j = blockposition.getY() - 2;
int k = blockposition.getZ();
+ // CraftBukkit start
+ org.bukkit.craftbukkit.util.BlockStateListPopulator blockList = new org.bukkit.craftbukkit.util.BlockStateListPopulator(worldserver);
2021-11-21 23:00:00 +01:00
BlockPosition.betweenClosed(i - 2, j + 1, k - 2, i + 2, j + 3, k + 2).forEach((blockposition1) -> {
- worldserver.setBlockAndUpdate(blockposition1, Blocks.AIR.defaultBlockState());
+ blockList.setBlock(blockposition1, Blocks.AIR.defaultBlockState(), 3);
2020-06-25 02:00:00 +02:00
});
2021-11-21 23:00:00 +01:00
BlockPosition.betweenClosed(i - 2, j, k - 2, i + 2, j, k + 2).forEach((blockposition1) -> {
- worldserver.setBlockAndUpdate(blockposition1, Blocks.OBSIDIAN.defaultBlockState());
+ blockList.setBlock(blockposition1, Blocks.OBSIDIAN.defaultBlockState(), 3);
2020-06-25 02:00:00 +02:00
});
+ org.bukkit.World bworld = worldserver.getWorld();
+ org.bukkit.event.world.PortalCreateEvent portalEvent = new org.bukkit.event.world.PortalCreateEvent((List<org.bukkit.block.BlockState>) (List) blockList.getList(), bworld, (entity == null) ? null : entity.getBukkitEntity(), org.bukkit.event.world.PortalCreateEvent.CreateReason.END_PLATFORM);
+
2021-06-11 13:33:49 +02:00
+ worldserver.getCraftServer().getPluginManager().callEvent(portalEvent);
2020-06-25 02:00:00 +02:00
+ if (!portalEvent.isCancelled()) {
+ blockList.updateList();
+ }
+ // CraftBukkit end
}
2021-06-11 07:00:00 +02:00
@Override
2022-06-07 18:00:00 +02:00
@@ -1733,6 +1967,7 @@
2021-06-11 07:00:00 +02:00
}
2022-06-07 18:00:00 +02:00
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
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) {
2022-06-07 18:00:00 +02:00
@@ -1769,6 +2004,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) {