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;
}
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;
}
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) {
;
}
}
}
}
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);
}
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);
}
}
Aggregations