Skip to content

Commit

Permalink
find_empty_slots tag (#2485)
Browse files Browse the repository at this point in the history
* Add `find_empty_slots` tag

* use `ElementTag` for index

* Use same function

* Add material type check for item.

* Update meta
  • Loading branch information
BreadcrumbIsTaken committed Jun 10, 2023
1 parent b4118b8 commit faa9d0f
Showing 1 changed file with 21 additions and 0 deletions.
Expand Up @@ -2356,6 +2356,27 @@ else if ((object.inventory instanceof FurnaceInventory)) {
}
return list;
});

// <--[tag]
// @attribute <InventoryTag.find_empty_slots>
// @returns ListTag
// @description
// Returns the index of all the empty slots in an inventory.
// -->
tagProcessor.registerTag(ListTag.class, "find_empty_slots", (attribute, object) -> {
if (object == null) {
return new ListTag();
}
ListTag indexes = new ListTag(object.getContents().length);
int index = 1;
for (ItemStack itemStack : object.getContents()) {
if (itemStack == null || itemStack.getType() == Material.AIR) {
indexes.addObject(new ElementTag(index));
}
index++;
}
return indexes;
});
}

public static ObjectTagProcessor<InventoryTag> tagProcessor = new ObjectTagProcessor<>();
Expand Down

0 comments on commit faa9d0f

Please sign in to comment.