Search in sources :

Example 26 with ModContainer

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

the class DirectoryDiscoverer method discover.

@Override
public List<ModContainer> discover(ModCandidate candidate, ASMDataTable table) {
    this.table = table;
    List<ModContainer> found = Lists.newArrayList();
    FMLLog.fine("Examining directory %s for potential mods", candidate.getModContainer().getName());
    exploreFileSystem("", candidate.getModContainer(), found, candidate, null);
    for (ModContainer mc : found) {
        table.addContainer(mc);
    }
    return found;
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer)

Example 27 with ModContainer

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

the class JarDiscoverer method discover.

@Override
public List<ModContainer> discover(ModCandidate candidate, ASMDataTable table) {
    List<ModContainer> foundMods = Lists.newArrayList();
    FMLLog.fine("Examining file %s for potential mods", candidate.getModContainer().getName());
    JarFile jar = null;
    try {
        jar = new JarFile(candidate.getModContainer());
        ZipEntry modInfo = jar.getEntry("mcmod.info");
        MetadataCollection mc = null;
        if (modInfo != null) {
            FMLLog.finer("Located mcmod.info file in file %s", candidate.getModContainer().getName());
            InputStream inputStream = jar.getInputStream(modInfo);
            try {
                mc = MetadataCollection.from(inputStream, candidate.getModContainer().getName());
            } finally {
                IOUtils.closeQuietly(inputStream);
            }
        } else {
            FMLLog.fine("The mod container %s appears to be missing an mcmod.info file", candidate.getModContainer().getName());
            mc = MetadataCollection.from(null, "");
        }
        for (ZipEntry ze : Collections.list(jar.entries())) {
            if (ze.getName() != null && ze.getName().startsWith("__MACOSX")) {
                continue;
            }
            Matcher match = classFile.matcher(ze.getName());
            if (match.matches()) {
                ASMModParser modParser;
                try {
                    InputStream inputStream = jar.getInputStream(ze);
                    try {
                        modParser = new ASMModParser(inputStream);
                    } finally {
                        IOUtils.closeQuietly(inputStream);
                    }
                    candidate.addClassEntry(ze.getName());
                } catch (LoaderException e) {
                    FMLLog.log(Level.ERROR, e, "There was a problem reading the entry %s in the jar %s - probably a corrupt zip", ze.getName(), candidate.getModContainer().getPath());
                    jar.close();
                    throw e;
                }
                modParser.validate();
                modParser.sendToTable(table, candidate);
                ModContainer container = ModContainerFactory.instance().build(modParser, candidate.getModContainer(), candidate);
                if (container != null) {
                    table.addContainer(container);
                    foundMods.add(container);
                    container.bindMetadata(mc);
                    container.setClassVersion(modParser.getClassVersion());
                }
            }
        }
    } catch (Exception e) {
        FMLLog.log(Level.WARN, e, "Zip file %s failed to read properly, it will be ignored", candidate.getModContainer().getName());
    } finally {
        Java6Utils.closeZipQuietly(jar);
    }
    return foundMods;
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer) LoaderException(net.minecraftforge.fml.common.LoaderException) Matcher(java.util.regex.Matcher) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ASMModParser(net.minecraftforge.fml.common.discovery.asm.ASMModParser) MetadataCollection(net.minecraftforge.fml.common.MetadataCollection) JarFile(java.util.jar.JarFile) LoaderException(net.minecraftforge.fml.common.LoaderException)

Example 28 with ModContainer

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

the class EventBus method register.

public void register(Object target) {
    if (listeners.containsKey(target)) {
        return;
    }
    ModContainer activeModContainer = Loader.instance().activeModContainer();
    if (activeModContainer == null) {
        FMLLog.log(Level.ERROR, new Throwable(), "Unable to determine registrant mod for %s. This is a critical error and should be impossible", target);
        activeModContainer = Loader.instance().getMinecraftModContainer();
    }
    listenerOwners.put(target, activeModContainer);
    boolean isStatic = target.getClass() == Class.class;
    @SuppressWarnings("unchecked") Set<? extends Class<?>> supers = isStatic ? Sets.newHashSet((Class<?>) target) : TypeToken.of(target.getClass()).getTypes().rawTypes();
    for (Method method : (isStatic ? (Class<?>) target : target.getClass()).getMethods()) {
        if (isStatic && !Modifier.isStatic(method.getModifiers()))
            continue;
        else if (!isStatic && Modifier.isStatic(method.getModifiers()))
            continue;
        for (Class<?> cls : supers) {
            try {
                Method real = cls.getDeclaredMethod(method.getName(), method.getParameterTypes());
                if (real.isAnnotationPresent(SubscribeEvent.class)) {
                    Class<?>[] parameterTypes = method.getParameterTypes();
                    if (parameterTypes.length != 1) {
                        throw new IllegalArgumentException("Method " + method + " has @SubscribeEvent annotation, but requires " + parameterTypes.length + " arguments.  Event handler methods must require a single argument.");
                    }
                    Class<?> eventType = parameterTypes[0];
                    if (!Event.class.isAssignableFrom(eventType)) {
                        throw new IllegalArgumentException("Method " + method + " has @SubscribeEvent annotation, but takes a argument that is not an Event " + eventType);
                    }
                    register(eventType, target, real, activeModContainer);
                    break;
                }
            } catch (NoSuchMethodException e) {
                ;
            }
        }
    }
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer) Method(java.lang.reflect.Method)

Example 29 with ModContainer

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

the class ASMDataTable method getAnnotationsFor.

public SetMultimap<String, ASMData> getAnnotationsFor(ModContainer container) {
    if (containerAnnotationData == null) {
        ImmutableMap.Builder<ModContainer, SetMultimap<String, ASMData>> mapBuilder = ImmutableMap.builder();
        for (ModContainer cont : containers) {
            Multimap<String, ASMData> values = Multimaps.filterValues(globalAnnotationData, new ModContainerPredicate(cont));
            mapBuilder.put(cont, ImmutableSetMultimap.copyOf(values));
        }
        containerAnnotationData = mapBuilder.build();
    }
    return containerAnnotationData.get(container);
}
Also used : SetMultimap(com.google.common.collect.SetMultimap) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) ASMData(net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData) ModContainer(net.minecraftforge.fml.common.ModContainer) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 30 with ModContainer

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

the class EntitySpawnHandler method spawnEntity.

private void spawnEntity(FMLMessage.EntitySpawnMessage spawnMsg) {
    ModContainer mc = Loader.instance().getIndexedModList().get(spawnMsg.modId);
    EntityRegistration er = EntityRegistry.instance().lookupModSpawn(mc, spawnMsg.modEntityTypeId);
    if (er == null) {
        throw new RuntimeException("Could not spawn mod entity ModID: " + spawnMsg.modId + " EntityID: " + spawnMsg.modEntityTypeId + " at ( " + spawnMsg.rawX + "," + spawnMsg.rawY + ", " + spawnMsg.rawZ + ") Please contact mod author or server admin.");
    }
    WorldClient wc = FMLClientHandler.instance().getWorldClient();
    Class<? extends Entity> cls = er.getEntityClass();
    try {
        Entity entity;
        if (er.hasCustomSpawning()) {
            entity = er.doCustomSpawning(spawnMsg);
        } else {
            entity = cls.getConstructor(World.class).newInstance(wc);
            int offset = spawnMsg.entityId - entity.getEntityId();
            entity.setEntityId(spawnMsg.entityId);
            entity.setUniqueId(spawnMsg.entityUUID);
            entity.setLocationAndAngles(spawnMsg.rawX, spawnMsg.rawY, spawnMsg.rawZ, spawnMsg.scaledYaw, spawnMsg.scaledPitch);
            if (entity instanceof EntityLiving) {
                ((EntityLiving) entity).rotationYawHead = spawnMsg.scaledHeadYaw;
            }
            Entity[] parts = entity.getParts();
            if (parts != null) {
                for (int j = 0; j < parts.length; j++) {
                    parts[j].setEntityId(parts[j].getEntityId() + offset);
                }
            }
        }
        EntityTracker.updateServerPosition(entity, spawnMsg.rawX, spawnMsg.rawY, spawnMsg.rawZ);
        EntityPlayerSP clientPlayer = FMLClientHandler.instance().getClientPlayerEntity();
        if (entity instanceof IThrowableEntity) {
            Entity thrower = clientPlayer.getEntityId() == spawnMsg.throwerId ? clientPlayer : wc.getEntityByID(spawnMsg.throwerId);
            ((IThrowableEntity) entity).setThrower(thrower);
        }
        if (spawnMsg.dataWatcherList != null) {
            entity.getDataManager().setEntryValues(spawnMsg.dataWatcherList);
        }
        if (spawnMsg.throwerId > 0) {
            entity.setVelocity(spawnMsg.speedScaledX, spawnMsg.speedScaledY, spawnMsg.speedScaledZ);
        }
        if (entity instanceof IEntityAdditionalSpawnData) {
            ((IEntityAdditionalSpawnData) entity).readSpawnData(spawnMsg.dataStream);
        }
        wc.addEntityToWorld(spawnMsg.entityId, entity);
    } catch (Exception e) {
        FMLLog.log(Level.ERROR, e, "A severe problem occurred during the spawning of an entity at ( " + spawnMsg.rawX + "," + spawnMsg.rawY + ", " + spawnMsg.rawZ + ")");
        throw Throwables.propagate(e);
    }
}
Also used : IEntityAdditionalSpawnData(net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData) Entity(net.minecraft.entity.Entity) IThrowableEntity(net.minecraftforge.fml.common.registry.IThrowableEntity) ModContainer(net.minecraftforge.fml.common.ModContainer) EntityLiving(net.minecraft.entity.EntityLiving) IThrowableEntity(net.minecraftforge.fml.common.registry.IThrowableEntity) WorldClient(net.minecraft.client.multiplayer.WorldClient) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) EntityRegistration(net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration)

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