Created
March 5, 2020 21:53
-
-
Save arjolpanci/5e1aa52909d8cb62494d08167e85d634 to your computer and use it in GitHub Desktop.
Slot Update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void updateSlots(int offset){ | |
inventorySlots.clear(); | |
if(offset <= 0) offset = 0; | |
int startingIndex = (offset)*9; | |
for(int i=0; i<3; i++){ | |
for(int j=0; j<9; j++){ | |
this.addSlot(new Slot(pi, j+i*9+9, 198 + j*18, 28 + i*18)); | |
} | |
} | |
for(int i=0; i<9; i++){ | |
this.addSlot(new Slot( pi, i, 198 + i*18, 88)); | |
} | |
ArrayList<Slot> itemSlots = new ArrayList<>(tile.getSb().getItemSlots()); | |
ArrayList<Slot> emptySlots = new ArrayList<>(tile.getSb().getEmptySlots()); | |
System.out.println(emptySlots.size()); | |
int maxItemIndex = itemSlots.size() - 1; | |
int emptyIndex = 0; | |
int maxEmptyIndex = emptySlots.size() - 1; | |
for(int i=0; i<6; i++) { | |
for (int j = 0; j < 9; j++) { | |
if(startingIndex > maxItemIndex || startingIndex < 0){ | |
if(emptyIndex > maxEmptyIndex) return; | |
Slot slot = emptySlots.get(emptyIndex++); | |
slot.xPos = 9 + j * 18; | |
slot.yPos = 18 + i * 18; | |
this.addSlot(slot); | |
}else{ | |
Slot slot = itemSlots.get(startingIndex++); | |
slot.xPos = 9 + j * 18; | |
slot.yPos = 18 + i * 18; | |
this.addSlot(slot); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment