Search in sources :

Example 1 with Message

use of net.modificationstation.stationapi.api.packet.Message in project StationAPI by ModificationStation.

the class GuiHelperImpl method openGUI.

public void openGUI(PlayerBase player, Identifier identifier, InventoryBase inventory, ContainerBase container, Consumer<Message> customData) {
    Message message = new Message(Identifier.of(StationAPI.MODID, "open_gui"));
    message.strings = new String[] { identifier.toString() };
    sideDependentPacket(player, inventory, message);
    customData.accept(message);
    PacketHelper.sendTo(player, message);
    afterPacketSent(player, container);
}
Also used : Message(net.modificationstation.stationapi.api.packet.Message)

Example 2 with Message

use of net.modificationstation.stationapi.api.packet.Message in project StationAPI by ModificationStation.

the class ClientVanillaChecker method handleServerLogin.

@EventListener(priority = ListenerPriority.HIGH)
private static void handleServerLogin(ServerLoginSuccessEvent event) {
    if (Arrays.asList(event.loginRequestPacket.username.split(";")).contains(MODID.toString())) {
        ((ModdedPacketHandlerSetter) event.networkHandler).setModded();
        Message message = new Message(of(MODID, "modlist"));
        List<String> mods = new ArrayList<>();
        mods.add(MODID.getVersion().getFriendlyString());
        FabricLoader.getInstance().getAllMods().stream().map(ModContainer::getMetadata).forEach(modMetadata -> Collections.addAll(mods, modMetadata.getId(), modMetadata.getVersion().getFriendlyString()));
        message.strings = mods.toArray(new String[0]);
        event.networkHandler.sendPacket(message);
    }
}
Also used : ModdedPacketHandlerSetter(net.modificationstation.stationapi.impl.network.ModdedPacketHandlerSetter) Message(net.modificationstation.stationapi.api.packet.Message) EventListener(net.mine_diver.unsafeevents.listener.EventListener)

Example 3 with Message

use of net.modificationstation.stationapi.api.packet.Message in project StationAPI by ModificationStation.

the class MobSpawnDataProvider method getSpawnData.

@Override
default AbstractPacket getSpawnData() {
    Living mob = (Living) this;
    Message message = new Message(of(MODID, "spawn_mob"));
    message.strings = new String[] { getHandlerIdentifier().toString() };
    message.ints = new int[] { mob.entityId, MathHelper.floor(mob.x * 32.0D), MathHelper.floor(mob.y * 32.0D), MathHelper.floor(mob.z * 32.0D) };
    byte[] rotations = new byte[] { (byte) ((int) (mob.yaw * 256.0F / 360.0F)), (byte) ((int) (mob.pitch * 256.0F / 360.0F)) };
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    mob.getDataTracker().write(new DataOutputStream(outputStream));
    byte[] data = outputStream.toByteArray();
    message.bytes = Bytes.concat(rotations, data);
    writeToMessage(message);
    return message;
}
Also used : Message(net.modificationstation.stationapi.api.packet.Message) Living(net.minecraft.entity.Living)

Example 4 with Message

use of net.modificationstation.stationapi.api.packet.Message in project StationAPI by ModificationStation.

the class ServerRegistrySender method sendLevelRegistry.

@EventListener(priority = ListenerPriority.HIGH)
private static void sendLevelRegistry(PlayerPacketHandlerSetEvent event) {
    if (((ModdedPacketHandler) event.player.packetHandler).isModded()) {
        LOGGER.info("Sending level registries to \"" + event.player.name + "\"...");
        CompoundTag registries = new CompoundTag();
        LevelSerialRegistry.saveAll(registries);
        ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
        NBTIO.writeGzipped(registries, byteOutputStream);
        Message message = new Message(of(MODID, "server_registry_sync"));
        message.bytes = byteOutputStream.toByteArray();
        PacketHelper.sendTo(event.player, message);
    }
}
Also used : Message(net.modificationstation.stationapi.api.packet.Message) ModdedPacketHandler(net.modificationstation.stationapi.api.network.ModdedPacketHandler) CompoundTag(net.minecraft.util.io.CompoundTag) EventListener(net.mine_diver.unsafeevents.listener.EventListener)

Aggregations

Message (net.modificationstation.stationapi.api.packet.Message)4 EventListener (net.mine_diver.unsafeevents.listener.EventListener)2 Living (net.minecraft.entity.Living)1 CompoundTag (net.minecraft.util.io.CompoundTag)1 ModdedPacketHandler (net.modificationstation.stationapi.api.network.ModdedPacketHandler)1 ModdedPacketHandlerSetter (net.modificationstation.stationapi.impl.network.ModdedPacketHandlerSetter)1