Commits
md_5 authored f152cadda7b
99 99 | + this.maxHealthCache = this.getMaxHealth(); |
100 100 | + } |
101 101 | + |
102 102 | + // Use method to resend items in hands in case of client desync, because the item use got cancelled. |
103 103 | + // For example, when cancelling the leash event |
104 104 | + public void resendItemInHands() { |
105 105 | + containerMenu.findSlot(getInventory(), getInventory().selected).ifPresent(s -> { |
106 106 | + containerSynchronizer.sendSlotChange(containerMenu, s, getMainHandItem()); |
107 107 | + }); |
108 108 | + containerSynchronizer.sendSlotChange(inventoryMenu, ContainerPlayer.SHIELD_SLOT, getOffhandItem()); |
109 - | } |
110 - | |
109 + | + } |
110 + | + |
111 111 | + // Yes, this doesn't match Vanilla, but it's the best we can do for now. |
112 112 | + // If this is an issue, PRs are welcome |
113 113 | + public final BlockPosition getSpawnPoint(WorldServer worldserver) { |
114 114 | + BlockPosition blockposition = worldserver.getSharedSpawnPos(); |
115 115 | + |
116 116 | + if (worldserver.dimensionType().hasSkyLight() && worldserver.serverLevelData.getGameType() != EnumGamemode.ADVENTURE) { |
117 117 | + int i = Math.max(0, this.server.getSpawnRadius(worldserver)); |
118 118 | + int j = MathHelper.floor(worldserver.getWorldBorder().getDistanceToBorder((double) blockposition.getX(), (double) blockposition.getZ())); |
119 119 | + |
120 120 | + if (j < i) { |
137 137 | + int k2 = i2 / (i * 2 + 1); |
138 138 | + BlockPosition blockposition1 = WorldProviderNormal.getOverworldRespawnPos(worldserver, blockposition.getX() + j2 - i, blockposition.getZ() + k2 - i); |
139 139 | + |
140 140 | + if (blockposition1 != null) { |
141 141 | + return blockposition1; |
142 142 | + } |
143 143 | + } |
144 144 | + } |
145 145 | + |
146 146 | + return blockposition; |
147 - | + } |
147 + | } |
148 148 | + // CraftBukkit end |
149 - | + |
149 + | |
150 150 | @Override |
151 151 | public BlockPosition adjustSpawnLocation(WorldServer worldserver, BlockPosition blockposition) { |
152 152 | AxisAlignedBB axisalignedbb = this.getDimensions(EntityPose.STANDING).makeBoundingBox(Vec3D.ZERO); |
153 153 | BlockPosition blockposition1 = blockposition; |
154 154 | |
155 155 | - if (worldserver.dimensionType().hasSkyLight() && worldserver.getServer().getWorldData().getGameType() != EnumGamemode.ADVENTURE) { |
156 156 | + if (worldserver.dimensionType().hasSkyLight() && worldserver.serverLevelData.getGameType() != EnumGamemode.ADVENTURE) { // CraftBukkit |
157 157 | int i = Math.max(0, this.server.getSpawnRadius(worldserver)); |
158 158 | int j = MathHelper.floor(worldserver.getWorldBorder().getDistanceToBorder((double) blockposition.getX(), (double) blockposition.getZ())); |
159 159 | |
537 537 | + isAnchorSpawn = entityplayer_respawnposangle.isAnchorSpawn(); |
538 538 | + teleportTransition = new TeleportTransition(worldserver, entityplayer_respawnposangle.position(), Vec3D.ZERO, entityplayer_respawnposangle.yaw(), 0.0F, teleporttransition_a); |
539 539 | + // CraftBukkit end |
540 540 | } else { |
541 541 | - return TeleportTransition.missingRespawnBlock(this.server.overworld(), this, teleporttransition_a); |
542 542 | + teleportTransition = TeleportTransition.missingRespawnBlock(this.server.overworld(), this, teleporttransition_a); // CraftBukkit |
543 543 | } |
544 544 | } else { |
545 545 | - return new TeleportTransition(this.server.overworld(), this, teleporttransition_a); |
546 546 | + teleportTransition = new TeleportTransition(this.server.overworld(), this, teleporttransition_a); // CraftBukkit |
547 - | } |
547 + | + } |
548 548 | + // CraftBukkit start |
549 549 | + if (reason == null) { |
550 550 | + return teleportTransition; |
551 - | + } |
551 + | } |
552 552 | + |
553 553 | + Player respawnPlayer = this.getBukkitEntity(); |
554 554 | + Location location = CraftLocation.toBukkit(teleportTransition.position(), teleportTransition.newLevel().getWorld(), teleportTransition.yRot(), teleportTransition.xRot()); |
555 555 | + |
556 556 | + PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn, isAnchorSpawn, reason); |
557 557 | + this.level().getCraftServer().getPluginManager().callEvent(respawnEvent); |
558 558 | + |
559 559 | + location = respawnEvent.getRespawnLocation(); |
560 560 | + |
561 561 | + 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()); |
1071 1071 | + this.server.server.getPluginManager().callEvent(event); |
1072 1072 | + } |
1073 1073 | + if (!this.language.equals(clientinformation.language())) { |
1074 1074 | + PlayerLocaleChangeEvent event = new PlayerLocaleChangeEvent(getBukkitEntity(), clientinformation.language()); |
1075 1075 | + this.server.server.getPluginManager().callEvent(event); |
1076 1076 | + } |
1077 1077 | + // CraftBukkit end |
1078 1078 | this.language = clientinformation.language(); |
1079 1079 | this.requestedViewDistance = clientinformation.viewDistance(); |
1080 1080 | this.chatVisibility = clientinformation.chatVisibility(); |
1081 - | |
1081 + | |
1082 1082 | if (world instanceof WorldServer) { |
1083 1083 | WorldServer worldserver = (WorldServer) world; |
1084 1084 | |
1085 1085 | - this.teleportTo(worldserver, this.camera.getX(), this.camera.getY(), this.camera.getZ(), Set.of(), this.getYRot(), this.getXRot(), false); |
1086 - | + this.teleportTo(worldserver, this.camera.getX(), this.camera.getY(), this.camera.getZ(), Set.of(), this.getYRot(), this.getXRot(), false, TeleportCause.SPECTATE); // CraftBukkit |
1086 + | + // CraftBukkit start |
1087 + | + boolean result = this.teleportTo(worldserver, this.camera.getX(), this.camera.getY(), this.camera.getZ(), Set.of(), this.getYRot(), this.getXRot(), false, TeleportCause.SPECTATE); |
1088 + | + if (!result) { |
1089 + | + this.camera = entity1; |
1090 + | + return; |
1091 + | + } |
1092 + | + // CraftBukkit end |
1087 1093 | } |
1088 1094 | |
1089 1095 | if (entity != null) { |
1090 - | |
1096 + | |
1091 1097 | |
1092 1098 | @Nullable |
1093 1099 | public IChatBaseComponent getTabListDisplayName() { |
1094 1100 | - return null; |
1095 1101 | + return listName; // CraftBukkit |
1096 1102 | } |
1097 1103 | |
1098 1104 | public int getTabListOrder() { |
1099 1105 | - return 0; |
1100 1106 | + return listOrder; // CraftBukkit |
1101 1107 | } |
1102 1108 | |
1103 1109 | @Override |
1104 - | |
1110 + | |
1105 1111 | } |
1106 1112 | |
1107 1113 | public void setRespawnPosition(ResourceKey<World> resourcekey, @Nullable BlockPosition blockposition, float f, boolean flag, boolean flag1) { |
1108 1114 | + // CraftBukkit start |
1109 1115 | + this.setRespawnPosition(resourcekey, blockposition, f, flag, flag1, PlayerSpawnChangeEvent.Cause.UNKNOWN); |
1110 1116 | + } |
1111 1117 | + |
1112 1118 | + public void setRespawnPosition(ResourceKey<World> resourcekey, @Nullable BlockPosition blockposition, float f, boolean flag, boolean flag1, PlayerSpawnChangeEvent.Cause cause) { |
1113 1119 | + WorldServer newWorld = this.server.getLevel(resourcekey); |
1114 1120 | + Location newSpawn = (blockposition != null) ? CraftLocation.toBukkit(blockposition, newWorld.getWorld(), f, 0) : null; |
1127 1133 | + f = newSpawn.getYaw(); |
1128 1134 | + } else { |
1129 1135 | + resourcekey = World.OVERWORLD; |
1130 1136 | + blockposition = null; |
1131 1137 | + f = 0.0F; |
1132 1138 | + } |
1133 1139 | + // CraftBukkit end |
1134 1140 | if (blockposition != null) { |
1135 1141 | boolean flag2 = blockposition.equals(this.respawnPosition) && resourcekey.equals(this.respawnDimension); |
1136 1142 | |
1137 - | |
1143 + | |
1138 1144 | } |
1139 1145 | |
1140 1146 | @Override |
1141 1147 | - public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1) { |
1142 1148 | + public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1, boolean callEvent) { // CraftBukkit - SPIGOT-2942: Add boolean to call event |
1143 1149 | EntityItem entityitem = this.createItemStackToDrop(itemstack, flag, flag1); |
1144 1150 | |
1145 1151 | if (entityitem == null) { |
1146 1152 | return null; |
1147 1153 | } else { |
1167 1173 | + player.getInventory().addItem(drop.getItemStack()); |
1168 1174 | + } |
1169 1175 | + return null; |
1170 1176 | + } |
1171 1177 | + } |
1172 1178 | + // CraftBukkit end |
1173 1179 | + |
1174 1180 | this.level().addFreshEntity(entityitem); |
1175 1181 | ItemStack itemstack1 = entityitem.getItem(); |
1176 1182 | |
1177 - | |
1183 + | |
1178 1184 | return TicketType.ENDER_PEARL.timeout(); |
1179 1185 | } |
1180 1186 | |
1181 1187 | - public static record RespawnPosAngle(Vec3D position, float yaw) { |
1182 1188 | + // CraftBukkit start |
1183 1189 | + public static record RespawnPosAngle(Vec3D position, float yaw, boolean isBedSpawn, boolean isAnchorSpawn) { |
1184 1190 | |
1185 1191 | - public static EntityPlayer.RespawnPosAngle of(Vec3D vec3d, BlockPosition blockposition) { |
1186 1192 | - return new EntityPlayer.RespawnPosAngle(vec3d, calculateLookAtYaw(vec3d, blockposition)); |
1187 1193 | + public static EntityPlayer.RespawnPosAngle of(Vec3D vec3d, BlockPosition blockposition, boolean isBedSpawn, boolean isAnchorSpawn) { |
1188 1194 | + return new EntityPlayer.RespawnPosAngle(vec3d, calculateLookAtYaw(vec3d, blockposition), isBedSpawn, isAnchorSpawn); |
1189 1195 | + // CraftBukkit end |
1190 1196 | } |
1191 1197 | |
1192 1198 | private static float calculateLookAtYaw(Vec3D vec3d, BlockPosition blockposition) { |
1193 - | |
1199 + | |
1194 1200 | return (float) MathHelper.wrapDegrees(MathHelper.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D); |
1195 1201 | } |
1196 1202 | } |
1197 1203 | + |
1198 1204 | + // CraftBukkit start - Add per-player time and weather. |
1199 1205 | + public long timeOffset = 0; |
1200 1206 | + public boolean relativeTime = true; |
1201 1207 | + |
1202 1208 | + public long getPlayerTime() { |
1203 1209 | + if (this.relativeTime) { |