java类cpw.mods.fml.common.event.FMLInterModComms.IMCMessage的实例源码

IMCManager.java 文件源码 项目:MagicBees 阅读 20 收藏 0 点赞 0 评论 0
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());
        }
    }
}
IMCManager.java 文件源码 项目:MagicBees 阅读 19 收藏 0 点赞 0 评论 0
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.");
    }
}
IMCRightClickCrop.java 文件源码 项目:EnderCore 阅读 19 收藏 0 点赞 0 评论 0
@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);
}
RandomThoughtsMod.java 文件源码 项目:RandomThoughtsMod 阅读 18 收藏 0 点赞 0 评论 0
@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));
        }
    }
}
AdvancedMod.java 文件源码 项目:AdvancedMod 阅读 21 收藏 0 点赞 0 评论 0
@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));
        }
    }
}
ForgeUpdater.java 文件源码 项目:ForgeUpdater 阅读 19 收藏 0 点赞 0 评论 0
@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();
                }
            }
        }
    }
}
FactoryRegistry.java 文件源码 项目:Dendrology 阅读 16 收藏 0 点赞 0 评论 0
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();
    }
}
PluginForestryStorage.java 文件源码 项目:ForestryLegacy 阅读 45 收藏 0 点赞 0 评论 0
@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;
}
ModCartLivery.java 文件源码 项目:CartLivery 阅读 27 收藏 0 点赞 0 评论 0
@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());
        }
    }
}
EnderNet.java 文件源码 项目:endernet 阅读 22 收藏 0 点赞 0 评论 0
@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() + "!");
            }
        }
    }
}
FactoryRegistry.java 文件源码 项目:PneumaticCraft 阅读 19 收藏 0 点赞 0 评论 0
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();
    }
}
EtFuturum.java 文件源码 项目:connor41-etfuturum2 阅读 25 收藏 0 点赞 0 评论 0
@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);
        }
}
EnderStructures.java 文件源码 项目:Structures 阅读 25 收藏 0 点赞 0 评论 0
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) {
    }
  }
}
IMCRegistry.java 文件源码 项目:EnderCore 阅读 20 收藏 0 点赞 0 评论 0
public void handleEvent(IMCEvent event) {
  for (IIMC handler : handlers) {
    for (IMCMessage msg : event.getMessages()) {
      if (msg.key.equals(handler.getKey())) {
        handler.act(msg);
      }
    }
  }
}
EtFuturum.java 文件源码 项目:Et-Futurum 阅读 23 收藏 0 点赞 0 评论 0
@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);
        }
}
IMCHandler.java 文件源码 项目:Chisel-2 阅读 21 收藏 0 点赞 0 评论 0
public void handleMessage(IMCMessage message) {
    for (IMC imc : IMC.values()) {
        if (imc.key.equals(message.key)) {
            handle(message, imc, message.getStringValue());
        }
    }
}
IMCHandler.java 文件源码 项目:Chisel-2 阅读 21 收藏 0 点赞 0 评论 0
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();
    }
}
MMod.java 文件源码 项目:NausicaaMod 阅读 21 收藏 0 点赞 0 评论 0
@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() + " ");
      } 

}
LapMain.java 文件源码 项目:NausicaaMod 阅读 21 收藏 0 点赞 0 评论 0
/** 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();
}
Main.java 文件源码 项目:NausicaaMod 阅读 19 收藏 0 点赞 0 评论 0
/** 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();
}
IMCHandler.java 文件源码 项目:OresPlus 阅读 21 收藏 0 点赞 0 评论 0
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();
        }
    }
}
Main.java 文件源码 项目:The-Derpy-Shiz-Mod 阅读 19 收藏 0 点赞 0 评论 0
@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;
        }
    }
}
ForestryCore.java 文件源码 项目:ForestryLegacy 阅读 21 收藏 0 点赞 0 评论 0
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;
        }
    }
}
PluginForestryCore.java 文件源码 项目:ForestryLegacy 阅读 23 收藏 0 点赞 0 评论 0
@Override
public boolean processIMCMessage(IMCMessage message) {
    if(message.key.equals("securityViolation")) {
        Config.invalidFingerprint = true;
    }
    return false;
}
IMCHandler.java 文件源码 项目:Open-Exchange 阅读 27 收藏 0 点赞 0 评论 0
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);
      }
    }
  }
}
IMCHandler.java 文件源码 项目:Open-Exchange 阅读 23 收藏 0 点赞 0 评论 0
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());
  }
}
LookingGlass.java 文件源码 项目:LookingGlass 阅读 26 收藏 0 点赞 0 评论 0
@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);
}
IMCAPIRegister.java 文件源码 项目:LookingGlass 阅读 18 收藏 0 点赞 0 评论 0
@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());
}
IMCHandler.java 文件源码 项目:vsminecraft 阅读 22 收藏 0 点赞 0 评论 0
@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();
            }
        }
    }
}
Chisel.java 文件源码 项目:Chisel-2 阅读 19 收藏 0 点赞 0 评论 0
@EventHandler
public void onIMC(IMCEvent event) {
    for (IMCMessage msg : event.getMessages()) {
        IMCHandler.INSTANCE.handleMessage(msg);
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号