Jump to content

How to reflect on a class before the class loader loads it?


ILuvYouCompanionCube

Recommended Posts

Minecraft 1.6.2, Forge version 1.6.2-9.10.0.804

 

I don't suppose this is a usual problem.

 

I need to make a tiny change to the Block class at runtime that won't break any other mod because it's such an insignificant change (I only want to make Block.blockMaterial not final). But by the time my mod gets the first chance to run anything (even during the preInit event) the Block class has already been loaded and Java doesn't alow class reloading. The exception message is this:

 

java.lang.LinkageError:

loader (instance of  net/minecraft/launchwrapper/LaunchClassLoader):

attempted  duplicate class definition for name: "net/minecraft/block/Block"

 

I can't even find that package net/minecraft/launchwrapper, but I noticed some Forge classes use that LaunchClassLoader class and import it. Even if I've found it, I wouldn't know what to do...

 

Is there any way to execute code before the Block class is loaded OR is there some other thing I can do to reflect on Block and change it's byte code just a tiny bit, even though it's already loaded?

 

It would be monstruous to manually strip that field off that final modifier, because I'd have to make some kind of installer to replace the old Block class by my altered one... or something.

Link to comment
Share on other sites

I am thinking ASM (coremod) would serve you very well here.

 

There is a good tutorial about changing things from public to private etc. on the wiki...

 

Here it is: http://www.minecraftforge.net/wiki/Using_Access_Transformers

 

 

I am pretty sure it explains how to change something from being final to non-final and vice-versa. Have fun :D If it's not want your wanting though... :S

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

Not that simple? It made a lot of sense to me... Oh well, just the way things work.

 

I hope it solves your problem though.

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

The tutorial tells me to create a package inside Minecraft\common folder but I can't. I can create packages in Minecraft\src only. I created the package in src and dragged it to common but then it was no longer a package , just a folder. And recompile.bat doesn't bother with it. Is there something wrong with my eclipse setup? Will it work normally if I create the package in src instead?

 

EDIT: I tried creating the package in src. Recompiled and then reobfuscated. But the tutorial tells me to put my mod in a coremods folder. My minecraft installation has no such folder. Is this tutorial outdated by any chance?

 

By the way, when I run it I get the expected IllegalAccessError caused by me trying to set the value of a final field

Link to comment
Share on other sites

yeah, the tutorial is pretty outdated. But yes, it is just a new package type thing in your mod src area :D

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

:/ I know when I followed that tutorial it worked. Oh well. Now I need help too :/

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

Thanks for your help Mew. I quit for now. Maybe I'll need to try something like this again someday, but I'm very tired. I have modding surges these days, then I spend hours modding and playing minecraft, then I rest from anything minecraft related for days lol. (well I actually rest from everything, minecraft related or not)

 

Anyway thanks a lot. Good luck on your coddings  :D

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.