use of cpw.mods.fml.common.ModContainer in project Engine by VoltzEngine-Project.
the class GoogleAnalytics method postInit.
//http://www.dmurph.com/2011/01/google-analytics-tracking-with-java/
@Override
public void postInit() {
JGoogleAnalyticsTracker.setProxy(System.getenv("http_proxy"));
AnalyticsConfigData config = new AnalyticsConfigData("UA-58617158-3");
JGoogleAnalyticsTracker tracker = new JGoogleAnalyticsTracker(config, JGoogleAnalyticsTracker.GoogleAnalyticsVersion.V_4_7_2);
tracker.setDispatchMode(JGoogleAnalyticsTracker.DispatchMode.MULTI_THREAD);
for (ModContainer mod : Loader.instance().getActiveModList()) {
String modPage = mod.getModId() + "-" + mod.getVersion() + "-" + FMLCommonHandler.instance().getEffectiveSide();
tracker.trackPageView(modPage, null, null);
}
tracker.completeBackgroundTasks(1000);
}
use of cpw.mods.fml.common.ModContainer in project BluePower by Qmunity.
the class AlloyFurnaceRegistry method addRecyclingRecipe.
@Override
public void addRecyclingRecipe(ItemStack recycledItem, String... blacklist) {
if (recycledItem == null)
throw new NullPointerException("Recycled item can't be null!");
bufferedRecyclingItems.add(recycledItem);
if (blacklist.length > 0) {
ModContainer mc = Loader.instance().activeModContainer();
BluePower.log.info((mc != null ? mc.getName() : "Unknown mod") + " added to the Alloy Furnace recycling blacklist: " + Arrays.toString(blacklist));
Collections.addAll(this.blacklist, blacklist);
}
}
use of cpw.mods.fml.common.ModContainer in project LogisticsPipes by RS485.
the class LogisticsClassTransformer method handleLPTransformation.
@SuppressWarnings("unchecked")
private byte[] handleLPTransformation(byte[] bytes) {
final ClassNode node = new ClassNode();
ClassReader reader = new ClassReader(bytes);
reader.accept(node, 0);
boolean changed = false;
if (node.visibleAnnotations != null) {
for (AnnotationNode a : node.visibleAnnotations) {
if (a.desc.equals("Llogisticspipes/asm/ModDependentInterface;")) {
if (a.values.size() == 4 && a.values.get(0).equals("modId") && a.values.get(2).equals("interfacePath")) {
List<String> modId = (List<String>) a.values.get(1);
List<String> interfacePath = (List<String>) a.values.get(3);
if (modId.size() != interfacePath.size()) {
throw new RuntimeException("The Arrays have to be of the same size.");
}
for (int i = 0; i < modId.size(); i++) {
if (!ModStatusHelper.isModLoaded(modId.get(i))) {
interfacesToClearA.add(interfacePath.get(i));
interfacesToClearB.add(interfacePath.get(i));
for (String inter : node.interfaces) {
if (inter.replace("/", ".").equals(interfacePath.get(i))) {
node.interfaces.remove(inter);
changed = true;
break;
}
}
}
}
} else {
throw new UnsupportedOperationException("Can't parse the annotations correctly");
}
}
}
}
List<MethodNode> methodsToRemove = new ArrayList<>();
for (MethodNode m : node.methods) {
if (m.visibleAnnotations != null) {
for (AnnotationNode a : m.visibleAnnotations) {
if (a.desc.equals("Llogisticspipes/asm/ModDependentMethod;")) {
if (a.values.size() == 2 && a.values.get(0).equals("modId")) {
String modId = a.values.get(1).toString();
if (!ModStatusHelper.isModLoaded(modId)) {
methodsToRemove.add(m);
break;
}
} else {
throw new UnsupportedOperationException("Can't parse the annotation correctly");
}
} else if (a.desc.equals("Llogisticspipes/asm/ClientSideOnlyMethodContent;")) {
if (FMLCommonHandler.instance().getSide().equals(Side.SERVER)) {
m.instructions.clear();
m.localVariables.clear();
m.tryCatchBlocks.clear();
m.visitCode();
Label l0 = new Label();
m.visitLabel(l0);
m.visitMethodInsn(Opcodes.INVOKESTATIC, "logisticspipes/asm/LogisticsASMHookClass", "callingClearedMethod", "()V");
Label l1 = new Label();
m.visitLabel(l1);
m.visitInsn(Opcodes.RETURN);
Label l2 = new Label();
m.visitLabel(l2);
m.visitLocalVariable("this", "Llogisticspipes/network/packets/DummyPacket;", null, l0, l2, 0);
m.visitLocalVariable("player", "Lnet/minecraft/entity/player/EntityPlayer;", null, l0, l2, 1);
m.visitMaxs(0, 2);
m.visitEnd();
changed = true;
break;
}
} else if (a.desc.equals("Llogisticspipes/asm/ModDependentMethodName;")) {
if (a.values.size() == 6 && a.values.get(0).equals("modId") && a.values.get(2).equals("newName") && a.values.get(4).equals("version")) {
String modId = a.values.get(1).toString();
final String newName = a.values.get(3).toString();
final String version = a.values.get(5).toString();
boolean loaded = ModStatusHelper.isModLoaded(modId);
if (loaded && !version.equals("")) {
ModContainer mod = Loader.instance().getIndexedModList().get(modId);
if (mod != null) {
VersionRange range = VersionParser.parseRange(version);
ArtifactVersion artifactVersion = new DefaultArtifactVersion("Version", mod.getVersion());
loaded = range.containsVersion(artifactVersion);
} else {
loaded = false;
}
}
if (loaded) {
final String oldName = m.name;
m.name = newName;
MethodNode newM = new MethodNode(Opcodes.ASM4, m.access, m.name, m.desc, m.signature, m.exceptions.toArray(new String[0])) {
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc) {
if (name.equals(oldName) && owner.equals(node.superName)) {
super.visitMethodInsn(opcode, owner, newName, desc);
} else {
super.visitMethodInsn(opcode, owner, name, desc);
}
}
};
m.accept(newM);
node.methods.set(node.methods.indexOf(m), newM);
changed = true;
break;
}
} else {
throw new UnsupportedOperationException("Can't parse the annotation correctly");
}
}
}
}
}
for (MethodNode m : methodsToRemove) {
node.methods.remove(m);
}
List<FieldNode> fieldsToRemove = new ArrayList<>();
for (FieldNode f : node.fields) {
if (f.visibleAnnotations != null) {
for (AnnotationNode a : f.visibleAnnotations) {
if (a.desc.equals("Llogisticspipes/asm/ModDependentField;")) {
if (a.values.size() == 2 && a.values.get(0).equals("modId")) {
String modId = a.values.get(1).toString();
if (!ModStatusHelper.isModLoaded(modId)) {
fieldsToRemove.add(f);
break;
}
} else {
throw new UnsupportedOperationException("Can't parse the annotation correctly");
}
}
}
}
}
for (FieldNode f : fieldsToRemove) {
node.fields.remove(f);
}
if (!changed && methodsToRemove.isEmpty() && fieldsToRemove.isEmpty()) {
return bytes;
}
ClassWriter writer = new ClassWriter(0);
node.accept(writer);
return writer.toByteArray();
}
use of cpw.mods.fml.common.ModContainer in project LogisticsPipes by RS485.
the class ModStatusHelper method isModLoaded.
public static boolean isModLoaded(String modId) {
if (modId.contains("@")) {
String version = modId.substring(modId.indexOf('@') + 1);
modId = modId.substring(0, modId.indexOf('@'));
if (Loader.isModLoaded(modId)) {
ModContainer mod = Loader.instance().getIndexedModList().get(modId);
if (mod != null) {
return mod.getVersion().startsWith(version);
}
}
return false;
} else if (Loader.isModLoaded(modId)) {
return true;
} else {
return ModAPIManager.INSTANCE.hasAPI(modId);
}
}
use of cpw.mods.fml.common.ModContainer in project Engine by VoltzEngine-Project.
the class JsonContentLoader method loadResources.
/** Loads resources from folders and class path */
public void loadResources() {
debug.start("Loading json resources");
//---------------------------------------------------------------------------
debug.start("\tScanning mod packages for json data");
for (ModContainer container : Loader.instance().getModList()) {
File file = container.getSource();
debug.log("Mod: " + container.getName() + " " + container.getDisplayVersion());
debug.log("File: " + file);
Object mod = container.getMod();
if (mod != null) {
loadResourcesFromPackage(mod.getClass(), "/content/" + container.getModId() + "/");
}
}
debug.end();
//===========================================================================
debug.start("Scanning for external files");
loadResourcesFromFolder(externalContentFolder);
debug.end();
//===========================================================================
debug.start("Loading external resources");
//Load external files
for (File file : externalFiles) {
try {
debug.log("Loading resource: " + file);
JsonLoader.loadJsonFile(file, jsonEntries);
} catch (IOException e) {
//Crash as the file may be important
throw new RuntimeException("Failed to load external resource " + file, e);
}
}
debug.end();
//===========================================================================
debug.start("Loading class path resources");
//Load internal files
for (URL resource : classPathResources) {
try {
debug.log("Loading resource: " + resource);
JsonLoader.loadJsonFileFromResources(resource, jsonEntries);
} catch (Exception e) {
//Crash as the file may be important
throw new RuntimeException("Failed to load classpath resource " + resource, e);
}
}
debug.end();
//---------------------------------------------------------------------------
debug.end("Done....");
}
Aggregations