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

项目:MagicBees    文件:IMCManager.java   
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());
        }
    }
}
项目:MagicBees    文件:IMCManager.java   
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.");
    }
}
项目:EnderCore    文件:IMCRightClickCrop.java   
@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    文件:RandomThoughtsMod.java   
@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    文件:AdvancedMod.java   
@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    文件:ForgeUpdater.java   
@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();
                }
            }
        }
    }
}
项目:Dendrology    文件:FactoryRegistry.java   
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();
    }
}
项目:ForestryLegacy    文件:PluginForestryStorage.java   
@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;
}
项目:CartLivery    文件:ModCartLivery.java   
@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    文件:EnderNet.java   
@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() + "!");
            }
        }
    }
}
项目:PneumaticCraft    文件:FactoryRegistry.java   
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();
    }
}
项目:connor41-etfuturum2    文件:EtFuturum.java   
@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);
        }
}
项目:Structures    文件:EnderStructures.java   
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) {
    }
  }
}
项目:EnderCore    文件:IMCRegistry.java   
public void handleEvent(IMCEvent event) {
  for (IIMC handler : handlers) {
    for (IMCMessage msg : event.getMessages()) {
      if (msg.key.equals(handler.getKey())) {
        handler.act(msg);
      }
    }
  }
}
项目:Et-Futurum    文件:EtFuturum.java   
@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);
        }
}
项目:Chisel-2    文件:IMCHandler.java   
public void handleMessage(IMCMessage message) {
    for (IMC imc : IMC.values()) {
        if (imc.key.equals(message.key)) {
            handle(message, imc, message.getStringValue());
        }
    }
}
项目:Chisel-2    文件:IMCHandler.java   
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();
    }
}
项目:NausicaaMod    文件:MMod.java   
@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() + " ");
      } 

}
项目:NausicaaMod    文件:LapMain.java   
/** 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();
}
项目:NausicaaMod    文件:Main.java   
/** 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();
}
项目:OresPlus    文件:IMCHandler.java   
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();
        }
    }
}
项目:The-Derpy-Shiz-Mod    文件:Main.java   
@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;
        }
    }
}
项目:ForestryLegacy    文件:ForestryCore.java   
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;
        }
    }
}
项目:ForestryLegacy    文件:PluginForestryCore.java   
@Override
public boolean processIMCMessage(IMCMessage message) {
    if(message.key.equals("securityViolation")) {
        Config.invalidFingerprint = true;
    }
    return false;
}
项目:Open-Exchange    文件:IMCHandler.java   
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);
      }
    }
  }
}
项目:Open-Exchange    文件:IMCHandler.java   
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    文件:LookingGlass.java   
@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);
}
项目:LookingGlass    文件:IMCAPIRegister.java   
@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());
}
项目:vsminecraft    文件:IMCHandler.java   
@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-2    文件:Chisel.java   
@EventHandler
public void onIMC(IMCEvent event) {
    for (IMCMessage msg : event.getMessages()) {
        IMCHandler.INSTANCE.handleMessage(msg);
    }
}
项目:ForestryLegacy    文件:NativePlugin.java   
public boolean processIMCMessage(IMCMessage message) {
    return false;
}
项目:Open-Exchange    文件:IMCHandler.java   
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");
}
项目:LookingGlass    文件:IMCHandler.java   
public void process(IMCMessage message);
项目:EnderCore    文件:IMCRegistry.java   
void act(IMCMessage msg);