Search in sources :

Example 31 with ModContainer

use of net.minecraftforge.fml.common.ModContainer in project MinecraftForge by MinecraftForge.

the class ModSortingException method printStackTrace.

@Override
protected void printStackTrace(WrappedPrintStream stream) {
    SortingExceptionData<ModContainer> exceptionData = getExceptionData();
    stream.println("A dependency cycle was detected in the input mod set so an ordering cannot be determined");
    stream.println("The first mod in the cycle is " + exceptionData.getFirstBadNode());
    stream.println("The mod cycle involves:");
    for (ModContainer mc : exceptionData.getVisitedNodes()) {
        stream.println(String.format("\t%s : before: %s, after: %s", mc.toString(), mc.getDependants(), mc.getDependencies()));
    }
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer)

Example 32 with ModContainer

use of net.minecraftforge.fml.common.ModContainer in project MinecraftForge by MinecraftForge.

the class EntityRegistry method doModEntityRegistration.

private void doModEntityRegistration(ResourceLocation registryName, Class<? extends Entity> entityClass, String entityName, int id, Object mod, int trackingRange, int updateFrequency, boolean sendsVelocityUpdates) {
    ModContainer mc = FMLCommonHandler.instance().findContainerFor(mod);
    EntityRegistration er = new EntityRegistration(mc, registryName, entityClass, entityName, id, trackingRange, updateFrequency, sendsVelocityUpdates);
    try {
        entityClassRegistrations.put(entityClass, er);
        if (!ForgeRegistries.ENTITIES.containsKey(registryName)) {
            EntityEntry entry = new EntityEntry(entityClass, entityName).setRegistryName(registryName);
            ForgeRegistries.ENTITIES.register(entry);
            FMLLog.finer("Automatically registered mod %s entity %s as %s", mc.getModId(), entityName, entry.getRegistryName());
        } else {
            FMLLog.fine("Skipping automatic mod %s entity registration for already registered entry %s class %s", mc.getModId(), registryName, entityClass.getName());
        }
    } catch (IllegalArgumentException e) {
        FMLLog.log(Level.WARN, e, "The mod %s tried to register the entity (registry,name,class) (%s,%s,%s) one or both of which are already registered", mc.getModId(), registryName, entityName, entityClass.getName());
        return;
    }
    entityRegistrations.put(mc, er);
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer)

Example 33 with ModContainer

use of net.minecraftforge.fml.common.ModContainer in project MinecraftForge by MinecraftForge.

the class OreDictionary method registerOreImpl.

/**
     * Registers a ore item into the dictionary.
     * Raises the registerOre function in all registered handlers.
     *
     * @param name The name of the ore
     * @param ore The ore's ItemStack
     */
private static void registerOreImpl(String name, @Nonnull ItemStack ore) {
    //prevent bad IDs.
    if ("Unknown".equals(name))
        return;
    if (ore.isEmpty()) {
        FMLLog.bigWarning("Invalid registration attempt for an Ore Dictionary item with name %s has occurred. The registration has been denied to prevent crashes. The mod responsible for the registration needs to correct this.", name);
        //prevent bad ItemStacks.
        return;
    }
    int oreID = getOreID(name);
    // HACK: use the registry name's ID. It is unique and it knows about substitutions. Fallback to a -1 value (what Item.getIDForItem would have returned) in the case where the registry is not aware of the item yet
    // IT should be noted that -1 will fail the gate further down, if an entry already exists with value -1 for this name. This is what is broken and being warned about.
    // APPARENTLY it's quite common to do this. OreDictionary should be considered alongside Recipes - you can't make them properly until you've registered with the game.
    ResourceLocation registryName = ore.getItem().delegate.name();
    int hash;
    if (registryName == null) {
        ModContainer modContainer = Loader.instance().activeModContainer();
        String modContainerName = modContainer == null ? null : modContainer.getName();
        FMLLog.bigWarning("A broken ore dictionary registration with name %s has occurred. It adds an item (type: %s) which is currently unknown to the game registry. This dictionary item can only support a single value when" + " registered with ores like this, and NO I am not going to turn this spam off. Just register your ore dictionary entries after the GameRegistry.\n" + "TO USERS: YES this is a BUG in the mod " + modContainerName + " report it to them!", name, ore.getItem().getClass());
        hash = -1;
    } else {
        hash = GameData.getItemRegistry().getId(registryName);
    }
    if (ore.getItemDamage() != WILDCARD_VALUE) {
        // +1 so 0 is significant
        hash |= ((ore.getItemDamage() + 1) << 16);
    }
    //Add things to the baked version, and prevent duplicates
    List<Integer> ids = stackToId.get(hash);
    if (ids != null && ids.contains(oreID))
        return;
    if (ids == null) {
        ids = Lists.newArrayList();
        stackToId.put(hash, ids);
    }
    ids.add(oreID);
    //Add to the unbaked version
    ore = ore.copy();
    idToStack.get(oreID).add(ore);
    MinecraftForge.EVENT_BUS.post(new OreRegisterEvent(name, ore));
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 34 with ModContainer

use of net.minecraftforge.fml.common.ModContainer in project Bookshelf by Darkhax-Minecraft.

the class ModUtils method getModName.

/**
     * Gets the name of a mod that registered the passed object. Has support for a wide range
     * of registerable objects such as blocks, items, enchantments, potions, sounds, villagers,
     * biomes, and so on.
     *
     * @param registerable The registerable object. Accepts anything that extends
     *        IForgeRegistryEntry.Impl. Current list includes BiomeGenBase, Block, Enchantment,
     *        Item, Potion, PotionType, SoundEvent and VillagerProfession.
     * @return String The name of the mod that registered the object.
     */
public static String getModName(IForgeRegistryEntry.Impl<?> registerable) {
    final String modID = registerable.getRegistryName().getResourceDomain();
    final ModContainer mod = getModContainer(modID);
    return mod != null ? mod.getName() : "minecraft".equals(modID) ? "Minecraft" : "Unknown";
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer)

Aggregations

ModContainer (net.minecraftforge.fml.common.ModContainer)34 ResourceLocation (net.minecraft.util.ResourceLocation)4 DummyModContainer (net.minecraftforge.fml.common.DummyModContainer)4 LoaderException (net.minecraftforge.fml.common.LoaderException)4 Nullable (javax.annotation.Nullable)3 ForgeModContainer (net.minecraftforge.common.ForgeModContainer)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 JsonObject (com.google.gson.JsonObject)2 File (java.io.File)2 InputStream (java.io.InputStream)2 List (java.util.List)2 Map (java.util.Map)2 BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1 SetMultimap (com.google.common.collect.SetMultimap)1 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 RCConfig (ivorius.reccomplex.RCConfig)1