Something I thought you might find amusing, given that you say on the main site "I enjoy hearing about how you use this data".
Well, I have a pretty unusual use, specifically using your online commodity price data to determine the value of trades with Villagers in a Minecraft mod:
https://github.com/ReikaKalseki/ChromatiCraft/blob/master/Magic/Artefact/UATrades.java#L83-L129
Well, I have a pretty unusual use, specifically using your online commodity price data to determine the value of trades with Villagers in a Minecraft mod:
https://github.com/ReikaKalseki/ChromatiCraft/blob/master/Magic/Artefact/UATrades.java#L83-L129
Code:
try {
URL url = new URL("https://eddb.io/archive/v5/commodities.json"); //dynamically load the prices from eddb, so that the ones in CC can match the ones in E:D in real time, because :D
Reader r = ReikaFileReader.getReader(url, 2000, this, null);
if (r == null) {
throw new IOException("Could not read URL!");
}
else {
this.loadJSONData(r);
if (jvm) {
File f = new File(DragonAPICore.getMinecraftDirectoryString()+"/ChromatiCraft_Data/eddbcache.json");
f.getParentFile().mkdirs();
f.delete();
ReikaFileReader.copyFile(url.openStream(), new FileOutputStream(f), 4096, null);
ChromatiCraft.logger.log("Downloaded eddb.io commodity data for caching.");
}
}
}
catch (MalformedURLException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
private void loadJSONData(Reader r) {
JsonReader jr = new JsonReader(r);
jr.setLenient(true);
JsonElement e = new JsonParser().parse(jr);
if (e instanceof JsonArray) {
JsonArray j = (JsonArray)e;
Iterator<JsonElement> it = j.iterator();
while (it.hasNext()) {
JsonElement elem = it.next();
if (elem instanceof JsonObject) {
JsonObject obj = (JsonObject)elem;
JsonElement n = obj.get("name");
String data = n.getAsString();
if (prices.containsKey(data)) {
int price = obj.get("average_price").getAsInt();
prices.put(data, price);
ChromatiCraft.logger.log("Loading price data for "+data+" from eddb.io database: "+price+" CR");
}
}
}
}
}
Last edited: