50 Zeilen
2.1 KiB
Java
50 Zeilen
2.1 KiB
Java
/*
|
|
This file is a part of the SteamWar software.
|
|
|
|
Copyright (C) 2020 SteamWar.de-Serverteam
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
package de.steamwar.modsender;
|
|
|
|
import com.google.gson.JsonArray;
|
|
import io.netty.buffer.Unpooled;
|
|
import net.fabricmc.api.ModInitializer;
|
|
import net.fabricmc.loader.api.FabricLoader;
|
|
import net.fabricmc.loader.api.ModContainer;
|
|
import net.minecraft.client.MinecraftClient;
|
|
import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket;
|
|
import net.minecraft.util.Identifier;
|
|
import net.minecraft.util.PacketByteBuf;
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
public class ModSender implements ModInitializer {
|
|
|
|
private final Logger logger = LogManager.getLogger();
|
|
|
|
@Override public void onInitialize() {
|
|
logger.info("Initializing Steamwar System Mod");
|
|
}
|
|
|
|
public static void sendInformationPacket() {
|
|
Identifier channelIdentifier = new Identifier("steamwar:mods");
|
|
JsonArray ja = new JsonArray();
|
|
for(ModContainer container : FabricLoader.getInstance().getAllMods()) {
|
|
ja.add(container.getMetadata().getId());
|
|
}
|
|
PacketByteBuf packetByteBuf = new PacketByteBuf(Unpooled.buffer());
|
|
packetByteBuf.writeString(String.valueOf(ja));
|
|
CustomPayloadC2SPacket packet = new CustomPayloadC2SPacket(channelIdentifier,packetByteBuf);
|
|
MinecraftClient.getInstance().getNetworkHandler().sendPacket(packet);
|
|
}
|
|
}
|