Skip to content

Commit aec99ab

Browse files
committed
rebrand from qalcyo to w-overflow
optimize mixin update updater
1 parent cf45ecf commit aec99ab

File tree

13 files changed

+174
-272
lines changed

13 files changed

+174
-272
lines changed

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
version = mod_ver
9-
group = "xyz.qalcyo"
9+
group = "net.wyvest"
1010
archivesBaseName = mod_name
1111

1212
sourceCompatibility = targetCompatibility = 1.8
@@ -42,11 +42,11 @@ dependencies {
4242
// implementation "com.example:example:1.0.0"
4343
// If you would like to include it (have the library inside your jar) instead use
4444
// include "com.example:example:1.0.0"
45-
include ('gg.essential:loader-launchwrapper:1.1.1') {
45+
include ('gg.essential:loader-launchwrapper:1.1.3') {
4646
transitive = false
4747
}
48-
implementation 'gg.essential:essential-1.8.9-forge:1495+release-launch'
49-
annotationProcessor 'org.spongepowered:mixin:0.7.11-SNAPSHOT'
48+
compileOnly 'gg.essential:essential-1.8.9-forge:1788'
49+
annotationProcessor compileOnly('org.spongepowered:mixin:0.7.11-SNAPSHOT')
5050

5151
}
5252

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ org.gradle.jvmargs=-Xmx4G
22

33
mod_name=DamageTint
44
mod_id=damagetint
5-
mod_ver=3.1.0
5+
mod_ver=3.2.0

src/main/java/xyz/qalcyo/damagetint/DamageTint.java renamed to src/main/java/net/wyvest/damagetint/DamageTint.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
1-
package xyz.qalcyo.damagetint;
1+
package net.wyvest.damagetint;
22

3-
import gg.essential.api.EssentialAPI;
43
import net.minecraft.client.Minecraft;
5-
import net.minecraft.util.EnumChatFormatting;
64
import net.minecraftforge.fml.common.Mod;
75
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
86
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
9-
import xyz.qalcyo.damagetint.command.DamageTintCommand;
10-
import xyz.qalcyo.damagetint.config.Config;
11-
import xyz.qalcyo.damagetint.utils.Updater;
7+
import net.wyvest.damagetint.command.DamageTintCommand;
8+
import net.wyvest.damagetint.config.Config;
9+
import net.wyvest.damagetint.updater.Updater;
1210

1311
import java.io.File;
1412

1513
@Mod(name = DamageTint.NAME, version = DamageTint.VER, modid = DamageTint.ID)
1614
public class DamageTint {
1715
public static final String NAME = "@NAME@", VER = "@VER@", ID = "@ID@";
1816
public static File jarFile;
19-
public static File modDir = new File(new File(new File(Minecraft.getMinecraft().mcDataDir, "config"), "Qalcyo"), NAME);
20-
public static void sendMessage(String message) {
21-
EssentialAPI.getMinecraftUtil().sendMessage(EnumChatFormatting.DARK_PURPLE + "[" + NAME + "] ", message);
22-
}
17+
public static File modDir = new File(new File(Minecraft.getMinecraft().mcDataDir, "W-OVERFLOW"), NAME);
2318
public static Config config;
24-
public static DamageTintCommand command;
2519

2620
@Mod.EventHandler
2721
protected void onFMLPreInitialization(FMLPreInitializationEvent event) {
@@ -33,8 +27,7 @@ protected void onFMLPreInitialization(FMLPreInitializationEvent event) {
3327
protected void onInitialization(FMLInitializationEvent event) {
3428
config = new Config();
3529
config.preload();
36-
command = new DamageTintCommand();
37-
command.register();
30+
new DamageTintCommand().register();
3831
Updater.update();
3932
}
4033

src/main/java/xyz/qalcyo/damagetint/command/DamageTintCommand.java renamed to src/main/java/net/wyvest/damagetint/command/DamageTintCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package xyz.qalcyo.damagetint.command;
1+
package net.wyvest.damagetint.command;
22

33
import gg.essential.api.EssentialAPI;
44
import gg.essential.api.commands.Command;
55
import gg.essential.api.commands.DefaultHandler;
6-
import xyz.qalcyo.damagetint.DamageTint;
6+
import net.wyvest.damagetint.DamageTint;
77

88
public class DamageTintCommand extends Command {
99
public DamageTintCommand() {

src/main/java/xyz/qalcyo/damagetint/config/Config.java renamed to src/main/java/net/wyvest/damagetint/config/Config.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
package xyz.qalcyo.damagetint.config;
1+
package net.wyvest.damagetint.config;
22

33
import gg.essential.api.EssentialAPI;
44
import gg.essential.vigilance.Vigilant;
55
import gg.essential.vigilance.data.Property;
66
import gg.essential.vigilance.data.PropertyType;
7-
import net.minecraft.client.Minecraft;
8-
import xyz.qalcyo.damagetint.DamageTint;
9-
import xyz.qalcyo.damagetint.gui.DownloadConfirmGui;
10-
import xyz.qalcyo.damagetint.utils.Updater;
7+
import net.wyvest.damagetint.DamageTint;
8+
import net.wyvest.damagetint.updater.DownloadGui;
9+
import net.wyvest.damagetint.updater.Updater;
1110

1211
import java.awt.*;
1312
import java.io.File;
@@ -75,7 +74,7 @@ public Config() {
7574
)
7675
public void update() {
7776
if (Updater.shouldUpdate) EssentialAPI.getGuiUtil()
78-
.openScreen(new DownloadConfirmGui(Minecraft.getMinecraft().currentScreen));
77+
.openScreen(new DownloadGui());
7978
else EssentialAPI.getNotifications()
8079
.push("Damage Tint", "No update had been detected at startup, and thus the update GUI has not been shown.");
8180
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package net.wyvest.damagetint.mixin;
2+
3+
import net.minecraft.client.renderer.entity.RendererLivingEntity;
4+
import net.minecraft.entity.EntityLivingBase;
5+
import net.wyvest.damagetint.config.Config;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.injection.At;
8+
import org.spongepowered.asm.mixin.injection.Inject;
9+
import org.spongepowered.asm.mixin.injection.ModifyArg;
10+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
11+
12+
import java.awt.*;
13+
14+
@Mixin(RendererLivingEntity.class)
15+
public class RendererLivingEntityMixin {
16+
private EntityLivingBase entitylivingbaseIn;
17+
18+
@Inject(method = "setBrightness", at = @At("HEAD"))
19+
private void set(EntityLivingBase entitylivingbaseIn, float partialTicks, boolean combineTextures, CallbackInfoReturnable<Boolean> cir) {
20+
this.entitylivingbaseIn = entitylivingbaseIn;
21+
}
22+
23+
@ModifyArg(method = "setBrightness", at = @At(value = "INVOKE", target = "Ljava/nio/FloatBuffer;put(F)Ljava/nio/FloatBuffer;", ordinal = 0))
24+
private float getRedTint(float f) {
25+
if (Config.toggle) {
26+
if (Config.chroma) {
27+
return ((float) ((timeBasedChroma() >> 16) & 0xFF)) / 255;
28+
} else {
29+
return ((float) Config.color.getRed()) / 255;
30+
}
31+
}
32+
return f;
33+
}
34+
35+
@ModifyArg(method = "setBrightness", at = @At(value = "INVOKE", target = "Ljava/nio/FloatBuffer;put(F)Ljava/nio/FloatBuffer;", ordinal = 1))
36+
private float getGreenTint(float f) {
37+
if (Config.toggle) {
38+
if (Config.chroma) {
39+
return ((float) ((timeBasedChroma() >> 8) & 0xFF)) / 255;
40+
} else {
41+
return ((float) Config.color.getGreen()) / 255;
42+
}
43+
}
44+
return f;
45+
}
46+
47+
@ModifyArg(method = "setBrightness", at = @At(value = "INVOKE", target = "Ljava/nio/FloatBuffer;put(F)Ljava/nio/FloatBuffer;", ordinal = 2))
48+
private float getBlueTint(float f) {
49+
if (Config.toggle) {
50+
if (Config.chroma) {
51+
return ((float) (timeBasedChroma() & 0xFF)) / 255;
52+
} else {
53+
return ((float) Config.color.getBlue()) / 255;
54+
}
55+
}
56+
return f;
57+
}
58+
59+
@ModifyArg(method = "setBrightness", at = @At(value = "INVOKE", target = "Ljava/nio/FloatBuffer;put(F)Ljava/nio/FloatBuffer;", ordinal = 3))
60+
private float getAlphaTint(float f) {
61+
if (Config.toggle) {
62+
if (Config.fade) {
63+
float percent = 1.0F - (float) entitylivingbaseIn.hurtTime / (float) entitylivingbaseIn.maxHurtTime;
64+
percent = percent < 0.5F ? percent / 0.5F : (1.0F - percent) / 0.5F;
65+
return (float) Config.color.getAlpha() * percent / 255.0F;
66+
} else {
67+
return (float) Config.color.getAlpha() / 255.0F;
68+
}
69+
}
70+
return f;
71+
}
72+
73+
public int timeBasedChroma() {
74+
return Color.HSBtoRGB((float) (System.currentTimeMillis() % (long) ((int) (10000.0F / (float) Config.speed))) / (10000.0F / (float) Config.speed), 1.0F, 1.0F);
75+
}
76+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package net.wyvest.damagetint.updater;
2+
3+
import gg.essential.api.EssentialAPI;
4+
import gg.essential.api.gui.ConfirmationModalBuilder;
5+
import gg.essential.api.utils.Multithreading;
6+
import gg.essential.elementa.ElementaVersion;
7+
import gg.essential.elementa.WindowScreen;
8+
import kotlin.Unit;
9+
import net.wyvest.damagetint.DamageTint;
10+
11+
import java.io.File;
12+
13+
public class DownloadGui extends WindowScreen {
14+
public DownloadGui() {
15+
super(ElementaVersion.V1, true, true, true, -1);
16+
}
17+
18+
@Override
19+
public void initScreen(int width, int height) {
20+
super.initScreen(width, height);
21+
EssentialAPI.getEssentialComponentFactory().build(makeModal()).setChildOf(getWindow());
22+
}
23+
24+
private ConfirmationModalBuilder makeModal() {
25+
ConfirmationModalBuilder builder = new ConfirmationModalBuilder();
26+
builder.setText("Are you sure you want to update?");
27+
builder.setSecondaryText("(This will update from v" + DamageTint.VER + " to " + Updater.latestTag + ")");
28+
builder.setOnConfirm((wyvest) -> {
29+
restorePreviousScreen();
30+
Multithreading.runAsync(() -> {
31+
if (Updater.download(
32+
Updater.updateUrl,
33+
new File(
34+
"mods/" + DamageTint.NAME + "-" + Updater.latestTag.substring(Updater.latestTag.indexOf("v")) + ".jar"
35+
)
36+
) && Updater.download(
37+
"https://github.com/Wyvest/Deleter/releases/download/v1.2/Deleter-1.2.jar",
38+
new File(DamageTint.modDir.getParentFile(), "Deleter-1.2.jar")
39+
)
40+
) {
41+
EssentialAPI.getNotifications()
42+
.push(DamageTint.NAME, "The ingame updater has successfully installed the newest version.");
43+
Updater.addShutdownHook();
44+
Updater.shouldUpdate = false;
45+
} else {
46+
EssentialAPI.getNotifications().push(
47+
DamageTint.NAME,
48+
"The ingame updater has NOT installed the newest version as something went wrong."
49+
);
50+
}
51+
});
52+
return Unit.INSTANCE;
53+
});
54+
55+
builder.setOnDeny(() -> {
56+
restorePreviousScreen();
57+
return Unit.INSTANCE;
58+
});
59+
60+
return builder;
61+
}
62+
}

src/main/java/xyz/qalcyo/damagetint/utils/Updater.java renamed to src/main/java/net/wyvest/damagetint/updater/Updater.java

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
package xyz.qalcyo.damagetint.utils;
1+
package net.wyvest.damagetint.updater;
22

33
import com.google.gson.JsonObject;
44
import gg.essential.api.EssentialAPI;
55
import gg.essential.api.utils.Multithreading;
6+
import gg.essential.api.utils.WebUtil;
7+
import gg.essential.universal.UDesktop;
68
import kotlin.Unit;
79
import net.minecraft.client.Minecraft;
810
import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion;
11+
import net.wyvest.damagetint.DamageTint;
12+
import net.wyvest.damagetint.config.Config;
913
import org.apache.commons.lang3.StringUtils;
10-
import org.apache.http.HttpResponse;
11-
import org.apache.http.client.methods.HttpGet;
12-
import xyz.qalcyo.damagetint.DamageTint;
13-
import xyz.qalcyo.damagetint.config.Config;
14-
import xyz.qalcyo.damagetint.gui.DownloadConfirmGui;
1514

16-
import java.awt.*;
1715
import java.io.File;
18-
import java.io.FileOutputStream;
1916
import java.io.IOException;
2017
import java.util.Locale;
2118

@@ -27,12 +24,11 @@ public class Updater {
2724
public static void update() {
2825
Multithreading.runAsync(() -> {
2926
try {
30-
JsonObject latestRelease = APIUtil.getJSONResponse("https://api.github.com/repos/Qalcyo/" + DamageTint.ID + "/releases/latest");
27+
JsonObject latestRelease = WebUtil.fetchJSON("https://api.github.com/repos/W-OVERFLOW/" + DamageTint.ID + "/releases/latest").getObject();
3128
latestTag = latestRelease.get("tag_name").getAsString();
3229
DefaultArtifactVersion currentVersion = new DefaultArtifactVersion(StringUtils.substringBefore(DamageTint.VER, "-"));
3330
DefaultArtifactVersion latestVersion = new DefaultArtifactVersion(StringUtils.substringBefore(StringUtils.substringAfter(latestTag, "v"), "-"));
34-
if (DamageTint.VER.contains("BETA") || currentVersion.compareTo(latestVersion) >= 0) {
35-
System.out.println("Either current version is on a beta, or the current version is the same or newer than the latest version.");
31+
if (currentVersion.compareTo(latestVersion) >= 0) {
3632
return;
3733
}
3834
updateUrl = latestRelease.get("assets").getAsJsonArray().get(0).getAsJsonObject().get("browser_download_url").getAsString();
@@ -47,27 +43,22 @@ public static void update() {
4743
}
4844
});
4945
}
46+
5047
public static Unit openUpdateGui() {
51-
EssentialAPI.getGuiUtil().openScreen(new DownloadConfirmGui(Minecraft.getMinecraft().currentScreen));
48+
EssentialAPI.getGuiUtil().openScreen(new DownloadGui());
5249
return Unit.INSTANCE;
5350
}
5451

5552
public static boolean download(String url, File file) {
5653
if (file.exists()) return true;
5754
url = url.replace(" ", "%20");
58-
try (FileOutputStream fileOut = new FileOutputStream(file)) {
59-
HttpResponse downloadResponse = APIUtil.builder.build().execute(new HttpGet(url));
60-
byte[] buffer = new byte[1024];
61-
62-
int read;
63-
while ((read = downloadResponse.getEntity().getContent().read(buffer)) > 0) {
64-
fileOut.write(buffer, 0, read);
65-
}
55+
try {
56+
WebUtil.downloadToFile(url, file, DamageTint.NAME + "/" + DamageTint.VER);
6657
} catch (Exception e) {
6758
e.printStackTrace();
6859
return false;
6960
}
70-
return true;
61+
return file.exists();
7162
}
7263

7364
/**
@@ -80,7 +71,7 @@ public static void addShutdownHook() {
8071
try {
8172
String runtime = getJavaRuntime();
8273
if (Minecraft.isRunningOnMac) {
83-
Desktop.getDesktop().open(DamageTint.jarFile.getParentFile());
74+
UDesktop.open(DamageTint.jarFile.getParentFile());
8475
}
8576
File file = new File(DamageTint.modDir.getParentFile(), "Deleter-1.2.jar");
8677
Runtime.getRuntime()
@@ -94,15 +85,16 @@ public static void addShutdownHook() {
9485

9586
/**
9687
* Gets the current Java runtime being used.
88+
*
9789
* @link https://stackoverflow.com/a/47925649
9890
*/
9991
public static String getJavaRuntime() throws IOException {
10092
String os = System.getProperty("os.name");
10193
String java = System.getProperty("java.home") + File.separator + "bin" + File.separator +
10294
(os != null && os.toLowerCase(Locale.ENGLISH).startsWith("windows") ? "java.exe" : "java");
10395
if (!new File(java).isFile()) {
104-
throw new IOException("Unable to find suitable java runtime at "+java);
96+
throw new IOException("Unable to find suitable java runtime at " + java);
10597
}
10698
return java;
10799
}
108-
}
100+
}

0 commit comments

Comments
 (0)