|
18 | 18 | import net.minecraft.core.BlockPos; |
19 | 19 | import net.minecraft.network.protocol.Packet; |
20 | 20 | import net.minecraft.network.protocol.game.ClientboundLevelEventPacket; |
| 21 | +import net.minecraft.network.protocol.game.ClientboundSoundEntityPacket; |
| 22 | +import net.minecraft.network.protocol.game.ClientboundSoundPacket; |
21 | 23 | import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; |
| 24 | +import net.minecraft.core.registries.BuiltInRegistries; |
22 | 25 | import net.minecraft.world.entity.Entity; |
23 | 26 | import net.minecraft.world.entity.player.Player; |
24 | 27 | import net.minecraft.world.phys.Vec3; |
@@ -310,6 +313,20 @@ public void onReceivedPacket(PacketInputEvent event) |
310 | 313 | if(packet instanceof ClientboundLevelEventPacket lvl) |
311 | 314 | { |
312 | 315 | handleLevelEvent(lvl); |
| 316 | + return; |
| 317 | + } |
| 318 | + |
| 319 | + // Sound packets (used by some servers/versions for wither spawn |
| 320 | + // direction hints) |
| 321 | + if(packet instanceof ClientboundSoundPacket sound) |
| 322 | + { |
| 323 | + handleSoundPacket(sound); |
| 324 | + return; |
| 325 | + } |
| 326 | + |
| 327 | + if(packet instanceof ClientboundSoundEntityPacket soundEntity) |
| 328 | + { |
| 329 | + handleSoundEntityPacket(soundEntity); |
313 | 330 | } |
314 | 331 | }catch(Throwable t) |
315 | 332 | { |
@@ -499,6 +516,83 @@ private void handleLevelEvent(ClientboundLevelEventPacket packet) |
499 | 516 | } |
500 | 517 | } |
501 | 518 |
|
| 519 | + private void handleSoundPacket(ClientboundSoundPacket packet) |
| 520 | + { |
| 521 | + if(packet == null || MC == null || MC.player == null) |
| 522 | + return; |
| 523 | + if(!logMobs.isChecked()) |
| 524 | + return; |
| 525 | + |
| 526 | + String soundId; |
| 527 | + try |
| 528 | + { |
| 529 | + soundId = BuiltInRegistries.SOUND_EVENT |
| 530 | + .getKey(packet.getSound().value()).toString(); |
| 531 | + }catch(Throwable t) |
| 532 | + { |
| 533 | + return; |
| 534 | + } |
| 535 | + |
| 536 | + if(!"minecraft:entity.wither.spawn".equals(soundId)) |
| 537 | + return; |
| 538 | + |
| 539 | + Vec3 soundPos = new Vec3(packet.getX(), packet.getY(), packet.getZ()); |
| 540 | + double dist = MC.player.position().distanceTo(soundPos); |
| 541 | + if(dist < minDistance.getValue()) |
| 542 | + return; |
| 543 | + |
| 544 | + String dir = getCompassDirection(MC.player.position(), soundPos); |
| 545 | + String msg = String.format( |
| 546 | + "[CoordLogger] Wither spawn sound at x=%.1f, y=%.1f, z=%.1f (dist=%.1f, dir=%s)", |
| 547 | + soundPos.x, soundPos.y, soundPos.z, dist, dir); |
| 548 | + MC.execute(() -> ChatUtils.message(msg)); |
| 549 | + |
| 550 | + boolean isFar = dist > NEAR_EVENT_DISTANCE; |
| 551 | + markers.add(new EventMarker(soundPos, isFar, 1023, "WITHER_SPAWN_SOUND", |
| 552 | + EventCategory.MOBS)); |
| 553 | + } |
| 554 | + |
| 555 | + private void handleSoundEntityPacket(ClientboundSoundEntityPacket packet) |
| 556 | + { |
| 557 | + if(packet == null || MC == null || MC.player == null |
| 558 | + || MC.level == null) |
| 559 | + return; |
| 560 | + if(!logMobs.isChecked()) |
| 561 | + return; |
| 562 | + |
| 563 | + String soundId; |
| 564 | + try |
| 565 | + { |
| 566 | + soundId = BuiltInRegistries.SOUND_EVENT |
| 567 | + .getKey(packet.getSound().value()).toString(); |
| 568 | + }catch(Throwable t) |
| 569 | + { |
| 570 | + return; |
| 571 | + } |
| 572 | + |
| 573 | + if(!"minecraft:entity.wither.spawn".equals(soundId)) |
| 574 | + return; |
| 575 | + |
| 576 | + Entity entity = MC.level.getEntity(packet.getId()); |
| 577 | + if(entity == null) |
| 578 | + return; |
| 579 | + |
| 580 | + Vec3 soundPos = entity.position(); |
| 581 | + double dist = MC.player.position().distanceTo(soundPos); |
| 582 | + if(dist < minDistance.getValue()) |
| 583 | + return; |
| 584 | + |
| 585 | + String dir = getCompassDirection(MC.player.position(), soundPos); |
| 586 | + String msg = String.format( |
| 587 | + "[CoordLogger] Wither spawn sound(entity) at x=%.1f, y=%.1f, z=%.1f (dist=%.1f, dir=%s)", |
| 588 | + soundPos.x, soundPos.y, soundPos.z, dist, dir); |
| 589 | + MC.execute(() -> ChatUtils.message(msg)); |
| 590 | + |
| 591 | + boolean isFar = dist > NEAR_EVENT_DISTANCE; |
| 592 | + markers.add(new EventMarker(soundPos, isFar, 1023, |
| 593 | + "WITHER_SPAWN_SOUND_ENTITY", EventCategory.MOBS)); |
| 594 | + } |
| 595 | + |
502 | 596 | private double distanceToPlayer(BlockPos pos) |
503 | 597 | { |
504 | 598 | if(MC.player == null) |
|
0 commit comments