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
|
/*
* Copyright (C) 2023 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.profileviewer.level.task;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.profileviewer.level.LevelPage;
import io.github.moulberry.notenoughupdates.util.Constants;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.util.EnumChatFormatting;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
public class EssenceTaskLevel extends GuiTaskLevel {
public EssenceTaskLevel(LevelPage levelPage) {
super(levelPage);
}
@Override
public void drawTask(JsonObject object, int mouseX, int mouseY, int guiLeft, int guiTop) {
List<String> lore = new ArrayList<>();
JsonObject categoryXp = levelPage.getConstant().get("category_xp").getAsJsonObject();
JsonObject essenceShopTask = levelPage.getConstant().get("essence_shop_task").getAsJsonObject();
JsonArray essenceSteps = essenceShopTask.get("essence_shop_xp").getAsJsonArray();
JsonObject essencePerks = object.has("perks") ? object.get("perks").getAsJsonObject() : new JsonObject();
Map<String, EssenceShop> loreMap = new HashMap<>();
for (Map.Entry<String, JsonElement> stringJsonElementEntry : Constants.ESSENCESHOPS.entrySet()) {
String name = stringJsonElementEntry.getKey();
JsonObject individualObjects = stringJsonElementEntry.getValue().getAsJsonObject();
for (Map.Entry<String, JsonElement> jsonElementEntry : individualObjects.entrySet()) {
int essenceAmount = Utils.getElementAsInt(Utils.getElement(
object,
"player_data.perks." + jsonElementEntry.getKey()
), 0);
int amountReceivedForEach = 0;
for (int i = essenceAmount - 1; i >= 0; i--) {
amountReceivedForEach += essenceSteps.get(i).getAsInt();
}
if (!loreMap.containsKey(name)) {
EssenceShop value = new EssenceShop();
value.current += amountReceivedForEach;
value.name = name;
loreMap.put(name, value);
} else {
EssenceShop essenceShop = loreMap.get(name);
essenceShop.current += amountReceivedForEach;
}
}
}
// bad workaround (pls fix later maybe)
for (Map.Entry<String, JsonElement> stringJsonElementEntry : essenceShopTask.entrySet()) {
String key = stringJsonElementEntry.getKey();
if (!key.endsWith("_shop")) continue;
String name = key.split("_shop")[0].toUpperCase(Locale.ROOT);
if (!loreMap.containsKey(name)) {
loreMap.put(name, new EssenceShop().setName(name).setCurrent(0));
}
}
int total = 0;
for (Map.Entry<String, EssenceShop> stringEssenceShopEntry : loreMap.entrySet()) {
String key = stringEssenceShopEntry.getKey();
EssenceShop value = stringEssenceShopEntry.getValue();
JsonObject jsonObject = NotEnoughUpdates.INSTANCE.manager
.createItemResolutionQuery()
.withKnownInternalName(key)
.resolveToItemListJson();
if (jsonObject == null){
Utils.showOutdatedRepoNotification(key);
continue;
}
value.name = jsonObject
.get("displayname")
.getAsString();
String name = key.toLowerCase(Locale.ROOT) + "_shop";
if (!essenceShopTask.has(name)) continue;
value.max = essenceShopTask.get(name).getAsInt();
lore.add(levelPage.buildLore(
EnumChatFormatting.getTextWithoutFormattingCodes(value.name),
value.current,
value.max,
false
));
total += value.current;
}
levelPage.renderLevelBar(
"Essence",
NotEnoughUpdates.INSTANCE.manager.createItemResolutionQuery()
.withKnownInternalName("ESSENCE_WITHER")
.resolveToItemStack(),
guiLeft + 299, guiTop + 25,
110,
total,
total,
categoryXp.get("essence_shop_task").getAsInt(),
mouseX, mouseY,
true,
lore
);
}
class EssenceShop {
String name;
double max;
double current;
public EssenceShop setCurrent(double current) {
this.current = current;
return this;
}
public EssenceShop setName(String name) {
this.name = name;
return this;
}
}
}
|