Skip to content

Commit cfe1eb9

Browse files
authored
Update Jingle dep, update some item tracker logic, add crafted items to item tracker, add 1.15 item tracking (#4)
* Rename item constants with version * Update build.gradle * Add crafted item tracking, add 1.15 item tracking, tweak some other item logic
1 parent b4ae2ce commit cfe1eb9

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies {
2626
// Choose Julti version: https://jitpack.io/#DuncanRuns/Julti/
2727
implementation 'com.github.DuncanRuns:Julti:v1.6.0'
2828
// Choose Jingle version: https://jitpack.io/#DuncanRuns/Jingle/
29-
implementation 'com.github.DuncanRuns:Jingle:eeb4291b13'
29+
implementation 'com.github.DuncanRuns:Jingle:v1.1.0'
3030

3131
provided 'com.jetbrains.intellij.java:java-gui-forms-rt:203.7148.30'
3232
provided 'com.google.code.gson:gson:2.10'

src/main/java/gg/paceman/tracker/ItemTracker.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
import java.io.IOException;
1010
import java.nio.file.Files;
1111
import java.nio.file.Path;
12+
import java.nio.file.Paths;
1213
import java.util.*;
1314

1415
public class ItemTracker {
1516
private static final Gson GSON = new Gson();
1617
private Dictionary<String, Integer> estimatedCounts;
1718
private Dictionary<String, Integer> usages;
19+
private Dictionary<String, Integer> crafted;
1820

1921
public void tryUpdate(Path worldPath) {
2022
try {
@@ -28,6 +30,7 @@ private void update(Path worldPath) throws IOException, JsonSyntaxException {
2830
// Clear tables (and trash old ones)
2931
this.estimatedCounts = new Hashtable<>();
3032
this.usages = new Hashtable<>();
33+
this.crafted = new Hashtable<>();
3134

3235
Path recordFile = worldPath.resolve("speedrunigt").resolve("record.json");
3336
if (!Files.exists(recordFile)) { // No record file shouldn't happen, but I guess if it does then give up /shrug
@@ -75,27 +78,51 @@ private void update(Path worldPath) throws IOException, JsonSyntaxException {
7578
this.usages.put(entry.getKey(), entry.getValue().getAsInt());
7679
}
7780
}
81+
82+
if (stats.has("minecraft:crafted")) {
83+
JsonObject pickedUp = stats.getAsJsonObject("minecraft:crafted");
84+
for (Map.Entry<String, JsonElement> entry : pickedUp.entrySet()) {
85+
// Set crafted count for this item
86+
this.crafted.put(entry.getKey(), entry.getValue().getAsInt());
87+
}
88+
}
7889
}
7990

8091
public int getEstimatedCount(String item) {
8192
return Optional.ofNullable(this.estimatedCounts.get(item)).orElse(0);
8293
}
8394

95+
private int getCraftedCount(String item) {
96+
return Optional.ofNullable(this.crafted.get(item)).orElse(0);
97+
}
98+
8499
public int getUsages(String item) {
85100
return Optional.ofNullable(this.usages.get(item)).orElse(0);
86101
}
87102

88-
public Optional<JsonObject> constructItemData(Set<String> itemsToGetEstimate, Set<String> itemsToGetUsage) {
103+
/**
104+
* @param itemsToGetEstimate items to get an estimated count for
105+
* @param itemsToGetUsage items to get an exact amount of times used for
106+
* @param itemsToGetCrafted items to get an exact amount of times crafted/traded for
107+
* @return a json object suitable to be sent as item data to PaceMan.gg
108+
*/
109+
public Optional<JsonObject> constructItemData(Set<String> itemsToGetEstimate, Set<String> itemsToGetUsage, Set<String> itemsToGetCrafted) {
89110
JsonObject estimatedCounts = new JsonObject();
90111
itemsToGetEstimate.stream().filter(s -> this.getEstimatedCount(s) > 0).forEach(s -> estimatedCounts.addProperty(s, this.getEstimatedCount(s)));
112+
113+
JsonObject crafted = new JsonObject();
114+
itemsToGetCrafted.stream().filter(s -> this.getCraftedCount(s) > 0).forEach(s -> crafted.addProperty(s, this.getCraftedCount(s)));
115+
91116
JsonObject usages = new JsonObject();
92117
itemsToGetUsage.stream().filter(s -> this.getUsages(s) > 0).forEach(s -> usages.addProperty(s, this.getUsages(s)));
118+
93119
JsonObject itemData = new JsonObject();
94-
if (estimatedCounts.size() == 0 && usages.size() == 0) {
120+
if (estimatedCounts.size() == 0 && usages.size() == 0 && crafted.size() == 0) {
95121
return Optional.empty();
96122
}
97-
itemData.add("estimatedCounts", estimatedCounts);
98-
itemData.add("usages", usages);
123+
if (!itemsToGetEstimate.isEmpty()) itemData.add("estimatedCounts", estimatedCounts);
124+
if (!itemsToGetCrafted.isEmpty()) itemData.add("crafted", crafted);
125+
if (!itemsToGetUsage.isEmpty()) itemData.add("usages", usages);
99126
return Optional.of(itemData);
100127
}
101128
}

src/main/java/gg/paceman/tracker/PaceManTracker.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ public class PaceManTracker {
4444
// Unimportant events are not considered when determining if an event is recent enough to send the run to PaceMan
4545
private static final List<String> UNIMPORTANT_EVENTS = Arrays.asList("common.leave_world", "common.rejoin_world");
4646

47-
private static final Set<String> IMPORTANT_ITEM_COUNTS = new HashSet<>(Arrays.asList("minecraft:ender_pearl", "minecraft:obsidian", "minecraft:blaze_rod"));
48-
private static final Set<String> IMPORTANT_ITEM_USAGES = new HashSet<>(Arrays.asList("minecraft:ender_pearl", "minecraft:obsidian"));
47+
private static final Set<String> IMPORTANT_ITEM_COUNTS_116 = new HashSet<>(Arrays.asList("minecraft:ender_pearl", "minecraft:obsidian", "minecraft:blaze_rod"));
48+
private static final Set<String> IMPORTANT_ITEM_USAGES_116 = new HashSet<>(Arrays.asList("minecraft:ender_pearl", "minecraft:obsidian"));
49+
50+
private static final Set<String> IMPORTANT_ITEM_COUNTS_115 = Collections.singleton("minecraft:blaze_rod");
51+
private static final Set<String> IMPORTANT_ITEM_CRAFTED_115 = Collections.singleton("minecraft:ender_pearl");
4952

5053
public static final Pattern RANDOM_WORLD_PATTERN = Pattern.compile("^Random Speedrun #\\d+$");
5154
private static final Pattern GAME_VERSION_PATTERN = Pattern.compile("1\\.(\\d+)(?:\\.\\d+)?");
@@ -292,7 +295,9 @@ private PaceManResponse sendEventsToPacemanGG() {
292295

293296
private Optional<JsonObject> constructItemData() {
294297
if (this.eventTracker.getGameVersion().equals("1.16.1")) {
295-
return this.itemTracker.constructItemData(IMPORTANT_ITEM_COUNTS, IMPORTANT_ITEM_USAGES);
298+
return this.itemTracker.constructItemData(IMPORTANT_ITEM_COUNTS_116, IMPORTANT_ITEM_USAGES_116, Collections.emptySet());
299+
} else if (this.eventTracker.getGameVersion().equals("1.15.2")) {
300+
return this.itemTracker.constructItemData(IMPORTANT_ITEM_COUNTS_115, Collections.emptySet(), IMPORTANT_ITEM_CRAFTED_115);
296301
}
297302
return Optional.empty();
298303
}
@@ -390,7 +395,7 @@ private void tick() {
390395
}
391396
}
392397

393-
if (this.eventTracker.getGameVersion().equals("1.16.1")) {
398+
if (this.eventTracker.getGameVersion().equals("1.16.1") || this.eventTracker.getGameVersion().equals("1.15.2")) {
394399
this.itemTracker.tryUpdate(this.eventTracker.getWorldPath());
395400
}
396401

0 commit comments

Comments
 (0)