Everything posted by Croa
-
[Solved][1.14.4] Get all files in specific folder
Thanks for your assistance Umbra and Ghost. Here is ultimately what I got to work. try { URI uri = ZombeCore.class.getClassLoader().getResource("com/zombe/zombecore/mods").toURI(); Path myPath; if (uri.getScheme().equals("modjar")) { System.out.println(" | Jar loaded | "); JarFile jarFile = new JarFile(Minecraft.getInstance().gameDir+"/mods/"+NAME+"-"+VERSION+".jar"); final Enumeration<JarEntry> entries = jarFile.entries(); while(entries.hasMoreElements()) { JarEntry entry = (JarEntry)entries.nextElement(); String name = entry.getName(); if(name.startsWith("com/zombe/zombecore/mods/Z") && name.endsWith(".class")) arrMods.add(Class.forName(name.replaceAll("/", ".").replaceAll(".class", ""))); } } else { System.out.println(" | Source loaded | "); myPath = Paths.get(uri); Stream<Path> walk = Files.walk(myPath, 1); int temp = 0; for (Iterator<Path> it = walk.iterator(); it.hasNext();){ if(temp ==0) { it.next(); temp = 1; } arrMods.add(Class.forName("com.zombe.zombecore.mods."+it.next().getFileName().toString().replaceAll(".class", ""))); }walk.close(); } }catch (URISyntaxException e) {}catch (IOException e) {}catch (ClassNotFoundException e) {}
-
[Solved][1.14.4] Get all files in specific folder
If I am ultimately reading from another jar file, I still need a path to identify and assign each file to a variable. Do you have an example how this will work or even terms to begin a search?
-
[Solved][1.14.4] Get all files in specific folder
Currently, I have everything working in a dev environment where all java files are discovered in a certain folder and assigned to variables. My issue is locating the files in a compiled jar. Obviously, the path needs to change since the files are no longer java sources. I am unaware what exactly needs to be changed to what. I have searched for anything directory and path related, but have been unable to locate a solution so far. What steps do I need to take to find class files without importing? The entire purpose is to be modular so that any class (within the jar) in "com/zombe/zombecore/mods" can be removed or added. modNums = Paths.get("src/main/java/com/zombe/zombecore/mods").toFile().exists() ? Paths.get("src/main/java/com/zombe/zombecore/mods").toFile().list().length : 0;//count the number of files in "com/zombe/zombecore/mods" modFiles = Paths.get("src/main/java/com/zombe/zombecore/mods").toFile().listFiles();//list of files in the directory try { for(int i =0; i < modNums; i++) { mod[i] = Class.forName("com.zombe.zombecore.mods."+modFiles[i].toString().substring(39, modFiles[i].toString().length()).replaceAll(".java", "").replaceAll(".class", ""));//assign each result to a class variable } } catch (ClassNotFoundException e) { System.out.println(e); }
-
[Solved] [1.14.4] Trouble converting Iterable to ArrayList
diesieben07, I am aware how to convert the Stream into a Collection. I took a look at that previously and could not avoid the original problem of each array slot being filled with the last BlockPos in the stream. getAllInBox appears to return MutableBlockPos according to the console. The only way so far I have successfully received correct coordinates to the Collection is with my previous code CODE: Stream<BlockPos> b1 = BlockPos.getAllInBox(new BlockPos(0,0,0),new BlockPos(3,0,0)); if(!ZBuild.doneSelection) { List<BlockPos> result = (b1.collect(Collectors.toList())); result.forEach(System.out::println); ZBuild.doneSelection=true; } OUTPUT: MutableBlockPos{x=3, y=0, z=0} MutableBlockPos{x=3, y=0, z=0} MutableBlockPos{x=3, y=0, z=0} MutableBlockPos{x=3, y=0, z=0}
-
[Solved] [1.14.4] Trouble converting Iterable to ArrayList
Draco, It is easier (with my current knowledge) to convert the Iterable that getAllInBoxMutable returns to a Collection than the Stream that getAllInBox returns. The rest of the class requires a Collection to operate as intended the way it is currently written. This part of the mod will copy/paste/cut/etc areas in the world with individual button presses. I am sure that this is inefficient, but I will don't want to ask people to code my mod for me unless it is absolutely necessary.
-
[Solved] [1.14.4] Trouble converting Iterable to ArrayList
Draco18s, Thanks for the pointer. My mind just wanted to create a new BlockPos as the previous comments suggested. Selected.add(pos.toImmutable()); is now what I have in the for loop
-
[Solved] [1.14.4] Trouble converting Iterable to ArrayList
Thanks for the assistance. The try block was to temporarily prevent the game from crashing while I toyed around with all of my solutions. For example, I forgot that I closed a stream and tried to use it again resulting in a notification rather than a crash. Anyway, my final code is here if anyone runs into the same issue: public static ArrayList<BlockPos> Selected = new ArrayList<BlockPos>(); public static BlockPos blockBuildpos1,blockBuildpos2; //the rest of my class Iterable<BlockPos> blocks = BlockPos.getAllInBoxMutable(blockBuildpos1,blockBuildpos2); if(!ZBuild.doneSelection) { for(BlockPos pos:blocks) { BlockPos temp = new BlockPos(pos); Selected.add(temp.toImmutable()); } ZBuild.doneSelection=true; }
-
[Solved] [1.14.4] Trouble converting Iterable to ArrayList
I am updating my code from 1.12.2 to 1.14.4 and I am having trouble with converting BlockPos.getAllInBoxMutable() to an ArrayList. My issue is that the last BlockPos in the Iterable is copied to all parts of the array instead of each to their own. My code and output are here: CODE: ArrayList<BlockPos> list = new ArrayList<BlockPos>(); Iterable<BlockPos> blocks = BlockPos.getAllInBoxMutable(new MutableBlockPos(0,0,0),new MutableBlockPos(2,0,0)); Iterable<BlockPos> iterable = Arrays.asList(new MutableBlockPos(0,0,0),new MutableBlockPos(1,0,0),new MutableBlockPos(2,0,0)); if(!ZBuild.doneSelection) { try { blocks.forEach(x->System.out.println(x)); blocks.forEach(x->list.add(x)); System.out.println(list+"\n\n"); list.clear(); iterable.forEach(x->System.out.println(x)); iterable.forEach(x->list.add(x)); System.out.println(list); }catch(Exception e) { System.out.println(e); } ZBuild.doneSelection=true; } ====================================================================================================== OUTPUT: MutableBlockPos{x=0, y=0, z=0} MutableBlockPos{x=1, y=0, z=0} MutableBlockPos{x=2, y=0, z=0} [MutableBlockPos{x=2, y=0, z=0}, MutableBlockPos{x=2, y=0, z=0}, MutableBlockPos{x=2, y=0, z=0}] MutableBlockPos{x=0, y=0, z=0} MutableBlockPos{x=1, y=0, z=0} MutableBlockPos{x=2, y=0, z=0} [MutableBlockPos{x=0, y=0, z=0}, MutableBlockPos{x=1, y=0, z=0}, MutableBlockPos{x=2, y=0, z=0}] Some of the solutions I have tried so far include: a for loop that adds each BlockPos individually changing getAllInBoxMutable to getAllInBox and converting the stream into an array changing all MutableBlockPos into BlockPos commenting out all code in the class that pertains to any of the variables Everything so far has yielded the same results and I am not quite sure why. Any help would be appreciated.
IPS spam blocked by CleanTalk.