@@ -184,7 +184,7 @@ private static String getTextResource(ResourceLocation identifier) {
184184 static <T extends JsonConfigurable <T , ?>> T getAsT (EType type , String location ) throws InvalidExpressionException {
185185 if (StringUtils .isEmpty (location )) {
186186 CLSLog .warn ("Location was given as null!" , new Throwable ());
187- return null ;
187+ throw new JsonSyntaxException ( "Invalid location '" + location + "'" ) ;
188188 }
189189 CLSLog .info ("Getting " + location + " as " + type );
190190 ResourceLocation loc = getLocation (type , location );
@@ -196,7 +196,7 @@ private static String getTextResource(ResourceLocation identifier) {
196196 return (T ) failed ;
197197 }
198198 CLSLog .warn ("The text inside of \" " + loc + "\" was null!" );
199- return null ;
199+ throw new JsonSyntaxException ( "Invalid location '" + location + "': the text inside it was null!" ) ;
200200 }
201201 try {
202202 T t = (T ) GSON_ADAPTORS .fromJson (text , type .clazz );
@@ -241,22 +241,55 @@ public static void getAsScript(String location) {
241241 }
242242
243243 public static ResourceLocation getLocation (EType type , String base ) {
244+
245+ /* Namespace rules: */
246+
247+ // If the location starts contains a colon before a slash then it's a namespace,
248+ // and we don't do anything special other that use it instead of the default.
249+
250+ // If the location starts with "config/" then we use "config" as the namespace
251+ // and we *don't* add the type prefix if the type is EType.CONFIG.
252+
253+ /* Path rules: */
254+
255+ // We always append ".json" to the path, no exceptions
256+ // The other rules are a bit more complicated:
257+
258+ // If it starts with "builtin/" or "sample/" then we bring that to the front.
259+
260+ // Then we add "type"
261+
262+ String namespace = "customloadingscreen" ;
244263 String path ;
245- if (base .startsWith ("builtin/" )) {
246- path = "builtin/" + type .resourceBase + "/" + base .substring ("builtin/" .length ()) + ".json" ;
247- } else if (base .startsWith ("sample/" )) {
248- path = "sample/" + type .resourceBase + "/" + base .substring ("sample/" .length ()) + ".json" ;
249- } else if (base .startsWith ("config/" )) {
250- if (type == EType .CONFIG ) {
251- path = base .substring ("config/" .length ()) + ".json" ;
264+ int colon = base .indexOf (':' );
265+ int slash = base .indexOf ('/' );
266+
267+ if (colon > 0 && (colon < slash || slash < 0 )) {
268+ namespace = base .substring (0 , colon );
269+ base = base .substring (colon + 1 );
270+
271+ if ("config" .equals (namespace ) && type == EType .CONFIG ) {
272+ path = base ;
252273 } else {
253- path = type .resourceBase + "/" + base . substring ( "config/" . length ()) + ".json" ;
274+ path = type .resourceBase + "/" + base ;
254275 }
255- return new ResourceLocation ("config" , path );
256276 } else {
257- path = type .resourceBase + "/" + base + ".json" ;
277+ if (base .startsWith ("builtin/" )) {
278+ path = "builtin/" + type .resourceBase + base .substring (slash );
279+ } else if (base .startsWith ("sample/" )) {
280+ path = "sample/" + type .resourceBase + base .substring (slash );
281+ } else if (base .startsWith ("config/" )) {
282+ if (type == EType .CONFIG ) {
283+ path = base .substring (slash + 1 );
284+ } else {
285+ path = type .resourceBase + base .substring (slash );
286+ }
287+ namespace = "config" ;
288+ } else {
289+ path = type .resourceBase + "/" + base ;
290+ }
258291 }
259292
260- return new ResourceLocation ("customloadingscreen" , path );
293+ return new ResourceLocation (namespace , path + ".json" );
261294 }
262295}
0 commit comments