/** {@inheritDoc} */ @Init public void load(final FMLInitializationEvent event) { klaxon = new ItemKlaxon(klaxonId); LanguageRegistry.addName(klaxon, "Klaxon"); GameRegistry.addRecipe( new ItemStack(klaxon), " x ", "xox", " x ", 'x', new ItemStack(Item.stick), 'o', new ItemStack(Item.leather)); if (event.getSide() == Side.CLIENT) { String name = "klaxon" + Minecraft.getMinecraft().session.username; Minecraft.getMinecraft().sndManager.addSound(name + ".ogg", file); FMLLog.log(MOD_ID, Level.INFO, "klaxon name %s", name); } // Adds listeners. if (event.getSide() == Side.CLIENT) { providerListener = new MyProviderListener(); fileListener = new MyFileListener(); IProvider p = P2P.get(P2P.CLIENT_PROVIDER); p.addListener(providerListener); p.getFileProvider().addListener(fileListener); } }
/** * Gets the klaxon with given name. * * @param name klaxon's name. */ public static synchronized void getKlaxon(String name) { if (running) { if (!loadingKlaxons.contains(name)) { FMLLog.log(MOD_ID, Level.INFO, "Must get the klaxon %s", name); loadedKlaxons.remove(name); loadingKlaxons.add(name); File file = new File(klaxons, name + ".ogg"); IFileProvider p = P2P.get(P2P.CLIENT_PROVIDER).getFileProvider(); p.download(MOD_ID, name, file); } } }
/** * Called when the client has been started. * * @param event the event. */ private static synchronized void clientStarted(IProviderEvent event) { running = true; clear(); P2P.get(P2P.CLIENT_PROVIDER).getFileProvider().addListener(fileListener); // Klaxon file exists. if (file.exists() && file.isFile()) { // Uploads the klaxon. String name = "klaxon" + Minecraft.getMinecraft().thePlayer.username + "a"; FMLLog.log(MOD_ID, Level.INFO, "Client started, uploading the klaxon to %s", name); event.getFileProvider().upload(MOD_ID, file, name); } }