Skip to content

Commit

Permalink
inventory contents improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 1, 2020
1 parent 6d6d302 commit c8a3e31
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
Expand Up @@ -43,7 +43,7 @@ private EntityInventory(EntityTag ent) {

@Override
public String getPropertyString() {
return new InventoryContents(entity.getInventory()).getContents(0).identify();
return new InventoryContents(entity.getInventory()).getContents(false).identify();
}

@Override
Expand Down
Expand Up @@ -36,16 +36,16 @@ public InventoryContents(InventoryTag inventory) {
this.inventory = inventory;
}

public ListTag getContents(int simpleOrFull) {
public ListTag getContents(boolean simple) {
if (inventory.getInventory() == null) {
return null;
}
int lastNonAir = -1;
ListTag contents = new ListTag();
boolean containsNonAir = false;
for (ItemStack item : inventory.getInventory().getContents()) {
if (item != null && item.getType() != Material.AIR) {
containsNonAir = true;
if (simpleOrFull == 1) {
lastNonAir = contents.size();
if (simple) {
contents.add(new ItemTag(item).identifySimple());
}
else {
Expand All @@ -56,16 +56,9 @@ public ListTag getContents(int simpleOrFull) {
contents.addObject(new ItemTag(Material.AIR));
}
}
if (!containsNonAir) {
contents.clear();
}
else {
for (int x = contents.size() - 1; x >= 0; x--) {
if (!contents.get(x).equals("i@air")) {
break;
}
contents.remove(x);
}
lastNonAir++;
while (contents.size() > lastNonAir) {
contents.remove(lastNonAir);
}
return contents;
}
Expand Down Expand Up @@ -103,7 +96,7 @@ public String getPropertyString() {
if (!inventory.getIdType().equals("generic") && !inventory.isUnique()) {
return null;
}
ListTag contents = getContents(0);
ListTag contents = getContents(false);
if (contents == null || contents.isEmpty()) {
return null;
}
Expand Down Expand Up @@ -160,7 +153,7 @@ public static void registerTags() {
// -->
if (attribute.startsWith("simple", 2)) {
attribute.fulfill(1);
return contents.getContents(1);
return contents.getContents(true);
}

// <--[tag]
Expand Down Expand Up @@ -198,7 +191,7 @@ public static void registerTags() {
return contents.getContentsWithLore(lore, false);
}

return contents.getContents(0);
return contents.getContents(false);
});
}

Expand Down
Expand Up @@ -84,7 +84,7 @@ public ListTag getInventoryContents() {
if (inventory == null) {
return null;
}
return InventoryContents.getFrom(inventory).getContents(0);
return InventoryContents.getFrom(inventory).getContents(false);
}

@Override
Expand Down Expand Up @@ -123,7 +123,7 @@ public void adjust(Mechanism mechanism) {
BlockStateMeta bsm = ((BlockStateMeta) itemStack.getItemMeta());
InventoryHolder invHolder = (InventoryHolder) bsm.getBlockState();

ListTag items = InventoryContents.getFrom(inventoryPair.getValue()).getContents(0);
ListTag items = InventoryContents.getFrom(inventoryPair.getValue()).getContents(false);
if (items.size() > invHolder.getInventory().getSize()) {
Debug.echoError("Invalid inventory_contents input size; expected " + invHolder.getInventory().getSize() + " or less.");
return;
Expand Down

0 comments on commit c8a3e31

Please sign in to comment.