-
Notifications
You must be signed in to change notification settings - Fork 1
/
InventoryPane.java
53 lines (42 loc) · 1.28 KB
/
InventoryPane.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.github.sanctum.labyrinth.gui.basalt;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.IntStream;
public enum InventoryPane {
/**
* The top bar of slots within the inventory.
*/
TOP(i -> IntStream.range(0, 9).toArray()),
/**
* The bottom bar of slots within the inventory.
*/
BOTTOM(i -> IntStream.range(i - 9, i).toArray()),
/**
* The middle space of the inventory.
*/
MIDDLE(i -> {
if (i <= 18) {
return IntStream.range(0, 9).toArray();
}
return IntStream.range(10, i).filter(n -> n < i - 9 && n % 9 != 0 && n % 9 != 8).toArray();
}),
/**
* The left bar of slots within the inventory.
*/
LEFT(i -> IntStream.iterate(0, n -> n + 9).limit(i / 9).toArray()),
/**
* The right bar of slots within the inventory.
*/
RIGHT(i -> IntStream.iterate(8, n -> n + 9).limit(i / 9).toArray());
private final Function<Integer, int[]> generatorFunction;
private final Map<Integer, int[]> cache = new HashMap<>();
InventoryPane(final Function<Integer, int[]> generatorFunction) {
this.generatorFunction = generatorFunction;
}
public int[] get(int slots) {
int[] result = cache.computeIfAbsent(slots, generatorFunction);
return Arrays.copyOf(result, result.length);
}
}