An exported mod's 'current working directory'

Started by EnsurdFrndship on Fri, 06/05/2020 - 20:52

Topic category: Advanced modding

Last seen on 20:43, 10. Jun 2020
Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
An exported mod's 'current working directory'
Tue, 06/09/2020 - 16:02 (edited)

Hello,

   I know this might sound like an interesting question, but I discovered that the 'current working directory' for a project in MCreator is...

C:\Users\<username>\MCreatorWorkspaces\<project name>\run\

   and when I put a folder in that directory with .txt files in them, and had code in <proceedure name>CommandExecutedProceedure.Java that read from files, the directory above was the 'current working directory' (meaning if I wanted to open "file.txt", it would open "C:\Users\<username>\MCreatorWorkspaces\<project name>\run\file.txt".

   After exporting the .jar file of me mod into...

C:\Users\<username>\AppData\Roaming\.minecraft\mods\ 

  My mod uploads perfectly fine EXCEPT it causes Minecraft to crash because the 'current working directory' is no longer...  

C:\Users\<username>\MCreatorWorkspaces\<project name>\run\

    anymore. To get around this, I was wondering what directory to transfer the .txt files my mod reads from (as the NEW 'current working directory'). Thank you. 

 

Edited by EnsurdFrndship on Tue, 06/09/2020 - 16:02
Last seen on 20:43, 10. Jun 2020
Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
     I have an idea... Is…
Sat, 06/06/2020 - 00:26

     I have an idea... Is there a way to deliberately cause an exported mod to crash with the error message containing a message that has...

System.getProperty("user.dir")

     (the 'current working directory') inside the error message? This COULD be a way to get the 'current working directory' of wherever the exported mod sits. Thank you for any information.

 

  My mod uploads perfectly…
Sun, 06/07/2020 - 11:47

  My mod uploads perfectly fine EXCEPT it causes Minecraft to crash because the 'current working directory' is no longer...  

This is not caused by this. Instead of assuming, provide the full crash log.

Last seen on 20:43, 10. Jun 2020
Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
   According to the crash…
Sat, 06/06/2020 - 16:34

   According to the crash log, I got...

java.lang.StringIndexOutOfBoundsException: String index out of range: -2

   as my error, and I know WHY that was... My java program in MCreator is set up to read .txt files from the...

C:\Users\<username>\MCreatorWorkspaces\<project name>\run\

   directory without any errors. As long as my files exist in THAT directory (as I am running MCreator), I don't get this error, BUT, when I export my finished mod into 

C:\Users\<username>\AppData\Roaming\.minecraft\mods\ 

   for Minecraft, I get this error because these files are not located anywhere in my Minecraft mods folder, and my mod is attempting to read them. That is why I wanted to know what the 'current working directory' would be for my Minecraft mods folder. I already found out what it was in my MCreator project... which was why I wanted my exported mod to deliberately crash with the message of where the 'current working directory' is of where my Minecraft mod sat.

   I already figured out a workaround around this problem, and had my .txt files put in my .java coding instead, but for the future, it might be a suggested feature to have exported mods read data from files in order to have the added gaming experiences be based on data in files. All I need to do now, is figure out how to put vanilla data in 'written books' and I will ultimately be finished with my mod. Thank you.   

I see now, I did not fully…
Sun, 06/07/2020 - 11:47

I see now, I did not fully understand what txt files you were reading. Nice to hear you sorted it out ;)

Last seen on 20:43, 10. Jun 2020
Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Thank you. All I need to…
Tue, 06/09/2020 - 15:10

Thank you. All I need to know now, is how to apply that text to show up in 'written books' inside my game when I run my mod. I need to know the code to write (in Java) for altering the vanilla tags for 'written books'. I know 'written books' require a 'title' that is a String, an 'author' that is also a String, and 'pages' that is a list of Strings. I just don't know the proper classes and functions to use to 'gain access' to changing that data.

Try to search recent topics,…
Tue, 06/09/2020 - 15:43

Try to search recent topics, one resolved this issue recently and provided some example code too.

Last seen on 20:43, 10. Jun 2020
Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Do you know what the subject…
Tue, 06/09/2020 - 17:04

Do you know what the subject was?

Last seen on 20:43, 10. Jun 2020
Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Thank you. I was the one who…
Tue, 06/09/2020 - 18:08

Thank you. I was the one who asked, but didn't have the question resolved because the code I used didn't work and my books still said, "*Invalid book tag*" in them. I don't know how to set the ContactNBT variable so that when I pass the variable to the setTagInfo(String tag, NBTBase nbt) function (where the NBTBase base class accepts a ContactNBT variable), that it would set the right vanilla tags for the books.  

Last seen on 20:43, 10. Jun 2020
Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Thank you. I noticed there…
Wed, 06/10/2020 - 19:25

Thank you. I noticed there aren't any coding examples on CompoundNBT in the link, nor under Google. The only examples I've seen closest to it so far were through the NBTTagString and NBTTagList classes, which seem to be outdated. Although, I KNOW it wouldn't make ANY sense to have outdated classes and functions out there that USED TO be able to accomplish the goals that are not able to be accomplished today. So far, I have the code...

 

					CompoundNBT nbtTag = new CompoundNBT();
					nbtTag.putString("author", "Michael S. Lowe");
					nbtTag.putString("title", "Scripture");
					nbtTag.putString("pages", scripture);
					nbtTag.putString("Author", "Michael S. Lowe");
					nbtTag.putString("Title", "Scripture");
					nbtTag.putString("Pages", scripture);
					nbtTag.putIntArray("pages", new int[3]);
					nbtTag.putIntArray("Pages", new int[3]);

					ItemStack itm = /*Written book item code (for short)*/

					itm.setTag(nbtTag);					

   but still haven't found the right classes or functions yet that sets the vanilla tags to have data appear in written books. 

The code seems fine, you…
Wed, 06/10/2020 - 19:28

The code seems fine (except empty int arrays possibly), you likely just need to find the right combo of elements to put in the tag.