-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTradeCraftChest.java
More file actions
82 lines (69 loc) · 1.91 KB
/
TradeCraftChest.java
File metadata and controls
82 lines (69 loc) · 1.91 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import java.util.ArrayList;
import java.util.List;
class TradeCraftChest {
private Chest chest;
public int id;
public int total;
public TradeCraftChest(Chest chest) {
this.chest = chest;
for (Item item : chest.getContents()) {
if (item != null) {
addItem(item);
}
}
}
private void addItem(Item item) {
if (total == 0) {
id = item.getItemId();
} else if (id != item.getItemId()) {
id = -1;
}
total += item.getAmount();
}
public boolean containsOnlyOneItemType() {
return id != -1;
}
public void clear() {
chest.clearContents();
}
public void add(int id, int amount) {
int maxStackSize = TradeCraft.getMaxStackSize(id);
int blocks = amount / maxStackSize;
for (int i = 0; i < blocks; i++) {
chest.addItem(new Item(id, maxStackSize));
}
int remainder = amount % maxStackSize;
if (remainder > 0) {
chest.addItem(new Item(id, remainder));
}
}
public void update() {
}
public void populateChest(int id, int amount) {
clear();
add(id, amount);
update();
}
public int getAmountOfCurrencyInChest() {
int amount = 0;
for (Item item : chest.getContents()) {
if (item != null) {
if (item.getItemId() == Item.Type.GoldIngot.getId()) {
amount += item.getAmount();
}
}
}
return amount;
}
public List<Item> getNonCurrencyItems() {
List<Item> items = new ArrayList<Item>();
for (Item item : chest.getContents()) {
if (item != null) {
if (item.getType() != Item.Type.GoldIngot) {
items.add(item);
}
}
}
return items;
}
}