Solved Send WorldBorder with packets

Discussion in 'Spigot Plugin Development' started by Peaches_MLG, Jun 11, 2021.

  1. Anyone know how to send a world border with packets on 1.17? Seems PacketPlayOutWorldBorder got deleted?

    This was my code for 1.16.5

    Code (Java):
        @Override
        public void sendWorldBorder(Player player, Color color, double size, Location centerLocation) {
            WorldBorder worldBorder = new WorldBorder();
            worldBorder.world = ((CraftWorld) centerLocation.getWorld()).getHandle();
            worldBorder.setCenter(centerLocation.getBlockX() + 0.5, centerLocation.getBlockZ() + 0.5);

            if (color == Color.OFF) {
                worldBorder.setSize(Integer.MAX_VALUE);
            } else {
                worldBorder.setSize(size);
            }

            worldBorder.setWarningDistance(0);
            worldBorder.setWarningTime(0);

            if (color == Color.RED) {
                worldBorder.transitionSizeBetween(size, size - 1.0D, 20000000L);
            } else if (color == Color.GREEN) {
                worldBorder.transitionSizeBetween(size - 0.1D, size, 20000000L);
            }

            ((CraftPlayer) player).getHandle().b.sendPacket(new PacketPlayOutWorldBorder(worldBorder, PacketPlayOutWorldBorder.EnumWorldBorderAction.INITIALIZE));
        }
     
  2. EDIT: Just found

    Code (Java):
        @Override
        public void sendWorldBorder(Player player, Color color, double size, Location centerLocation) {
            WorldBorder worldBorder = new WorldBorder();
            worldBorder.world = ((CraftWorld) centerLocation.getWorld()).getHandle();
            worldBorder.setCenter(centerLocation.getBlockX() + 0.5, centerLocation.getBlockZ() + 0.5);

            if (color == Color.OFF) {
                worldBorder.setSize(Integer.MAX_VALUE);
            } else {
                worldBorder.setSize(size);
            }

            worldBorder.setWarningDistance(0);
            worldBorder.setWarningTime(0);

            if (color == Color.RED) {
                worldBorder.transitionSizeBetween(size, size - 1.0D, 20000000L);
            } else if (color == Color.GREEN) {
                worldBorder.transitionSizeBetween(size - 0.1D, size, 20000000L);
            }

            ((CraftPlayer) player).getHandle().b.sendPacket(new ClientboundInitializeBorderPacket(worldBorder));
        }
    Which seems to work fine
     
  3. ClientboundSetBorderCenterPacket, constructor using a "net.minecraft.world.level.border.WorldBorder" object with two double fields newCenterX and newCenterZ
    ClientboundSetBorderLerpSizePacket (for changing size of a world border), also uses a WorldBorder object, 3 fields of 2 double and 1 long: oldSize, newSize, and lerpTime respectively
    ClientboundSetBorderSizePacket, also uses WorldBorder object, 1 double field "size"
    ClientboundSetBorderWarningDelayPacket, also uses WorldBorder object, 1 int field "warningDelay"
    ClientboundSetBorderWarningDistancePacket, also uses WorldBorder, 1 int field "warningBlocks"
     
    • Friendly Friendly x 1
  4. The packet name appears to be "ClientboundInitializeBorderPacket" in 1.17

    EDIT: Double sniped, I'm slow today
     
    • Like Like x 1
    • Friendly Friendly x 1