Skip to content

Commit

Permalink
update (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
RacoonDog authored Nov 20, 2022
1 parent 3a7e492 commit 60823f7
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 29 deletions.
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
org.gradle.jvmargs=-Xmx2G

# Fabric (https://fabricmc.net/versions.html)
minecraft_version=1.19
yarn_mappings=1.19+build.1
loader_version=0.14.7
minecraft_version=1.19.2
yarn_mappings=1.19.2+build.4
loader_version=0.14.9

# Mod Properties
mod_version=0.1
maven_group=dummy.package
maven_group=anticope
archives_base_name=e621-addon

# Dependency Versions
# Dependency Versions.

# Meteor (https://maven.meteordev.org/)
meteor_version=0.5.0-SNAPSHOT
meteor_version=0.5.1-SNAPSHOT
1 change: 0 additions & 1 deletion src/main/java/anticope/esixtwoone/E621Hud.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,5 @@ public String getCommit() {
.getCustomValue("github:sha")
.getAsString();
return commit.isEmpty() ? null : commit.trim();

}
}
44 changes: 27 additions & 17 deletions src/main/java/anticope/esixtwoone/ImageHUD.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package anticope.esixtwoone;

import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.renderer.Renderer2D;
import meteordevelopment.meteorclient.renderer.GL;
Expand All @@ -20,7 +21,6 @@
import net.minecraft.client.texture.NativeImageBackedTexture;
import net.minecraft.util.Identifier;

import anticope.esixtwoone.sources.ESixTwoOne;
import anticope.esixtwoone.sources.Source;
import anticope.esixtwoone.sources.Source.Size;
import anticope.esixtwoone.sources.Source.SourceType;
Expand All @@ -34,7 +34,7 @@ public class ImageHUD extends HudElement {
private boolean locked = false;
private boolean empty = true;
private int ticks = 0;
private Source source = new ESixTwoOne();
private Source source;

private static final Identifier TEXID = new Identifier("e621", "tex");

Expand All @@ -46,6 +46,7 @@ public class ImageHUD extends HudElement {
.defaultValue(100)
.min(10)
.sliderRange(70, 1000)
.onChanged(o -> updateSize())
.build()
);

Expand All @@ -55,40 +56,31 @@ public class ImageHUD extends HudElement {
.defaultValue(100)
.min(10)
.sliderRange(70, 1000)
.onChanged(o -> updateSize())
.build()
);

private final Setting<String> tags = sgGeneral.add(new StringSetting.Builder()
.name("tags")
.description("Tags")
.defaultValue("femboy")
.onChanged((v) -> {
source.reset();
empty = true;
})
.onChanged((v) -> updateSource())
.build()
);

private final Setting<Size> size = sgGeneral.add(new EnumSetting.Builder<Size>()
.name("size")
.description("Size mode.")
.defaultValue(Size.preview)
.onChanged((v) -> {
source.reset();
empty = true;
})
.onChanged((v) -> updateSource())
.build()
);

private final Setting<SourceType> sourceType = sgGeneral.add(new EnumSetting.Builder<SourceType>()
.name("source")
.description("Source Type.")
.defaultValue(SourceType.e621)
.onChanged((v) -> {
source = Source.getSource(v);
source.reset();
empty = true;
})
.onChanged(v -> updateSource())
.build()
);

Expand All @@ -98,11 +90,20 @@ public class ImageHUD extends HudElement {
.defaultValue(1200)
.max(3000)
.min(20)
.sliderRange(20, 3000)
.build()
);

public ImageHUD() {
super(INFO);
updateSource();
MeteorClient.EVENT_BUS.subscribe(this);
}

@Override
public void remove() {
super.remove();
MeteorClient.EVENT_BUS.unsubscribe(this);
}

private static ImageHUD create() {
Expand All @@ -111,7 +112,6 @@ private static ImageHUD create() {

@EventHandler
public void onTick(TickEvent.Post event) {
if (mc.world == null) return;
ticks ++;
if (ticks >= refreshRate.get()) {
ticks = 0;
Expand All @@ -132,6 +132,16 @@ public void render(HudRenderer renderer) {
Renderer2D.TEXTURE.render(null);
}

private void updateSize() {
setSize(imgWidth.get(), imgHeight.get());
}

private void updateSource() {
source = Source.getSource(sourceType.get());
source.reset();
empty = true;
}

private void loadImage() {
if (locked || source == null)
return;
Expand All @@ -152,6 +162,6 @@ private void loadImage() {
}
locked = false;
}).start();
setSize(imgWidth.get(), imgHeight.get());
updateSize();
}
}
1 change: 0 additions & 1 deletion src/main/java/anticope/esixtwoone/sources/ESixTwoOne.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ public String randomImage(String filter, Size size) {
}
return null;
}

}
5 changes: 2 additions & 3 deletions src/main/java/anticope/esixtwoone/sources/GelBooru.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public String randomImage(String filter, Size size) {
JsonElement result = Http.get(query).sendJson(JsonElement.class);
if (result == null) return null;
if (result instanceof JsonArray array) {
if (array.get(random.nextInt(0, 11)) instanceof JsonObject post) {
if (array.get(random.nextInt(0, Math.min(11, array.size()))) instanceof JsonObject post) {
var url = post.get(size.toString()+"_url").getAsString();
return url;
}
} else if (result instanceof JsonObject object) {
if (object.get("post") instanceof JsonArray array) {
if (array.get(random.nextInt(0, 11)) instanceof JsonObject post) {
if (array.get(random.nextInt(0, Math.min(11, array.size()))) instanceof JsonObject post) {
var url = post.get(size.toString()+"_url").getAsString();
return url;
}
Expand All @@ -40,5 +40,4 @@ public String randomImage(String filter, Size size) {

return null;
}

}
3 changes: 2 additions & 1 deletion src/main/java/anticope/esixtwoone/sources/Source.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package anticope.esixtwoone.sources;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Random;

import anticope.esixtwoone.E621Hud;
Expand All @@ -26,7 +27,7 @@ public enum SourceType {

public String getRandomImage(String filter, Size size) {
try {
return randomImage(URLEncoder.encode(filter, "UTF-8"), size);
return randomImage(URLEncoder.encode(filter, StandardCharsets.UTF_8), size);
} catch (Exception ex) {
E621Hud.LOG.error("Failed to fetch an image.", ex);
}
Expand Down

0 comments on commit 60823f7

Please sign in to comment.