Skip to content
This repository was archived by the owner on Aug 19, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@

import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.annotation.Config;
import me.shedaniel.autoconfig.annotation.ConfigEntry;

/**
* @author Jamalam360
*/

@Config(name = "notify")
public class ModConfig implements ConfigData {
@ConfigEntry.Gui.Tooltip
public boolean verboseLogging = false;
@ConfigEntry.Gui.Tooltip
public boolean displayUpdatedBadge = true;
@ConfigEntry.Gui.Tooltip
public boolean displayUnsupportedBadge = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@
import com.terraformersmc.modmenu.util.mod.ModBadgeRenderer;
import io.github.jamalam360.notify.NotifyModInit;
import io.github.jamalam360.notify.resolver.NotifyVersionChecker;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.OrderedText;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Group;
import org.spongepowered.asm.mixin.injection.Redirect;
Expand All @@ -47,7 +50,33 @@ public class ModBadgeRendererMixin {
@Shadow
protected Mod mod;

@Unique
private Text notify$capturedText = null;

//region Development Environment Redirects
@Group(name = "notify$drawBadgeRedirect")
@Dynamic("Modifying Class From ModMenu")
@Redirect(
method = "drawBadge(Lnet/minecraft/client/util/math/MatrixStack;Lcom/terraformersmc/modmenu/util/mod/Mod$Badge;II)V",
at = @At(
value = "INVOKE",
target = "Lcom/terraformersmc/modmenu/util/mod/ModBadgeRenderer;drawBadge(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/text/OrderedText;IIII)V"
)
)
public void notify$dev$drawBadgeRedirect(ModBadgeRenderer instance, MatrixStack matrixStack, OrderedText text, int outlineColor, int fillColor, int mouseX, int mouseY) {
if (notify$capturedText.asString().equals("Updated")) {
if (NotifyModInit.getConfig().displayUpdatedBadge) {
instance.drawBadge(matrixStack, text, outlineColor, fillColor, mouseX, mouseY);
}
} else if (notify$capturedText.asString().equals("Unsupported")) {
if (NotifyModInit.getConfig().displayUnsupportedBadge) {
instance.drawBadge(matrixStack, text, outlineColor, fillColor, mouseX, mouseY);
}
} else {
instance.drawBadge(matrixStack, text, outlineColor, fillColor, mouseX, mouseY);
}
}

@Group(name = "notify$getTextRedirect")
@Dynamic("Modifying Class From ModMenu")
@Redirect(
Expand All @@ -58,26 +87,23 @@ public class ModBadgeRendererMixin {
)
)
public Text notify$dev$getTextRedirect(Mod.Badge instance) {
Text returnValue;

if (instance == NotifyModInit.UPDATE_BADGE) {
NotifyVersionChecker.VersionComparisonResult version = NotifyModInit.MOD_UPDATE_STATUS_MAP.get(this.mod.getId());

switch (version) {
case UPDATED -> {
return new LiteralText("Updated");
}
case OUTDATED -> {
return new LiteralText("Update Available");
}
case UNSUPPORTED -> {
return new LiteralText("Unsupported");
}
default -> { // FAILURE, or nothing
return new LiteralText("Failed to Fetch Version");
}
case UPDATED -> returnValue = new LiteralText("Updated");
case OUTDATED -> returnValue = new LiteralText("Update Available");
case UNSUPPORTED -> returnValue = new LiteralText("Unsupported");
default -> returnValue = new LiteralText("Failed to Fetch Version");
}
} else {
return instance.getText();
returnValue = instance.getText();
}

notify$capturedText = returnValue;
return returnValue;
}

@Group(name = "notify$getOutlineColorRedirect")
Expand Down Expand Up @@ -140,6 +166,29 @@ public class ModBadgeRendererMixin {
//endregion

//region Production Environment Redirects
@Group(name = "notify$drawBadgeRedirect")
@Dynamic("Modifying Class From ModMenu")
@Redirect(
method = "drawBadge(Lnet/minecraft/class_4587;Lcom/terraformersmc/modmenu/util/mod/Mod$Badge;II)V",
at = @At(
value = "INVOKE",
target = "Lcom/terraformersmc/modmenu/util/mod/ModBadgeRenderer;drawBadge(Lnet/minecraft/class_4587;Lnet/minecraft/class_4581;IIII)V"
)
)
public void notify$production$drawBadgeRedirect(ModBadgeRenderer instance, MatrixStack matrixStack, OrderedText text, int outlineColor, int fillColor, int mouseX, int mouseY) {
if (notify$capturedText.asString().equals("Updated")) {
if (NotifyModInit.getConfig().displayUpdatedBadge) {
instance.drawBadge(matrixStack, text, outlineColor, fillColor, mouseX, mouseY);
}
} else if (notify$capturedText.asString().equals("Unsupported")) {
if (NotifyModInit.getConfig().displayUnsupportedBadge) {
instance.drawBadge(matrixStack, text, outlineColor, fillColor, mouseX, mouseY);
}
} else {
instance.drawBadge(matrixStack, text, outlineColor, fillColor, mouseX, mouseY);
}
}

@Group(name = "notify$getTextRedirect")
@Dynamic("Modifying Class From ModMenu")
@Redirect(
Expand All @@ -150,26 +199,23 @@ public class ModBadgeRendererMixin {
)
)
public Text notify$production$getTextRedirect(Mod.Badge instance) {
Text returnValue;

if (instance == NotifyModInit.UPDATE_BADGE) {
NotifyVersionChecker.VersionComparisonResult version = NotifyModInit.MOD_UPDATE_STATUS_MAP.get(this.mod.getId());

switch (version) {
case UPDATED -> {
return new LiteralText("Updated");
}
case OUTDATED -> {
return new LiteralText("Update Available");
}
case UNSUPPORTED -> {
return new LiteralText("Unsupported");
}
default -> { // FAILURE, or nothing
return new LiteralText("Failed to Fetch Version");
}
case UPDATED -> returnValue = new LiteralText("Updated");
case OUTDATED -> returnValue = new LiteralText("Update Available");
case UNSUPPORTED -> returnValue = new LiteralText("Unsupported");
default -> returnValue = new LiteralText("Failed to Fetch Version");
}
} else {
return instance.getText();
returnValue = instance.getText();
}

notify$capturedText = returnValue;
return returnValue;
}

@Group(name = "notify$getOutlineColorRedirect")
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/assets/notify/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"text.autoconfig.notify.title": "Notify Config (Requires Restart)",

"text.autoconfig.notify.option.verboseLogging": "Verbose Logging",
"text.autoconfig.notify.option.verboseLogging.@Tooltip": "Enable extra logging",

"text.autoconfig.notify.option.displayUpdatedBadge": "Display 'Updated' Badge",
"text.autoconfig.notify.option.displayUpdatedBadge.@Tooltip": "Enable the badge that tells you a mod is up-to-date",

"text.autoconfig.notify.option.displayUnsupportedBadge": "Display 'Unsupported' Badge",
"text.autoconfig.notify.option.displayUnsupportedBadge.@Tooltip": "Enable the badge that tells you a mod doesn't support Notify"
}