Skip to content

Commit

Permalink
w
Browse files Browse the repository at this point in the history
  • Loading branch information
ImToggle committed Dec 3, 2023
1 parent 304eac8 commit 8a92ffa
Show file tree
Hide file tree
Showing 21 changed files with 450 additions and 148 deletions.
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ val shade: Configuration by configurations.creating {

// Configures the output directory for when building from the `src/resources` directory.
sourceSets {
val dummy by creating

main {
output.setResourcesDir(java.classesDirectory)
compileClasspath += dummy.output
}
}

Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# gradle.properties file -- CHANGE THE VALUES STARTING WITH `mod_*` AND REMOVE THIS COMMENT.

# Sets the name of your mod.
mod_name=ExampleMod
mod_name=PolyCrosshair
# Sets the id of your mod that mod loaders use to recognize it.
mod_id=examplemod
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.0
# Sets the name of the jar file that you put in your 'mods' folder.
mod_archives_name=ExampleMod
mod_archives_name=PolyCrosshair

# Gradle Configuration -- DO NOT TOUCH THESE VALUES.
polyfrost.defaults.loom=1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cc.polyfrost.oneconfig.internal.config;

public class OneConfigConfig {
public static String currentProfile = "Default Profile";
}
11 changes: 11 additions & 0 deletions src/main/java/org/polyfrost/crosshair/mixin/GuiIngameAccessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.polyfrost.crosshair.mixin;

import net.minecraft.client.gui.GuiIngame;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(GuiIngame.class)
public interface GuiIngameAccessor {
@Invoker("showCrosshair")
boolean shouldShowCrosshair();
}
32 changes: 0 additions & 32 deletions src/main/java/org/polyfrost/example/ExampleMod.java

This file was deleted.

21 changes: 0 additions & 21 deletions src/main/java/org/polyfrost/example/command/ExampleCommand.java

This file was deleted.

48 changes: 0 additions & 48 deletions src/main/java/org/polyfrost/example/config/TestConfig.java

This file was deleted.

20 changes: 0 additions & 20 deletions src/main/java/org/polyfrost/example/hud/TestHud.java

This file was deleted.

21 changes: 0 additions & 21 deletions src/main/java/org/polyfrost/example/mixin/MinecraftMixin.java

This file was deleted.

89 changes: 89 additions & 0 deletions src/main/kotlin/org/polyfrost/crosshair/PolyCrosshair.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package org.polyfrost.crosshair

import cc.polyfrost.oneconfig.utils.dsl.mc
import net.minecraft.client.gui.Gui
import net.minecraft.client.renderer.texture.DynamicTexture
import net.minecraftforge.client.event.RenderGameOverlayEvent
import net.minecraftforge.fml.common.Mod
import net.minecraftforge.fml.common.event.FMLInitializationEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import org.lwjgl.opengl.GL11
import org.polyfrost.crosshair.config.ModConfig
import org.polyfrost.crosshair.mixin.GuiIngameAccessor
import net.minecraft.client.renderer.GlStateManager as GL

@Mod(modid = PolyCrosshair.MODID, name = PolyCrosshair.NAME, version = PolyCrosshair.VERSION)
class PolyCrosshair {
companion object {
const val MODID = "@ID@"
const val NAME = "@NAME@"
const val VERSION = "@VER@"

val texture by lazy {
DynamicTexture(15, 15)
}
val resourceLocation by lazy {
mc.textureManager.getDynamicTextureLocation("polycrosshair", texture)
}


fun updateTexture() {
val profile = ModConfig.profiles.selectedProfile ?: return
for (i in 0 until 225) {
texture.textureData[i] = if (profile.image.get(i)) profile.mainColor.rgb else 0x00000000
}
texture.updateDynamicTexture()
} // test now? ok
}

@Mod.EventHandler
fun onFMLInitialization(event: FMLInitializationEvent) {
ModConfig
updateTexture()
}

@SubscribeEvent
fun onRenderCrosshair(event: RenderGameOverlayEvent.Pre) {
if (event.type != RenderGameOverlayEvent.ElementType.CROSSHAIRS) return
if (!ModConfig.enabled) return
if ((mc.ingameGUI as? GuiIngameAccessor)?.shouldShowCrosshair() == false) return

val profile = ModConfig.profiles.selectedProfile ?: return
event.isCanceled = true


GL.enableBlend()
if (profile.invertColor) {
GL.tryBlendFuncSeparate(GL11.GL_ONE_MINUS_DST_COLOR, GL11.GL_ONE_MINUS_SRC_COLOR, 1, 0)
}
GL.enableAlpha()
with(profile.mainColor) {
GL.color(red / 255f, green / 255f, blue / 255f, alpha / 255f)
}

// GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1)
//
// GL11.glRasterPos2f(event.resolution.scaledWidth / 2f - 7.5f, event.resolution.scaledHeight / 2f - 7.5f)
// GL11.glDrawPixels(15, 15, GL11.GL_COLOR_INDEX, GL11.GL_BITMAP, ByteBuffer.wrap(profile.image.toByteArray()))
// test this first?\

// draw
mc.textureManager.bindTexture(resourceLocation)
Gui.drawModalRectWithCustomSizedTexture(
(event.resolution.scaledWidth - 15) / 2,
(event.resolution.scaledHeight - 15) / 2,
0f,
0f,
15,
15,
15f,
15f
)
// GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 4)

if (profile.invertColor) {
GL.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0)
}
GL.disableBlend()
}
}
40 changes: 40 additions & 0 deletions src/main/kotlin/org/polyfrost/crosshair/config/Drawer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.polyfrost.crosshair.config

import cc.polyfrost.oneconfig.config.elements.BasicOption
import cc.polyfrost.oneconfig.utils.InputHandler
import org.polyfrost.crosshair.PolyCrosshair
import org.polyfrost.crosshair.config.configlist.Profile
import java.util.*

@Suppress("UnstableAPIUsage")
object Drawer : BasicOption(null, null, "", "", "", "", 1) {
private var currentProfile: Profile? = null
private val pixels: Array<Pixel> = Array(225) { Pixel(it) }

override fun draw(vg: Long, x: Int, y: Int, inputHandler: InputHandler) {
for (pixel in pixels) {
pixel.draw(vg, x.toFloat(), y.toFloat(), inputHandler)
}
}

fun load(profile: Profile) {
currentProfile = profile
val bitSet = profile.image
for (pixel in pixels) {
pixel.state = bitSet.get(pixel.index)
}
}

override fun finishUpAndClose() {
val profile = currentProfile ?: return

val bitSet = BitSet(225)
for (pixel in pixels) {
bitSet.set(pixel.index, pixel.state)
}
profile.image = bitSet
PolyCrosshair.updateTexture()
}

override fun getHeight() = 254
}
44 changes: 44 additions & 0 deletions src/main/kotlin/org/polyfrost/crosshair/config/ModConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.polyfrost.crosshair.config

import cc.polyfrost.oneconfig.config.Config
import cc.polyfrost.oneconfig.config.annotations.CustomOption
import cc.polyfrost.oneconfig.config.core.ConfigUtils
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 org.polyfrost.crosshair.PolyCrosshair
import org.polyfrost.crosshair.config.configlist.ConfigList
import org.polyfrost.crosshair.config.configlist.Profile
import java.lang.reflect.Field

object ModConfig : Config(Mod(PolyCrosshair.NAME, ModType.HUD), "${PolyCrosshair.MODID}/config.json") {

@CustomOption
var profiles = ProfileList()

init {
initialize()
}

override fun getCustomOption(
field: Field,
annotation: CustomOption,
page: OptionPage,
mod: Mod,
migrate: Boolean
): BasicOption? {
ConfigUtils.getSubCategory(page, "General", "").options.add(Drawer)
profiles.addOptionTo(this, page, category = "General")
return null
}

class ProfileList : ConfigList<Profile>() {
override fun onSelected(profile: Profile) {
Drawer.load(profile)
}

override fun newConfig() = Profile()
override fun getName(profile: Profile) = profile.name
}
}
Loading

0 comments on commit 8a92ffa

Please sign in to comment.