public static void handle(IMCEvent event) { for (IMCMessage message : event.getMessages()) { try { if (message.key.equals("addCrumblePair")) { handleCrumbleBlock(message); } else { FMLLog.warning("Magic Bees recieved an IMC Message from a mod %s " + "but does not support messages keyed with %s.", message.getSender(), message.key); } } catch (Exception e) { FMLLog.warning("Magic Bees recieved an invalid IMC Message from a mod %s! Please inform " + "the author of %s that they may not be correctly implementing message for key '%s'. Error details follow.", message.getSender(), message.key); FMLLog.info(e.getMessage()); } } }
private static void handleCrumbleBlock(IMCMessage message) throws Exception { NBTTagCompound root = message.getNBTValue(); NBTBase source = root.getTag("source"); NBTBase target = root.getTag("target"); if (source != null && source instanceof NBTTagCompound) { ItemStack sourceItem = ItemStack.loadItemStackFromNBT((NBTTagCompound)source); if (target instanceof NBTTagCompound) { ItemStack targetItem = ItemStack.loadItemStackFromNBT((NBTTagCompound)target); AlleleEffectCrumbling.addPairToMap(sourceItem, targetItem); } else { throw new Exception("Required tag 'target' was either empty, or not a valid ItemStack."); } } else { throw new Exception("Required tag 'source' was either empty, or not a valid ItemStack."); } }
@Override public void act(IMCMessage msg) { if (!msg.isStringMessage()) { return; } String[] data = msg.getStringValue().split("\\|"); if (data.length != 3) { return; } PlantInfo plantinfo = new PlantInfo(data[0], data[1], Integer.parseInt(data[2]), Integer.parseInt(data[3])); plantinfo.init(); RightClickCropHandler.INSTANCE.addCrop(plantinfo); }
@Mod.EventHandler public void onIMCMessages(IMCEvent event){ for(IMCMessage message : event.getMessages()) { if(message.key.equalsIgnoreCase("camoMineBlacklist")) { if(message.isItemStackMessage()) { ItemStack blacklistedStack = message.getItemStackValue(); if(blacklistedStack.getItem() != null) { TileEntityCamoMine.camouflageBlacklist.add(blacklistedStack); LogHelper.info(String.format("Mod %s added %s to be blacklisted as camouflage for the Camo Mine", message.getSender(), blacklistedStack.toString())); } else { throw new IllegalStateException(String.format("ItemStack tried to be used in registry by the mod %s has a null item.", message.getSender())); } } else { LogHelper.warn(String.format("Mod %s sent a non-ItemStack message, where an ItemStack was expected.", message.getSender())); } } else { LogHelper.warn(String.format("Mod %s used an invalid IMC key: %s", message.getSender(), message.key)); } } }
@Mod.EventHandler public void onIMCMessages(IMCEvent event){ Log.info("Receiving IMC"); for(IMCMessage message : event.getMessages()) { if(message.key.equalsIgnoreCase("camoMineBlacklist")) { if(message.isItemStackMessage()) { ItemStack blacklistedStack = message.getItemStackValue(); if(blacklistedStack.getItem() != null) { TileEntityCamoMine.camouflageBlacklist.add(blacklistedStack); Log.info(String.format("Mod %s added %s to be blacklisted as camouflage for the Camo Mine", message.getSender(), blacklistedStack.toString())); } else { throw new IllegalStateException(String.format("ItemStack tried to be used in registry by the mod %s has a null item.", message.getSender())); } } else { Log.warn(String.format("Mod %s sent a non-ItemStack message, where an ItemStack message was expected.", message.getSender())); } } else { Log.warn(String.format("Mod %s used an invalid IMC key: %s", message.getSender(), message.key)); } } }
@EventHandler public void interModMessages(IMCEvent event) { for (IMCMessage message : event.getMessages()) { if (message.key.equalsIgnoreCase("updaterInfo")) { if (message.isStringMessage()) { System.out.println("The mod " + message.getSender() + " has sent the following message: " + message.getStringValue()); try { MessageDecoder.decodeMessage(message.getSender(), message.getStringValue()); } catch (IllegalArgumentException e) { e.printStackTrace(); } } } } }
public static void sendMessage(String message, Object value) { if (!Loader.isModLoaded("MineFactoryReloaded") || Loader.instance().activeModContainer() == null) return; try { Method m = FMLInterModComms.class.getDeclaredMethod("enqueueMessage", Object.class, String.class, IMCMessage.class); m.setAccessible(true); Constructor<IMCMessage> c = IMCMessage.class.getDeclaredConstructor(String.class, Object.class); c.setAccessible(true); m.invoke(null, Loader.instance().activeModContainer(), "MineFactoryReloaded", c.newInstance(message, value)); } catch(Exception e) { e.printStackTrace(); } }
@Override public boolean processIMCMessage(IMCMessage message) { if(message.key.equals("add-backpack-items")) { String[] tokens = message.getStringValue().split("@"); if(tokens.length != 2) { Logger.getLogger("Forestry").log(Level.INFO, String.format("Received an invalid 'add-backpack-items' request %s from mod %s", message.getStringValue(), message.getSender())); return true; } if(!BackpackManager.definitions.containsKey(tokens[0])) { Logger.getLogger("Forestry").log(Level.INFO, String.format("Received an invalid 'add-backpack-items' request %s from mod %s for non-existent backpack %s.", message.getStringValue(), message.getSender(), tokens[0])); return true; } parseBackpackItems(tokens[0] + "'s Backpack", tokens[1], BackpackManager.definitions.get(tokens[0])); return true; } return false; }
@Mod.EventHandler public void handleIMCMessage(FMLInterModComms.IMCEvent event) { for (IMCMessage message : event.getMessages()) { if ("addClassExclusion".equals(message.key) && message.isStringMessage()) { try { Class<?> clazz = Class.forName(message.getStringValue()); CommonProxy.excludedClasses.add(clazz); } catch (ClassNotFoundException e) { I18n.format("message.cartlivery.invalidExclusion", message.getSender(), message.getStringValue()); } } if ("addBuiltInLiveries".equals(message.key) && message.isStringMessage() && FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) { String[] liveries = message.getStringValue().split(","); log.info(I18n.format("message.cartlivery.registerBuiltIn", liveries.length, message.getSender())); for(String livery : liveries) LiveryTextureRegistry.builtInLiveries.put(livery, message.getSender()); } } }
@EventHandler public void receiveMessages(IMCEvent event) { ImmutableList<IMCMessage> messages = event.getMessages(); for(IMCMessage msg : messages) { if(msg.key.equals("WhitelistItemNBT")) { EnderID.whitelistedNBTItems.add(EnderID.getItemIdentifierFor(msg.getItemStackValue())); } if(msg.key.equals("BlacklistItem")) { EnderID.blacklistedItems.add(EnderID.getItemIdentifierFor(msg.getItemStackValue())); } if(msg.key.equals("RegisterURIHandler")) { try { Class handlerClass = this.getClass().getClassLoader().loadClass(msg.getStringValue()); httpServer.registerHandler((IURIHandler)handlerClass.newInstance()); } catch(Exception e) { e.printStackTrace(); log.error("Could not load handler " + msg.getStringValue() + "!"); } } } }
@EventHandler public void processIMCRequests(IMCEvent event) { for (IMCMessage message : event.getMessages()) if (message.key.equals("register-brewing-fuel")) { NBTTagCompound nbt = message.getNBTValue(); ItemStack stack = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("Fuel")); int brews = nbt.getInteger("Brews"); BrewingFuelRegistry.registerFuel(stack, brews); } }
private void processImc(ImmutableList<IMCMessage> messages) { //TODO: Villager gens, loot tables and custom types StructureGenRegister reg = StructureGenRegister.instance; for (IMCMessage msg : messages) { String key = msg.key; try { if(msg.isStringMessage()) { if(API.ADD_RESOURCE_DIR.equalsIgnoreCase(key)) { reg.getResourceManager().addResourceDirectory(new File(msg.getStringValue())); } else if(API.ADD_RESOURCE_PATH.equalsIgnoreCase(key)) { reg.getResourceManager().addClassLoaderResourcePath(msg.getStringValue()); } else if(API.REGISTER_GENERATOR.equalsIgnoreCase(key)) { IStructureGenerator gen = StructureGenRegister.instance.getResourceManager().loadGenerator(msg.getStringValue()); if(gen != null) { reg.registerGenerator(gen); } } else if(API.REGISTER_VILLAGE_GENERATOR.equalsIgnoreCase(key)) { IVillagerGenerator vil = StructureGenRegister.instance.getResourceManager().loadVillager(msg.getStringValue()); if(vil != null) { reg.registerVillagerGenerator(vil); } } else if(API.REGISTER_TYPE.equalsIgnoreCase(key)) { ITyped inst = (ITyped)Class.forName(msg.getStringValue()).newInstance(); TypeRegister.INSTANCE.register(inst); ParserRegister.instance.register(new GsonParserAdapter(inst)); } } else if(msg.isNBTMessage()) { } } catch (Exception e) { } } }
public void handleEvent(IMCEvent event) { for (IIMC handler : handlers) { for (IMCMessage msg : event.getMessages()) { if (msg.key.equals(handler.getKey())) { handler.act(msg); } } } }
public void handleMessage(IMCMessage message) { for (IMC imc : IMC.values()) { if (imc.key.equals(message.key)) { handle(message, imc, message.getStringValue()); } } }
private void handle(IMCMessage message, IMC type, String value) { ICarvingRegistry reg = Carving.chisel; String[] data = value.split("\\|"); try { switch (type) { case ADD_VARIATION: case REMOVE_VARIATION: Block block = (Block) Block.blockRegistry.getObject(data[1]); int meta = Short.parseShort(data[2]); if (type == IMC.ADD_VARIATION) { reg.addVariation(data[0], block, meta, order++); } else { reg.removeVariation(block, meta, data[0]); } break; case REGISTER_GROUP_ORE: reg.registerOre(data[0], data[1]); break; default: throw new IllegalArgumentException("Invalid IMC constant! How...what...?"); } } catch (Exception e) { Chisel.logger.error("Could not handle data {} for IMC type {}. This was sent from mod {}.\n" + "!! This is a bug in that mod !!\nSwallowing error and continuing...", value, type.name(), message.getSender()); e.printStackTrace(); } }
@EventHandler public void messageRecieve(IMCEvent event) { Iterator<IMCMessage> itr = event.getMessages().iterator(); while(itr.hasNext()) { IMCMessage element = itr.next(); logger.info("Sender: " + element.getSender() + " Value: " + element.getStringValue() + " "); } }
/** this is more just for future reference than anything else * you dont need to understand it */ @Override @EventHandler public void messageRecieve(IMCEvent event) { Iterator<IMCMessage> itr = event.getMessages().iterator(); while(itr.hasNext()) { IMCMessage element = itr.next(); logger.info("Sender: " + element.getSender() + "Value: " + element.getStringValue() + " "); } System.out.println(); }
/** this is more just for future reference than anything else */ @Override @EventHandler public void messageRecieve(IMCEvent event) { Iterator<IMCMessage> itr = event.getMessages().iterator(); while(itr.hasNext()) { IMCMessage element = itr.next(); logger.info("Sender: " + element.getSender() + "Value: " + element.getStringValue() + " "); } System.out.println(); }
public void recieveIMC(FMLInterModComms.IMCEvent event) { OresPlus.log.info("Recieved IMC evemt"); for (IMCMessage message : event.getMessages()) { try { if (!message.isNBTMessage()) break; NBTTagCompound messageData = message.getNBTValue(); if (message.key.equals("registerOre")) { if (!messageData.getString("oreName").equals("") && !Ores.manager.isOreRegistered(messageData.getString("oreName"))) { Ores.manager.registerOre(messageData.getString("oreName"), GameRegistry.findBlock(message.getSender(), messageData.getString("oreName"))); } } else if (message.key.equals("registerGenerator")) { if (!messageData.getString("oreName").equals("") && !Ores.manager.isOreRegistered(messageData.getString("oreName"))) { OreGenClass oreGen = new OreGenClass( messageData.getString("genName"), messageData.getString("oreName"), messageData.getBoolean("genEnabled"), messageData.getInteger("genDim"), messageData.getInteger("numVeins"), messageData.getInteger("veinSize"), messageData.getInteger("minY"), messageData.getInteger("maxY"), messageData.getBoolean("doRegen"), OreGenType.NORMAL, messageData.getInteger("oreDensity"), messageData.getString("regenKey")); new WorldGenOre(oreGen); } } } catch (Exception e) { OresPlus.log.info("Error, recieved invalid IMC message from " + message.getSender()); e.printStackTrace(); } } }
@EventHandler public void IMCCallback(IMCEvent event) { for (IMCMessage msg : event.getMessages()) { switch (msg.key) { case "registerLeafType": DerpyRegistry.leafTypes.add(new BasicBlockEntry(GameRegistry.findBlock(msg.getNBTValue().getString("sourceMod"), msg.getNBTValue().getString("blockID")), msg.getNBTValue().getInteger("meta"))); break; } } }
public void processIMCMessages(ImmutableList<IMCMessage> messages) { for (IMCMessage message : messages) { for(IPlugin plugin : PluginManager.plugins) { if(!(plugin instanceof NativePlugin)) continue; if(((NativePlugin)plugin).processIMCMessage(message)) break; } } }
@Override public boolean processIMCMessage(IMCMessage message) { if(message.key.equals("securityViolation")) { Config.invalidFingerprint = true; } return false; }
public static void processIMCMessages(IMCEvent event) { for (IMCMessage imcMessage : event.getMessages()) { if (imcMessage.getMessageType() == NBTTagCompound.class) { if (imcMessage.key.equalsIgnoreCase(addQMCItemStack)) { addQMCItemStack(imcMessage); } else if (imcMessage.key.equalsIgnoreCase(toolBlackList)) { toolBlackList(imcMessage); } } } }
private static void addQMCItemStack(IMCMessage imc) { NBTTagCompound nbt = imc.getNBTValue(); double qmc = nbt.getDouble("qmc"); Object o = null; if (nbt.hasKey("ore")) { o = nbt.getString("ore"); } else { o = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("item")); } if (o != null && qmc > 0) { QMC.add(o, qmc); Log.debug("[IMC] Added QMC to " + o.toString() + ", value " + qmc + " " + QMC.name + ", from " + imc.getSender()); } }
@EventHandler public void handleIMC(IMCEvent event) { // Catch IMC messages and send them off to our IMC handler ImmutableList<IMCMessage> messages = event.getMessages(); IMCHandler.process(messages); }
@Override public void process(IMCMessage message) { if (!message.isStringMessage()) return; LoggerUtils.info(String.format("Receiving API registration request from [%s] for method %s", message.getSender(), message.getStringValue())); callbackRegistration(message.getStringValue(), message.getSender()); }
@EventHandler public void onIMCEvent(List<IMCMessage> messages) { for(IMCMessage msg : messages) { if(msg.isNBTMessage()) { try { boolean found = false; for(Recipe type : Recipe.values()) { if(msg.key.equalsIgnoreCase(type.getRecipeName() + "Recipe")) { MachineInput input = type.createInput(msg.getNBTValue()); if(input != null && input.isValid()) { MachineRecipe recipe = type.createRecipe(input, msg.getNBTValue()); if(recipe != null && recipe.recipeOutput != null) { RecipeHandler.addRecipe(type, recipe); Mekanism.logger.info("[Mekanism] " + msg.getSender() + " added recipe of type " + type.getRecipeName() + " to the recipe list."); } else { Mekanism.logger.error("[Mekanism] " + msg.getSender() + " attempted to add recipe of type " + type.getRecipeName() + " with an invalid output."); } } else { Mekanism.logger.error("[Mekanism] " + msg.getSender() + " attempted to add recipe of type " + type.getRecipeName() + " with an invalid input."); } found = true; break; } } if(!found) { Mekanism.logger.error("[Mekanism] " + msg.getSender() + " sent unknown IMC message with key '" + msg.key + ".'"); } } catch(Exception e) { e.printStackTrace(); } } } }
@EventHandler public void onIMC(IMCEvent event) { for (IMCMessage msg : event.getMessages()) { IMCHandler.INSTANCE.handleMessage(msg); } }
public boolean processIMCMessage(IMCMessage message) { return false; }
private static void toolBlackList(IMCMessage imc) { NBTTagCompound nbt = imc.getNBTValue(); int blockID = nbt.getInteger("blockID"); QuantumToolBlackList.add(Block.getBlockById(blockID)); Log.debug("[IMC] Added id " + Block.getBlockById(blockID) + " to QuantumToolBlackList"); }
public void process(IMCMessage message);
void act(IMCMessage msg);