diff --git a/src/lib/Tags.hx b/src/lib/Tags.hx new file mode 100644 index 0000000..d7e79c5 --- /dev/null +++ b/src/lib/Tags.hx @@ -0,0 +1,49 @@ +package lib; + +import lib.PaN; + +using Lambda; +using lua.Table; + +/** + Represents a list a minecraft tags. + + Needed because tags are SOMETIMES retuned not as arrays. +**/ +@:forward +enum abstract Tags(Array) from Array to Array { + inline public function new(arr:Array) { + this = arr; + } + + /** + From values that are object with the tag as the filed and the value set to true. + **/ + @:from + public static function fromBoolTable(from:Table) { + var rtn = []; + for (k => _ in Table.toMap(from)) { + rtn.push(k); + } + + return new Tags(rtn); + } + + /** + From values that are lua arrays. + **/ + @:from + public static function fromIntTable(from:Table) { + return new Tags(from.toArray()); + } + + public function sortByName():Tags { + var copy = this.copy(); + + copy.sort((a:String, b:String) -> { + return if (a < b) -1 else 1; + }); + + return copy; + } +}