Skip to content

Commit

Permalink
Fixed list iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlegiantJGC committed Jul 12, 2024
1 parent 27e8047 commit 15eaa01
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/amulet_nbt/cpp/tag/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ namespace Amulet {

ListTagIterator::ListTagIterator(Amulet::ListTagPtr tag, size_t start, std::ptrdiff_t step): tag(tag), index(start), step(step) {};
Amulet::TagNode ListTagIterator::next() {
return Amulet::ListTag_get_node<size_t>(*tag, index++);
auto node = Amulet::ListTag_get_node<size_t>(*tag, index);
index += step;
return node;
}
bool ListTagIterator::has_next(){
return index >= 0 && index < ListTag_size(*tag);
Expand Down
2 changes: 1 addition & 1 deletion src/amulet_nbt/pybind/tag/py_list_tag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ void init_list(py::module& m) {
ListTag.def(
"__reversed__",
[](const Amulet::ListTagWrapper& self) {
return Amulet::ListTagIterator(self.tag, ListTag_size(*self.tag), -1);
return Amulet::ListTagIterator(self.tag, ListTag_size(*self.tag) - 1, -1);
}
);
ListTag.def(
Expand Down

0 comments on commit 15eaa01

Please sign in to comment.