blob: a7b914b668e38b24544d41e5c334c41ffc32ba21 (
plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
/*
* Copyright (C) 2022 NotEnoughUpdates contributors
*
* This file is part of NotEnoughUpdates.
*
* NotEnoughUpdates is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* NotEnoughUpdates is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
*/
package io.github.moulberry.notenoughupdates.miscgui.minionhelper;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.auction.APIManager;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.render.renderables.OverviewLine;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.requirements.MinionRequirement;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.CraftingSource;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.CustomSource;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.MinionSource;
import io.github.moulberry.notenoughupdates.util.ItemResolutionQuery;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.item.ItemStack;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class Minion extends OverviewLine {
private final String internalName;
private final int tier;
private String displayName;
private MinionSource minionSource;
private CustomSource customSource;
private Minion parent;
private final List<MinionRequirement> requirements = new ArrayList<>();
private boolean crafted = false;
private final int xpGain;
private boolean meetRequirements = false;
public Minion(String internalName, int tier, int xpGain) {
this.internalName = internalName;
this.tier = tier;
this.xpGain = xpGain;
}
public MinionSource getMinionSource() {
return minionSource;
}
public void setMinionSource(MinionSource minionSource) {
this.minionSource = minionSource;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public boolean isCrafted() {
return crafted;
}
public void setCrafted(boolean crafted) {
this.crafted = crafted;
}
public String getInternalName() {
return internalName;
}
public void setParent(Minion parent) {
this.parent = parent;
}
public Minion getParent() {
return parent;
}
public int getTier() {
return tier;
}
public List<MinionRequirement> getRequirements() {
return requirements;
}
public boolean doesMeetRequirements() {
return meetRequirements;
}
public void setMeetRequirements(boolean meetRequirements) {
this.meetRequirements = meetRequirements;
}
public int getXpGain() {
return xpGain;
}
@Override
public void onClick() {
if (Mouse.getEventButton() != 0 || !Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) {
NotEnoughUpdates.INSTANCE.manager.displayGuiItemRecipe(internalName);
} else {
if (minionSource instanceof CraftingSource) {
CraftingSource craftingSource = (CraftingSource) minionSource;
Map<String, Integer> counts = new HashMap<>();
for (Map.Entry<String, Integer> entry : craftingSource.getItems().entries()) {
counts.compute(entry.getKey(), (k, v) -> (v == null ? 0 : v) + entry.getValue());
}
Optional<Map.Entry<String, Integer>> resource = counts
.entrySet()
.stream()
.filter(it -> !APIManager.hardcodedVanillaItems.contains(it.getKey()))
.max(Comparator.comparingInt(Map.Entry::getValue));
if (!resource.isPresent()) return;
String bazaarName = resource.get().getKey();
int totalAmount = resource.get().getValue();
Utils.copyToClipboard(String.valueOf(totalAmount));
ItemStack itemStack = new ItemResolutionQuery(NotEnoughUpdates.INSTANCE.manager).withKnownInternalName(
bazaarName).resolveToItemStack();
if (itemStack != null) {
String displayName = Utils.cleanColour(itemStack.getDisplayName());
NotEnoughUpdates.INSTANCE.trySendCommand("/bz " + displayName);
}
}
}
}
public void setCustomSource(CustomSource customSource) {
this.customSource = customSource;
}
public CustomSource getCustomSource() {
return customSource;
}
}
|