From f2dcecf4d9ebab16d1f0f846de8798be60e4d05e Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sun, 12 Jun 2022 11:47:24 -0700 Subject: [PATCH] Add option for strict advancement dimension checks Craftbukkit attempts to translate worlds that use the same generation as the Overworld, The Nether, or The End to use those dimensions when checking the `changed_dimension` criteria trigger, or whether to trigger the `NETHER_TRAVEL` distance trigger. This adds a config option to ignore that and use the exact dimension key of the worlds involved. --- .../critereon/LocationPredicate.java.patch | 11 ++ .../server/level/ServerPlayer.java.patch | 109 +++++++++--------- 2 files changed, 68 insertions(+), 52 deletions(-) create mode 100644 paper-server/patches/sources/net/minecraft/advancements/critereon/LocationPredicate.java.patch diff --git a/paper-server/patches/sources/net/minecraft/advancements/critereon/LocationPredicate.java.patch b/paper-server/patches/sources/net/minecraft/advancements/critereon/LocationPredicate.java.patch new file mode 100644 index 000000000..7f7873fc4 --- /dev/null +++ b/paper-server/patches/sources/net/minecraft/advancements/critereon/LocationPredicate.java.patch @@ -0,0 +1,11 @@ +--- a/net/minecraft/advancements/critereon/LocationPredicate.java ++++ b/net/minecraft/advancements/critereon/LocationPredicate.java +@@ -44,7 +44,7 @@ + public boolean matches(ServerLevel world, double x, double y, double z) { + if (this.position.isPresent() && !this.position.get().matches(x, y, z)) { + return false; +- } else if (this.dimension.isPresent() && this.dimension.get() != world.dimension()) { ++ } else if (this.dimension.isPresent() && this.dimension.get() != (io.papermc.paper.configuration.GlobalConfiguration.get().misc.strictAdvancementDimensionCheck ? world.dimension() : org.bukkit.craftbukkit.util.CraftDimensionUtil.getMainDimensionKey(world))) { // Paper - Add option for strict advancement dimension checks + return false; + } else { + BlockPos blockPos = BlockPos.containing(x, y, z); diff --git a/paper-server/patches/sources/net/minecraft/server/level/ServerPlayer.java.patch b/paper-server/patches/sources/net/minecraft/server/level/ServerPlayer.java.patch index 2a6604bc8..44c03dc91 100644 --- a/paper-server/patches/sources/net/minecraft/server/level/ServerPlayer.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/level/ServerPlayer.java.patch @@ -114,7 +114,7 @@ @Nullable private Vec3 startingToFallPosition; @Nullable -@@ -258,7 +293,35 @@ +@@ -258,6 +293,34 @@ private final CommandSource commandSource; private int containerCounter; public boolean wonGame; @@ -125,7 +125,7 @@ + public boolean queueHealthUpdatePacket; + public net.minecraft.network.protocol.game.ClientboundSetHealthPacket queuedHealthUpdatePacket; + // Paper end - cancellable death event - ++ + // CraftBukkit start + public CraftPlayer.TransferCookieConnection transferCookieConnection; + public String displayName; @@ -146,10 +146,9 @@ + public com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper - PlayerNaturallySpawnCreaturesEvent + public @Nullable String clientBrandName = null; // Paper - Brand support + public org.bukkit.event.player.PlayerQuitEvent.QuitReason quitReason = null; // Paper - Add API for quit reason; there are a lot of changes to do if we change all methods leading to the event -+ + public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile, ClientInformation clientOptions) { super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile); - this.chatVisibility = ChatVisiblity.FULL; @@ -266,7 +329,7 @@ this.canChatColor = true; this.lastActionTime = Util.getMillis(); @@ -188,8 +187,8 @@ + this.adventure$displayName = net.kyori.adventure.text.Component.text(this.getScoreboardName()); // Paper + 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() { @@ -235,9 +234,9 @@ + } + + return blockposition; -+ } + } + // CraftBukkit end -+ + @Override public BlockPos adjustSpawnLocation(ServerLevel world, BlockPos basePos) { AABB axisalignedbb = this.getDimensions(Pose.STANDING).makeBoundingBox(Vec3.ZERO); @@ -288,14 +287,14 @@ if (this.isSleeping()) { this.stopSleeping(); -+ } + } + + // CraftBukkit start + String spawnWorld = nbt.getString("SpawnWorld"); + CraftWorld oldWorld = (CraftWorld) Bukkit.getWorld(spawnWorld); + if (oldWorld != null) { + this.respawnDimension = oldWorld.getHandle().dimension(); - } ++ } + // CraftBukkit end if (nbt.contains("SpawnX", 99) && nbt.contains("SpawnY", 99) && nbt.contains("SpawnZ", 99)) { @@ -527,8 +526,8 @@ + this.level().getCraftServer().getScoreboardManager().forAllObjectives(criterion, this, (scoreaccess) -> { scoreaccess.set(score); }); -+ } -+ + } + + // Paper start - PlayerDeathEvent#getItemsToKeep + private static void processKeep(org.bukkit.event.entity.PlayerDeathEvent event, NonNullList inv) { + List itemsToKeep = event.getItemsToKeep(); @@ -566,9 +565,9 @@ + inv.set(i, ItemStack.EMPTY); + } + } - } ++ } + // Paper end - PlayerDeathEvent#getItemsToKeep - ++ @Override public void die(DamageSource damageSource) { - this.gameEvent(GameEvent.ENTITY_DIE); @@ -951,7 +950,7 @@ public void forceSetRotation(float yaw, float pitch) { this.connection.send(new ClientboundPlayerRotationPacket(yaw, pitch)); } -@@ -1228,13 +1642,21 @@ +@@ -1228,13 +1642,27 @@ public void triggerDimensionChangeTriggers(ServerLevel origin) { ResourceKey resourcekey = origin.dimension(); ResourceKey resourcekey1 = this.level().dimension(); @@ -961,6 +960,12 @@ - CriteriaTriggers.CHANGED_DIMENSION.trigger(this, resourcekey, resourcekey1); - if (resourcekey == Level.NETHER && resourcekey1 == Level.OVERWORLD && this.enteredNetherPosition != null) { ++ // Paper start - Add option for strict advancement dimension checks ++ if (io.papermc.paper.configuration.GlobalConfiguration.get().misc.strictAdvancementDimensionCheck) { ++ maindimensionkey = resourcekey; ++ maindimensionkey1 = resourcekey1; ++ } ++ // Paper end - Add option for strict advancement dimension checks + CriteriaTriggers.CHANGED_DIMENSION.trigger(this, maindimensionkey, maindimensionkey1); + if (maindimensionkey != resourcekey || maindimensionkey1 != resourcekey1) { + CriteriaTriggers.CHANGED_DIMENSION.trigger(this, resourcekey, resourcekey1); @@ -976,7 +981,7 @@ this.enteredNetherPosition = null; } -@@ -1251,36 +1673,63 @@ +@@ -1251,36 +1679,63 @@ this.containerMenu.broadcastChanges(); } @@ -1055,7 +1060,7 @@ this.awardStat(Stats.SLEEP_IN_BED); CriteriaTriggers.SLEPT_IN_BED.trigger(this); }); -@@ -1293,9 +1742,8 @@ +@@ -1293,9 +1748,8 @@ return either; } } @@ -1066,7 +1071,7 @@ } @Override -@@ -1322,13 +1770,31 @@ +@@ -1322,13 +1776,31 @@ @Override public void stopSleepInBed(boolean skipSleepTimer, boolean updateSleepingPlayers) { @@ -1099,7 +1104,7 @@ } } -@@ -1341,7 +1807,7 @@ +@@ -1341,7 +1813,7 @@ @Override public boolean isInvulnerableTo(ServerLevel world, DamageSource source) { @@ -1108,7 +1113,7 @@ } @Override -@@ -1387,8 +1853,9 @@ +@@ -1387,8 +1859,9 @@ this.connection.send(new ClientboundOpenSignEditorPacket(sign.getBlockPos(), front)); } @@ -1119,7 +1124,7 @@ } @Override -@@ -1396,13 +1863,35 @@ +@@ -1396,13 +1869,35 @@ if (factory == null) { return OptionalInt.empty(); } else { @@ -1155,7 +1160,7 @@ if (container == null) { if (this.isSpectator()) { this.displayClientMessage(Component.translatable("container.spectatorCantOpen").withStyle(ChatFormatting.RED), true); -@@ -1410,9 +1899,11 @@ +@@ -1410,9 +1905,11 @@ return OptionalInt.empty(); } else { @@ -1169,7 +1174,7 @@ return OptionalInt.of(this.containerCounter); } } -@@ -1425,15 +1916,26 @@ +@@ -1425,15 +1922,26 @@ @Override public void openHorseInventory(AbstractHorse horse, Container inventory) { @@ -1199,7 +1204,7 @@ this.initMenu(this.containerMenu); } -@@ -1456,9 +1958,28 @@ +@@ -1456,9 +1964,28 @@ @Override public void closeContainer() { @@ -1212,7 +1217,7 @@ + // Paper end - Inventory close reason this.connection.send(new ClientboundContainerClosePacket(this.containerMenu.containerId)); this.doCloseContainer(); - } ++ } + // Paper start - special close for unloaded inventory + @Override + public void closeUnloadedInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) { @@ -1223,12 +1228,12 @@ + this.connection.send(new ClientboundContainerClosePacket(this.containerMenu.containerId)); + this.containerMenu = this.inventoryMenu; + // do not run close logic -+ } + } + // Paper end - special close for unloaded inventory @Override public void doCloseContainer() { -@@ -1485,19 +2006,19 @@ +@@ -1485,19 +2012,19 @@ i = Math.round((float) Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) * 100.0F); if (i > 0) { this.awardStat(Stats.SWIM_ONE_CM, i); @@ -1251,7 +1256,7 @@ } } else if (this.onClimbable()) { if (deltaY > 0.0D) { -@@ -1508,13 +2029,13 @@ +@@ -1508,13 +2035,13 @@ if (i > 0) { if (this.isSprinting()) { this.awardStat(Stats.SPRINT_ONE_CM, i); @@ -1268,7 +1273,7 @@ } } } else if (this.isFallFlying()) { -@@ -1557,7 +2078,7 @@ +@@ -1557,7 +2084,7 @@ @Override public void awardStat(Stat stat, int amount) { this.stats.increment(this, stat, amount); @@ -1277,7 +1282,7 @@ scoreaccess.add(amount); }); } -@@ -1565,7 +2086,7 @@ +@@ -1565,7 +2092,7 @@ @Override public void resetStat(Stat stat) { this.stats.setValue(this, stat, 0); @@ -1286,7 +1291,7 @@ } @Override -@@ -1597,9 +2118,9 @@ +@@ -1597,9 +2124,9 @@ super.jumpFromGround(); this.awardStat(Stats.JUMP); if (this.isSprinting()) { @@ -1298,7 +1303,7 @@ } } -@@ -1613,6 +2134,13 @@ +@@ -1613,6 +2140,13 @@ public void disconnect() { this.disconnected = true; this.ejectPassengers(); @@ -1312,7 +1317,7 @@ if (this.isSleeping()) { this.stopSleepInBed(true, false); } -@@ -1625,6 +2153,7 @@ +@@ -1625,6 +2159,7 @@ public void resetSentInfo() { this.lastSentHealth = -1.0E8F; @@ -1320,7 +1325,7 @@ } @Override -@@ -1661,7 +2190,7 @@ +@@ -1661,7 +2196,7 @@ this.onUpdateAbilities(); if (alive) { this.getAttributes().assignBaseValues(oldPlayer.getAttributes()); @@ -1329,7 +1334,7 @@ this.setHealth(oldPlayer.getHealth()); this.foodData = oldPlayer.foodData; Iterator iterator = oldPlayer.getActiveEffects().iterator(); -@@ -1669,7 +2198,7 @@ +@@ -1669,7 +2204,7 @@ while (iterator.hasNext()) { MobEffectInstance mobeffect = (MobEffectInstance) iterator.next(); @@ -1338,7 +1343,7 @@ } this.getInventory().replaceWith(oldPlayer.getInventory()); -@@ -1680,7 +2209,7 @@ +@@ -1680,7 +2215,7 @@ this.portalProcess = oldPlayer.portalProcess; } else { this.getAttributes().assignBaseValues(oldPlayer.getAttributes()); @@ -1347,7 +1352,7 @@ if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || oldPlayer.isSpectator()) { this.getInventory().replaceWith(oldPlayer.getInventory()); this.experienceLevel = oldPlayer.experienceLevel; -@@ -1696,7 +2225,7 @@ +@@ -1696,7 +2231,7 @@ this.lastSentExp = -1; this.lastSentHealth = -1.0F; this.lastSentFood = -1; @@ -1356,7 +1361,7 @@ this.seenCredits = oldPlayer.seenCredits; this.enteredNetherPosition = oldPlayer.enteredNetherPosition; this.chunkTrackingView = oldPlayer.chunkTrackingView; -@@ -1752,19 +2281,19 @@ +@@ -1752,19 +2287,19 @@ } @Override @@ -1380,7 +1385,7 @@ } return flag1; -@@ -1799,10 +2328,18 @@ +@@ -1799,10 +2334,18 @@ } public boolean setGameMode(GameType gameMode) { @@ -1401,7 +1406,7 @@ } else { this.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.CHANGE_GAME_MODE, (float) gameMode.getId())); if (gameMode == GameType.SPECTATOR) { -@@ -1818,7 +2355,7 @@ +@@ -1818,7 +2361,7 @@ this.onUpdateAbilities(); this.updateEffectVisibility(); @@ -1410,7 +1415,7 @@ } } -@@ -1861,8 +2398,13 @@ +@@ -1861,8 +2404,13 @@ } public void sendChatMessage(OutgoingChatMessage message, boolean filterMaskEnabled, ChatType.Bound params) { @@ -1425,7 +1430,7 @@ } } -@@ -1878,7 +2420,36 @@ +@@ -1878,7 +2426,36 @@ } public void updateOptions(ClientInformation clientOptions) { @@ -1462,7 +1467,7 @@ this.requestedViewDistance = clientOptions.viewDistance(); this.chatVisibility = clientOptions.chatVisibility(); this.canChatColor = clientOptions.chatColors(); -@@ -1957,12 +2528,27 @@ +@@ -1957,12 +2534,27 @@ this.camera = (Entity) (entity == null ? this : entity); if (entity1 != this.camera) { @@ -1491,7 +1496,7 @@ } if (entity != null) { -@@ -1999,11 +2585,11 @@ +@@ -1999,11 +2591,11 @@ @Nullable public Component getTabListDisplayName() { @@ -1505,7 +1510,7 @@ } @Override -@@ -2045,12 +2631,44 @@ +@@ -2045,12 +2637,44 @@ this.setRespawnPosition(player.getRespawnDimension(), player.getRespawnPosition(), player.getRespawnAngle(), player.isRespawnForced(), false); } @@ -1552,7 +1557,7 @@ } this.respawnPosition = pos; -@@ -2064,6 +2682,7 @@ +@@ -2064,6 +2688,7 @@ this.respawnForced = false; } @@ -1560,7 +1565,7 @@ } public SectionPos getLastSectionPos() { -@@ -2088,18 +2707,44 @@ +@@ -2088,18 +2713,44 @@ } @Override @@ -1609,7 +1614,7 @@ } this.awardStat(Stats.DROP); -@@ -2115,6 +2760,11 @@ +@@ -2115,6 +2766,11 @@ return null; } else { double d0 = this.getEyeY() - 0.30000001192092896D; @@ -1621,7 +1626,7 @@ ItemEntity entityitem = new ItemEntity(this.level(), this.getX(), d0, this.getZ(), stack); entityitem.setPickUpDelay(40); -@@ -2166,6 +2816,16 @@ +@@ -2166,6 +2822,16 @@ } public void loadGameTypes(@Nullable CompoundTag nbt) { @@ -1638,7 +1643,7 @@ this.gameMode.setGameModeForPlayer(this.calculateGameModeForNewPlayer(ServerPlayer.readPlayerMode(nbt, "playerGameType")), ServerPlayer.readPlayerMode(nbt, "previousPlayerGameType")); } -@@ -2275,9 +2935,15 @@ +@@ -2275,9 +2941,15 @@ @Override public void stopRiding() { @@ -1655,7 +1660,7 @@ if (entity instanceof LivingEntity entityliving) { Iterator iterator = entityliving.getActiveEffects().iterator(); -@@ -2375,10 +3041,12 @@ +@@ -2375,10 +3047,12 @@ return TicketType.ENDER_PEARL.timeout(); } @@ -1671,7 +1676,7 @@ } private static float calculateLookAtYaw(Vec3 respawnPos, BlockPos currentPos) { -@@ -2387,4 +3055,147 @@ +@@ -2387,4 +3061,147 @@ return (float) Mth.wrapDegrees(Mth.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D); } }