Skip to content

Commit

Permalink
*sneezes in rewrite*
Browse files Browse the repository at this point in the history
  • Loading branch information
nextdayy committed Nov 28, 2024
1 parent 3e732d6 commit 79256d5
Show file tree
Hide file tree
Showing 23 changed files with 442 additions and 1,218 deletions.
4 changes: 1 addition & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ toolkitLoomHelper {

// Configures the output directory for when building from the `src/resources` directory.
sourceSets {
val dummy by creating
main {
dummy.compileClasspath += compileClasspath
compileClasspath += dummy.output
output.setResourcesDir(java.classesDirectory)
}
}
Expand All @@ -48,6 +45,7 @@ sourceSets {
repositories {
mavenLocal()
maven("https://repo.polyfrost.org/releases")
maven("https://repo.polyfrost.org/snapshots")
}

// Configures the libraries/dependencies for your mod.
Expand Down
19 changes: 6 additions & 13 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
# gradle.properties file -- CHANGE THE VALUES STARTING WITH `mod.*` AND REMOVE THIS COMMENT.

# Sets the name of your mod.
mod.name=PolyCrosshair
# Sets the id of your mod that mod loaders use to recognize it.
mod.id=polycrosshair
# Sets the version of your mod. Make sure to update this when you make changes according to semver.
mod.version=1.0.3
# Sets the name of the jar file that you put in your 'mods' folder.
mod.group=org.polyfrost

# Gradle Configuration -- DO NOT TOUCH THESE VALUES.
polyfrost.defaults.loom=3
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureoncommand=true
org.gradle.parallel.threads=4
org.gradle.jvmargs=-Xmx2G
org.gradle.jvmargs=-Xmx2G

mod.group=org.polyfrost
mod.id=polycrosshair
mod.name=PolyCrosshair
mod.version=2.0.0
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pluginManagement {

plugins {
kotlin("jvm") version("2.0.0")
id("dev.deftu.gradle.multiversion-root") version("2.11.2")
id("dev.deftu.gradle.multiversion-root") version("2.12.0")
}
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

16 changes: 3 additions & 13 deletions src/main/java/org/polyfrost/crosshair/mixin/GuiIngameMixin.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
package org.polyfrost.crosshair.mixin;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiIngame;
import org.polyfrost.crosshair.config.PolyCrosshairConfig;
import org.polyfrost.crosshair.config.RenderConfig;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(GuiIngame.class)
public class GuiIngameMixin {
@Inject(method = "showCrosshair", at = @At("HEAD"), cancellable = true)
private void check(CallbackInfoReturnable<Boolean> cir) {
RenderConfig cfg = PolyCrosshairConfig.INSTANCE.getRenderConfig();
Minecraft mc = Minecraft.getMinecraft();
if (!PolyCrosshairConfig.INSTANCE.enabled) return;
if ((!cfg.getShowInGuis() && mc.currentScreen != null) || (!cfg.getShowInThirdPerson() && mc.gameSettings.thirdPersonView != 0)) {
cir.setReturnValue(false);
}
if ((cfg.getShowInSpectator() && mc.playerController.isSpectator()) || (cfg.getShowInDebug() && mc.gameSettings.showDebugInfo)) {
cir.setReturnValue(true);
}
cir.setReturnValue(false);
}
}
50 changes: 50 additions & 0 deletions src/main/kotlin/org/polyfrost/crosshair/CrosshairHUD.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.polyfrost.crosshair

import org.polyfrost.oneconfig.api.config.v1.annotations.Include
import org.polyfrost.oneconfig.api.config.v1.annotations.Switch
import org.polyfrost.oneconfig.api.hud.v1.Hud
import org.polyfrost.polyui.component.impl.Image
import org.polyfrost.polyui.unit.Vec2
import org.polyfrost.polyui.utils.getResourceStream
import java.nio.file.Files
import java.nio.file.Paths

object CrosshairHUD : Hud<Image>() {
@Switch(title = "Show in F3")
private var showInDebug = false

@Switch(title = "Show in GUIs")
private var showInGUIs = true

@Switch(title = "Show in Spectator")
private var showInSpectator = true

@Switch(title = "Show in 3rd Person")
private var showInThirdPerson = true

@Include
var currentCrosshair: String = "null"

override fun category() = Category.COMBAT

override fun create(): Image {
if (currentCrosshair == "null") {
Files.copy(getResourceStream("assets/polycrosshair/default.png"), Paths.get("polycrosshair.png"))
} else {
Files.copy(Paths.get(currentCrosshair), Paths.get("polycrosshair.png"))
}
return Image("polycrosshair.png")
}

fun reload() {
get().renderer.delete(get().image)
}

override fun defaultPosition() = Vec2(1920f / 2f - 7f, 1080f / 2f - 7f)

override fun id() = "polycrosshair.json"

override fun title() = "PolyCrosshair"

override fun update() = false
}
39 changes: 2 additions & 37 deletions src/main/kotlin/org/polyfrost/crosshair/PolyCrosshair.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
package org.polyfrost.crosshair

import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.fml.common.Mod
import net.minecraftforge.fml.common.event.FMLInitializationEvent
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent
import org.polyfrost.crosshair.config.PolyCrosshairConfig
import org.polyfrost.crosshair.render.CrosshairRenderer
import org.polyfrost.oneconfig.api.event.v1.EventManager
import org.polyfrost.oneconfig.api.event.v1.events.ShutdownEvent
import org.polyfrost.oneconfig.api.event.v1.invoke.impl.Subscribe
import java.io.File
import org.polyfrost.oneconfig.api.hud.v1.HudManager

@Mod(
modid = PolyCrosshair.MODID,
Expand All @@ -22,37 +15,9 @@ object PolyCrosshair {
const val NAME = "@MOD_NAME@"
const val VERSION = "@MOD_VERSION@"

// val path = "${ConfigUtils.getProfileDir().absolutePath}/${MODID}/caches/"
val path = "config/${MODID}/caches/"

val dir = File(path)

@Mod.EventHandler
fun onFMLInitialization(event: FMLInitializationEvent) {
clearCaches()
dir.mkdirs()
PolyCrosshairConfig
MinecraftForge.EVENT_BUS.register(CrosshairRenderer)
EventManager.INSTANCE.register(this)
}

@Mod.EventHandler
fun onFMLPostInitialization(event: FMLPostInitializationEvent) {
CrosshairRenderer.updateVanilla()
}

@Subscribe
fun onShutDown(e: ShutdownEvent) {
clearCaches()
}

fun clearCaches() {
if (dir.listFiles()?.isNotEmpty() == true) {
for (file in dir.listFiles()!!) {
file.delete()
}
}
dir.delete()
HudManager.register(CrosshairHUD)
}

}
Loading

0 comments on commit 79256d5

Please sign in to comment.