Jump to content

[1.8] Plugin system only works in development environment


CraftedCart

Recommended Posts

TL;DR

A plugin system which adds Jars to the classloader can call several Minecraft methods when running from within IntelliJ Idea, however it errors when running it in standard Forge (when the mod jar is dropped in the mods folder)

 

Hi there!

I'm trying to develop a plugin system for my mod, however I'm very confused as to why it works when I run / debug it from IntelliJ Idea, but it doesn't work when I put the mod jar in my mods folder, and the plugin in the mods/CraftedCart/MFFClientPlugins folder.

 

The plugin loads, however it errors whenever I try to use several Minecraft methods.

GLStateManager

seems to be broken. It couldn't

pushMatrix

or

translate

BlockPos

also seems to be broken. It errors when I try to

getX()

 

Here's the error for the

getX()

method (

testMFFPlugin

is the plugin, and it's trying to draw a

TESR

).

Caused by: java.lang.NoSuchMethodError: net.minecraft.util.BlockPos.getX()I

The whole stack:

10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: java.lang.reflect.InvocationTargetException
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at java.lang.reflect.Method.invoke(Method.java:497)
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at io.github.craftedcart.MFF.client.render.blocks.TERendererFFProjector.func_180535_a(TERendererFFProjector.java:37)
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher.func_178469_a(SourceFile:114)
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher.func_180546_a(SourceFile:102)
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.client.renderer.RenderGlobal.func_180446_a(RenderGlobal.java:655)
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.client.renderer.EntityRenderer.func_175068_a(EntityRenderer.java:1294)
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.client.renderer.EntityRenderer.func_78471_a(EntityRenderer.java:1207)
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.client.renderer.EntityRenderer.func_78480_b(EntityRenderer.java:1032)
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.client.Minecraft.func_71411_J(Minecraft.java:1048)
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:345)
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.client.main.Main.main(SourceFile:120)
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at java.lang.reflect.Method.invoke(Method.java:497)
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: Caused by: java.lang.NoSuchMethodError: net.minecraft.util.BlockPos.getX()I
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at io.github.craftedcart.TestMFFPlugin.TestMFFPluginBase.renderTEFFProjector(TestMFFPluginBase.java:65)
[10:19:29] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	... 19 more
FramebufferStatus 0x0000 at beginHand
FramebufferStatus 0x0000 at pre endHand
GL error 0x0502: Invalid operation at renderCompositeFinal

 

The details of how plugins are loaded:

 

1: Plugins are added to the class loader

LaunchClassLoader loader = (LaunchClassLoader) DependencyUtils.class.getClassLoader(); //DependencyUtils is one of my classes
loader.addURL(file.toURI().toURL()); //In this case, the file variable would be the mods/CraftedCart/MFFClientPlugins/testMFFPlugin.jar file

 

2: Plugins are searched for an

@MFFClientPlugin

annotation using Reflections (Note the extra s on the end of that. It's an external library)

Reflections reflections = new Reflections();
clientPlugins = reflections.getTypesAnnotatedWith(MFFClientPlugin.class);

 

3: The

load()

method is called on all plugins using Reflection

for (Class clazz : clientPlugins) {
    Method loadMethod = clazz.getMethod("load");
    loadMethod.invoke(clazz.newInstance());
}

 

In the test plugin, it would set 2 variables (The method to call when rendering the TESR, and its class)

The TESR then uses Reflection to invoke the method on that class

Link to comment
Share on other sites

If you want to run code in actual Minecraft, not in dev, you need to reobfuscate your code. ForgeGradle does this automatically for you when you run

gradle build

.

 

You also need to keep this in mind if you use reflection with Minecraft's classes.

 

Every field/method has an SRG (semi-obfuscated) name like

field_00120_a

/

func_12345_b

and most fields/methods also have an MCP (deobfuscated) name like

thing

/

getThing

. You need to make sure you check both names when using reflection. FML's

ReflectionHelper

and

ObfuscationReflectionHelper

have methods to find a field/method with one of several names via reflection.

 

You can find the SRG name of a field/method in the MCP mapping CSVs. If you've set up a ForgeGradle workspace for 1.8+, you can find the mappings it's using in the Gradle cache (~/.gradle/caches/minecraft/de/oceanlabs/mcp/<mappings_channel>/<mappings_version>, replace ~ with %USERPROFILE% on Windows). You can also download them from the MCPBot website.

 

External libraries and Forge/FML code (including new methods/fields in vanilla classes) aren't affected by this, everything just has the one name.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

If you want to run code in actual Minecraft, not in dev, you need to reobfuscate your code. ForgeGradle does this automatically for you when you run

gradle build

.

 

Ah, I probably should have said that I packaged the code into a .jar (IntelliJ's Build > Build Artifact) when it was running in the dev environment, and that the dev environment read from that jar, rather than reading from the soruce.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • https://drive.google.com/file/d/1M0EG-c5yfRd08DSnE5HVQNCu2v0YtA7A/view?usp=sharing  
    • so im not sure if your still watching this TileEntity but once we loaded a FTB modpack we wanted to run on the server it no longer seems to run. The console opens like normal but we've been sitting here for like a little over an hour and the server screen has not yet opened. Should we just keep waiting at this point?
    • I have now easily fixed the duplication error present, I was just not looking.   I have been working for the past half hour to try and fix another error present, this time with the Creative Mode Tab.   I have changed some things around to get where I am currently. (ModFoods to ModDrinks*) and it cannot find the symbol ".get" at the end of the code. *The custom class you recommended pOutput.accept(ModDrinks.ORANGE_JUICE.get()); I think the point I am at currently is the closest I have to how it should be but because I am not as experienced with java I would not know.  I have also removed ORANGE_JUICE and LEMON_JUICE from the ModFoods class, to avoid confliction. I do hope all this can be fully resolved soon.  
    • [SOLVED]  public class RenderGUIHandler { @SubscribeEvent public void renderGUI(RenderGameOverlayEvent.Text event){ Client.hud.draw(); } } As I was playing around a little with the code, i found out about an option to change The RenderGameOverlayEvent.Post to RenderGameOverlayEvent.Text
    • public class HUD { public Minecraft mc = Minecraft.getMinecraft(); public static class ModuleComparator implements Comparator<Module>{ @Override public int compare(Module o1, Module o2) { if (Minecraft.getMinecraft().fontRendererObj.getStringWidth(o1.name) > Minecraft.getMinecraft().fontRendererObj.getStringWidth(o2.name)){ return -1; } if (Minecraft.getMinecraft().fontRendererObj.getStringWidth(o1.name) < Minecraft.getMinecraft().fontRendererObj.getStringWidth(o2.name)){ return 1; } return 0; } } public void draw(){ ScaledResolution sr = new ScaledResolution(mc); FontRenderer fr = mc.fontRendererObj; Collections.sort(Client.modules, new ModuleComparator()); GlStateManager.pushMatrix(); GlStateManager.translate(4,4,0); GlStateManager.scale(1.5,1.5,1); GlStateManager.translate(-4, -4, 0); fr.drawString("Skyline", 10, 10, -1); GlStateManager.popMatrix(); int count = 0; for (Module m : Client.modules){ if (!m.toggled || m.name.equals("TabGUI")) continue; int offset = count* (fr.FONT_HEIGHT + 6); GL11.glTranslated(0.0f, 0.0f, -1.0f); Gui.drawRect(sr.getScaledWidth() - fr.getStringWidth(m.name) - 10, offset, sr.getScaledWidth() - fr.getStringWidth(m.name) - 8, 6 + fr.FONT_HEIGHT + offset, -1); Gui.drawRect(sr.getScaledWidth() - fr.getStringWidth(m.name) - 8, offset, sr.getScaledWidth(), 6 + fr.FONT_HEIGHT + offset, 0x90000000); fr.drawString(m.name, sr.getScaledWidth() - fr.getStringWidth(m.name) - 4, offset + 4, -1); count++; } Client.onEvent(new EventRenderGUI()); } } I have just recently stumbled upon this Problem, where the HudRenderer renders the wrong section of the textures and therefore completely destroys the Minecraft Armour and Hunger Bar. I am currently thinking if it is an issue with the DrawRect changing something it shouldn't. But I couldn't find anything about it. (To keep things Clean, the function is Called from another file) public class RenderGUIHandler { @SubscribeEvent public void renderGUI(RenderGameOverlayEvent.Post event){ Client.hud.draw(); } } Any help would be greatly appreciated  
  • Topics

×
×
  • Create New...

Important Information

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