Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.

now CommonIO doesn't even try to read mods when they aren't loaded

+32 -21
+1 -1
gradle.properties
··· 9 9 loader_version=0.16.2 10 10 11 11 # Mod Properties 12 - mod_version = 1.12.4-1.21.1 12 + mod_version = 1.12.5-1.21.1 13 13 maven_group = net.lerariemann 14 14 archives_base_name = infinity 15 15
+31 -20
src/main/java/net/lerariemann/infinity/util/CommonIO.java
··· 1 1 package net.lerariemann.infinity.util; 2 2 3 3 import com.mojang.brigadier.exceptions.CommandSyntaxException; 4 + import net.fabricmc.loader.api.FabricLoader; 4 5 import net.minecraft.nbt.*; 5 6 import org.apache.commons.io.FileUtils; 6 7 ··· 143 144 return res; 144 145 } 145 146 147 + private static boolean _checkIfModLoaded(File path1) { 148 + String modname = path1.toPath().getName(path1.toPath().getNameCount() - 1).toString(); 149 + return FabricLoader.getInstance().isModLoaded(modname); 150 + } 151 + 152 + private static NbtList _extractElements(File path1, String subpath) { 153 + if (_checkIfModLoaded(path1)) { 154 + File file = path1.toPath().resolve(subpath).toFile(); 155 + if (file.exists()) { 156 + NbtCompound base = read(file); 157 + return base.getList("elements", NbtElement.COMPOUND_TYPE); 158 + } 159 + } 160 + return new NbtList(); 161 + } 162 + 146 163 public static WeighedStructure<String> weighedListReader(String path, String subpath) { 147 164 WeighedStructure<String> res = new WeighedStructure<>(); 148 165 for (File path1: Objects.requireNonNull((new File(path)).listFiles(File::isDirectory))) { 149 - File readingthis = path1.toPath().resolve(subpath).toFile(); 150 - if (readingthis.exists()) { 151 - NbtCompound base = read(readingthis); 152 - NbtList list = base.getList("elements", NbtElement.COMPOUND_TYPE); 153 - for(int i = 0; i < list.size(); i++) { 154 - NbtCompound a = list.getCompound(i); 155 - res.add(a.getString("key"), a.getDouble("weight")); 156 - } 166 + NbtList list = _extractElements(path1, subpath); 167 + for(int i = 0; i < list.size(); i++) { 168 + NbtCompound a = list.getCompound(i); 169 + res.add(a.getString("key"), a.getDouble("weight")); 157 170 } 158 171 } 159 172 return res; ··· 162 175 public static WeighedStructure<NbtElement> blockListReader(String path, String subpath) { 163 176 WeighedStructure<NbtElement> res = new WeighedStructure<>(); 164 177 for (File path1: Objects.requireNonNull((new File(path)).listFiles(File::isDirectory))) { 165 - File file = path1.toPath().resolve(subpath).toFile(); 166 - if (file.exists()) { 167 - NbtCompound base = read(file); 168 - NbtList list = base.getList("elements", NbtElement.COMPOUND_TYPE); 169 - for(int i = 0; i < list.size(); i++) { 170 - NbtCompound a = list.getCompound(i); 171 - res.add(a.get("key"), a.getDouble("weight")); 172 - } 178 + NbtList list = _extractElements(path1, subpath); 179 + for(int i = 0; i < list.size(); i++) { 180 + NbtCompound a = list.getCompound(i); 181 + res.add(a.get("key"), a.getDouble("weight")); 173 182 } 174 183 } 175 184 return res; ··· 178 187 public static NbtList nbtListReader(String path, String subpath) { 179 188 NbtList res = new NbtList(); 180 189 for (File path1: Objects.requireNonNull((new File(path)).listFiles(File::isDirectory))) { 181 - File readingthis = new File(path1.getPath() + "/" + subpath); 182 - if (readingthis.exists()) { 183 - NbtList add = read(path1.getPath() + "/" + subpath).getList("elements", NbtElement.STRING_TYPE); 184 - res.addAll(add); 190 + if (_checkIfModLoaded(path1)) { 191 + File readingthis = new File(path1.getPath() + "/" + subpath); 192 + if (readingthis.exists()) { 193 + NbtList add = read(path1.getPath() + "/" + subpath).getList("elements", NbtElement.STRING_TYPE); 194 + res.addAll(add); 195 + } 185 196 } 186 197 } 187 198 return res;