Skip to content

Commit

Permalink
closes #2
Browse files Browse the repository at this point in the history
closes #3
closes #7
closes #16
closes #17

Signed-off-by: Lyzev <[email protected]>
  • Loading branch information
Lyzev committed Feb 26, 2024
1 parent 46a22f9 commit 258a975
Show file tree
Hide file tree
Showing 84 changed files with 2,837 additions and 607 deletions.
2 changes: 1 addition & 1 deletion Settings
12 changes: 6 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ exec {
}
val lastCommitHash = stdout.toByteArray().decodeToString().trim()

val CI = System.getenv("CI")?.toBooleanStrictOrNull() ?: false
val ci = System.getenv("CI")?.toBooleanStrictOrNull() ?: false

version = if (CI) "nightly+$lastCommitHash" else project.extra["mod_version"] as String
version = if (ci) "nightly+$lastCommitHash" else project.extra["mod_version"] as String
group = project.extra["maven_group"] as String

repositories {
Expand Down Expand Up @@ -64,7 +64,7 @@ dependencies {
}

loom {
accessWidenerPath.set(File("src/main/resources/${project.extra["archives_base_name"] as String}.accesswidener"))
// accessWidenerPath.set(File("src/main/resources/${project.extra["archives_base_name"] as String}.accesswidener"))
}

tasks.register("updateFabric") {
Expand Down Expand Up @@ -134,13 +134,13 @@ tasks.register("updateKotlin") {
val kotlinVersion = HttpClient.request(
HttpMethod.GET, "https://api.github.com/repos/JetBrains/kotlin/releases/latest"
).let { data ->
JsonParser.parseString(data.toString()).asJsonObject["target_commitish"].asString
JsonParser.parseString(data.toString()).asJsonObject["tag_name"].asString.removePrefix("v")
}

val dokkaVersion = HttpClient.request(
HttpMethod.GET, "https://api.github.com/repos/Kotlin/dokka/releases/latest"
).let { data ->
JsonParser.parseString(data.toString()).asJsonObject["target_commitish"].asString
JsonParser.parseString(data.toString()).asJsonObject["tag_name"].asString.removePrefix("v")
}

val versions = mapOf(
Expand Down Expand Up @@ -199,7 +199,7 @@ tasks {
}

runClient {
this.systemProperty("CI", CI.toString())
this.systemProperty("CI", ci.toString())
}

// Run `./gradlew wrapper --gradle-version <newVersion>` or `gradle wrapper --gradle-version <newVersion>` to update gradle scripts
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ org.gradle.warning.mode=all
java_version=17
##########################################################################
# Mod Properties
mod_version=1.0.0
mod_version=0.0.1
maven_group=dev.lyzev
archives_base_name=schizoid
##########################################################################
16 changes: 8 additions & 8 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
# All rights reserved.

[versions]
kotlin = "1.9.20"
kotlin = "1.9.22"
dokka = "1.9.10"

# https://fabricmc.net/develop
minecraft = "1.20.2"
yarn_mappings = "1.20.2+build.4"
fabric_loader = "0.14.24"
fabric_api = "0.90.7+1.20.2"
minecraft = "1.20.4"
yarn_mappings = "1.20.4+build.3"
fabric_loader = "0.15.7"
fabric_api = "0.96.3+1.20.4"
# https://github.com/FabricMC/fabric-language-kotlin
fabric_kl = "1.10.13+kotlin.1.9.20"
fabric_kl = "1.10.18+kotlin.1.9.22"
# https://github.com/FabricMC/fabric-loom
fabric_loom = "1.4-SNAPSHOT"
fabric_loom = "1.5-SNAPSHOT"

# https://github.com/Lyzev
lyzev_events = "1.0.3"
Expand All @@ -26,7 +26,7 @@ imgui = "1.86.11"
# https://github.com/intuit/fuzzy-matcher
fuzzywuzzy = "1.4.0"
# https://github.com/KyoriPowered/adventure-platform-fabric
adventure = "5.10.0"
adventure = "5.12.0"

[libraries]
minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2024. Schizoid
* All rights reserved.
*/

package dev.lyzev.schizoid.mixins.minecraft.client;

import dev.lyzev.api.events.EventKeystroke;
import net.minecraft.client.Keyboard;
import org.lwjgl.glfw.GLFW;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(Keyboard.class)
public class MixinKeyboard {

@Inject(method = "onKey", at = @At("TAIL"))
private void onKey(long window, int key, int scancode, int action, int modifiers, CallbackInfo ci) {
if (key != GLFW.GLFW_KEY_UNKNOWN)
new EventKeystroke(window, key, scancode, action, modifiers).fire();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2024. Schizoid
* All rights reserved.
*/

package dev.lyzev.schizoid.mixins.minecraft.client;

import dev.lyzev.api.events.EventWindowResize;
import net.minecraft.client.MinecraftClient;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(MinecraftClient.class)
public class MixinMinecraftClient {

@Inject(method = "onResolutionChanged", at = @At("TAIL"))
private void onResolutionChanged(CallbackInfo ci) {
EventWindowResize.INSTANCE.fire();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2024. Schizoid
* All rights reserved.
*/

package dev.lyzev.schizoid.mixins.minecraft.client;

import dev.lyzev.api.events.EventKeystroke;
import dev.lyzev.api.events.EventMouseClick;
import net.minecraft.client.Mouse;
import org.lwjgl.glfw.GLFW;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(Mouse.class)
public class MixinMouse {

@Inject(method = "onMouseButton", at = @At("TAIL"))
private void onMouseButton(long window, int button, int action, int mods, CallbackInfo ci) {
if (button != GLFW.GLFW_KEY_UNKNOWN)
new EventMouseClick(window, button, action, mods).fire();
}
}
20 changes: 18 additions & 2 deletions src/main/kotlin/dev/lyzev/api/events/Events.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

package dev.lyzev.api.events

import dev.lyzev.api.imgui.ImGuiScreen
import dev.lyzev.schizoid.Schizoid
import dev.lyzev.schizoid.feature.features.gui.ImGuiScreen
import net.minecraft.network.packet.Packet

/**
Expand All @@ -16,7 +17,13 @@ object EventStartup : Event
/**
* This event is triggered during the shutdown phase of the application.
*/
object EventShutdown : Event
object EventShutdown : Event {

override fun fire() {
Schizoid.logger.info("Shutting down the client...")
super.fire()
}
}

/**
* This event is triggered when GLFW is initialized.
Expand All @@ -39,3 +46,12 @@ object EventPreRenderImGui : Event
object EventPostRenderImGui : Event

class EventSendPacket(val packet: Packet<*>) : CancellableEvent()

class EventKeystroke(val window: Long, val key: Int, val scancode: Int, val action: Int, val modifiers: Int) : Event

class EventMouseClick(val window: Long, val button: Int, val action: Int, val mods: Int) : Event

object EventKeybindsRequest : Event
class EventKeybindsResponse(val key: Int) : Event

object EventWindowResize : Event
74 changes: 74 additions & 0 deletions src/main/kotlin/dev/lyzev/api/glfw/GLFWKey.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2024. Schizoid
* All rights reserved.
*/

package dev.lyzev.api.glfw

enum class GLFWKey(val code: Int) {
NONE(-1), MOUSE_BUTTON_LEFT(0), MOUSE_BUTTON_RIGHT(1), MOUSE_BUTTON_MIDDLE(2), SPACE(32), APOSTROPHE(39), COMMA(44), MINUS(
45
),
PERIOD(
46
),
SLASH(47), KEY_0(48), KEY_1(49), KEY_2(50), KEY_3(51), KEY_4(52), KEY_5(
53
),
KEY_6(54), KEY_7(55), KEY_8(56), KEY_9(57), SEMICOLON(59), EQUAL(
61
),
A(65), B(66), C(67), D(68), E(69), F(70), G(71), H(72), I(73), J(
74
),
K(75), L(76), M(77), N(78), O(79), P(80), Q(81), R(82), S(83), T(
84
),
U(85), V(86), W(87), X(88), Y(90), Z(89), LEFT_BRACKET(91), BACKSLASH(
92
),
RIGHT_BRACKET(93), GRAVE_ACCENT(96), WORLD_1(161), WORLD_2(
162
),
ESCAPE(256), ENTER(257), TAB(258), BACKSPACE(259), INSERT(
260
),
DELETE(261), RIGHT(262), LEFT(263), DOWN(264), UP(265), PAGE_UP(
266
),
PAGE_DOWN(267), HOME(268), END(269), CAPS_LOCK(280), SCROLL_LOCK(
281
),
NUM_LOCK(282), PRINT_SCREEN(283), PAUSE(284), F1(290), F2(291), F3(
292
),
F4(293), F5(294), F6(295), F7(296), F8(297), F9(298), F10(299), F11(
300
),
F12(301), F13(302), F14(303), F15(304), F16(305), F17(306), F18(
307
),
F19(308), F20(309), F21(310), F22(311), F23(312), F24(313), F25(
314
),
KP_0(320), KP_1(321), KP_2(322), KP_3(323), KP_4(324), KP_5(
325
),
KP_6(326), KP_7(327), KP_8(328), KP_9(329), KP_DECIMAL(
330
),
KP_DIVIDE(331), KP_MULTIPLY(332), KP_SUBTRACT(333), KP_ADD(
334
),
KP_ENTER(335), KP_EQUAL(336), LEFT_SHIFT(340), LEFT_CONTROL(
341
),
LEFT_ALT(342), LEFT_SUPER(343), RIGHT_SHIFT(344), RIGHT_CONTROL(
345
),
RIGHT_ALT(346), RIGHT_SUPER(347), MENU(348);

companion object {
operator fun get(keyCode: Int): GLFWKey = entries.firstOrNull { it.code == keyCode } ?: NONE
}
}
Loading

0 comments on commit 258a975

Please sign in to comment.