Posted August 8, 201510 yr Hey guys, I am triing to save data in text files and read them at runtime. My problem right now is that I want this to work in dev environment and "playing" environment without changing code. So what I tried is ResourceLocation loc = new ResourceLocation("minigames:maps"); File file = new File(loc.getResourcePath()); System.out.println(file.getAbsolutePath()); But this throws me inside the eclipse folder, which I tried to NOT do. Which is the thing I need to use here?
August 8, 201510 yr Hi Where do you want the data to be saved? in the saved game folder? If so- CommonProxy:: /** * Obtains the folder that world save backups should be stored in. * For Integrated Server, this is the saves folder * For Dedicated Server, a new 'backupsaves' folder is created in the same folder that contains the world save directory * @return the folder where backup saves should be created */ public abstract Path getOrCreateSaveBackupsFolder() throws IOException; ClientProxy:: @Override public Path getOrCreateSaveBackupsFolder() throws IOException { return new File(Minecraft.getMinecraft().mcDataDir, "saves").toPath(); } DedicatedServerProxy:: @Override public Path getOrCreateSaveBackupsFolder() throws IOException { Path universeFolder = FMLServerHandler.instance().getSavesDirectory().toPath(); Path backupsFolder = universeFolder.resolve(SpeedyToolsOptions.nameForSavesBackupFolder()); if (!Files.exists(backupsFolder)) { Files.createDirectory(backupsFolder); } return backupsFolder; } -TGG
August 8, 201510 yr Author I want to get the path of the assets folder for read only tasks. I am storing data there and want to read that on server initializing to store the data in arrays. So I want what in eclipse is assets.minigames.maps
August 8, 201510 yr Hi You could use the resource manager to open your file as a stream, you don't need to worry about absolute paths at all then, just give it your domain eg from SoundHandler: final SoundList.SoundEntry soundentry = (SoundList.SoundEntry)iterator.next(); String s = soundentry.getSoundEntryName(); ResourceLocation resourcelocation1 = new ResourceLocation(s); final String s1 = s.contains(":") ? resourcelocation1.getResourceDomain() : p_147693_1_.getResourceDomain(); Object object; switch (SoundHandler.SwitchType.field_148765_a[soundentry.getSoundEntryType().ordinal()]) { case 1: ResourceLocation resourcelocation2 = new ResourceLocation(s1, "sounds/" + resourcelocation1.getResourcePath() + ".ogg"); InputStream inputstream = null; try { inputstream = this.mcResourceManager.getResource(resourcelocation2).getInputStream(); } catch (FileNotFoundException filenotfoundexception) { logger.warn("File {} does not exist, cannot add it to event {}", new Object[] {resourcelocation2, p_147693_1_}); continue; } catch (IOException ioexception) { logger.warn("Could not load sound file " + resourcelocation2 + ", cannot add it to event " + p_147693_1_, ioexception); continue; } finally { IOUtils.closeQuietly(inputstream); } -TGG
August 8, 201510 yr Author I feel like I dont understood the ResourceLocation 100% right now. It is not taking me to the assets folder, but to total nonsense. I am using this right now, the method is called with the arg "archer" (which is the name of the "map" to look for) [13:05:43] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: java.io.FileNotFoundException: minigames:maps/archer.fail private static int[][][] readFile(String key) { ResourceLocation loc = new ResourceLocation("minigames:maps/"+key+".fail"); try { InputStream stream = Minecraft.getMinecraft().getResourceManager().getResource(new ResourceLocation("minigames" ,"maps/"+key+".fail")).getInputStream(); ObjectInputStream in = new ObjectInputStream(stream); int[][][] ret = (int[][][]) in.readObject(); in.close(); return ret; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Critical error loading File"); } }
August 8, 201510 yr Author Fixxed it. Welcome to the world of spelling mistakes. thank you anyways :'D
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.