Search in sources :

Example 11 with EventListener

use of net.mine_diver.unsafeevents.listener.EventListener 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 12 with EventListener

use of net.mine_diver.unsafeevents.listener.EventListener in project StationAPI by ModificationStation.

the class ServerVanillaChecker method registerMessages.

@EventListener(priority = ListenerPriority.HIGH)
private static void registerMessages(MessageListenerRegistryEvent event) {
    event.registry.register(of(MODID, "modlist"), (player, message) -> {
        if (!CLIENT_REQUIRED_MODS.isEmpty()) {
            LOGGER.info("Received a list of mods from player \"" + player.name + "\", verifying...");
            ServerPlayer serverPlayer = (ServerPlayer) player;
            String version = message.strings[0];
            String serverStationVersion = MODID.getVersion().getFriendlyString();
            if (!version.equals(serverStationVersion)) {
                LOGGER.error("Player \"" + player.name + "\" has a mismatching " + MODID.getName() + " version \"" + version + "\", disconnecting.");
                serverPlayer.packetHandler.kick(I18n.translate("disconnect.stationapi:station_version_mismatch", serverStationVersion, version));
                return;
            }
            Map<String, String> clientMods = new HashMap<>();
            for (int i = 1; i < message.strings.length; i += 2) clientMods.put(message.strings[i], message.strings[i + 1]);
            LOGGER.info("Player \"" + player.name + "\"'s mods: " + clientMods.entrySet().stream().map(stringStringEntry -> "modid=" + stringStringEntry.getKey() + " version=" + stringStringEntry.getValue()).collect(Collectors.joining(", ", "[", "]")));
            String modid;
            String clientVersion;
            String serverVersion;
            for (ModContainer serverMod : CLIENT_REQUIRED_MODS) {
                ModMetadata modMetadata = serverMod.getMetadata();
                modid = modMetadata.getId();
                serverVersion = modMetadata.getVersion().getFriendlyString();
                if (clientMods.containsKey(modid)) {
                    clientVersion = clientMods.get(modid);
                    if (clientVersion == null || !clientVersion.equals(serverVersion)) {
                        LOGGER.error("Player \"" + player.name + "\" has a mismatching " + modMetadata.getName() + " (" + modid + ")" + " version \"" + clientVersion + "\", disconnecting.");
                        serverPlayer.packetHandler.kick(I18n.translate("disconnect.stationapi:mod_version_mismatch", modMetadata.getName(), modid, serverVersion, clientVersion == null ? "null" : clientVersion));
                        return;
                    }
                } else {
                    LOGGER.error("Player \"" + player.name + "\" has a missing mod " + modMetadata.getName() + " (" + modid + "), disconnecting.");
                    serverPlayer.packetHandler.kick(I18n.translate("disconnect.stationapi:missing_mod", modMetadata.getName(), modid, serverVersion));
                    return;
                }
            }
            LOGGER.info("Player \"" + player.name + "\"'s mods have passed verification.");
        }
    });
}
Also used : java.util(java.util) MODID(net.modificationstation.stationapi.api.StationAPI.MODID) MASK(net.modificationstation.stationapi.impl.network.VanillaChecker.MASK) I18n(net.minecraft.client.resource.language.I18n) ModdedPacketHandlerSetter(net.modificationstation.stationapi.impl.network.ModdedPacketHandlerSetter) java.util.stream(java.util.stream) Identifier.of(net.modificationstation.stationapi.api.registry.Identifier.of) CLIENT_REQUIRED_MODS(net.modificationstation.stationapi.impl.network.VanillaChecker.CLIENT_REQUIRED_MODS) EventListener(net.mine_diver.unsafeevents.listener.EventListener) ModMetadata(net.fabricmc.loader.api.metadata.ModMetadata) PlayerAttemptLoginEvent(net.modificationstation.stationapi.api.server.event.network.PlayerAttemptLoginEvent) ListenerPriority(net.mine_diver.unsafeevents.listener.ListenerPriority) EventBusPolicy(net.modificationstation.stationapi.api.mod.entrypoint.EventBusPolicy) LOGGER(net.modificationstation.stationapi.api.StationAPI.LOGGER) Entrypoint(net.modificationstation.stationapi.api.mod.entrypoint.Entrypoint) MessageListenerRegistryEvent(net.modificationstation.stationapi.api.event.registry.MessageListenerRegistryEvent) ServerPlayer(net.minecraft.entity.player.ServerPlayer) ModContainer(net.fabricmc.loader.api.ModContainer) ModContainer(net.fabricmc.loader.api.ModContainer) ModMetadata(net.fabricmc.loader.api.metadata.ModMetadata) ServerPlayer(net.minecraft.entity.player.ServerPlayer) Entrypoint(net.modificationstation.stationapi.api.mod.entrypoint.Entrypoint) EventListener(net.mine_diver.unsafeevents.listener.EventListener)

Example 13 with EventListener

use of net.mine_diver.unsafeevents.listener.EventListener in project StationAPI by ModificationStation.

the class StationRenderImpl method stitchExpandableAtlasesPostInit.

@EventListener(priority = ListenerPriority.LOW)
private static void stitchExpandableAtlasesPostInit(TextureRegisterEvent event) {
    // noinspection deprecation
    Minecraft minecraft = (Minecraft) FabricLoader.getInstance().getGameInstance();
    TexturePack texturePack = minecraft.texturePackManager.texturePack;
    ResourceReloader.create(minecraft.texturePackManager.texturePack, Collections.singletonList(StationRenderAPI.getBakedModelManager()), Util.getMainWorkerExecutor(), Runnable::run, COMPLETED_UNIT_FUTURE);
    ItemModels.reloadModelsAll();
    TERRAIN.registerTextureBinders(minecraft.textureManager, texturePack);
    GUI_ITEMS.registerTextureBinders(minecraft.textureManager, texturePack);
    debugExportAtlases();
}
Also used : TexturePack(net.minecraft.client.resource.TexturePack) Minecraft(net.minecraft.client.Minecraft) EventListener(net.mine_diver.unsafeevents.listener.EventListener)

Example 14 with EventListener

use of net.mine_diver.unsafeevents.listener.EventListener in project StationAPI by ModificationStation.

the class StationRenderImpl method init.

@EventListener(priority = ListenerPriority.HIGH)
private static void init(TextureRegisterEvent event) {
    TERRAIN = new ExpandableAtlas(Atlases.GAME_ATLAS_TEXTURE);
    GUI_ITEMS = new ExpandableAtlas(of("textures/atlas/gui/items.png"));
    TERRAIN.addSpritesheet("/terrain.png", 16, TerrainHelper.INSTANCE);
    GUI_ITEMS.addSpritesheet("/gui/items.png", 16, GuiItemsHelper.INSTANCE);
}
Also used : ExpandableAtlas(net.modificationstation.stationapi.api.client.texture.atlas.ExpandableAtlas) EventListener(net.mine_diver.unsafeevents.listener.EventListener)

Example 15 with EventListener

use of net.mine_diver.unsafeevents.listener.EventListener in project StationAPI by ModificationStation.

the class DimensionListener method registerDimensions.

@EventListener
private static void registerDimensions(DimensionRegistryEvent event) {
    DimensionRegistry r = event.registry;
    r.register(of(MODID, "test_dimension"), new DimensionContainer<>(TestDimension::new));
}
Also used : DimensionRegistry(net.modificationstation.stationapi.api.registry.DimensionRegistry) EventListener(net.mine_diver.unsafeevents.listener.EventListener)

Aggregations

EventListener (net.mine_diver.unsafeevents.listener.EventListener)24 Environment (net.fabricmc.api.Environment)2 ModMetadata (net.fabricmc.loader.api.metadata.ModMetadata)2 Achievement (net.minecraft.achievement.Achievement)2 CompoundTag (net.minecraft.util.io.CompoundTag)2 ExpandableAtlas (net.modificationstation.stationapi.api.client.texture.atlas.ExpandableAtlas)2 MessageListenerRegistryEvent (net.modificationstation.stationapi.api.event.registry.MessageListenerRegistryEvent)2 Message (net.modificationstation.stationapi.api.packet.Message)2 DimensionRegistry (net.modificationstation.stationapi.api.registry.DimensionRegistry)2 ModdedPacketHandlerSetter (net.modificationstation.stationapi.impl.network.ModdedPacketHandlerSetter)2 java.util (java.util)1 java.util.stream (java.util.stream)1 ModContainer (net.fabricmc.loader.api.ModContainer)1 EventBus (net.mine_diver.unsafeevents.EventBus)1 ListenerPriority (net.mine_diver.unsafeevents.listener.ListenerPriority)1 Minecraft (net.minecraft.client.Minecraft)1 KeyBinding (net.minecraft.client.options.KeyBinding)1 TexturePack (net.minecraft.client.resource.TexturePack)1 I18n (net.minecraft.client.resource.language.I18n)1 ServerPlayer (net.minecraft.entity.player.ServerPlayer)1