json-able attributes (#8334)

This commit is contained in:
MEEPofFaith
2023-03-08 10:11:53 -08:00
committed by GitHub
parent d937af7497
commit 515a6f9c8d
2 changed files with 10 additions and 1 deletions

View File

@@ -79,7 +79,11 @@ public class ContentParser{
put(Interp.class, (type, data) -> field(Interp.class, data));
put(Blending.class, (type, data) -> field(Blending.class, data));
put(CacheLayer.class, (type, data) -> field(CacheLayer.class, data));
put(Attribute.class, (type, data) -> Attribute.get(data.asString()));
put(Attribute.class, (type, data) -> {
String attr = data.asString();
if(Attribute.exists(attr)) return Attribute.get(attr);
return Attribute.add(attr);
});
put(BuildVisibility.class, (type, data) -> field(BuildVisibility.class, data));
put(Schematic.class, (type, data) -> {
Object result = fieldOpt(Loadouts.class, data);

View File

@@ -47,6 +47,11 @@ public class Attribute{
return map.getThrow(name, () -> new IllegalArgumentException("Unknown Attribute type: " + name));
}
/** @return Whether an attribute exists. */
public static boolean exists(String name){
return map.containsKey(name);
}
/** Automatically registers this attribute for use. Do not call after mod init. */
public static Attribute add(String name){
Attribute a = new Attribute(all.length, name);