Update to Minecraft 1.21.2

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2024-10-23 02:15:00 +11:00
parent 2c4beb962b
commit d3a23f42c3
522 changed files with 8501 additions and 6477 deletions

View File

@@ -1,18 +1,22 @@
--- a/net/minecraft/server/level/ChunkMapDistance.java
+++ b/net/minecraft/server/level/ChunkMapDistance.java
@@ -121,6 +121,11 @@
}
@@ -117,6 +117,15 @@
PlayerChunk playerchunk;
if (!this.chunksToUpdateFutures.isEmpty()) {
+ // CraftBukkit start - SPIGOT-7780: Call chunk unload events before updateHighestAllowedStatus
+ this.chunksToUpdateFutures.forEach((playerchunk) -> {
+ while (iterator.hasNext()) {
+ playerchunk = (PlayerChunk) iterator.next();
+ playerchunk.callEventIfUnloading(playerchunkmap);
+ });
+ }
+
+ iterator = this.chunksToUpdateFutures.iterator();
+ // CraftBukkit end
this.chunksToUpdateFutures.forEach((playerchunk) -> {
+
while (iterator.hasNext()) {
playerchunk = (PlayerChunk) iterator.next();
playerchunk.updateHighestAllowedStatus(playerchunkmap);
});
@@ -163,7 +168,7 @@
@@ -165,7 +174,7 @@
}
}
@@ -21,7 +25,7 @@
ArraySetSorted<Ticket<?>> arraysetsorted = this.getTickets(i);
int j = getTicketLevelAt(arraysetsorted);
Ticket<?> ticket1 = (Ticket) arraysetsorted.addOrGet(ticket);
@@ -173,13 +178,15 @@
@@ -175,13 +184,15 @@
this.ticketTracker.update(i, ticket.getTicketLevel(), true);
}
@@ -39,7 +43,7 @@
}
if (arraysetsorted.isEmpty()) {
@@ -187,6 +194,7 @@
@@ -189,6 +200,7 @@
}
this.ticketTracker.update(i, getTicketLevelAt(arraysetsorted), false);
@@ -47,7 +51,7 @@
}
public <T> void addTicket(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
@@ -200,19 +208,33 @@
@@ -202,19 +214,33 @@
}
public <T> void addRegionTicket(TicketType<T> tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
@@ -83,7 +87,7 @@
}
private ArraySetSorted<Ticket<?>> getTickets(long i) {
@@ -251,6 +273,7 @@
@@ -253,6 +279,7 @@
ChunkCoordIntPair chunkcoordintpair = sectionposition.chunk();
long i = chunkcoordintpair.toLong();
ObjectSet<EntityPlayer> objectset = (ObjectSet) this.playersPerChunk.get(i);
@@ -91,7 +95,7 @@
objectset.remove(entityplayer);
if (objectset.isEmpty()) {
@@ -380,6 +403,26 @@
@@ -391,6 +418,26 @@
return !this.tickets.isEmpty();
}

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/ChunkProviderServer.java
+++ b/net/minecraft/server/level/ChunkProviderServer.java
@@ -82,6 +82,16 @@
@@ -96,6 +96,16 @@
this.clearCache();
}
@@ -17,7 +17,7 @@
@Override
public LightEngineThreaded getLightEngine() {
return this.lightEngine;
@@ -125,7 +135,7 @@
@@ -139,7 +149,7 @@
if (k == this.lastChunkPos[l] && chunkstatus == this.lastChunkStatus[l]) {
IChunkAccess ichunkaccess = this.lastChunk[l];
@@ -26,7 +26,7 @@
return ichunkaccess;
}
}
@@ -138,7 +148,7 @@
@@ -152,7 +162,7 @@
Objects.requireNonNull(completablefuture);
chunkproviderserver_b.managedBlock(completablefuture::isDone);
ChunkResult<IChunkAccess> chunkresult = (ChunkResult) completablefuture.join();
@@ -35,7 +35,7 @@
if (ichunkaccess1 == null && flag) {
throw (IllegalStateException) SystemUtils.pauseInIde(new IllegalStateException("Chunk not there when requested: " + chunkresult.getError()));
@@ -218,7 +228,15 @@
@@ -232,7 +242,15 @@
int l = ChunkLevel.byStatus(chunkstatus);
PlayerChunk playerchunk = this.getVisibleChunkIfPresent(k);
@@ -51,8 +51,8 @@
+ // CraftBukkit end
this.distanceManager.addTicket(TicketType.UNKNOWN, chunkcoordintpair, l, chunkcoordintpair);
if (this.chunkAbsent(playerchunk, l)) {
GameProfilerFiller gameprofilerfiller = this.level.getProfiler();
@@ -237,7 +255,7 @@
GameProfilerFiller gameprofilerfiller = Profiler.get();
@@ -251,7 +269,7 @@
}
private boolean chunkAbsent(@Nullable PlayerChunk playerchunk, int i) {
@@ -61,7 +61,7 @@
}
@Override
@@ -292,11 +310,31 @@
@@ -310,12 +328,34 @@
@Override
public void close() throws IOException {
@@ -75,40 +75,63 @@
+ this.save(true);
+ }
+ // CraftBukkit end
this.dataStorage.close();
this.lightEngine.close();
this.chunkMap.close();
}
+ // CraftBukkit start - modelled on below
+ public void purgeUnload() {
+ this.level.getProfiler().push("purge");
+ GameProfilerFiller gameprofilerfiller = Profiler.get();
+
+ gameprofilerfiller.push("purge");
+ this.distanceManager.purgeStaleTickets();
+ this.runDistanceManagerUpdates();
+ this.level.getProfiler().popPush("unload");
+ gameprofilerfiller.popPush("unload");
+ this.chunkMap.tick(() -> true);
+ this.level.getProfiler().pop();
+ gameprofilerfiller.pop();
+ this.clearCache();
+ }
+ // CraftBukkit end
+
@Override
public void tick(BooleanSupplier booleansupplier, boolean flag) {
this.level.getProfiler().push("purge");
@@ -346,11 +384,11 @@
GameProfilerFiller gameprofilerfiller = Profiler.get();
@@ -402,14 +442,14 @@
this.lastSpawnState = spawnercreature_d;
gameprofilerfiller.popPush("spawnAndTick");
- boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING);
+ boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !this.level.players().isEmpty(); // CraftBukkit
this.lastSpawnState = spawnercreature_d;
gameprofilerfiller.popPush("spawnAndTick");
- boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING);
+ boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !this.level.players().isEmpty(); // CraftBukkit
int k = this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING);
List list1;
SystemUtils.shuffle(list, this.level.random);
int l = this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING);
- boolean flag1 = this.level.getLevelData().getGameTime() % 400L == 0L;
+ boolean flag1 = this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) != 0L && this.level.getLevelData().getGameTime() % this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) == 0L; // CraftBukkit
Iterator iterator1 = list.iterator();
if (flag && (this.spawnEnemies || this.spawnFriendlies)) {
- boolean flag1 = this.level.getLevelData().getGameTime() % 400L == 0L;
+ boolean flag1 = this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) != 0L && this.level.getLevelData().getGameTime() % this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) == 0L; // CraftBukkit
while (iterator1.hasNext()) {
@@ -560,13 +598,19 @@
- list1 = SpawnerCreature.getFilteredSpawningCategories(spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag1);
+ list1 = SpawnerCreature.getFilteredSpawningCategories(spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag1, this.level); // CraftBukkit
} else {
list1 = List.of();
}
@@ -542,8 +582,14 @@
@Override
public void setSpawnSettings(boolean flag) {
+ // CraftBukkit start
+ this.setSpawnSettings(flag, this.spawnFriendlies);
+ }
+
+ public void setSpawnSettings(boolean flag, boolean spawnFriendlies) {
this.spawnEnemies = flag;
- this.spawnFriendlies = this.spawnFriendlies;
+ this.spawnFriendlies = spawnFriendlies;
+ // CraftBukkit end
}
public String getChunkDebugData(ChunkCoordIntPair chunkcoordintpair) {
@@ -619,13 +665,19 @@
}
@Override

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/EntityPlayer.java
+++ b/net/minecraft/server/level/EntityPlayer.java
@@ -166,6 +166,40 @@
@@ -184,6 +184,41 @@
import net.minecraft.world.scores.criteria.IScoreboardCriteria;
import org.slf4j.Logger;
@@ -15,6 +15,7 @@
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.WeatherType;
+import org.bukkit.command.CommandSender;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.CraftWorldBorder;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
@@ -28,20 +29,20 @@
+import org.bukkit.event.player.PlayerBedLeaveEvent;
+import org.bukkit.event.player.PlayerChangedMainHandEvent;
+import org.bukkit.event.player.PlayerChangedWorldEvent;
+import org.bukkit.event.player.PlayerDropItemEvent;
+import org.bukkit.event.player.PlayerLocaleChangeEvent;
+import org.bukkit.event.player.PlayerPortalEvent;
+import org.bukkit.event.player.PlayerRespawnEvent;
+import org.bukkit.event.player.PlayerSpawnChangeEvent;
+import org.bukkit.event.player.PlayerTeleportEvent;
+import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
+import org.bukkit.event.player.PlayerToggleSneakEvent;
+import org.bukkit.inventory.MainHand;
+// CraftBukkit end
+
public class EntityPlayer extends EntityHuman {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -204,7 +238,7 @@
@@ -227,7 +262,7 @@
private int levitationStartTime;
private boolean disconnected;
private int requestedViewDistance;
@@ -50,7 +51,7 @@
@Nullable
private Vec3D startingToFallPosition;
@Nullable
@@ -235,6 +269,21 @@
@@ -261,6 +296,22 @@
private int containerCounter;
public boolean wonGame;
@@ -58,6 +59,7 @@
+ public CraftPlayer.TransferCookieConnection transferCookieConnection;
+ public String displayName;
+ public IChatBaseComponent listName;
+ public int listOrder = 0;
+ public org.bukkit.Location compassTarget;
+ public int newExp = 0;
+ public int newLevel = 0;
@@ -72,7 +74,21 @@
public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, ClientInformation clientinformation) {
super(worldserver, worldserver.getSharedSpawnPos(), worldserver.getSharedSpawnAngle(), gameprofile);
this.chatVisibility = EnumChatVisibility.FULL;
@@ -302,14 +351,67 @@
@@ -342,6 +393,13 @@
public void sendSystemMessage(IChatBaseComponent ichatbasecomponent) {
EntityPlayer.this.sendSystemMessage(ichatbasecomponent);
}
+
+ // CraftBukkit start
+ @Override
+ public CommandSender getBukkitSender(CommandListenerWrapper wrapper) {
+ return getBukkitEntity();
+ }
+ // CraftBukkit end
};
this.textFilter = minecraftserver.createTextFilterForPlayer(this);
this.gameMode = minecraftserver.createGameModeForPlayer(this);
@@ -354,14 +412,67 @@
this.moveTo(this.adjustSpawnLocation(worldserver, worldserver.getSharedSpawnPos()).getBottomCenter(), 0.0F, 0.0F);
this.updateOptions(clientinformation);
this.object = null;
@@ -81,8 +97,8 @@
+ this.displayName = this.getScoreboardName();
+ this.bukkitPickUpLoot = true;
+ this.maxHealthCache = this.getMaxHealth();
}
+ }
+
+ // Use method to resend items in hands in case of client desync, because the item use got cancelled.
+ // For example, when cancelling the leash event
+ public void resendItemInHands() {
@@ -128,9 +144,9 @@
+ }
+
+ return blockposition;
+ }
}
+ // CraftBukkit end
+
@Override
public BlockPosition adjustSpawnLocation(WorldServer worldserver, BlockPosition blockposition) {
AxisAlignedBB axisalignedbb = this.getDimensions(EntityPose.STANDING).makeBoundingBox(Vec3D.ZERO);
@@ -141,7 +157,30 @@
int i = Math.max(0, this.server.getSpawnRadius(worldserver));
int j = MathHelper.floor(worldserver.getWorldBorder().getDistanceToBorder((double) blockposition.getX(), (double) blockposition.getZ()));
@@ -366,7 +468,7 @@
@@ -397,14 +508,20 @@
Objects.requireNonNull(blockposition);
crashreportsystemdetails.setDetail("Origin", blockposition::toString);
+ // CraftBukkit start - decompile error
+ int finalI = i;
crashreportsystemdetails.setDetail("Radius", () -> {
- return Integer.toString(i);
+ return Integer.toString(finalI);
+ // CraftBukkit end
});
crashreportsystemdetails.setDetail("Candidate", () -> {
return "[" + l2 + "," + i3 + "]";
});
+ // CraftBukkit start - decompile error
+ int finalL1 = l1;
crashreportsystemdetails.setDetail("Progress", () -> {
- return "" + l1 + " out of " + i1;
+ return "" + finalL1 + " out of " + i1;
+ // CraftBukkit end
});
throw new ReportedException(crashreport);
}
@@ -442,7 +559,7 @@
dataresult = WardenSpawnTracker.CODEC.parse(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.get("warden_spawn_tracker")));
logger = EntityPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -150,9 +189,9 @@
this.wardenSpawnTracker = wardenspawntracker;
});
}
@@ -381,17 +483,26 @@
if (nbttagcompound.contains("recipeBook", 10)) {
this.recipeBook.fromNbt(nbttagcompound.getCompound("recipeBook"), this.server.getRecipeManager());
@@ -459,17 +576,26 @@
return this.server.getRecipeManager().byKey(resourcekey).isPresent();
});
}
+ this.getBukkitEntity().readExtraData(nbttagcompound); // CraftBukkit
@@ -178,7 +217,7 @@
Logger logger1 = EntityPlayer.LOGGER;
Objects.requireNonNull(logger1);
@@ -406,7 +517,7 @@
@@ -484,7 +610,7 @@
dataresult = BlockPosition.CODEC.parse(DynamicOpsNBT.INSTANCE, nbtbase);
logger = EntityPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -187,7 +226,7 @@
this.raidOmenPosition = blockposition;
});
}
@@ -416,7 +527,7 @@
@@ -494,7 +620,7 @@
@Override
public void addAdditionalSaveData(NBTTagCompound nbttagcompound) {
super.addAdditionalSaveData(nbttagcompound);
@@ -196,7 +235,15 @@
Logger logger = EntityPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -437,7 +548,20 @@
@@ -528,6 +654,7 @@
nbttagcompound.put("SpawnDimension", nbtbase);
});
}
+ this.getBukkitEntity().setExtraData(nbttagcompound); // CraftBukkit
nbttagcompound.putBoolean("spawn_extra_particles_on_fall", this.spawnExtraParticlesOnFall);
if (this.raidOmenPosition != null) {
@@ -546,7 +673,20 @@
Entity entity = this.getRootVehicle();
Entity entity1 = this.getVehicle();
@@ -215,18 +262,43 @@
+
+ if (persistVehicle && entity1 != null && entity != this && entity.hasExactlyOnePlayerPassenger()) {
+ // CraftBukkit end
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
NBTTagCompound nbttagcompound2 = new NBTTagCompound();
NBTTagCompound nbttagcompound3 = new NBTTagCompound();
@@ -462,6 +586,7 @@
nbttagcompound.put("SpawnDimension", nbtbase);
});
}
+ this.getBukkitEntity().setExtraData(nbttagcompound); // CraftBukkit
@@ -600,12 +740,12 @@
nbttagcompound.putBoolean("spawn_extra_particles_on_fall", this.spawnExtraParticlesOnFall);
if (this.raidOmenPosition != null) {
@@ -475,6 +600,29 @@
if (!this.isPassenger()) {
EntityPlayer.LOGGER.warn("Couldn't reattach entity to player");
- entity.discard();
+ entity.discard(null); // CraftBukkit - add Bukkit remove cause
iterator = entity.getIndirectPassengers().iterator();
while (iterator.hasNext()) {
entity1 = (Entity) iterator.next();
- entity1.discard();
+ entity1.discard(null); // CraftBukkit - add Bukkit remove cause
}
}
}
@@ -627,7 +767,7 @@
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
entityenderpearl.save(nbttagcompound1);
- DataResult dataresult = MinecraftKey.CODEC.encodeStart(DynamicOpsNBT.INSTANCE, entityenderpearl.level().dimension().location());
+ DataResult<NBTBase> dataresult = MinecraftKey.CODEC.encodeStart(DynamicOpsNBT.INSTANCE, entityenderpearl.level().dimension().location()); // CraftBukkit - decompile error
Logger logger = EntityPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -653,7 +793,7 @@
nbttaglist.forEach((nbtbase1) -> {
if (nbtbase1 instanceof NBTTagCompound nbttagcompound) {
if (nbttagcompound.contains("ender_pearl_dimension")) {
- DataResult dataresult = World.RESOURCE_KEY_CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.get("ender_pearl_dimension"));
+ DataResult<ResourceKey<World>> dataresult = World.RESOURCE_KEY_CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.get("ender_pearl_dimension")); // CraftBukkit - decompile error
Logger logger = EntityPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -688,6 +828,29 @@
}
@@ -256,7 +328,7 @@
public void setExperiencePoints(int i) {
float f = (float) this.getXpNeededForNextLevel();
float f1 = (f - 1.0F) / f;
@@ -533,6 +681,11 @@
@@ -746,6 +909,11 @@
@Override
public void tick() {
@@ -268,7 +340,7 @@
this.gameMode.tick();
this.wardenSpawnTracker.tick();
--this.spawnInvulnerableTime;
@@ -613,7 +766,7 @@
@@ -822,7 +990,7 @@
}
if (this.getHealth() != this.lastSentHealth || this.lastSentFood != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.lastFoodSaturationZero) {
@@ -277,7 +349,7 @@
this.lastSentHealth = this.getHealth();
this.lastSentFood = this.foodData.getFoodLevel();
this.lastFoodSaturationZero = this.foodData.getSaturationLevel() == 0.0F;
@@ -644,6 +797,12 @@
@@ -853,6 +1021,12 @@
this.updateScoreForCriteria(IScoreboardCriteria.EXPERIENCE, MathHelper.ceil((float) this.lastRecordedExperience));
}
@@ -290,7 +362,7 @@
if (this.experienceLevel != this.lastRecordedLevel) {
this.lastRecordedLevel = this.experienceLevel;
this.updateScoreForCriteria(IScoreboardCriteria.LEVEL, MathHelper.ceil((float) this.lastRecordedLevel));
@@ -658,6 +817,20 @@
@@ -867,6 +1041,20 @@
CriterionTriggers.LOCATION.trigger(this);
}
@@ -311,7 +383,16 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking player");
CrashReportSystemDetails crashreportsystemdetails = crashreport.addCategory("Player being ticked");
@@ -703,7 +876,8 @@
@@ -895,7 +1083,7 @@
if (this.level().getDifficulty() == EnumDifficulty.PEACEFUL && this.serverLevel().getGameRules().getBoolean(GameRules.RULE_NATURAL_REGENERATION)) {
if (this.tickCount % 20 == 0) {
if (this.getHealth() < this.getMaxHealth()) {
- this.heal(1.0F);
+ this.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.REGEN); // CraftBukkit - added regain reason of "REGEN" for filtering purposes.
}
float f = this.foodData.getSaturationLevel();
@@ -948,7 +1136,8 @@
}
private void updateScoreForCriteria(IScoreboardCriteria iscoreboardcriteria, int i) {
@@ -321,16 +402,16 @@
scoreaccess.set(i);
});
}
@@ -712,9 +886,47 @@
@@ -957,9 +1146,47 @@
public void die(DamageSource damagesource) {
this.gameEvent(GameEvent.ENTITY_DIE);
boolean flag = this.level().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
boolean flag = this.serverLevel().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
+ // CraftBukkit start - fire PlayerDeathEvent
+ if (this.isRemoved()) {
+ return;
+ }
+ java.util.List<org.bukkit.inventory.ItemStack> loot = new java.util.ArrayList<>(this.getInventory().getContainerSize());
+ boolean keepInventory = this.level().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || this.isSpectator();
+ boolean keepInventory = this.serverLevel().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || this.isSpectator();
- if (flag) {
- IChatBaseComponent ichatbasecomponent = this.getCombatTracker().getDeathMessage();
@@ -342,7 +423,7 @@
+ }
+ }
+ // SPIGOT-5071: manually add player loot tables (SPIGOT-5195 - ignores keepInventory rule)
+ this.dropFromLootTable(damagesource, this.lastHurtByPlayerTime > 0);
+ this.dropFromLootTable(this.serverLevel(), damagesource, this.lastHurtByPlayerTime > 0);
+ this.dropCustomDeathLoot(this.serverLevel(), damagesource, flag);
+
+ loot.addAll(this.drops);
@@ -371,15 +452,15 @@
this.connection.send(new ClientboundPlayerCombatKillPacket(this.getId(), ichatbasecomponent), PacketSendListener.exceptionallySend(() -> {
boolean flag1 = true;
@@ -745,12 +957,18 @@
if (this.level().getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) {
@@ -990,12 +1217,18 @@
if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) {
this.tellNeutralMobsThatIDied();
}
-
- if (!this.isSpectator()) {
- this.dropAllDeathLoot(this.serverLevel(), damagesource);
+ // SPIGOT-5478 must be called manually now
+ this.dropExperience(damagesource.getEntity());
+ this.dropExperience(this.serverLevel(), damagesource.getEntity());
+ // we clean the player's inventory after the EntityDeathEvent is called so plugins can get the exact state of the inventory.
+ if (!event.getKeepInventory()) {
+ this.getInventory().clearContent();
@@ -394,7 +475,7 @@
EntityLiving entityliving = this.getKillCredit();
if (entityliving != null) {
@@ -785,10 +1003,12 @@
@@ -1030,10 +1263,12 @@
if (entity != this) {
super.awardKillScore(entity, i, damagesource);
this.increaseScore(i);
@@ -409,7 +490,7 @@
} else {
this.awardStat(StatisticList.MOB_KILLS);
}
@@ -806,7 +1026,8 @@
@@ -1051,7 +1286,8 @@
int i = scoreboardteam.getColor().getId();
if (i >= 0 && i < aiscoreboardcriteria.length) {
@@ -419,7 +500,7 @@
}
}
@@ -856,10 +1077,16 @@
@@ -1101,10 +1337,16 @@
}
private boolean isPvpAllowed() {
@@ -428,53 +509,53 @@
+ return this.level().pvpMode;
}
- public DimensionTransition findRespawnPositionAndUseSpawnBlock(boolean flag, DimensionTransition.a dimensiontransition_a) {
- public TeleportTransition findRespawnPositionAndUseSpawnBlock(boolean flag, TeleportTransition.a teleporttransition_a) {
+ // CraftBukkit start
+ public DimensionTransition findRespawnPositionAndUseSpawnBlock(boolean flag, DimensionTransition.a dimensiontransition_a, PlayerRespawnEvent.RespawnReason reason) {
+ DimensionTransition dimensionTransition;
+ public TeleportTransition findRespawnPositionAndUseSpawnBlock(boolean flag, TeleportTransition.a teleporttransition_a, PlayerRespawnEvent.RespawnReason reason) {
+ TeleportTransition teleportTransition;
+ boolean isBedSpawn = false;
+ boolean isAnchorSpawn = false;
+ // CraftBukkit end
BlockPosition blockposition = this.getRespawnPosition();
float f = this.getRespawnAngle();
boolean flag1 = this.isRespawnForced();
@@ -871,13 +1098,32 @@
@@ -1116,13 +1358,32 @@
if (optional.isPresent()) {
EntityPlayer.RespawnPosAngle entityplayer_respawnposangle = (EntityPlayer.RespawnPosAngle) optional.get();
- return new DimensionTransition(worldserver, entityplayer_respawnposangle.position(), Vec3D.ZERO, entityplayer_respawnposangle.yaw(), 0.0F, dimensiontransition_a);
- return new TeleportTransition(worldserver, entityplayer_respawnposangle.position(), Vec3D.ZERO, entityplayer_respawnposangle.yaw(), 0.0F, teleporttransition_a);
+ // CraftBukkit start
+ isBedSpawn = entityplayer_respawnposangle.isBedSpawn();
+ isAnchorSpawn = entityplayer_respawnposangle.isAnchorSpawn();
+ dimensionTransition = new DimensionTransition(worldserver, entityplayer_respawnposangle.position(), Vec3D.ZERO, entityplayer_respawnposangle.yaw(), 0.0F, dimensiontransition_a);
+ teleportTransition = new TeleportTransition(worldserver, entityplayer_respawnposangle.position(), Vec3D.ZERO, entityplayer_respawnposangle.yaw(), 0.0F, teleporttransition_a);
+ // CraftBukkit end
} else {
- return DimensionTransition.missingRespawnBlock(this.server.overworld(), this, dimensiontransition_a);
+ dimensionTransition = DimensionTransition.missingRespawnBlock(this.server.overworld(), this, dimensiontransition_a); // CraftBukkit
- return TeleportTransition.missingRespawnBlock(this.server.overworld(), this, teleporttransition_a);
+ teleportTransition = TeleportTransition.missingRespawnBlock(this.server.overworld(), this, teleporttransition_a); // CraftBukkit
}
} else {
- return new DimensionTransition(this.server.overworld(), this, dimensiontransition_a);
+ dimensionTransition = new DimensionTransition(this.server.overworld(), this, dimensiontransition_a); // CraftBukkit
- return new TeleportTransition(this.server.overworld(), this, teleporttransition_a);
+ teleportTransition = new TeleportTransition(this.server.overworld(), this, teleporttransition_a); // CraftBukkit
}
+ // CraftBukkit start
+ if (reason == null) {
+ return dimensionTransition;
+ return teleportTransition;
+ }
+
+ Player respawnPlayer = this.getBukkitEntity();
+ Location location = CraftLocation.toBukkit(dimensionTransition.pos(), dimensionTransition.newLevel().getWorld(), dimensionTransition.yRot(), dimensionTransition.xRot());
+ Location location = CraftLocation.toBukkit(teleportTransition.position(), teleportTransition.newLevel().getWorld(), teleportTransition.yRot(), teleportTransition.xRot());
+
+ PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn, isAnchorSpawn, reason);
+ this.level().getCraftServer().getPluginManager().callEvent(respawnEvent);
+
+ location = respawnEvent.getRespawnLocation();
+
+ return new DimensionTransition(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location), dimensionTransition.speed(), location.getYaw(), location.getPitch(), dimensionTransition.missingRespawnBlock(), dimensionTransition.postDimensionTransition(), dimensionTransition.cause());
+ return new TeleportTransition(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location), teleportTransition.deltaMovement(), location.getYaw(), location.getPitch(), teleportTransition.missingRespawnBlock(), teleportTransition.asPassenger(), teleportTransition.relatives(), teleportTransition.postTeleportTransition(), teleportTransition.cause());
+ // CraftBukkit end
}
public static Optional<EntityPlayer.RespawnPosAngle> findRespawnAndUseSpawnBlock(WorldServer worldserver, BlockPosition blockposition, float f, boolean flag, boolean flag1) {
@@ -892,11 +1138,11 @@
@@ -1137,11 +1398,11 @@
}
return optional.map((vec3d) -> {
@@ -488,7 +569,7 @@
});
} else if (!flag) {
return Optional.empty();
@@ -905,7 +1151,7 @@
@@ -1150,7 +1411,7 @@
IBlockData iblockdata1 = worldserver.getBlockState(blockposition.above());
boolean flag3 = iblockdata1.getBlock().isPossibleToRespawnInThis(iblockdata1);
@@ -497,32 +578,49 @@
}
}
@@ -923,6 +1169,7 @@
@@ -1168,6 +1429,7 @@
@Nullable
@Override
public Entity changeDimension(DimensionTransition dimensiontransition) {
public EntityPlayer teleport(TeleportTransition teleporttransition) {
+ if (this.isSleeping()) return null; // CraftBukkit - SPIGOT-3154
if (this.isRemoved()) {
return null;
} else {
@@ -932,14 +1179,21 @@
@@ -1177,18 +1439,38 @@
WorldServer worldserver = dimensiontransition.newLevel();
WorldServer worldserver = teleporttransition.newLevel();
WorldServer worldserver1 = this.serverLevel();
- ResourceKey<World> resourcekey = worldserver1.dimension();
+ // CraftBukkit start
+ ResourceKey<WorldDimension> resourcekey = worldserver1.getTypeKey();
+
+ Location enter = this.getBukkitEntity().getLocation();
+ PositionMoveRotation absolutePosition = PositionMoveRotation.calculateAbsolute(PositionMoveRotation.of(this), PositionMoveRotation.of(teleporttransition), teleporttransition.relatives());
+ Location exit = (worldserver == null) ? null : CraftLocation.toBukkit(absolutePosition.position(), worldserver.getWorld(), absolutePosition.yRot(), absolutePosition.xRot());
+ PlayerTeleportEvent tpEvent = new PlayerTeleportEvent(this.getBukkitEntity(), enter, exit, teleporttransition.cause());
+ Bukkit.getServer().getPluginManager().callEvent(tpEvent);
+ Location newExit = tpEvent.getTo();
+ if (tpEvent.isCancelled() || newExit == null) {
+ return null;
+ }
+ if (!newExit.equals(exit)) {
+ worldserver = ((CraftWorld) newExit.getWorld()).getHandle();
+ teleporttransition = new TeleportTransition(worldserver, CraftLocation.toVec3D(newExit), Vec3D.ZERO, newExit.getYaw(), newExit.getPitch(), teleporttransition.missingRespawnBlock(), teleporttransition.asPassenger(), Set.of(), teleporttransition.postTeleportTransition(), teleporttransition.cause());
+ }
+ // CraftBukkit end
if (!teleporttransition.asPassenger()) {
this.stopRiding();
}
- if (worldserver.dimension() == resourcekey) {
- this.connection.teleport(dimensiontransition.pos().x, dimensiontransition.pos().y, dimensiontransition.pos().z, dimensiontransition.yRot(), dimensiontransition.xRot());
+ if (worldserver != null && worldserver.dimension() == worldserver1.dimension()) { // CraftBukkit
+ boolean result = this.connection.teleport(dimensiontransition.pos().x, dimensiontransition.pos().y, dimensiontransition.pos().z, dimensiontransition.yRot(), dimensiontransition.xRot(), dimensiontransition.cause());
+ if (!result) {
+ return null;
+ }
- this.connection.teleport(PositionMoveRotation.of(teleporttransition), teleporttransition.relatives());
+ // CraftBukkit start
+ if (worldserver != null && worldserver.dimension() == worldserver1.dimension()) {
+ this.connection.internalTeleport(PositionMoveRotation.of(teleporttransition), teleporttransition.relatives());
+ // CraftBukkit end
this.connection.resetPosition();
dimensiontransition.postDimensionTransition().onTransition(this);
teleporttransition.postTeleportTransition().onTransition(this);
return this;
} else {
+ // CraftBukkit start
@@ -530,31 +628,22 @@
this.isChangingDimension = true;
WorldData worlddata = worldserver.getLevelData();
@@ -950,15 +1204,40 @@
@@ -1199,17 +1481,31 @@
playerlist.sendPlayerPermissionLevel(this);
worldserver1.removePlayerImmediately(this, Entity.RemovalReason.CHANGED_DIMENSION);
this.unsetRemoved();
+ */
+ // CraftBukkit end
worldserver1.getProfiler().push("moving");
GameProfilerFiller gameprofilerfiller = Profiler.get();
gameprofilerfiller.push("moving");
- if (resourcekey == World.OVERWORLD && worldserver.dimension() == World.NETHER) {
+ if (worldserver != null && resourcekey == WorldDimension.OVERWORLD && worldserver.getTypeKey() == WorldDimension.NETHER) { // CraftBukkit - empty to fall through to null to event
this.enteredNetherPosition = this.position();
}
+ // CraftBukkit start
+ Location enter = this.getBukkitEntity().getLocation();
+ Location exit = (worldserver == null) ? null : CraftLocation.toBukkit(dimensiontransition.pos(), worldserver.getWorld(), dimensiontransition.yRot(), dimensiontransition.xRot());
+ PlayerTeleportEvent tpEvent = new PlayerTeleportEvent(this.getBukkitEntity(), enter, exit, dimensiontransition.cause());
+ Bukkit.getServer().getPluginManager().callEvent(tpEvent);
+ if (tpEvent.isCancelled() || tpEvent.getTo() == null) {
+ return null;
+ }
+ exit = tpEvent.getTo();
+ worldserver = ((CraftWorld) exit.getWorld()).getHandle();
+ // CraftBukkit end
worldserver1.getProfiler().pop();
worldserver1.getProfiler().push("placing");
gameprofilerfiller.pop();
gameprofilerfiller.push("placing");
+ // CraftBukkit start
+ this.isChangingDimension = true; // CraftBukkit - Set teleport invulnerability only if player changing worlds
+ WorldData worlddata = worldserver.getLevelData();
@@ -568,12 +657,12 @@
+ this.unsetRemoved();
+ // CraftBukkit end
this.setServerLevel(worldserver);
- this.connection.teleport(dimensiontransition.pos().x, dimensiontransition.pos().y, dimensiontransition.pos().z, dimensiontransition.yRot(), dimensiontransition.xRot());
+ this.connection.teleport(exit); // CraftBukkit - use internal teleport without event
- this.connection.teleport(PositionMoveRotation.of(teleporttransition), teleporttransition.relatives());
+ this.connection.internalTeleport(PositionMoveRotation.of(teleporttransition), teleporttransition.relatives()); // CraftBukkit - use internal teleport without event
this.connection.resetPosition();
worldserver.addDuringTeleport(this);
worldserver1.getProfiler().pop();
@@ -971,21 +1250,47 @@
gameprofilerfiller.pop();
@@ -1223,11 +1519,29 @@
this.lastSentExp = -1;
this.lastSentHealth = -1.0F;
this.lastSentFood = -1;
@@ -600,6 +689,10 @@
+ }
+ // CraftBukkit end
+
@Override
public void forceSetRotation(float f, float f1) {
this.connection.send(new ClientboundPlayerRotationPacket(f, f1));
@@ -1236,13 +1550,21 @@
public void triggerDimensionChangeTriggers(WorldServer worldserver) {
ResourceKey<World> resourcekey = worldserver.dimension();
ResourceKey<World> resourcekey1 = this.level().dimension();
@@ -624,7 +717,7 @@
this.enteredNetherPosition = null;
}
@@ -1002,19 +1307,17 @@
@@ -1259,19 +1581,17 @@
this.containerMenu.broadcastChanges();
}
@@ -648,7 +741,7 @@
if (this.level().isDay()) {
return Either.left(EntityHuman.EnumBedResult.NOT_POSSIBLE_NOW);
} else {
@@ -1031,7 +1334,36 @@
@@ -1288,7 +1608,36 @@
}
}
@@ -686,7 +779,7 @@
this.awardStat(StatisticList.SLEEP_IN_BED);
CriterionTriggers.SLEPT_IN_BED.trigger(this);
});
@@ -1044,9 +1376,8 @@
@@ -1301,9 +1650,8 @@
return either;
}
}
@@ -697,7 +790,7 @@
}
@Override
@@ -1073,13 +1404,31 @@
@@ -1330,13 +1678,31 @@
@Override
public void stopSleepInBed(boolean flag, boolean flag1) {
@@ -730,7 +823,7 @@
}
}
@@ -1146,8 +1495,9 @@
@@ -1403,8 +1769,9 @@
this.connection.send(new PacketPlayOutOpenSignEditor(tileentitysign.getBlockPos(), flag));
}
@@ -741,7 +834,7 @@
}
@Override
@@ -1155,13 +1505,35 @@
@@ -1412,13 +1779,35 @@
if (itileinventory == null) {
return OptionalInt.empty();
} else {
@@ -777,7 +870,7 @@
if (container == null) {
if (this.isSpectator()) {
this.displayClientMessage(IChatBaseComponent.translatable("container.spectatorCantOpen").withStyle(EnumChatFormat.RED), true);
@@ -1169,9 +1541,11 @@
@@ -1426,9 +1815,11 @@
return OptionalInt.empty();
} else {
@@ -791,7 +884,7 @@
return OptionalInt.of(this.containerCounter);
}
}
@@ -1184,15 +1558,26 @@
@@ -1441,15 +1832,26 @@
@Override
public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) {
@@ -820,7 +913,7 @@
this.initMenu(this.containerMenu);
}
@@ -1215,6 +1600,7 @@
@@ -1472,6 +1874,7 @@
@Override
public void closeContainer() {
@@ -828,24 +921,7 @@
this.connection.send(new PacketPlayOutCloseWindow(this.containerMenu.containerId));
this.doCloseContainer();
}
@@ -1237,6 +1623,16 @@
}
this.jumping = flag;
+ // CraftBukkit start
+ if (flag1 != this.isShiftKeyDown()) {
+ PlayerToggleSneakEvent event = new PlayerToggleSneakEvent(this.getBukkitEntity(), flag1);
+ this.server.server.getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+ }
+ // CraftBukkit end
this.setShiftKeyDown(flag1);
}
@@ -1270,19 +1666,19 @@
@@ -1501,19 +1904,19 @@
i = Math.round((float) Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F);
if (i > 0) {
this.awardStat(StatisticList.SWIM_ONE_CM, i);
@@ -868,7 +944,7 @@
}
} else if (this.onClimbable()) {
if (d1 > 0.0D) {
@@ -1293,13 +1689,13 @@
@@ -1524,13 +1927,13 @@
if (i > 0) {
if (this.isSprinting()) {
this.awardStat(StatisticList.SPRINT_ONE_CM, i);
@@ -885,7 +961,7 @@
}
}
} else if (this.isFallFlying()) {
@@ -1342,7 +1738,7 @@
@@ -1573,7 +1976,7 @@
@Override
public void awardStat(Statistic<?> statistic, int i) {
this.stats.increment(this, statistic, i);
@@ -894,7 +970,7 @@
scoreaccess.add(i);
});
}
@@ -1350,7 +1746,7 @@
@@ -1581,7 +1984,7 @@
@Override
public void resetStat(Statistic<?> statistic) {
this.stats.setValue(this, statistic, 0);
@@ -903,7 +979,19 @@
}
@Override
@@ -1398,6 +1794,7 @@
@@ -1613,9 +2016,9 @@
super.jumpFromGround();
this.awardStat(StatisticList.JUMP);
if (this.isSprinting()) {
- this.causeFoodExhaustion(0.2F);
+ this.causeFoodExhaustion(0.2F, EntityExhaustionEvent.ExhaustionReason.JUMP_SPRINT); // CraftBukkit - EntityExhaustionEvent
} else {
- this.causeFoodExhaustion(0.05F);
+ this.causeFoodExhaustion(0.05F, EntityExhaustionEvent.ExhaustionReason.JUMP); // CraftBukkit - EntityExhaustionEvent
}
}
@@ -1641,6 +2044,7 @@
public void resetSentInfo() {
this.lastSentHealth = -1.0E8F;
@@ -911,16 +999,7 @@
}
@Override
@@ -1433,7 +1830,7 @@
this.gameMode.setGameModeForPlayer(entityplayer.gameMode.getGameModeForPlayer(), entityplayer.gameMode.getPreviousGameModeForPlayer());
this.onUpdateAbilities();
this.getAttributes().assignBaseValues(entityplayer.getAttributes());
- this.setHealth(this.getMaxHealth());
+ // this.setHealth(this.getMaxHealth()); // CraftBukkit
if (flag) {
this.getInventory().replaceWith(entityplayer.getInventory());
this.setHealth(entityplayer.getHealth());
@@ -1443,7 +1840,7 @@
@@ -1685,7 +2089,7 @@
while (iterator.hasNext()) {
MobEffect mobeffect = (MobEffect) iterator.next();
@@ -928,8 +1007,17 @@
+ // this.addEffect(new MobEffect(mobeffect)); // CraftBukkit
}
this.experienceLevel = entityplayer.experienceLevel;
@@ -1465,7 +1862,7 @@
this.getInventory().replaceWith(entityplayer.getInventory());
@@ -1696,7 +2100,7 @@
this.portalProcess = entityplayer.portalProcess;
} else {
this.getAttributes().assignBaseValues(entityplayer.getAttributes());
- this.setHealth(this.getMaxHealth());
+ // this.setHealth(this.getMaxHealth()); // CraftBukkit
if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || entityplayer.isSpectator()) {
this.getInventory().replaceWith(entityplayer.getInventory());
this.experienceLevel = entityplayer.experienceLevel;
@@ -1712,7 +2116,7 @@
this.lastSentExp = -1;
this.lastSentHealth = -1.0F;
this.lastSentFood = -1;
@@ -938,32 +1026,25 @@
this.seenCredits = entityplayer.seenCredits;
this.enteredNetherPosition = entityplayer.enteredNetherPosition;
this.chunkTrackingView = entityplayer.chunkTrackingView;
@@ -1516,6 +1913,12 @@
@@ -1768,7 +2172,7 @@
}
@Override
public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set<RelativeMovement> set, float f, float f1) {
+ // CraftBukkit start
+ return teleportTo(worldserver, d0, d1, d2, set, f, f1, TeleportCause.UNKNOWN);
+ }
+
+ public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set<RelativeMovement> set, float f, float f1, TeleportCause cause) {
+ // CraftBukkit end
- public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set<Relative> set, float f, float f1, boolean flag) {
+ public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set<Relative> set, float f, float f1, boolean flag, TeleportCause cause) { // CraftBukkit
ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(BlockPosition.containing(d0, d1, d2));
worldserver.getChunkSource().addRegionTicket(TicketType.POST_TELEPORT, chunkcoordintpair, 1, this.getId());
@@ -1525,9 +1928,9 @@
@@ -1780,7 +2184,7 @@
this.setCamera(this);
}
if (worldserver == this.level()) {
- this.connection.teleport(d0, d1, d2, f, f1, set);
+ this.connection.teleport(d0, d1, d2, f, f1, set, cause); // CraftBukkit
} else {
- this.teleportTo(worldserver, d0, d1, d2, f, f1);
+ this.teleportTo(worldserver, d0, d1, d2, f, f1, cause); // CraftBukkit
}
- boolean flag1 = super.teleportTo(worldserver, d0, d1, d2, set, f, f1, flag);
+ boolean flag1 = super.teleportTo(worldserver, d0, d1, d2, set, f, f1, flag, cause); // CraftBukkit
this.setYHeadRot(f);
@@ -1635,6 +2038,16 @@
if (flag1) {
this.setYHeadRot(set.contains(Relative.Y_ROT) ? this.getYHeadRot() + f : f);
@@ -1897,6 +2301,16 @@
}
public void updateOptions(ClientInformation clientinformation) {
@@ -980,16 +1061,16 @@
this.language = clientinformation.language();
this.requestedViewDistance = clientinformation.viewDistance();
this.chatVisibility = clientinformation.chatVisibility();
@@ -1718,7 +2131,7 @@
@@ -1981,7 +2395,7 @@
if (world instanceof WorldServer) {
WorldServer worldserver = (WorldServer) world;
- this.teleportTo(worldserver, this.camera.getX(), this.camera.getY(), this.camera.getZ(), Set.of(), this.getYRot(), this.getXRot());
+ this.teleportTo(worldserver, this.camera.getX(), this.camera.getY(), this.camera.getZ(), Set.of(), this.getYRot(), this.getXRot(), TeleportCause.SPECTATE); // CraftBukkit
- this.teleportTo(worldserver, this.camera.getX(), this.camera.getY(), this.camera.getZ(), Set.of(), this.getYRot(), this.getXRot(), false);
+ this.teleportTo(worldserver, this.camera.getX(), this.camera.getY(), this.camera.getZ(), Set.of(), this.getYRot(), this.getXRot(), false, TeleportCause.SPECTATE); // CraftBukkit
}
if (entity != null) {
@@ -1755,7 +2168,7 @@
@@ -2018,11 +2432,11 @@
@Nullable
public IChatBaseComponent getTabListDisplayName() {
@@ -997,33 +1078,13 @@
+ return listName; // CraftBukkit
}
public int getTabListOrder() {
- return 0;
+ return listOrder; // CraftBukkit
}
@Override
@@ -1776,14 +2189,24 @@
return this.advancements;
}
+ // CraftBukkit start
public void teleportTo(WorldServer worldserver, double d0, double d1, double d2, float f, float f1) {
+ this.teleportTo(worldserver, d0, d1, d2, f, f1, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.UNKNOWN);
+ }
+
+ public void teleportTo(WorldServer worldserver, double d0, double d1, double d2, float f, float f1, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) {
+ // CraftBukkit end
this.setCamera(this);
this.stopRiding();
+ /* CraftBukkit start - replace with bukkit handling for multi-world
if (worldserver == this.level()) {
this.connection.teleport(d0, d1, d2, f, f1);
} else {
this.changeDimension(new DimensionTransition(worldserver, new Vec3D(d0, d1, d2), Vec3D.ZERO, f, f1, DimensionTransition.DO_NOTHING));
}
+ */
+ this.getBukkitEntity().teleport(new Location(worldserver.getWorld(), d0, d1, d2, f, f1), cause);
+ // CraftBukkit end
}
@@ -1809,6 +2232,32 @@
@@ -2065,6 +2479,32 @@
}
public void setRespawnPosition(ResourceKey<World> resourcekey, @Nullable BlockPosition blockposition, float f, boolean flag, boolean flag1) {
@@ -1056,24 +1117,48 @@
if (blockposition != null) {
boolean flag2 = blockposition.equals(this.respawnPosition) && resourcekey.equals(this.respawnDimension);
@@ -1852,7 +2301,14 @@
@@ -2107,12 +2547,38 @@
}
@Override
public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1) {
- EntityItem entityitem = super.drop(itemstack, flag, flag1);
+ // CraftBukkit start - SPIGOT-2942: Add boolean to call event
+ return drop(itemstack, flag, flag1, true);
+ }
+
+ @Override
+ public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1, boolean callEvent) {
+ EntityItem entityitem = super.drop(itemstack, flag, flag1, callEvent);
+ // CraftBukkit end
- public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1) {
+ public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1, boolean callEvent) { // CraftBukkit - SPIGOT-2942: Add boolean to call event
EntityItem entityitem = this.createItemStackToDrop(itemstack, flag, flag1);
if (entityitem == null) {
return null;
@@ -2049,10 +2505,12 @@
this.awardStat(StatisticList.ITEM_BROKEN.get(item));
} else {
+ // CraftBukkit start - fire PlayerDropItemEvent
+ if (callEvent) {
+ Player player = (Player) this.getBukkitEntity();
+ org.bukkit.entity.Item drop = (org.bukkit.entity.Item) entityitem.getBukkitEntity();
+
+ PlayerDropItemEvent event = new PlayerDropItemEvent(player, drop);
+ this.level().getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ org.bukkit.inventory.ItemStack cur = player.getInventory().getItemInHand();
+ if (flag1 && (cur == null || cur.getAmount() == 0)) {
+ // The complete stack was dropped
+ player.getInventory().setItemInHand(drop.getItemStack());
+ } else if (flag1 && cur.isSimilar(drop.getItemStack()) && cur.getAmount() < cur.getMaxStackSize() && drop.getItemStack().getAmount() == 1) {
+ // Only one item is dropped
+ cur.setAmount(cur.getAmount() + 1);
+ player.getInventory().setItemInHand(cur);
+ } else {
+ // Fallback
+ player.getInventory().addItem(drop.getItemStack());
+ }
+ return null;
+ }
+ }
+ // CraftBukkit end
+
this.level().addFreshEntity(entityitem);
ItemStack itemstack1 = entityitem.getItem();
@@ -2394,10 +2860,12 @@
return TicketType.ENDER_PEARL.timeout();
}
- public static record RespawnPosAngle(Vec3D position, float yaw) {
@@ -1088,7 +1173,7 @@
}
private static float calculateLookAtYaw(Vec3D vec3d, BlockPosition blockposition) {
@@ -2061,4 +2519,147 @@
@@ -2406,4 +2874,146 @@
return (float) MathHelper.wrapDegrees(MathHelper.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D);
}
}
@@ -1195,7 +1280,6 @@
+
+ public void reset() {
+ float exp = 0;
+ boolean keepInventory = this.level().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY);
+
+ if (this.keepLevel) { // CraftBukkit - SPIGOT-6687: Only use keepLevel (was pre-set with RULE_KEEPINVENTORY value in PlayerDeathEvent)
+ exp = this.experienceProgress;
@@ -1207,7 +1291,7 @@
+ this.stopUsingItem(); // CraftBukkit - SPIGOT-6682: Clear active item on reset
+ this.setRemainingFireTicks(0);
+ this.fallDistance = 0;
+ this.foodData = new FoodMetaData(this);
+ this.foodData = new FoodMetaData();
+ this.experienceLevel = this.newLevel;
+ this.totalExperience = this.newTotalExp;
+ this.experienceProgress = 0;

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/EntityTrackerEntry.java
+++ b/net/minecraft/server/level/EntityTrackerEntry.java
@@ -46,6 +46,12 @@
@@ -50,6 +50,12 @@
import net.minecraft.world.phys.Vec3D;
import org.slf4j.Logger;
@@ -13,7 +13,7 @@
public class EntityTrackerEntry {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -70,8 +76,12 @@
@@ -74,8 +80,12 @@
private boolean wasOnGround;
@Nullable
private List<DataWatcher.c<?>> trackedDataValues;
@@ -27,7 +27,7 @@
this.level = worldserver;
this.broadcast = consumer;
this.entity = entity;
@@ -90,7 +100,7 @@
@@ -94,7 +104,7 @@
List<Entity> list = this.entity.getPassengers();
if (!list.equals(this.lastPassengers)) {
@@ -36,7 +36,7 @@
removedPassengers(list, this.lastPassengers).forEach((entity) -> {
if (entity instanceof EntityPlayer entityplayer) {
entityplayer.connection.teleport(entityplayer.getX(), entityplayer.getY(), entityplayer.getZ(), entityplayer.getYRot(), entityplayer.getXRot());
@@ -103,18 +113,18 @@
@@ -107,18 +117,18 @@
Entity entity = this.entity;
if (entity instanceof EntityItemFrame entityitemframe) {
@@ -59,7 +59,7 @@
worldmap.tickCarriedBy(entityplayer, itemstack);
Packet<?> packet = worldmap.getUpdatePacket(mapid, entityplayer);
@@ -232,6 +242,27 @@
@@ -248,6 +258,27 @@
++this.tickCount;
if (this.entity.hurtMarked) {
@@ -87,7 +87,7 @@
this.entity.hurtMarked = false;
this.broadcastAndSend(new PacketPlayOutEntityVelocity(this.entity));
}
@@ -260,7 +291,10 @@
@@ -298,7 +329,10 @@
public void sendPairingData(EntityPlayer entityplayer, Consumer<Packet<PacketListenerPlayOut>> consumer) {
if (this.entity.isRemoved()) {
@@ -99,7 +99,7 @@
}
Packet<PacketListenerPlayOut> packet = this.entity.getAddEntityPacket(this);
@@ -275,6 +309,12 @@
@@ -313,6 +347,12 @@
if (this.entity instanceof EntityLiving) {
Collection<AttributeModifiable> collection = ((EntityLiving) this.entity).getAttributes().getSyncableAttributes();
@@ -112,7 +112,7 @@
if (!collection.isEmpty()) {
consumer.accept(new PacketPlayOutUpdateAttributes(this.entity.getId(), collection));
}
@@ -305,6 +345,7 @@
@@ -344,6 +384,7 @@
if (!list.isEmpty()) {
consumer.accept(new PacketPlayOutEntityEquipment(this.entity.getId(), list));
}
@@ -120,7 +120,7 @@
}
if (!this.entity.getPassengers().isEmpty()) {
@@ -358,6 +399,11 @@
@@ -396,6 +437,11 @@
Set<AttributeModifiable> set = ((EntityLiving) this.entity).getAttributes().getAttributesToSync();
if (!set.isEmpty()) {

View File

@@ -52,15 +52,15 @@
}
@Nullable
@@ -134,6 +150,7 @@
if (chunk != null) {
@@ -138,6 +154,7 @@
boolean flag = this.hasChangedSections;
int i = this.levelHeightAccessor.getSectionIndex(blockposition.getY());
+ if (i < 0 || i >= this.changedBlocksPerSection.length) return; // CraftBukkit - SPIGOT-6086, SPIGOT-6296
+ if (i < 0 || i >= this.changedBlocksPerSection.length) return false; // CraftBukkit - SPIGOT-6086, SPIGOT-6296
if (this.changedBlocksPerSection[i] == null) {
this.hasChangedSections = true;
this.changedBlocksPerSection[i] = new ShortOpenHashSet();
@@ -208,8 +225,11 @@
@@ -224,8 +241,11 @@
PacketPlayOutMultiBlockChange packetplayoutmultiblockchange = new PacketPlayOutMultiBlockChange(sectionposition, shortset, chunksection);
this.broadcast(list, packetplayoutmultiblockchange);
@@ -73,7 +73,7 @@
});
}
}
@@ -275,7 +295,7 @@
@@ -291,7 +311,7 @@
this.pendingFullStateConfirmation = completablefuture1;
completablefuture.thenAccept((chunkresult) -> {
chunkresult.ifSuccess((chunk) -> {
@@ -82,7 +82,7 @@
});
});
}
@@ -285,6 +305,38 @@
@@ -301,6 +321,38 @@
playerchunkmap.onFullChunkStatusChange(this.pos, fullchunkstatus);
}
@@ -102,7 +102,7 @@
+ // Minecraft will apply the chunks tick lists to the world once the chunk got loaded, and then store the tick
+ // lists again inside the chunk once the chunk becomes inaccessible and set the chunk's needsSaving flag.
+ // These actions may however happen deferred, so we manually set the needsSaving flag already here.
+ chunk.setUnsaved(true);
+ chunk.markUnsaved();
+ chunk.unloadCallback();
+ });
+ }
@@ -121,7 +121,7 @@
protected void updateFutures(PlayerChunkMap playerchunkmap, Executor executor) {
FullChunkStatus fullchunkstatus = ChunkLevel.fullStatus(this.oldTicketLevel);
FullChunkStatus fullchunkstatus1 = ChunkLevel.fullStatus(this.ticketLevel);
@@ -341,6 +393,26 @@
@@ -357,6 +409,26 @@
this.onLevelChange.onLevelChange(this.pos, this::getQueueLevel, this.ticketLevel, this::setQueueLevel);
this.oldTicketLevel = this.ticketLevel;

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/PlayerChunkMap.java
+++ b/net/minecraft/server/level/PlayerChunkMap.java
@@ -102,6 +102,10 @@
@@ -104,6 +104,10 @@
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.slf4j.Logger;
@@ -11,7 +11,7 @@
public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.b, GeneratingChunkMap {
private static final ChunkResult<List<IChunkAccess>> UNLOADED_CHUNK_LIST_RESULT = ChunkResult.error("Unloaded chunks found in range");
@@ -145,6 +149,27 @@
@@ -149,6 +153,27 @@
public int serverViewDistance;
private final WorldGenContext worldGenContext;
@@ -39,7 +39,7 @@
public PlayerChunkMap(WorldServer worldserver, Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, StructureTemplateManager structuretemplatemanager, Executor executor, IAsyncTaskHandler<Runnable> iasynctaskhandler, ILightAccess ilightaccess, ChunkGenerator chunkgenerator, WorldLoadListener worldloadlistener, ChunkStatusUpdateListener chunkstatusupdatelistener, Supplier<WorldPersistentData> supplier, int i, boolean flag) {
super(new RegionStorageInfo(convertable_conversionsession.getLevelId(), worldserver.dimension(), "chunk"), convertable_conversionsession.getDimensionPath(worldserver.dimension()).resolve("region"), datafixer, flag);
this.visibleChunkMap = this.updatingChunkMap.clone();
@@ -164,7 +189,13 @@
@@ -170,7 +195,13 @@
IRegistryCustom iregistrycustom = worldserver.registryAccess();
long j = worldserver.getSeed();
@@ -54,7 +54,7 @@
this.randomState = RandomState.create((GeneratorSettingBase) chunkgeneratorabstract.generatorSettings().value(), (HolderGetter) iregistrycustom.lookupOrThrow(Registries.NOISE), j);
} else {
this.randomState = RandomState.create(GeneratorSettingBase.dummy(), (HolderGetter) iregistrycustom.lookupOrThrow(Registries.NOISE), j);
@@ -318,7 +349,7 @@
@@ -325,7 +356,7 @@
throw this.debugFuturesAndCreateReportedException(new IllegalStateException("At least one of the chunk futures were null"), "n/a");
}
@@ -63,7 +63,7 @@
if (ichunkaccess == null) {
return PlayerChunkMap.UNLOADED_CHUNK_LIST_RESULT;
@@ -937,7 +968,8 @@
@@ -977,7 +1008,8 @@
return ichunkaccess instanceof Chunk ? Optional.of((Chunk) ichunkaccess) : Optional.empty();
});
@@ -73,7 +73,7 @@
return chunk.getBlockEntities().size();
}).orElse(0), tickingtracker.getTicketDebugString(i), tickingtracker.getLevel(i), optional1.map((chunk) -> {
return chunk.getBlockTicks().count();
@@ -950,7 +982,7 @@
@@ -990,7 +1022,7 @@
private static String printFuture(CompletableFuture<ChunkResult<Chunk>> completablefuture) {
try {
@@ -82,13 +82,13 @@
return chunkresult != null ? (chunkresult.isSuccess() ? "done" : "unloaded") : "not completed";
} catch (CompletionException completionexception) {
@@ -962,12 +994,14 @@
@@ -1002,12 +1034,14 @@
private CompletableFuture<Optional<NBTTagCompound>> readChunk(ChunkCoordIntPair chunkcoordintpair) {
return this.read(chunkcoordintpair).thenApplyAsync((optional) -> {
- return optional.map(this::upgradeChunkTag);
+ return optional.map((nbttagcompound) -> upgradeChunkTag(nbttagcompound, chunkcoordintpair)); // CraftBukkit
}, SystemUtils.backgroundExecutor());
}, SystemUtils.backgroundExecutor().forName("upgradeChunk"));
}
- private NBTTagCompound upgradeChunkTag(NBTTagCompound nbttagcompound) {
@@ -99,8 +99,8 @@
+ // CraftBukkit end
}
boolean anyPlayerCloseEnoughForSpawning(ChunkCoordIntPair chunkcoordintpair) {
@@ -1370,7 +1404,7 @@
void forEachSpawnCandidateChunk(Consumer<PlayerChunk> consumer) {
@@ -1424,7 +1458,7 @@
public final Set<ServerPlayerConnection> seenBy = Sets.newIdentityHashSet();
public EntityTracker(final Entity entity, final int i, final int j, final boolean flag) {
@@ -109,7 +109,7 @@
this.entity = entity;
this.range = i;
this.lastSectionPos = SectionPosition.of((EntityAccess) entity);
@@ -1430,6 +1464,11 @@
@@ -1484,6 +1518,11 @@
double d2 = d0 * d0;
boolean flag = d1 <= d2 && this.entity.broadcastToPlayer(entityplayer) && PlayerChunkMap.this.isChunkTracked(entityplayer, this.entity.chunkPosition().x, this.entity.chunkPosition().z);

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/PlayerInteractManager.java
+++ b/net/minecraft/server/level/PlayerInteractManager.java
@@ -28,6 +28,27 @@
@@ -26,6 +26,27 @@
import net.minecraft.world.phys.Vec3D;
import org.slf4j.Logger;
@@ -28,7 +28,7 @@
public class PlayerInteractManager {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -58,9 +79,16 @@
@@ -56,9 +77,16 @@
if (enumgamemode == this.gameModeForPlayer) {
return false;
} else {
@@ -46,7 +46,7 @@
this.level.updateSleepingPlayerList();
if (enumgamemode == EnumGamemode.CREATIVE) {
this.player.resetCurrentImpulseContext();
@@ -94,7 +122,7 @@
@@ -92,7 +120,7 @@
}
public void tick() {
@@ -55,7 +55,7 @@
IBlockData iblockdata;
if (this.hasDelayedDestroy) {
@@ -148,11 +176,33 @@
@@ -146,11 +174,33 @@
if (packetplayinblockdig_enumplayerdigtype == PacketPlayInBlockDig.EnumPlayerDigType.START_DESTROY_BLOCK) {
if (!this.level.mayInteract(this.player, blockposition)) {
@@ -89,7 +89,7 @@
if (this.isCreative()) {
this.destroyAndAck(blockposition, j, "creative destroy");
return;
@@ -168,7 +218,19 @@
@@ -166,7 +216,19 @@
float f = 1.0F;
iblockdata = this.level.getBlockState(blockposition);
@@ -110,7 +110,7 @@
EnchantmentManager.onHitBlock(this.level, this.player.getMainHandItem(), this.player, this.player, EnumItemSlot.MAINHAND, Vec3D.atCenterOf(blockposition), iblockdata, (item) -> {
this.player.onEquippedItemBroken(item, EnumItemSlot.MAINHAND);
});
@@ -176,6 +238,26 @@
@@ -174,6 +236,26 @@
f = iblockdata.getDestroyProgress(this.player, this.player.level(), blockposition);
}
@@ -137,7 +137,7 @@
if (!iblockdata.isAir() && f >= 1.0F) {
this.destroyAndAck(blockposition, j, "insta mine");
} else {
@@ -220,13 +302,15 @@
@@ -218,13 +300,15 @@
} else if (packetplayinblockdig_enumplayerdigtype == PacketPlayInBlockDig.EnumPlayerDigType.ABORT_DESTROY_BLOCK) {
this.isDestroyingBlock = false;
if (!Objects.equals(this.destroyPos, blockposition)) {
@@ -154,7 +154,7 @@
}
}
@@ -244,10 +328,65 @@
@@ -242,10 +326,65 @@
public boolean destroyBlock(BlockPosition blockposition) {
IBlockData iblockdata = this.level.getBlockState(blockposition);
@@ -221,7 +221,7 @@
TileEntity tileentity = this.level.getBlockEntity(blockposition);
Block block = iblockdata.getBlock();
@@ -257,6 +396,10 @@
@@ -255,6 +394,10 @@
} else if (this.player.blockActionRestricted(this.level, blockposition, this.gameModeForPlayer)) {
return false;
} else {
@@ -232,7 +232,7 @@
IBlockData iblockdata1 = block.playerWillDestroy(this.level, blockposition, iblockdata, this.player);
boolean flag = this.level.removeBlock(blockposition, false);
@@ -265,19 +408,32 @@
@@ -263,19 +406,32 @@
}
if (this.isCreative()) {
@@ -268,7 +268,7 @@
}
}
}
@@ -315,14 +471,53 @@
@@ -321,14 +477,53 @@
}
}
@@ -290,7 +290,7 @@
+ cancelledBlock = !(itileinventory instanceof ITileInventory);
+ }
+
+ if (entityplayer.getCooldowns().isOnCooldown(itemstack.getItem())) {
+ if (entityplayer.getCooldowns().isOnCooldown(itemstack)) {
+ cancelledBlock = true;
+ }
+
@@ -322,11 +322,11 @@
if (itileinventory != null) {
entityplayer.openMenu(itileinventory);
@@ -353,7 +548,7 @@
@@ -359,7 +554,7 @@
}
}
- if (!itemstack.isEmpty() && !entityplayer.getCooldowns().isOnCooldown(itemstack.getItem())) {
- if (!itemstack.isEmpty() && !entityplayer.getCooldowns().isOnCooldown(itemstack)) {
+ if (!itemstack.isEmpty() && !interactResult) { // add !interactResult SPIGOT-764
ItemActionContext itemactioncontext = new ItemActionContext(entityplayer, enumhand, movingobjectpositionblock);

View File

@@ -1,7 +1,7 @@
--- a/net/minecraft/server/level/TicketType.java
+++ b/net/minecraft/server/level/TicketType.java
@@ -22,6 +22,8 @@
public static final TicketType<BlockPosition> PORTAL = create("portal", BaseBlockPosition::compareTo, 300);
@@ -23,6 +23,8 @@
public static final TicketType<ChunkCoordIntPair> ENDER_PEARL = create("ender_pearl", Comparator.comparingLong(ChunkCoordIntPair::toLong), 40);
public static final TicketType<Integer> POST_TELEPORT = create("post_teleport", Integer::compareTo, 5);
public static final TicketType<ChunkCoordIntPair> UNKNOWN = create("unknown", Comparator.comparingLong(ChunkCoordIntPair::toLong), 1);
+ public static final TicketType<Unit> PLUGIN = create("plugin", (a, b) -> 0); // CraftBukkit

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/WorldServer.java
+++ b/net/minecraft/server/level/WorldServer.java
@@ -171,6 +171,23 @@
@@ -173,6 +173,23 @@
import net.minecraft.world.ticks.TickListServer;
import org.slf4j.Logger;
@@ -21,31 +21,28 @@
+import org.bukkit.event.world.TimeSkipEvent;
+// CraftBukkit end
+
public class WorldServer extends World implements GeneratorAccessSeed {
public class WorldServer extends World implements ServerEntityGetter, GeneratorAccessSeed {
public static final BlockPosition END_SPAWN_POINT = new BlockPosition(100, 50, 0);
@@ -184,7 +201,7 @@
final List<EntityPlayer> players;
@@ -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;
final EntityTickList entityTickList = new EntityTickList();
public final PersistentEntitySectionManager<Entity> entityManager;
@@ -211,12 +228,30 @@
@@ -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) {
- IRegistryCustom.Dimension iregistrycustom_dimension = minecraftserver.registryAccess();
- Holder holder = worlddimension.type();
- super(iworlddataserver, resourcekey, minecraftserver.registryAccess(), worlddimension.type(), false, flag, i, minecraftserver.getMaxChainedNeighborUpdates());
+ // CraftBukkit start
+ public final Convertable.ConversionSession convertable;
+ public final UUID uuid;
- Objects.requireNonNull(minecraftserver);
- super(iworlddataserver, resourcekey, iregistrycustom_dimension, holder, minecraftserver::getProfiler, false, flag, i, minecraftserver.getMaxChainedNeighborUpdates());
+
+ public Chunk getChunkIfLoaded(int x, int z) {
+ return this.chunkSource.getChunk(x, z, false);
+ }
@@ -57,19 +54,13 @@
+
+ // 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) {
+ // IRegistryCustom.Dimension iregistrycustom_dimension = minecraftserver.registryAccess(); // CraftBukkit - decompile error
+ // Holder holder = worlddimension.type(); // CraftBukkit - decompile error
+
+ // Objects.requireNonNull(minecraftserver); // CraftBukkit - decompile error
+ super(iworlddataserver, resourcekey, minecraftserver.registryAccess(), worlddimension.type(), minecraftserver::getProfiler, false, flag, i, minecraftserver.getMaxChainedNeighborUpdates(), gen, biomeProvider, env);
+ 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.players = Lists.newArrayList();
this.entityTickList = new EntityTickList();
this.blockTicks = new TickListServer<>(this::isPositionTickingWithEntitiesLoaded, this.getProfilerSupplier());
@@ -231,6 +266,22 @@
this.tickTime = flag1;
this.server = minecraftserver;
this.customSpawners = list;
this.serverLevelData = iworlddataserver;
ChunkGenerator chunkgenerator = worlddimension.generator();
@@ -77,7 +68,7 @@
+ serverLevelData.setWorld(this);
+
+ if (biomeProvider != null) {
+ WorldChunkManager worldChunkManager = new CustomWorldChunkManager(getWorld(), biomeProvider, server.registryAccess().registryOrThrow(Registries.BIOME));
+ 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) {
@@ -92,7 +83,7 @@
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);
@@ -258,9 +309,9 @@
@@ -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);
@@ -105,7 +96,7 @@
} else {
this.dragonFight = null;
}
@@ -270,6 +321,7 @@
@@ -259,6 +310,7 @@
this.randomSequences = (RandomSequences) Objects.requireNonNullElseGet(randomsequences, () -> {
return (RandomSequences) this.getDataStorage().computeIfAbsent(RandomSequences.factory(l), "random_sequences");
});
@@ -113,7 +104,7 @@
}
/** @deprecated */
@@ -314,12 +366,20 @@
@@ -304,12 +356,20 @@
long j;
if (this.sleepStatus.areEnoughSleeping(i) && this.sleepStatus.areEnoughDeepSleeping(i, this.players)) {
@@ -137,7 +128,7 @@
if (this.getGameRules().getBoolean(GameRules.RULE_WEATHER_CYCLE) && this.isRaining()) {
this.resetWeatherCycle();
}
@@ -354,7 +414,7 @@
@@ -344,7 +404,7 @@
this.handlingTick = false;
gameprofilerfiller.pop();
@@ -146,16 +137,7 @@
if (flag1) {
this.resetEmptyTime();
@@ -370,7 +430,7 @@
this.entityTickList.forEach((entity) -> {
if (!entity.isRemoved()) {
- if (this.shouldDiscardEntity(entity)) {
+ if (false && this.shouldDiscardEntity(entity)) { // CraftBukkit - We prevent spawning in general, so this butchering is not needed
entity.discard();
} else if (!tickratemanager.isEntityFrozen(entity)) {
gameprofilerfiller.push("checkDespawn");
@@ -442,7 +502,7 @@
@@ -428,7 +488,7 @@
private void wakeUpAllPlayers() {
this.sleepStatus.removeAllSleepers();
@@ -164,7 +146,7 @@
entityplayer.stopSleepInBed(false, false);
});
}
@@ -469,7 +529,7 @@
@@ -455,7 +515,7 @@
entityhorseskeleton.setTrap(true);
entityhorseskeleton.setAge(0);
entityhorseskeleton.setPos((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ());
@@ -173,7 +155,7 @@
}
}
@@ -478,7 +538,7 @@
@@ -464,7 +524,7 @@
if (entitylightning != null) {
entitylightning.moveTo(Vec3D.atBottomCenterOf(blockposition));
entitylightning.setVisualOnly(flag1);
@@ -182,7 +164,7 @@
}
}
}
@@ -534,7 +594,7 @@
@@ -520,7 +580,7 @@
BiomeBase biomebase = (BiomeBase) this.getBiome(blockposition1).value();
if (biomebase.shouldFreeze(this, blockposition2)) {
@@ -191,7 +173,7 @@
}
if (this.isRaining()) {
@@ -550,10 +610,10 @@
@@ -536,10 +596,10 @@
IBlockData iblockdata1 = (IBlockData) iblockdata.setValue(BlockSnow.LAYERS, j + 1);
Block.pushEntitiesUp(iblockdata, iblockdata1, this, blockposition1);
@@ -204,7 +186,7 @@
}
}
@@ -714,6 +774,7 @@
@@ -700,6 +760,7 @@
this.rainLevel = MathHelper.clamp(this.rainLevel, 0.0F, 1.0F);
}
@@ -212,7 +194,7 @@
if (this.oRainLevel != this.rainLevel) {
this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.RAIN_LEVEL_CHANGE, this.rainLevel), this.dimension());
}
@@ -732,15 +793,48 @@
@@ -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));
}
@@ -263,15 +245,15 @@
}
public void resetEmptyTime() {
@@ -775,6 +869,7 @@
@@ -762,6 +856,7 @@
});
gameprofilerfiller.incrementCounter("tickNonPassenger");
entity.tick();
+ entity.postTick(); // CraftBukkit
this.getProfiler().pop();
gameprofilerfiller.pop();
Iterator iterator = entity.getPassengers().iterator();
@@ -798,6 +893,7 @@
@@ -785,6 +880,7 @@
});
gameprofilerfiller.incrementCounter("tickPassenger");
entity1.rideTick();
@@ -279,7 +261,7 @@
gameprofilerfiller.pop();
Iterator iterator = entity1.getPassengers().iterator();
@@ -822,6 +918,7 @@
@@ -809,6 +905,7 @@
ChunkProviderServer chunkproviderserver = this.getChunkSource();
if (!flag1) {
@@ -287,7 +269,7 @@
if (iprogressupdate != null) {
iprogressupdate.progressStartNoAbort(IChatBaseComponent.translatable("menu.savingLevel"));
}
@@ -839,11 +936,19 @@
@@ -826,11 +923,19 @@
}
}
@@ -301,14 +283,14 @@
+ // CraftBukkit end
}
private void saveLevelData() {
private void saveLevelData(boolean flag) {
if (this.dragonFight != null) {
- this.server.getWorldData().setEndDragonFightData(this.dragonFight.saveData());
+ this.serverLevelData.setEndDragonFightData(this.dragonFight.saveData()); // CraftBukkit
}
this.getChunkSource().getDataStorage().save();
@@ -908,18 +1013,40 @@
WorldPersistentData worldpersistentdata = this.getChunkSource().getDataStorage();
@@ -902,18 +1007,40 @@
@Override
public boolean addFreshEntity(Entity entity) {
@@ -352,7 +334,7 @@
}
}
@@ -944,24 +1071,37 @@
@@ -938,24 +1065,37 @@
this.entityManager.addNewEntity(entityplayer);
}
@@ -394,19 +376,19 @@
return true;
}
}
@@ -972,13 +1112,35 @@
@@ -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);
+
@@ -431,7 +413,7 @@
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
@@ -987,6 +1149,12 @@
@@ -981,6 +1143,12 @@
double d1 = (double) blockposition.getY() - entityplayer.getY();
double d2 = (double) blockposition.getZ() - entityplayer.getZ();
@@ -444,7 +426,7 @@
if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) {
entityplayer.connection.send(new PacketPlayOutBlockBreakAnimation(i, blockposition, j));
}
@@ -1047,7 +1215,18 @@
@@ -1059,7 +1227,18 @@
Iterator iterator = this.navigatingMobs.iterator();
while (iterator.hasNext()) {
@@ -464,19 +446,52 @@
NavigationAbstract navigationabstract = entityinsentient.getNavigation();
if (navigationabstract.shouldRecomputePath(blockposition)) {
@@ -1109,6 +1288,11 @@
@@ -1125,6 +1304,12 @@
@Override
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);
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
+ if (explosion.wasCanceled) {
+ return explosion;
+ 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();
if (!explosion.interactsWithBlocks()) {
explosion.clearToBlow();
@@ -1181,13 +1365,20 @@
@@ -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) {
@@ -499,7 +514,7 @@
++j;
}
}
@@ -1238,7 +1429,7 @@
@@ -1282,7 +1485,7 @@
@Nullable
public BlockPosition findNearestMapStructure(TagKey<Structure> tagkey, BlockPosition blockposition, int i, boolean flag) {
@@ -507,8 +522,8 @@
+ if (!this.serverLevelData.worldGenOptions().generateStructures()) { // CraftBukkit
return null;
} else {
Optional<HolderSet.Named<Structure>> optional = this.registryAccess().registryOrThrow(Registries.STRUCTURE).getTag(tagkey);
@@ -1280,11 +1471,22 @@
Optional<HolderSet.Named<Structure>> optional = this.registryAccess().lookupOrThrow(Registries.STRUCTURE).get(tagkey);
@@ -1324,11 +1527,22 @@
@Nullable
@Override
public WorldMap getMapData(MapId mapid) {
@@ -532,7 +547,7 @@
this.getServer().overworld().getDataStorage().set(mapid.key(), worldmap);
}
@@ -1595,6 +1797,11 @@
@@ -1639,6 +1853,11 @@
@Override
public void blockUpdated(BlockPosition blockposition, Block block) {
if (!this.isDebug()) {
@@ -544,7 +559,7 @@
this.updateNeighborsAt(blockposition, block);
}
@@ -1614,12 +1821,12 @@
@@ -1658,12 +1877,12 @@
}
public boolean isFlat() {
@@ -559,7 +574,7 @@
}
@Nullable
@@ -1642,7 +1849,7 @@
@@ -1686,7 +1905,7 @@
private static <T> String getTypeCount(Iterable<T> iterable, Function<T, String> function) {
try {
Object2IntOpenHashMap<String> object2intopenhashmap = new Object2IntOpenHashMap();
@@ -568,7 +583,7 @@
while (iterator.hasNext()) {
T t0 = iterator.next();
@@ -1651,7 +1858,7 @@
@@ -1695,7 +1914,7 @@
object2intopenhashmap.addTo(s, 1);
}
@@ -577,7 +592,7 @@
String s1 = (String) entry.getKey();
return s1 + ":" + entry.getIntValue();
@@ -1796,6 +2003,8 @@
@@ -1854,6 +2073,8 @@
}
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
@@ -586,7 +601,7 @@
}
public void onTrackingEnd(Entity entity) {
@@ -1827,6 +2036,14 @@
@@ -1885,6 +2106,14 @@
}
entity.updateDynamicGameEventListener(DynamicGameEventListener::remove);