Jump to content

Integration with other mods without being a dependency


SkylordJoel

Recommended Posts

Hi,

I was working on my mod, AddedCompat, when I decided to stop permanent IC2 dependency and just have integration. I did follow a tutorial and wrote this:

 

package addedcompat.integration;

import java.util.logging.Level;

import ic2.api.item.Items;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import addedcompat.common.AddedCompat;
import addedcompat.common.CraftingManagerTable;
import addedcompat.common.LogHelper;
import cpw.mods.fml.common.Loader;

public class IC2Integration  {
public static void isIC2Installed() {
	if(Loader.isModLoaded("IC2")) {
		try {
			LogHelper.log(Level.INFO, "IC2 integration initialised");
			ItemStack energyCrystal = Items.getItem("energyCrystal");
			ItemStack lapotronCrystal = Items.getItem("lapotronCrystal");
			ItemStack advancedCircuit = Items.getItem("advancedCircuit");
			ItemStack lapiDust = Items.getItem("lapiDust");
			ItemStack bronzeIngot = Items.getItem("bronzeIngot");

			CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe((energyCrystal), new Object[] {
					"RRR",
					"RSR",
					"RRR", Character.valueOf('R'), Item.redstone, Character.valueOf('S'), new ItemStack(AddedCompat.metaItemCompat,1,0)
				}));

				CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe((lapotronCrystal), new Object[] {
					"LAL",
					"LRL",
					"LAL", Character.valueOf('R'), new ItemStack(AddedCompat.metaItemCompat,1,1), Character.valueOf('A'), advancedCircuit, Character.valueOf('L'), lapiDust 
				}));

				CraftingManagerTable.getInstance().getRecipeList().add(new ShapelessOreRecipe((bronzeIngot), new Object[] {
					Block.cobblestone, Item.ingotIron
				}));

				CraftingManagerTable.getInstance().getRecipeList().add(new ShapelessOreRecipe(new ItemStack(Item.ingotIron), new Object[] {
						Block.cobblestone, bronzeIngot
				}));
		 }
		catch(Exception e) {
			LogHelper.log(Level.INFO, "IC2 integration not initialised");
			e.printStackTrace(System.err);
                        }
	}else{
	}
}
}

 

However, it doesn't seem to work.

Thanks!

Link to comment
Share on other sites

How about you put that into your base class into PostInit?

 

Reason is, I don't see it being called anywhere, unless you show us your base class.

 

Oh, it is called anywhere. How would I do this?

 

Add to the dependency so you mod is loaded after IC2 maybe, you have not put up your main mod file so I don't know if you have done that already.

 

It is loaded after IC2, in dependencies it says after:IC2

 

Here is my base class:

 

package addedcompat.common;

import ic2.api.item.Items;

import java.io.File;
import java.util.logging.Level;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemSlab;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.EnumHelper;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid=AddedCompat.modid, name="AddedCompat: Alchemy", version=AddedCompat.version, dependencies="required-after:Forge;after:IC2;after:Forestry;after:ThermalExpansion")
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
public class AddedCompat {


public static CreativeTabs tabAddedCompat = new CreativeTabs("tabAddedCompat") {
	public ItemStack getIconItemStack() {
		return new ItemStack(AddedCompat.metaItemCompat);
	}
};

@SidedProxy(clientSide = "addedcompat.client.ClientProxy", serverSide = "addedcompat.common.CommonProxy")
public static CommonProxy proxy;

public static final String modid = "AddedCompat";

public static final String version = "Beta 0.5";

@Instance("AddedCompat")
public static AddedCompat instance;

private GuiHandlerTable guiHandlerTable = new GuiHandlerTable();

public static Block table;
public static int tableID;
public static Item metaItemCompat;
public static Block metaBlockCompat;
public static int metaItemCompatID;
public static int metaBlockCompatID;
public static Block metaQuartzCompat;
public static int metaQuartzCompatID;
public static Block fakeStair;
public static int fakeStairID;
public static Block fakeHalfSlab;
public static int fakeHalfSlabID;
public static Block fakeDoubleSlab;
public static int fakeDoubleSlabID;

public void initConfiguration(FMLInitializationEvent event) {
	Configuration config = new Configuration(new File("config/AwesCorp/AddedCompat.cfg"));
	config.load();

	metaItemCompatID = config.get("Items", "The ID AddedCompat uses for the generic item", 5022).getInt();
	metaBlockCompatID = config.get("Blocks", "The ID AddedCompat uses for the generic ore", 502).getInt();
	metaQuartzCompatID = config.get("Blocks", "The ID AddedCompat uses for the generic block", 507).getInt();
	tableID = config.get("Blocks", "The ID AddedCompat uses for the transmutator", 503).getInt();
	fakeStairID = config.get("Blocks", "The ID AddedCompat uses for the aesthetic stair", 504).getInt();
	fakeHalfSlabID = config.get("Blocks", "The ID AddedCompat uses for the aesthetic half slab", 505).getInt();
	fakeDoubleSlabID = config.get("Blocks", "The ID AddedCompat uses for the aesthetic double slab", 506).getInt();

	config.save();
}

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
	LogHelper.log(Level.INFO, "Preinitialised successfully");
}

@EventHandler
public void load(FMLInitializationEvent event) {
	this.initConfiguration(event);
	NetworkRegistry.instance().registerGuiHandler(this, guiHandlerTable);

	metaItemCompat = new ItemMetaCompat(this.metaItemCompatID).setUnlocalizedName("metaItemCompat");
	table = new BlockTable(this.tableID).setHardness(3.5F).setResistance(2000.0F).setStepSound(Block.soundMetalFootstep).setUnlocalizedName("table").setCreativeTab(AddedCompat.tabAddedCompat);
	metaBlockCompat = new BlockOreMetaCompat(this.metaBlockCompatID, Material.rock).setHardness(3.0F).setResistance(5.0F).setStepSound(Block.soundStoneFootstep).setUnlocalizedName("metaBlockCompat");
	metaQuartzCompat = new BlockMetaCompat(this.metaQuartzCompatID, Material.rock).setHardness(3.0F).setResistance(5.0F).setStepSound(Block.soundStoneFootstep).setUnlocalizedName("metaQuartzCompat");
	fakeStair = new BlockFakeStair(this.fakeStairID, Block.blockNetherQuartz, 0).setHardness(1.0F).setStepSound(Block.soundStoneFootstep).setUnlocalizedName("fakequartzstair").setCreativeTab(AddedCompat.tabAddedCompat);
	fakeHalfSlab = new BlockFakeSlab(this.fakeHalfSlabID, false, metaQuartzCompat, Material.rock).setUnlocalizedName("fakequartzslab");
	fakeDoubleSlab = new BlockFakeSlab(this.fakeDoubleSlabID, true, metaQuartzCompat, Material.rock).setUnlocalizedName("fakequartzdoubleslab");

	gameRegisters();
	languageRegisters();
	craftingRecipes();
	smeltingRecipes();
	blockHarvest();
	registerOre();

	proxy.registerRenderers();
}


public void blockHarvest() {
	MinecraftForge.setBlockHarvestLevel(metaBlockCompat, 0, "pickaxe", 2);
	MinecraftForge.setBlockHarvestLevel(metaBlockCompat, 0, "pickaxe", 2);
	MinecraftForge.setBlockHarvestLevel(metaBlockCompat, 1, "pickaxe", 2);
	MinecraftForge.setBlockHarvestLevel(metaBlockCompat, 1, "pickaxe", 2);

}

public void smeltingRecipes() {

}

public void craftingRecipes() {

	//Fake quartz block	
	CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe(new ItemStack(this.metaQuartzCompat,64,0), new Object[]{
		"BB ",
		"BB ",
		"   ", Character.valueOf('B'), new ItemStack(Item.dyePowder,1,15)
	}));

	ItemStack bonemealStack = new ItemStack(Item.dyePowder,1,15);

	GameRegistry.addShapedRecipe(new ItemStack(this.metaQuartzCompat,64,0), "BB ", "BB ",
			'B', bonemealStack);

	//Fake quartz pillar	
	CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe(new ItemStack(this.metaQuartzCompat,2,1), new Object[]{
		"Q  ",
		"Q  ",
		"   ", Character.valueOf('Q'), new ItemStack(this.metaQuartzCompat,1,0)
	}));

	ItemStack fakeQuartzStack = new ItemStack(AddedCompat.metaQuartzCompat,1,0);

	GameRegistry.addShapedRecipe(new ItemStack(this.metaQuartzCompat,2,1), "Q  ", "Q  ",
			'Q', fakeQuartzStack);

	//Fake quartz stairs with fake quartz	
	CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe(new ItemStack(this.fakeStair,4), new Object[]{
		"  Q",
		" QQ",
		"QQQ", Character.valueOf('Q'), new ItemStack(this.metaQuartzCompat,1,0)
	}));

	//Fake quartz stairs with fake quartz pillars	
	CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe(new ItemStack(this.fakeStair,4), new Object[]{
		"  Q",
		" QQ",
		"QQQ", Character.valueOf('Q'), new ItemStack(this.metaQuartzCompat,1,1)
	}));

	//Fake quartz slabs with fake quartz	
	CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe(new ItemStack(this.fakeHalfSlab,6), new Object[]{
		"QQQ",
		"   ",
		"   ", Character.valueOf('Q'), new ItemStack(this.metaQuartzCompat,1,0)
	}));

	GameRegistry.addShapedRecipe(new ItemStack(this.fakeHalfSlab,6), "QQQ",
			'Q', fakeQuartzStack);

	//Fake quartz slabs with fake quartz pillars	
	CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe(new ItemStack(this.fakeHalfSlab,6), new Object[]{
		"QQQ",
		"   ",
		"   ", Character.valueOf('Q'), new ItemStack(this.metaQuartzCompat,1,1)
	}));

	ItemStack fakeQuartzPillarStack = new ItemStack(AddedCompat.metaQuartzCompat,1,2);

	GameRegistry.addShapedRecipe(new ItemStack(this.fakeHalfSlab,6), "QQQ",
			'Q', fakeQuartzPillarStack);

	//Fake quartz blocks with fake quartz slabs	
	CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe(new ItemStack(this.metaQuartzCompat,1,0), new Object[]{
		"Q  ",
		"Q  ",
		"   ", Character.valueOf('Q'), new ItemStack(this.fakeHalfSlab)
	}));

	ItemStack fakeQuartzSlabStack = new ItemStack(AddedCompat.fakeHalfSlab);

	GameRegistry.addShapedRecipe(new ItemStack(this.metaQuartzCompat,1,0), "Q  ", "Q  ", 
			'Q', fakeQuartzSlabStack);

	CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe(new ItemStack(this.table), new Object[] {
		"BOB",
		"OCO",
		"PDO", Character.valueOf('B'), new ItemStack(Block.cloth,1,15), Character.valueOf('O'), Block.obsidian, Character.valueOf('C'), Block.workbench, Character.valueOf('P'), new ItemStack(metaItemCompat,1,2), Character.valueOf('D'), Item.diamond
	}));

	CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe(new ItemStack(this.metaItemCompat,1,2), new Object[] {
		"OGO",
		"ISI",
		"RGR", Character.valueOf('O'), Block.obsidian, Character.valueOf('G'), Item.ingotGold, Character.valueOf('I'), Item.ingotIron, Character.valueOf('S'), Block.stone, Character.valueOf('R'), new ItemStack(metaItemCompat,1,1)
	}));

	CraftingManagerTable.getInstance().getRecipeList().add(new ShapedOreRecipe(new ItemStack(this.table), new Object[] {
		"BOB",
		"OCO",
		"OOO", Character.valueOf('B'), new ItemStack(Block.cloth,1,15), Character.valueOf('O'), Block.obsidian, Character.valueOf('C'), Block.workbench, Character.valueOf('P'), new ItemStack(metaItemCompat,1,2)
	}));

	CraftingManager.getInstance().getRecipeList().add(new ShapelessOreRecipe(new ItemStack(Block.cobblestoneMossy), new Object[] {
		Block.cobblestone, Item.bucketWater
	}));

	CraftingManagerTable.getInstance().getRecipeList().add(new ShapelessOreRecipe(new ItemStack(Block.whiteStone), new Object[] {
		Block.cobblestone, Block.netherrack
	}));

	CraftingManagerTable.getInstance().getRecipeList().add(new ShapelessOreRecipe(new ItemStack(Block.netherrack), new Object[] {
		Block.cobblestone, Block.whiteStone
	}));

	CraftingManagerTable.getInstance().getRecipeList().add(new ShapelessOreRecipe(new ItemStack(Item.diamond), new Object[] {
		Item.ingotGold, Item.ingotGold, Item.ingotGold, Item.ingotGold, Block.cobblestone
	}));
	CraftingManagerTable.getInstance().getRecipeList().add(new ShapelessOreRecipe(new ItemStack(Item.ingotGold,4), new Object[] {
		Item.diamond, Block.cobblestone
	}));
	CraftingManagerTable.getInstance().getRecipeList().add(new ShapelessOreRecipe(new ItemStack(Item.ingotGold), new Object[] {
		Item.ingotIron, Item.ingotIron, Item.ingotIron, Item.ingotIron, Item.ingotIron, Item.ingotIron, Item.ingotIron, Item.ingotIron, Block.cobblestone
	}));
	CraftingManagerTable.getInstance().getRecipeList().add(new ShapelessOreRecipe(new ItemStack(Item.ingotIron,, new Object[] {
		Item.ingotGold, Block.cobblestone
	}));
	CraftingManagerTable.getInstance().getRecipeList().add(new ShapelessOreRecipe(new ItemStack(Item.ingotIron,4), new Object[] {
		Item.blazeRod, Block.cobblestone
	}));
	CraftingManagerTable.getInstance().getRecipeList().add(new ShapelessOreRecipe(new ItemStack(Item.ingotIron), new Object[] {
		Block.obsidian, Block.obsidian, Block.obsidian, Block.obsidian, Block.cobblestone
	}));
	CraftingManagerTable.getInstance().getRecipeList().add(new ShapelessOreRecipe(new ItemStack(Item.coal,1,0), new Object[] {
		new ItemStack(Item.coal,1,1), Block.cobblestone
	}));
	CraftingManagerTable.getInstance().getRecipeList().add(new ShapelessOreRecipe(new ItemStack(Item.blazeRod), new Object[] {
		Item.blazePowder, Item.blazePowder, Block.cobblestone
	}));
	CraftingManagerTable.getInstance().getRecipeList().add(new ShapelessOreRecipe(new ItemStack(Item.diamond,1), new Object[] {
		new ItemStack(this.metaItemCompat,1,0), new ItemStack(this.metaItemCompat,1,0), new ItemStack(this.metaItemCompat,1,1), new ItemStack(this.metaItemCompat,1,1), Block.cobblestone
	}));

	CraftingManagerTable.getInstance().getRecipeList().add(new ShapelessOreRecipe(new ItemStack(Block.cobblestone,1), new Object[] {
		Block.dirt, Block.dirt
	}));

	LogHelper.log(Level.INFO, "Initialised successfully");

}

public void registerOre() {
	OreDictionary.registerOre("gemSapphire", new ItemStack(this.metaItemCompat,1,0));
	OreDictionary.registerOre("gemRuby", new ItemStack(this.metaItemCompat,1,1));
	OreDictionary.registerOre("oreSapphire", new ItemStack(this.metaBlockCompat,1,0));
	OreDictionary.registerOre("oreRuby", new ItemStack(this.metaBlockCompat,1,1));

	LogHelper.log(Level.INFO, "Registered ores to the OreDictionary");
}


public void languageRegisters() {


	LanguageRegistry.addName(new ItemStack(this.metaItemCompat,1,0), "Sapphire");
	LanguageRegistry.addName(new ItemStack(this.metaItemCompat,1,1), "Ruby");
	LanguageRegistry.addName(new ItemStack(this.metaItemCompat,1,2), "Philosopher's Stone");

	LanguageRegistry.addName(new ItemStack(this.metaBlockCompat,1,0), "Sapphire Ore");
	LanguageRegistry.addName(new ItemStack(this.metaBlockCompat,1,1), "Ruby Ore");

	LanguageRegistry.addName(new ItemStack(this.metaQuartzCompat,1,0), "Quartz Block");
	LanguageRegistry.addName(new ItemStack(this.metaQuartzCompat,1,1), "Quartz Pillar");

	LanguageRegistry.addName(fakeStair, "Quartz Stair");
	LanguageRegistry.addName(fakeHalfSlab, "Quartz Slab");
	LanguageRegistry.addName(fakeDoubleSlab, "Quartz Slab");

	LanguageRegistry.addName(table, "Alchemical Transmutator");

	LanguageRegistry.instance().addStringLocalization("itemGroup.tabAddedCompat", "en_US", "AddedCompat: Alchemy");

	LanguageRegistry.instance().addStringLocalization("container.alchemy", "en_US", "Alchemical Transmutator");

}

public void gameRegisters() {
	GameRegistry.registerBlock(metaBlockCompat, ItemBlockOreMetaCompat.class, modid + (metaBlockCompat.getUnlocalizedName().substring(5)));

	GameRegistry.registerBlock(metaQuartzCompat, ItemBlockMetaCompat.class, modid + (metaQuartzCompat.getUnlocalizedName().substring(5)));

	GameRegistry.registerBlock(table, "Table");

	GameRegistry.registerBlock(fakeStair, "Quartz Stair");
	GameRegistry.registerBlock(fakeHalfSlab, "Quartz Slab");
	GameRegistry.registerBlock(fakeDoubleSlab, "Quartz Double Slab");

	GameRegistry.registerWorldGenerator(new WorldGeneratorCompat());

}

@EventHandler
public void postInit(FMLPostInitializationEvent event) {
	Item.itemsList[fakeHalfSlab.blockID] =  new ItemSlab(fakeHalfSlab.blockID-256, (BlockFakeSlab)fakeHalfSlab, (BlockFakeSlab)fakeDoubleSlab, false);
	LogHelper.log(Level.INFO, "Postinitialised successfully");
}
}

 

Link to comment
Share on other sites

I'm pretty sure that if you directly access the IC2 API it becomes a required dependency. Use reflection instead.

 

If you use any form of non-API checks to see if a mod is loaded before you call the API then it's not.

 

https://github.com/Draco18s/Artifacts/blob/master/draco18s/artifacts/worldgen/PlaceTraps.java

Check line 251.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I'm pretty sure that if you directly access the IC2 API it becomes a required dependency. Use reflection instead.

 

What's reflection? How do I use it?

 

If you use any form of non-API checks to see if a mod is loaded before you call the API then it's not.

 

https://github.com/Draco18s/Artifacts/blob/master/draco18s/artifacts/worldgen/PlaceTraps.java

Check line 251.

 

So how would I do this with IC2? Like maybe Class.forName("ic2.api.item.Items"); ?

 

Link to comment
Share on other sites

You can use Loader.isModLoaded("IC2") in place of that reflection call.

I wasn't aware of the Forge method when I did that.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I'm pretty sure that if you directly access the IC2 API it becomes a required dependency. Use reflection instead.

 

What's reflection? How do I use it?

Reflection is a soft dependency tool, its package is: java.lang.reflect.

The main methods you are likely to use are:

Class.forName(String)//load a class object from its path
Class#getMethod(String, Class...)//get a method object from the class object, with name and parameters
Method#invoke(Object, Object...)//call the method from the class object, with given parameters

 

See an example here.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.