Skip to content

Instantly share code, notes, and snippets.

@luiz-otavio
Last active January 13, 2024 15:29
Show Gist options
  • Save luiz-otavio/4213527e6ad57df1b81225316615a49c to your computer and use it in GitHub Desktop.
Save luiz-otavio/4213527e6ad57df1b81225316615a49c to your computer and use it in GitHub Desktop.
Labeling loop in a necessary case
// Make it ordered
for (int index = 0; index < contents.length; index++) {
ItemStack current = contents[index];
if (current == null) {
// Search for the most closed
searchFirst: for (int newSlot = index + 1; newSlot < contents.length; newSlot++) {
current = contents[newSlot];
if (current != null && current.getType() != Material.AIR) {
contents[newSlot] = null;
break searchFirst;
}
if (current != null) {
contents[index] = current;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment