Skip to content

Commit

Permalink
inventory.find.material: accept list input
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 7, 2020
1 parent 89027d6 commit b05c68c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Expand Up @@ -2058,20 +2058,24 @@ else if (item != null && item.hasItemMeta() && item.getItemMeta().hasDisplayName
// -->
registerTag("find", (attribute, object) -> {
// <--[tag]
// @attribute <InventoryTag.find.material[<material>]>
// @attribute <InventoryTag.find.material[<material>|...]>
// @returns ElementTag(Number)
// @description
// Returns the location of the first slot that contains the material.
// Returns the location of the first slot that contains any of the given materials.
// Returns -1 if there's no match.
// -->
if (attribute.startsWith("material", 2)) {
MaterialTag material = attribute.contextAsType(2, MaterialTag.class);
if (material == null) {
ListTag list = attribute.contextAsType(2, ListTag.class);
if (list == null) {
return null;
}
HashSet<Material> materials = new HashSet<>();
for (ObjectTag obj : list.objectForms) {
materials.add(obj.asType(MaterialTag.class, attribute.context).getMaterial());
}
int slot = -1;
for (int i = 0; i < object.inventory.getSize(); i++) {
if (object.inventory.getItem(i) != null && object.inventory.getItem(i).getType() == material.getMaterial()) {
if (object.inventory.getItem(i) != null && materials.contains(object.inventory.getItem(i).getType())) {
slot = i + 1;
break;
}
Expand Down
Expand Up @@ -2022,6 +2022,7 @@ else if (attribute.startsWith("percent", 2)) {
// @mechanism PlayerTag.fly_speed
// @description
// Returns the speed the player can fly at.
// Default value is '0.2'.
// -->
registerOnlineOnlyTag("fly_speed", (attribute, object) -> {
return new ElementTag(object.getPlayerEntity().getFlySpeed());
Expand Down

0 comments on commit b05c68c

Please sign in to comment.