Skip to content

Instantly share code, notes, and snippets.

@jordoncodes
Created December 6, 2022 04:57
Show Gist options
  • Save jordoncodes/3602e7a6a05715458a84904fee861f75 to your computer and use it in GitHub Desktop.
Save jordoncodes/3602e7a6a05715458a84904fee861f75 to your computer and use it in GitHub Desktop.
public void sendBlockDamage(Player player, Location location, float progress) {
int locationId = location.getBlockX() + location.getBlockY() + location.getBlockZ(); // not perfect, could be better (some blocks have duplicate ids)
PacketContainer packet = manager.createPacket(PacketType.Play.Server.BLOCK_BREAK_ANIMATION);
// set entity ID to the location so the block break animation doesn't break (this is why we need packets).
packet.getIntegers().write(0, locationId);
packet.getBlockPositionModifier().write(0, new BlockPosition(location.toVector())); // set the block location
packet.getIntegers().write(1, getBlockStage(location)); // set the damage to blockStage
try {
manager.sendServerPacket(player, packet);
} catch (InvocationTargetException e) {
e.printStackTrace(); // the packet was unable to send.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment