Skip to content

Commit

Permalink
twoconfig
Browse files Browse the repository at this point in the history
twoconfig
  • Loading branch information
azureskylines authored Aug 7, 2024
2 parents 4d80c1e + c159625 commit 8e7480d
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 58 deletions.
15 changes: 11 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ loom {
if (project.platform.isLegacyForge) {
runConfigs {
"client" {
programArgs("--tweakClass", "cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker")
programArgs("--tweakClass", "org.polyfrost.oneconfig.internal.legacy.OneConfigTweaker")
programArgs("--tweakClass", "org.spongepowered.asm.launch.MixinTweaker")
property("mixin.debug.export", "true")
}
}
Expand Down Expand Up @@ -85,12 +86,19 @@ sourceSets {
// Adds the Polyfrost maven repository so that we can get the libraries necessary to develop the mod.
repositories {
maven("https://repo.polyfrost.org/releases")
maven("https://repo.polyfrost.org/snapshots")
}

// Configures the libraries/dependencies for your mod.
dependencies {
// Adds the OneConfig library, so we can develop with it.
modCompileOnly("cc.polyfrost:oneconfig-$platform:0.2.2-alpha+")
val oneconfig = "1.0.0-alpha.19"
implementation("org.polyfrost.oneconfig:config-impl:$oneconfig")
implementation("org.polyfrost.oneconfig:commands:$oneconfig")
implementation("org.polyfrost.oneconfig:events:$oneconfig")
implementation("org.polyfrost.oneconfig:ui:$oneconfig")
implementation("org.polyfrost.oneconfig:internal:$oneconfig")
modImplementation("org.polyfrost.oneconfig:$platform:$oneconfig")

val loaderPlatform = when {
platform.isFabric -> "fabric"
Expand All @@ -101,7 +109,6 @@ dependencies {
// If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier.
if (platform.isLegacyForge) {
compileOnly("org.spongepowered:mixin:0.7.11-SNAPSHOT")
shade("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta17")
}
}

Expand Down Expand Up @@ -182,7 +189,7 @@ tasks {
"ForceLoadAsMod" to true, // We want to load this jar as a mod, so we force Forge to do so.
"TweakOrder" to "0", // Makes sure that the OneConfig launch wrapper is loaded as soon as possible.
"MixinConfigs" to "mixins.${mod_id}.json", // We want to use our mixin configuration, so we specify it here.
"TweakClass" to "cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker" // Loads the OneConfig launch wrapper.
"TweakClass" to "org.polyfrost.oneconfig.internal.legacy.OneConfigTweaker" // Loads the OneConfig launch wrapper.
)
}
dependsOn(shadowJar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public class OnlineIndicatorMixin {
)
)
private static void polyNametag$modifyNametagColor(Args args) {
if (!ModConfig.INSTANCE.enabled) return;
if (!ModConfig.INSTANCE.getEnabled()) return;
args.set(3, 0);
}

@Dynamic("Essential")
@Inject(method = "drawNametagIndicator", at = @At("HEAD"), cancellable = true)
private static void skip(UMatrixStack matrixStack, Entity entity, String str, int light, CallbackInfo ci) {
if (!ModConfig.INSTANCE.enabled) return;
if (!ModConfig.INSTANCE.getEnabled()) return;
if (!PolyNametag.INSTANCE.getDrawingIndicator()) ci.cancel();
}

Expand All @@ -51,7 +51,7 @@ private static void skip(UMatrixStack matrixStack, Entity entity, String str, in
index = 3
)
private static double polyNametag$modifyBackgroundZ(double z) {
if (!ModConfig.INSTANCE.enabled) return z;
if (!ModConfig.INSTANCE.getEnabled()) return z;
if (!NametagRenderingKt.shouldDrawBackground()) return z;
return z + 0.01;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public abstract class AboveHeadRenderMixin {
)
)
private boolean polyNametag$screwYouLevelhead(@Coerce Object instance, EntityPlayer player) {
return !(ModConfig.INSTANCE.enabled && ModConfig.INSTANCE.getShowOwnNametag()) && Minecraft.getMinecraft().thePlayer != null && Minecraft.getMinecraft().thePlayer.getUniqueID().equals(player.getUniqueID());
return !(ModConfig.INSTANCE.getEnabled() && ModConfig.INSTANCE.getShowOwnNametag()) && Minecraft.getMinecraft().thePlayer != null && Minecraft.getMinecraft().thePlayer.getUniqueID().equals(player.getUniqueID());
}

@Dynamic("LevelHead")
Expand All @@ -52,16 +52,16 @@ public abstract class AboveHeadRenderMixin {
)
)
private int polyNametag$modifyStringRendering(FontRenderer fontRenderer, String text, int x, int y, int color) {
if (!ModConfig.INSTANCE.enabled) return fontRenderer.drawString(text, x, y, color);
if (!ModConfig.INSTANCE.getEnabled()) return fontRenderer.drawString(text, x, y, color);
return NametagRenderingKt.drawStringWithoutZFighting(fontRenderer, text, x, y, color);
}

@Dynamic("LevelHead")
@Inject(method = "renderName", at = @At(value = "INVOKE", target = "Lgg/essential/universal/UGraphics;drawDirect()V", shift = At.Shift.AFTER))
private void drawBG(LevelheadTag tag, EntityPlayer entityIn, double x, double y, double z, CallbackInfo ci) {
if (!ModConfig.INSTANCE.enabled) return;
if (!ModConfig.INSTANCE.getEnabled()) return;
int stringWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(tag.getString()) / 2;
NametagRenderingKt.drawFrontBackground(-stringWidth - 2, stringWidth + 1, ModConfig.INSTANCE.getBackgroundColor().getRed(), ModConfig.INSTANCE.getBackgroundColor().getGreen(), ModConfig.INSTANCE.getBackgroundColor().getBlue(), NametagRenderingKt.getBackBackgroundAlpha(), entityIn);
NametagRenderingKt.drawFrontBackground(-stringWidth - 2, stringWidth + 1, ModConfig.INSTANCE.getBackgroundColor().red(), ModConfig.INSTANCE.getBackgroundColor().green(), ModConfig.INSTANCE.getBackgroundColor().blue(), NametagRenderingKt.getBackBackgroundAlpha(), entityIn);
GlStateManager.enableDepth();
NametagRenderingKt.setDrawingWithDepth(true);
NametagRenderingKt.drawFrontBackground(-stringWidth - 2, stringWidth + 1, entityIn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public abstract class AboveHeadRenderMixin_ModifyArgs {
@Dynamic("LevelHead")
@ModifyArg(method = "renderName", at = @At(value = "INVOKE", target = "Lgg/essential/universal/UGraphics$GL;translate(FFF)V"), index = 1, remap = false)
private float polyNametag$changeOffset(float original) {
if (!ModConfig.INSTANCE.enabled) return original;
if (!ModConfig.INSTANCE.getEnabled()) return original;
return original + ModConfig.INSTANCE.getHeightOffset();
}

@Dynamic("LevelHead")
@ModifyArgs(method = "renderName", at = @At(value = "INVOKE", target = "Lgg/essential/universal/UGraphics$GL;scale(DDD)V"), remap = false)
private void polyNametag$changeScale(Args args) {
if (!ModConfig.INSTANCE.enabled) return;
if (!ModConfig.INSTANCE.getEnabled()) return;
double scale = ModConfig.INSTANCE.getScale();
args.set(0, ((double) args.get(0)) * scale);
args.set(1, ((double) args.get(1)) * scale);
Expand All @@ -38,7 +38,7 @@ public abstract class AboveHeadRenderMixin_ModifyArgs {
@Dynamic("LevelHead")
@ModifyArgs(method = "renderName", remap = false, at = @At(value = "INVOKE", target = "Lgg/essential/universal/UGraphics;color(FFFF)Lgg/essential/universal/UGraphics;"))
private void polyNametag$changeBackgroundColor(Args args) {
if (!ModConfig.INSTANCE.enabled) return;
if (!ModConfig.INSTANCE.getEnabled()) return;
args.set(3, 0f);
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/org/polyfrost/polynametag/PolyNametag.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.polyfrost.polynametag

import cc.polyfrost.oneconfig.utils.dsl.mc
import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.OpenGlHelper
import net.minecraft.client.renderer.entity.Render
Expand All @@ -16,7 +16,7 @@ import org.polyfrost.polynametag.config.ModConfig
import org.polyfrost.polynametag.mixin.MinecraftAccessor
import org.polyfrost.polynametag.mixin.RenderAccessor

@Mod(modid = PolyNametag.MODID, name = PolyNametag.NAME, version = PolyNametag.VERSION, modLanguageAdapter = "cc.polyfrost.oneconfig.utils.KotlinLanguageAdapter")
@Mod(modid = PolyNametag.MODID, name = PolyNametag.NAME, version = PolyNametag.VERSION, modLanguageAdapter = "org.polyfrost.oneconfig.utils.v1.forge.KotlinLanguageAdapter")
object PolyNametag {
const val MODID = "@ID@"
const val NAME = "@NAME@"
Expand Down Expand Up @@ -49,6 +49,8 @@ object PolyNametag {
var drawingInventory = false
var shouldDrawIndicator = false

private val mc by lazy { Minecraft.getMinecraft() }

fun onRender() {
if (!ModConfig.enabled) return
if (nametags.isEmpty()) return
Expand Down
65 changes: 35 additions & 30 deletions src/main/kotlin/org/polyfrost/polynametag/config/ModConfig.kt
Original file line number Diff line number Diff line change
@@ -1,78 +1,79 @@
package org.polyfrost.polynametag.config

import cc.polyfrost.oneconfig.config.Config
import cc.polyfrost.oneconfig.config.annotations.*
import cc.polyfrost.oneconfig.config.core.ConfigUtils
import cc.polyfrost.oneconfig.config.core.OneColor
import cc.polyfrost.oneconfig.config.data.InfoType
import cc.polyfrost.oneconfig.config.data.Mod
import cc.polyfrost.oneconfig.config.data.ModType
import cc.polyfrost.oneconfig.config.elements.BasicOption
import cc.polyfrost.oneconfig.config.elements.OptionPage
import cc.polyfrost.oneconfig.utils.Notifications
import club.sk1er.patcher.config.OldPatcherConfig
import club.sk1er.patcher.config.PatcherConfig
import org.polyfrost.oneconfig.api.config.v1.Config
import org.polyfrost.oneconfig.api.config.v1.annotations.Color
import org.polyfrost.oneconfig.api.config.v1.annotations.Dropdown
import org.polyfrost.oneconfig.api.config.v1.annotations.Slider
import org.polyfrost.oneconfig.api.config.v1.annotations.Switch
import org.polyfrost.oneconfig.api.ui.v1.Notifications
import org.polyfrost.polynametag.PolyNametag
import org.polyfrost.polynametag.render.NametagPreview
import java.lang.reflect.Field
import org.polyfrost.polyui.utils.rgba

object ModConfig : Config(Mod("Nametags", ModType.UTIL_QOL, "/polynametag.svg"), "${PolyNametag.MODID}.json") {
object ModConfig : Config("nametag.json", "/polynametag.svg", PolyNametag.NAME, Category.QOL) {

@Slider(name = "Height offset", min = -0.5f, max = 0.5f, description = "How much to offset the nametag vertically")
@Switch(title = "Enabled")
var enabled = false

@Slider(title = "Height offset", min = -0.5f, max = 0.5f, description = "How much to offset the nametag vertically")
var heightOffset = 0f
get() = field.coerceIn(-0.5f, 0.5f)

@Slider(name = "Scale", min = 0f, max = 1f, description = "How much to scale the nametag")
@Slider(title = "Scale", min = 0f, max = 1f, description = "How much to scale the nametag")
var scale = 1f
get() = field.coerceIn(0f, 1f)

@Switch(name = "Rounded Corners")
@Switch(title = "Rounded Corners")
var rounded = false

@Slider(name = "Corner Radius", min = 0f, max = 10f)
@Slider(title = "Corner Radius", min = 0f, max = 10f)
var cornerRadius = 0f
get() = field.coerceIn(0f, 10f)

@Slider(name = "Padding X", min = 0f, max = 10f)
@Slider(title = "Padding X", min = 0f, max = 10f)
var paddingX = 0f
get() = field.coerceIn(0f, 10f)

@Slider(name = "Padding Y", min = 0f, max = 10f)
@Slider(title = "Padding Y", min = 0f, max = 10f)
var paddingY = 0f
get() = field.coerceIn(0f, 10f)

@Dropdown(name = "Text Type", options = ["No Shadow", "Shadow", "Full Shadow"], description = "The type of shadow to render")
@Dropdown(title = "Text Type", options = ["No Shadow", "Shadow", "Full Shadow"], description = "The type of shadow to render")
var textType = 0

/*
@Info(
type = InfoType.WARNING,
text = "Using Full Shadow may cause performance issues on low-end devices"
)
var info1 = 0
*/

@Switch(name = "Show own nametag", description = "Whether to show your own nametag")
@Switch(title = "Show own nametag", description = "Whether to show your own nametag")
var showOwnNametag = true

@Switch(name = "Show in inventory")
@Switch(title = "Show in inventory")
var showInInventory = false

@Switch(name = "Background", description = "Whether to render a background behind the nametag")
@Switch(title = "Background", description = "Whether to render a background behind the nametag")
var background = true

@Color(name = "Background color", description = "The color of the background")
var backgroundColor = OneColor(0, 0, 0, 63)
@Color(title = "Background color", description = "The color of the background")
var backgroundColor = rgba(0, 0, 0, 0.247F) // 0,0,0,63

@Switch(name = "Offset Essential Indicator", description = "Offset nametag to center if the player has essential indicator drawn")
@Switch(title = "Offset Essential Indicator", description = "Offset nametag to center if the player has essential indicator drawn")
var essentialOffset = true

/*
@CustomOption
@Transient
val nametagPreview = NametagPreview(category = "General")
*/

var hasMigratedPatcher = false
private var hasMigratedPatcher = false

init {
initialize()
addDependency("backgroundColor", "background")
addDependency("background", "Patcher's Disable Nametag Boxes. Please turn it off to use this feature.") {
!PolyNametag.isPatcher || !PatcherConfig.disableNametagBoxes
Expand All @@ -82,7 +83,9 @@ object ModConfig : Config(Mod("Nametags", ModType.UTIL_QOL, "/polynametag.svg"),
}
addDependency("cornerRadius", "rounded")
addDependency("showInInventory", "showOwnNametag")
hideIf("essentialOffset") { !PolyNametag.isEssential }

// TODO
//hideIf("essentialOffset") { !PolyNametag.isEssential }

if (!hasMigratedPatcher) {
try {
Expand All @@ -105,14 +108,15 @@ object ModConfig : Config(Mod("Nametags", ModType.UTIL_QOL, "/polynametag.svg"),
save()

if (didAnything) {
Notifications.INSTANCE.send("PolyNametag", "Migrated Patcher settings replaced by PolyNametag. Please check PolyNametag's settings to make sure they are correct.")
Notifications.enqueue(Notifications.Type.Info, "PolyNametag", "Migrated Patcher settings replaced by PolyNametag. Please check PolyNametag's settings to make sure they are correct.")
}
} catch (_: ClassNotFoundException) {

}
}
}

/*
override fun getCustomOption(
field: Field,
annotation: CustomOption,
Expand All @@ -122,4 +126,5 @@ object ModConfig : Config(Mod("Nametags", ModType.UTIL_QOL, "/polynametag.svg"),
): BasicOption = nametagPreview.also {
ConfigUtils.getSubCategory(page, it.category, it.subcategory).options.add(it)
}
*/
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package org.polyfrost.polynametag.render

import cc.polyfrost.oneconfig.config.elements.BasicOption
import cc.polyfrost.oneconfig.gui.OneConfigGui
import cc.polyfrost.oneconfig.libs.universal.UResolution
import cc.polyfrost.oneconfig.utils.InputHandler
import cc.polyfrost.oneconfig.utils.dsl.mc
import net.minecraft.client.renderer.OpenGlHelper
import net.minecraft.client.renderer.RenderHelper
import net.minecraft.client.renderer.entity.RendererLivingEntity
Expand All @@ -16,6 +11,8 @@ import org.lwjgl.opengl.GL11
import kotlin.math.atan
import net.minecraft.client.renderer.GlStateManager as GL

/*
class NametagPreview(
description: String = "",
category: String = "",
Expand Down Expand Up @@ -125,3 +122,5 @@ class NametagPreview(
GL.setActiveTexture(OpenGlHelper.defaultTexUnit)
}
}
*/
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package org.polyfrost.polynametag.render

import cc.polyfrost.oneconfig.renderer.TextRenderer
import cc.polyfrost.oneconfig.utils.dsl.getAlpha
import cc.polyfrost.oneconfig.utils.dsl.mc
import club.sk1er.patcher.config.PatcherConfig
import gg.essential.Essential
import gg.essential.config.EssentialConfig
import gg.essential.connectionmanager.common.enums.ProfileStatus
import gg.essential.data.OnboardingData
import gg.essential.handlers.OnlineIndicator
import gg.essential.universal.UMatrixStack
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.FontRenderer
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.entity.Entity
Expand All @@ -26,12 +24,14 @@ var drawingText = false

var drawingWithDepth = false

private val mc by lazy { Minecraft.getMinecraft() }

internal fun shouldDrawBackground() =
ModConfig.background && (!PolyNametag.isPatcher || !PatcherConfig.disableNametagBoxes)
fun getBackBackgroundAlpha(): Int = if (shouldDrawBackground()) ModConfig.backgroundColor.alpha.coerceAtMost(63) else 0
fun getBackBackgroundAlpha(): Int = if (shouldDrawBackground()) ModConfig.backgroundColor.a.coerceAtMost(63) else 0

fun drawFrontBackground(text: String, entity: Entity) {
drawFrontBackground(text, ModConfig.backgroundColor.red, ModConfig.backgroundColor.green, ModConfig.backgroundColor.blue, ModConfig.backgroundColor.alpha, entity)
drawFrontBackground(text, ModConfig.backgroundColor.r, ModConfig.backgroundColor.g, ModConfig.backgroundColor.b, ModConfig.backgroundColor.a, entity)
}

fun drawFrontBackground(text: String, red: Int, green: Int, blue: Int, alpha: Int, entity: Entity) {
Expand All @@ -49,7 +49,7 @@ fun drawFrontBackground(xStart: Double, xEnd: Double, red: Int, green: Int, blue
}

fun drawFrontBackground(xStart: Double, xEnd: Double, entity: Entity) {
drawBackground(xStart, xEnd, ModConfig.backgroundColor.red, ModConfig.backgroundColor.green, ModConfig.backgroundColor.blue, ModConfig.backgroundColor.alpha, entity)
drawBackground(xStart, xEnd, ModConfig.backgroundColor.r, ModConfig.backgroundColor.g, ModConfig.backgroundColor.b, ModConfig.backgroundColor.a, entity)
}

fun drawBackground(xStart: Double, xEnd: Double, red: Int, green: Int, blue: Int, alpha: Int, entity: Entity) {
Expand Down Expand Up @@ -122,7 +122,8 @@ internal fun FontRenderer.drawStringWithoutZFighting(text: String, x: Float, y:
return when (ModConfig.textType) {
0 -> drawString(text, x, y, color, false)
1 -> drawString(text, x, y, color, true)
2 -> TextRenderer.drawBorderedText(text, x, y, color, color.getAlpha())
// 2 -> TextRenderer.drawBorderedText(text, x, y, color, color.getAlpha())
// fixme
else -> 0
}.apply {
drawingText = false
Expand Down

0 comments on commit 8e7480d

Please sign in to comment.