Skip to content

Commit

Permalink
rebrand from qalcyo to w-overflow
Browse files Browse the repository at this point in the history
optimize mixin
update updater
  • Loading branch information
Wyvest committed Jan 14, 2022
1 parent cf45ecf commit aec99ab
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 272 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

version = mod_ver
group = "xyz.qalcyo"
group = "net.wyvest"
archivesBaseName = mod_name

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

}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ org.gradle.jvmargs=-Xmx4G

mod_name=DamageTint
mod_id=damagetint
mod_ver=3.1.0
mod_ver=3.2.0
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
package xyz.qalcyo.damagetint;
package net.wyvest.damagetint;

import gg.essential.api.EssentialAPI;
import net.minecraft.client.Minecraft;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import xyz.qalcyo.damagetint.command.DamageTintCommand;
import xyz.qalcyo.damagetint.config.Config;
import xyz.qalcyo.damagetint.utils.Updater;
import net.wyvest.damagetint.command.DamageTintCommand;
import net.wyvest.damagetint.config.Config;
import net.wyvest.damagetint.updater.Updater;

import java.io.File;

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

@Mod.EventHandler
protected void onFMLPreInitialization(FMLPreInitializationEvent event) {
Expand All @@ -33,8 +27,7 @@ protected void onFMLPreInitialization(FMLPreInitializationEvent event) {
protected void onInitialization(FMLInitializationEvent event) {
config = new Config();
config.preload();
command = new DamageTintCommand();
command.register();
new DamageTintCommand().register();
Updater.update();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package xyz.qalcyo.damagetint.command;
package net.wyvest.damagetint.command;

import gg.essential.api.EssentialAPI;
import gg.essential.api.commands.Command;
import gg.essential.api.commands.DefaultHandler;
import xyz.qalcyo.damagetint.DamageTint;
import net.wyvest.damagetint.DamageTint;

public class DamageTintCommand extends Command {
public DamageTintCommand() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package xyz.qalcyo.damagetint.config;
package net.wyvest.damagetint.config;

import gg.essential.api.EssentialAPI;
import gg.essential.vigilance.Vigilant;
import gg.essential.vigilance.data.Property;
import gg.essential.vigilance.data.PropertyType;
import net.minecraft.client.Minecraft;
import xyz.qalcyo.damagetint.DamageTint;
import xyz.qalcyo.damagetint.gui.DownloadConfirmGui;
import xyz.qalcyo.damagetint.utils.Updater;
import net.wyvest.damagetint.DamageTint;
import net.wyvest.damagetint.updater.DownloadGui;
import net.wyvest.damagetint.updater.Updater;

import java.awt.*;
import java.io.File;
Expand Down Expand Up @@ -75,7 +74,7 @@ public Config() {
)
public void update() {
if (Updater.shouldUpdate) EssentialAPI.getGuiUtil()
.openScreen(new DownloadConfirmGui(Minecraft.getMinecraft().currentScreen));
.openScreen(new DownloadGui());
else EssentialAPI.getNotifications()
.push("Damage Tint", "No update had been detected at startup, and thus the update GUI has not been shown.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package net.wyvest.damagetint.mixin;

import net.minecraft.client.renderer.entity.RendererLivingEntity;
import net.minecraft.entity.EntityLivingBase;
import net.wyvest.damagetint.config.Config;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.awt.*;

@Mixin(RendererLivingEntity.class)
public class RendererLivingEntityMixin {
private EntityLivingBase entitylivingbaseIn;

@Inject(method = "setBrightness", at = @At("HEAD"))
private void set(EntityLivingBase entitylivingbaseIn, float partialTicks, boolean combineTextures, CallbackInfoReturnable<Boolean> cir) {
this.entitylivingbaseIn = entitylivingbaseIn;
}

@ModifyArg(method = "setBrightness", at = @At(value = "INVOKE", target = "Ljava/nio/FloatBuffer;put(F)Ljava/nio/FloatBuffer;", ordinal = 0))
private float getRedTint(float f) {
if (Config.toggle) {
if (Config.chroma) {
return ((float) ((timeBasedChroma() >> 16) & 0xFF)) / 255;
} else {
return ((float) Config.color.getRed()) / 255;
}
}
return f;
}

@ModifyArg(method = "setBrightness", at = @At(value = "INVOKE", target = "Ljava/nio/FloatBuffer;put(F)Ljava/nio/FloatBuffer;", ordinal = 1))
private float getGreenTint(float f) {
if (Config.toggle) {
if (Config.chroma) {
return ((float) ((timeBasedChroma() >> 8) & 0xFF)) / 255;
} else {
return ((float) Config.color.getGreen()) / 255;
}
}
return f;
}

@ModifyArg(method = "setBrightness", at = @At(value = "INVOKE", target = "Ljava/nio/FloatBuffer;put(F)Ljava/nio/FloatBuffer;", ordinal = 2))
private float getBlueTint(float f) {
if (Config.toggle) {
if (Config.chroma) {
return ((float) (timeBasedChroma() & 0xFF)) / 255;
} else {
return ((float) Config.color.getBlue()) / 255;
}
}
return f;
}

@ModifyArg(method = "setBrightness", at = @At(value = "INVOKE", target = "Ljava/nio/FloatBuffer;put(F)Ljava/nio/FloatBuffer;", ordinal = 3))
private float getAlphaTint(float f) {
if (Config.toggle) {
if (Config.fade) {
float percent = 1.0F - (float) entitylivingbaseIn.hurtTime / (float) entitylivingbaseIn.maxHurtTime;
percent = percent < 0.5F ? percent / 0.5F : (1.0F - percent) / 0.5F;
return (float) Config.color.getAlpha() * percent / 255.0F;
} else {
return (float) Config.color.getAlpha() / 255.0F;
}
}
return f;
}

public int timeBasedChroma() {
return Color.HSBtoRGB((float) (System.currentTimeMillis() % (long) ((int) (10000.0F / (float) Config.speed))) / (10000.0F / (float) Config.speed), 1.0F, 1.0F);
}
}
62 changes: 62 additions & 0 deletions src/main/java/net/wyvest/damagetint/updater/DownloadGui.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package net.wyvest.damagetint.updater;

import gg.essential.api.EssentialAPI;
import gg.essential.api.gui.ConfirmationModalBuilder;
import gg.essential.api.utils.Multithreading;
import gg.essential.elementa.ElementaVersion;
import gg.essential.elementa.WindowScreen;
import kotlin.Unit;
import net.wyvest.damagetint.DamageTint;

import java.io.File;

public class DownloadGui extends WindowScreen {
public DownloadGui() {
super(ElementaVersion.V1, true, true, true, -1);
}

@Override
public void initScreen(int width, int height) {
super.initScreen(width, height);
EssentialAPI.getEssentialComponentFactory().build(makeModal()).setChildOf(getWindow());
}

private ConfirmationModalBuilder makeModal() {
ConfirmationModalBuilder builder = new ConfirmationModalBuilder();
builder.setText("Are you sure you want to update?");
builder.setSecondaryText("(This will update from v" + DamageTint.VER + " to " + Updater.latestTag + ")");
builder.setOnConfirm((wyvest) -> {
restorePreviousScreen();
Multithreading.runAsync(() -> {
if (Updater.download(
Updater.updateUrl,
new File(
"mods/" + DamageTint.NAME + "-" + Updater.latestTag.substring(Updater.latestTag.indexOf("v")) + ".jar"
)
) && Updater.download(
"https://github.com/Wyvest/Deleter/releases/download/v1.2/Deleter-1.2.jar",
new File(DamageTint.modDir.getParentFile(), "Deleter-1.2.jar")
)
) {
EssentialAPI.getNotifications()
.push(DamageTint.NAME, "The ingame updater has successfully installed the newest version.");
Updater.addShutdownHook();
Updater.shouldUpdate = false;
} else {
EssentialAPI.getNotifications().push(
DamageTint.NAME,
"The ingame updater has NOT installed the newest version as something went wrong."
);
}
});
return Unit.INSTANCE;
});

builder.setOnDeny(() -> {
restorePreviousScreen();
return Unit.INSTANCE;
});

return builder;
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
package xyz.qalcyo.damagetint.utils;
package net.wyvest.damagetint.updater;

import com.google.gson.JsonObject;
import gg.essential.api.EssentialAPI;
import gg.essential.api.utils.Multithreading;
import gg.essential.api.utils.WebUtil;
import gg.essential.universal.UDesktop;
import kotlin.Unit;
import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion;
import net.wyvest.damagetint.DamageTint;
import net.wyvest.damagetint.config.Config;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import xyz.qalcyo.damagetint.DamageTint;
import xyz.qalcyo.damagetint.config.Config;
import xyz.qalcyo.damagetint.gui.DownloadConfirmGui;

import java.awt.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Locale;

Expand All @@ -27,12 +24,11 @@ public class Updater {
public static void update() {
Multithreading.runAsync(() -> {
try {
JsonObject latestRelease = APIUtil.getJSONResponse("https://api.github.com/repos/Qalcyo/" + DamageTint.ID + "/releases/latest");
JsonObject latestRelease = WebUtil.fetchJSON("https://api.github.com/repos/W-OVERFLOW/" + DamageTint.ID + "/releases/latest").getObject();
latestTag = latestRelease.get("tag_name").getAsString();
DefaultArtifactVersion currentVersion = new DefaultArtifactVersion(StringUtils.substringBefore(DamageTint.VER, "-"));
DefaultArtifactVersion latestVersion = new DefaultArtifactVersion(StringUtils.substringBefore(StringUtils.substringAfter(latestTag, "v"), "-"));
if (DamageTint.VER.contains("BETA") || currentVersion.compareTo(latestVersion) >= 0) {
System.out.println("Either current version is on a beta, or the current version is the same or newer than the latest version.");
if (currentVersion.compareTo(latestVersion) >= 0) {
return;
}
updateUrl = latestRelease.get("assets").getAsJsonArray().get(0).getAsJsonObject().get("browser_download_url").getAsString();
Expand All @@ -47,27 +43,22 @@ public static void update() {
}
});
}

public static Unit openUpdateGui() {
EssentialAPI.getGuiUtil().openScreen(new DownloadConfirmGui(Minecraft.getMinecraft().currentScreen));
EssentialAPI.getGuiUtil().openScreen(new DownloadGui());
return Unit.INSTANCE;
}

public static boolean download(String url, File file) {
if (file.exists()) return true;
url = url.replace(" ", "%20");
try (FileOutputStream fileOut = new FileOutputStream(file)) {
HttpResponse downloadResponse = APIUtil.builder.build().execute(new HttpGet(url));
byte[] buffer = new byte[1024];

int read;
while ((read = downloadResponse.getEntity().getContent().read(buffer)) > 0) {
fileOut.write(buffer, 0, read);
}
try {
WebUtil.downloadToFile(url, file, DamageTint.NAME + "/" + DamageTint.VER);
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
return file.exists();
}

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

/**
* Gets the current Java runtime being used.
*
* @link https://stackoverflow.com/a/47925649
*/
public static String getJavaRuntime() throws IOException {
String os = System.getProperty("os.name");
String java = System.getProperty("java.home") + File.separator + "bin" + File.separator +
(os != null && os.toLowerCase(Locale.ENGLISH).startsWith("windows") ? "java.exe" : "java");
if (!new File(java).isFile()) {
throw new IOException("Unable to find suitable java runtime at "+java);
throw new IOException("Unable to find suitable java runtime at " + java);
}
return java;
}
}
}
Loading

0 comments on commit aec99ab

Please sign in to comment.