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);
}
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);
}
}
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;
}
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);
}
}
Aggregations