Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
literally just copy pasted most things from here: AntiCope#20
also changed the "contact repo"
  • Loading branch information
DequaviousBingleton committed Jan 5, 2025
1 parent 6331236 commit c64b94d
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ yarn_mappings=1.21.3+build.2
loader_version=0.16.9

# Mod Properties
mod_version=0.2
mod_version=0.6.9
maven_group=anticope
archives_base_name=e621-addon

Expand Down
17 changes: 14 additions & 3 deletions src/main/java/anticope/esixtwoone/ImageHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
import anticope.esixtwoone.sources.Source.Size;
import anticope.esixtwoone.sources.Source.SourceType;

import javax.imageio.ImageIO;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import static meteordevelopment.meteorclient.MeteorClient.mc;
import static meteordevelopment.meteorclient.utils.Utils.WHITE;

Expand Down Expand Up @@ -56,7 +61,11 @@ public class ImageHUD extends HudElement {
.defaultValue(100)
.min(10)
.sliderRange(70, 1000)
.onChanged(o -> updateSize())
.onChanged(o -> {
if (o != 0) {
updateSize();
}
})
.build()
);

Expand Down Expand Up @@ -154,8 +163,10 @@ private void loadImage() {
return;
}
E621Hud.LOG.info(url);
var img = NativeImage.read(Http.get(url).sendInputStream());
mc.getTextureManager().registerTexture(TEXID, new NativeImageBackedTexture(img));
var img = ImageIO.read(Http.get(url).sendInputStream());
var baos = new ByteArrayOutputStream();
ImageIO.write(img, "png", baos);
mc.getTextureManager().registerTexture(TEXID, new NativeImageBackedTexture(NativeImage.read(new ByteArrayInputStream(baos.toByteArray()))));
empty = false;
} catch (Exception ex) {
E621Hud.LOG.error("Failed to render the image.", ex);
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/anticope/esixtwoone/sources/DanBooru.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package anticope.esixtwoone.sources;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import meteordevelopment.meteorclient.utils.network.Http;

public class DanBooru extends Source {

private final String domain;
private final int lastPage;

public DanBooru(String domain, int lastPage) {
this.domain = domain;
this.lastPage = lastPage;
}

@Override
public void reset() {}

@Override
public String randomImage(String filter, Size size) {
String query = String.format("%s/posts.json?tags=%s&page=%d&format=json&limit=10", domain, filter, random.nextInt(0, lastPage));
JsonElement result = Http.get(query).sendJson(JsonElement.class);
if (result == null) return null;

if (result instanceof JsonArray array) {
if (array.get(random.nextInt(0, Math.min(11, array.size()))) instanceof JsonObject post) {
return switch (size) {
case preview -> post.get("preview_file_url").getAsString();
case sample -> post.get("large_file_url").getAsString();
case file -> post.get("file_url").getAsString();
};
}
}
return null;
}
}
10 changes: 7 additions & 3 deletions src/main/java/anticope/esixtwoone/sources/ESixTwoOne.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

public class ESixTwoOne extends Source {

private final String domain;

public ESixTwoOne(String domain) {
this.domain = domain;
}
private int maxPage = 30;

@Override
Expand All @@ -17,15 +22,14 @@ public void reset() {
@Override
public String randomImage(String filter, Size size) {
int pageNum = random.nextInt(1, maxPage);
JsonObject result = Http.get("https://e621.net/posts.json?limit=320&tags="+filter+"&page="+ pageNum).sendJson(JsonObject.class);
JsonObject result = Http.get(domain + "/posts.json?limit=320&tags="+filter+"&page="+ pageNum).sendJson(JsonObject.class);
if (result.get("posts") instanceof JsonArray array) {
if(array.size() <= 0) {
maxPage = pageNum - 1;
return null;
}
if (array.get(random.nextInt(array.size())) instanceof JsonObject post) {
var url = post.get(size.toString()).getAsJsonObject().get("url").getAsString();
return url;
return post.get(size.toString()).getAsJsonObject().get("url").getAsString();
}
}
return null;
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/anticope/esixtwoone/sources/NekosLife.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package anticope.esixtwoone.sources;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import meteordevelopment.meteorclient.utils.network.Http;

public class NekosLife extends Source {

private final String domain;

public NekosLife(String domain) {
this.domain = domain;
}

@Override
public void reset() {}

@Override
public String randomImage(String filter, Size size) {
String query = String.format("%s/api/v2/img/%s", domain, filter);
JsonElement result = Http.get(query).sendJson(JsonElement.class);
if (result == null) return null;

if (result instanceof JsonObject object) {
if (object.get("url") != null) {
return object.get("url").getAsString();
}
}

return null;
}
}
17 changes: 12 additions & 5 deletions src/main/java/anticope/esixtwoone/sources/Source.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ public enum Size {

public enum SourceType {
e621,
e926,
gelbooru,
rule34
danbooru,
safebooru,
rule34,
nekoslife
}

protected final Random random = new Random();
Expand All @@ -36,10 +40,13 @@ public String getRandomImage(String filter, Size size) {

public static Source getSource(SourceType type) {
return switch (type) {
case e621 -> new ESixTwoOne();
case gelbooru -> new GelBooru("https://gelbooru.com/", 700);
case rule34 -> new GelBooru("https://api.rule34.xxx/", 700);
default -> null;
case e621 -> new ESixTwoOne("https://e621.net");
case e926 -> new ESixTwoOne("https://e926.net");
case gelbooru -> new GelBooru("https://gelbooru.com", 700);
case danbooru -> new DanBooru("https://danbooru.donmai.us", 700);
case safebooru -> new GelBooru("https://safebooru.org", 700);
case rule34 -> new GelBooru("https://api.rule34.xxx", 700);
case nekoslife -> new NekosLife("https://nekos.life");
};
}
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"AntiCope"
],
"contact": {
"repo": "https://github.com/MeteorDevelopment/meteor-addon-template"
"repo": "https://github.com/AntiCope/meteor-e621-integration"
},
"icon": "assets/e621/icon.png",
"environment": "client",
Expand Down

0 comments on commit c64b94d

Please sign in to comment.