Jump to content

[1.8] Generate model file internally?


61352151511

Recommended Posts

Not sure if this is possible but what I'd like is to generate Strings in a json format within code, and then register that as the model, so instead of having an actual file, it's just done on launch. These will be cached if the user wishes to save them, it basically saves the effort of having to create model files for every block/item. If this is possible could I get some insight on how to do so?

Link to comment
Share on other sites

Thanks, I think I got most of it done however one issue I'm having is getting the field.

 

@SuppressWarnings({"rawtypes", "unchecked"}) public synchronized static void assembleResources() {
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
	try {
		Field field = Minecraft.getMinecraft().getClass().getDeclaredField("defaultResourcePacks");
		field.setAccessible(true);
		Field modField = Field.class.getDeclaredField("modifiers");
		modField.setAccessible(true);
		modField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
		List rPacks = (List) field.get(Lists.newArrayList());
		rPacks.add(new EasyModResourcePack());
		field.set(field, rPacks);
	} catch (Exception e) {
		LogHelper.warn("An exception was thrown creating resource pack");
		LogHelper.warn(e.getMessage() != null ? e.getMessage() : "");
		e.printStackTrace();
	}
}
}

 

The line "List rPacks = (List) field.get(Lists.newArrayList());" Throws an error, Can not set java.util.List field net.minecraft.client.Minecraft.defaultResourcePacks to java.util.ArrayList

 

If someone knows how to fix this issue, that would really help. I'm no reflection expert, I wouldn't even consider myself at the level of beginner yet, so I'm probably doing something wrong.

Link to comment
Share on other sites

private final DefaultResourcePack mcDefaultResourcePack;

It's not a static field but it's final, and I get illegal access exception's without it.

 

The only things I've changed are

Field field = Minecraft.class.getDeclaredField("defaultResourcePacks");

List rPacks = (List) field.get(Minecraft.getMinecraft());

 

Now if I don't set the field how am I supposed to add to the default resource packs? Does calling rPacks.add do it?

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.

×
×
  • Create New...

Important Information

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