Jump to content

CoreMods


oberjarlerak9039

Recommended Posts

So I want to have a button added in a GUI that is in a base class, that would trigger a method in my mod. It sounded like it would be simple, (because forge API covers almost everything  :) ) but I discovered only "coremods" can do this. I found only a few posts on this topic and 1 tutorial: http://www.minecraftforge.net/wiki/Using_Access_Transformers but In that tutorial the coremod did not give me an error, but I was not sure what exactly it did  :P. I downloaded a few examples of coremods, like chickenbonescore and ars magica (I had to decompile it). I was unsuccessful at finding how these worked. Another post on the forums said "only advanced modders who know what they're doing should use this tool" (or something along those lines), but If no one learns it in the first place, they can't become an advanced modder, can't they? Can anyone out there enlighten me on this topic? Not many tutorials show how this work, and I really want to know more about how this works, thanks.

 

 

P.S. Is there a way of doing this so that the regular mod doesn't have to be converted to a core mod, just have the core mod trigger a method in the regular mod? (eg. ars magica uses 2 mods, a core and a regular, since converting the regular to the core might be difficult) Oh yea, and if you could explain it rather than redirecting me too an api doc that would be nice!

Link to comment
Share on other sites

I just tried to do the part where i add a button, I don't know to much about java reflection so I probably made many boo boos! it does print "tick" on my screen when I open the book though, (YAY!)

	
        @Override
public void tickStart(EnumSet<TickType> type, Object... tickData) {
	if (Minecraft.getMinecraft().currentScreen instanceof GuiScreenBook) {
		Minecraft.getMinecraft().thePlayer.addChatMessage("tick");
		try {
			Class<?> c = Minecraft.getMinecraft().currentScreen.getClass();
			Field f = c.getDeclaredField("controlList");
			f.set(Minecraft.getMinecraft().currentScreen, new GuiButton(3,
					Minecraft.getMinecraft().currentScreen.width / 2 + 104,
					4 + Minecraft.getMinecraft().currentScreen.height, 98,
					20, StatCollector.translateToLocal("book.signButton")));
		} catch (NoSuchFieldException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
	}

Do I need to read the GuiScreenBook 's width and height? or can I use Minecrafts Gui height and width

P.S. it gives me an error at Field f = c.getDeclaredField("controlList");

 

Link to comment
Share on other sites

	
        @Override
public void tickStart(EnumSet<TickType> type, Object... tickData) {
	if (Minecraft.getMinecraft().currentScreen instanceof GuiScreenBook) {
		Minecraft.getMinecraft().thePlayer.addChatMessage("tick");
		try {
			Class<?> c = Minecraft.getMinecraft().currentScreen.getClass();
			Field f = c.getDeclaredField("controlList");
			f.set(Minecraft.getMinecraft().currentScreen, new GuiButton(3,
					Minecraft.getMinecraft().currentScreen.width / 2 + 104,
					4 + Minecraft.getMinecraft().currentScreen.height, 98,
					20, StatCollector.translateToLocal("book.signButton")));
		} catch...{
			e.printStackTrace();
		}
	}

I don't have much experience with reflection so it may not be entrirely true what I'm writing. Using relection is not cheap, it doesn't seem right to me to do in every tick when GUI is open. Also you're in every tick creating a new button? And with that button you are rewriting collection with GUI elements? I might be reading it wrong though...

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

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.