generated from Polyfrost/OneConfigExampleMod
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
450 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/dummy/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
src/main/java/org/polyfrost/crosshair/mixin/GuiIngameAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
src/main/java/org/polyfrost/example/command/ExampleCommand.java
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
src/main/java/org/polyfrost/example/config/TestConfig.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
src/main/java/org/polyfrost/example/mixin/MinecraftMixin.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
44
src/main/kotlin/org/polyfrost/crosshair/config/ModConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.