aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/dulkirfabric
diff options
context:
space:
mode:
authoringlettronald <inglettronald@gmail.com>2023-07-17 03:05:11 -0500
committeringlettronald <inglettronald@gmail.com>2023-07-17 03:05:11 -0500
commit1a8e45d8519a8ae69e14db8ea103a7fdf7b80923 (patch)
tree5568ffc7575c4da682a9526199ea535be57ae637 /src/main/kotlin/com/dulkirfabric
parent2003a3d2be24ae3faed0e45a8c6cc5e0b8343cc3 (diff)
downloadDulkirMod-Fabric-1a8e45d8519a8ae69e14db8ea103a7fdf7b80923.tar.gz
DulkirMod-Fabric-1a8e45d8519a8ae69e14db8ea103a7fdf7b80923.tar.bz2
DulkirMod-Fabric-1a8e45d8519a8ae69e14db8ea103a7fdf7b80923.zip
wip
Diffstat (limited to 'src/main/kotlin/com/dulkirfabric')
-rw-r--r--src/main/kotlin/com/dulkirfabric/Registrations.kt63
-rw-r--r--src/main/kotlin/com/dulkirfabric/events/EntityLoadEvent.kt10
-rw-r--r--src/main/kotlin/com/dulkirfabric/events/WorldLoadEvent.kt10
-rw-r--r--src/main/kotlin/com/dulkirfabric/features/CooldownDisplays.kt61
-rw-r--r--src/main/kotlin/com/dulkirfabric/features/RenderTest.kt6
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/GlowingEntityInterface.kt13
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/SoundInfo.kt7
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/TrackedCooldown.kt8
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/Utils.kt11
9 files changed, 159 insertions, 30 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/Registrations.kt b/src/main/kotlin/com/dulkirfabric/Registrations.kt
index 5fa7cd8..519319e 100644
--- a/src/main/kotlin/com/dulkirfabric/Registrations.kt
+++ b/src/main/kotlin/com/dulkirfabric/Registrations.kt
@@ -12,12 +12,14 @@ import com.dulkirfabric.features.*
import com.dulkirfabric.features.chat.AbiPhoneDND
import com.dulkirfabric.util.TablistUtils
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback
+import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientEntityEvents
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents
import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents
import net.fabricmc.fabric.api.client.message.v1.ClientSendMessageEvents
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents
import net.fabricmc.fabric.api.client.screen.v1.ScreenMouseEvents
+import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents
/**
@@ -59,43 +61,44 @@ object Registrations {
EVENT_BUS.subscribe(EffigyDisplay)
EVENT_BUS.subscribe(TablistUtils)
EVENT_BUS.subscribe(CullExplosionParticles)
+ EVENT_BUS.subscribe(CooldownDisplays)
}
fun registerEvents() {
// Register Custom Tick event, so we can use it like 1.8.9 forge
- ClientTickEvents.START_CLIENT_TICK.register(
- ClientTickEvents.StartTick { _ ->
- ClientTickEvent.post()
- if (tickCount % 20 == 0) LongUpdateEvent.post()
- tickCount++
- }
- )
- ClientReceiveMessageEvents.ALLOW_GAME.register(
- ClientReceiveMessageEvents.AllowGame { message, overlay ->
- if (overlay) !OverlayReceivedEvent(message.toString()).post()
- else !ChatReceivedEvent(message).post()
- }
- )
- ClientSendMessageEvents.MODIFY_COMMAND.register(
- ClientSendMessageEvents.ModifyCommand { command ->
- ModifyCommandEvent(command).also { it.post() }.command
- }
- )
- WorldRenderEvents.END.register(
- WorldRenderEvents.End { context -> WorldRenderLastEvent(context).post()}
- )
+ ClientTickEvents.START_CLIENT_TICK.register { _ ->
+ ClientTickEvent.post()
+ if (tickCount % 20 == 0) LongUpdateEvent.post()
+ tickCount++
+ }
+ ClientReceiveMessageEvents.ALLOW_GAME.register { message, overlay ->
+ if (overlay) !OverlayReceivedEvent(message.toString()).post()
+ else !ChatReceivedEvent(message).post()
+ }
+
+ ClientSendMessageEvents.MODIFY_COMMAND.register { command ->
+ ModifyCommandEvent(command).also { it.post() }.command
+ }
+
+ WorldRenderEvents.END.register { context -> WorldRenderLastEvent(context).post() }
+
ScreenEvents.BEFORE_INIT.register(
ScreenEvents.BeforeInit { client, screen, scaledWidth, scaledHeight ->
- ScreenMouseEvents.beforeMouseScroll(screen).register(ScreenMouseEvents.BeforeMouseScroll {
- coolScreen, mouseX, mouseY, horizontalAmount, verticalAmount ->
- MouseScrollEvent(coolScreen, mouseX, mouseY, horizontalAmount, verticalAmount).post()
- })
- }
- )
- WorldRenderEvents.BLOCK_OUTLINE.register(
- WorldRenderEvents.BlockOutline { worldRenderContext, blockOutlineContext ->
- !BlockOutlineEvent(worldRenderContext, blockOutlineContext).post()
+ ScreenMouseEvents.beforeMouseScroll(screen)
+ .register(ScreenMouseEvents.BeforeMouseScroll { coolScreen, mouseX, mouseY, horizontalAmount, verticalAmount ->
+ MouseScrollEvent(coolScreen, mouseX, mouseY, horizontalAmount, verticalAmount).post()
+ })
}
)
+
+ WorldRenderEvents.BLOCK_OUTLINE.register { worldRenderContext, blockOutlineContext ->
+ !BlockOutlineEvent(worldRenderContext, blockOutlineContext).post()
+ }
+ ClientEntityEvents.ENTITY_LOAD.register { entity, world ->
+ EntityLoadEvent(entity, world)
+ }
+ ServerWorldEvents.LOAD.register { server, world ->
+ WorldLoadEvent(server, world)
+ }
}
} \ No newline at end of file
diff --git a/src/main/kotlin/com/dulkirfabric/events/EntityLoadEvent.kt b/src/main/kotlin/com/dulkirfabric/events/EntityLoadEvent.kt
new file mode 100644
index 0000000..e588ed2
--- /dev/null
+++ b/src/main/kotlin/com/dulkirfabric/events/EntityLoadEvent.kt
@@ -0,0 +1,10 @@
+package com.dulkirfabric.events
+
+import com.dulkirfabric.events.base.Event
+import net.minecraft.entity.Entity
+import net.minecraft.world.World
+
+data class EntityLoadEvent(
+ val entity: Entity,
+ val world: World
+): Event()
diff --git a/src/main/kotlin/com/dulkirfabric/events/WorldLoadEvent.kt b/src/main/kotlin/com/dulkirfabric/events/WorldLoadEvent.kt
new file mode 100644
index 0000000..d43f74b
--- /dev/null
+++ b/src/main/kotlin/com/dulkirfabric/events/WorldLoadEvent.kt
@@ -0,0 +1,10 @@
+package com.dulkirfabric.events
+
+import com.dulkirfabric.events.base.Event
+import net.minecraft.server.MinecraftServer
+import net.minecraft.world.World
+
+data class WorldLoadEvent(
+ val server: MinecraftServer,
+ val world: World
+): Event()
diff --git a/src/main/kotlin/com/dulkirfabric/features/CooldownDisplays.kt b/src/main/kotlin/com/dulkirfabric/features/CooldownDisplays.kt
new file mode 100644
index 0000000..86a3863
--- /dev/null
+++ b/src/main/kotlin/com/dulkirfabric/features/CooldownDisplays.kt
@@ -0,0 +1,61 @@
+package com.dulkirfabric.features
+
+import com.dulkirfabric.events.PlaySoundEvent
+import com.dulkirfabric.events.WorldLoadEvent
+import com.dulkirfabric.util.SoundInfo
+import com.dulkirfabric.util.TrackedCooldown
+import meteordevelopment.orbit.EventHandler
+import net.minecraft.item.ItemStack
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable
+
+object CooldownDisplays {
+ private val trackedCooldowns: Map<SoundInfo, TrackedCooldown> = mapOf(
+ Pair(
+ SoundInfo("mob.zombie.remedy", 1f, .5f),
+ TrackedCooldown("(REAPER_CHESTPLATE)|(REAPER_LEGGINGS)|(REAPER_BOOTS)".toRegex(), 25000, 0)
+ ),
+ Pair(
+ SoundInfo("mob.zombie.remedy", 0.6984127f, 1f),
+ TrackedCooldown("(HYPERION|ASTRAEA|SCYLLA|VALKYRIE)".toRegex(), 5000, 0)
+ )
+ )
+
+ fun shouldDisplay(stack: ItemStack, cir: CallbackInfoReturnable<Boolean>) {
+ val cooldown = fetchCooldownItem(stack) ?: return
+ cir.returnValue = true
+ // cir.returnValue = System.currentTimeMillis() - cooldown.lastUsage < cooldown.cooldownDuration
+ }
+
+ fun calcDurability(stack: ItemStack, cir: CallbackInfoReturnable<Int>) {
+ val cooldown = fetchCooldownItem(stack) ?: return
+ cir.returnValue = 300
+ }
+ @EventHandler
+ fun onSound(event: PlaySoundEvent) {
+ val path = event.sound.id.path
+ val pitch = event.sound.pitch
+ val volume = event.sound.volume
+
+ // Figure out if we have a match in trackedCooldowns
+ val matchResult = trackedCooldowns[SoundInfo(path, pitch, volume)] ?: return
+ matchResult.lastUsage = System.currentTimeMillis()
+ }
+
+ @EventHandler
+ fun onWorldLoad(event: WorldLoadEvent) {
+ trackedCooldowns.forEach {
+ it.value.lastUsage = 0
+ }
+ }
+
+ private fun fetchCooldownItem(stack: ItemStack): TrackedCooldown? {
+ val tag = stack.nbt ?: return null
+ val id = tag.getCompound("ExtraAttributes").get("id") ?: return null
+ val idStr = id.toString().trim('"')
+ trackedCooldowns.forEach {
+ if (idStr matches it.value.itemID)
+ return it.value
+ }
+ return null
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt b/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt
index 8ad270d..1f96a7b 100644
--- a/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt
+++ b/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt
@@ -17,4 +17,10 @@ object RenderTest {
Vec3d(-183.5, 79.0, -465.5)
)
}
+
+// @EventHandler
+// fun onLoadEnt(event: EntityLoadEvent) {
+// if (event.entity !is GlowingEntityInterface) return
+// event.entity.setDulkirEntityGlow(true, Color(255, 255, 255, 255), true)
+// }
} \ No newline at end of file
diff --git a/src/main/kotlin/com/dulkirfabric/util/GlowingEntityInterface.kt b/src/main/kotlin/com/dulkirfabric/util/GlowingEntityInterface.kt
new file mode 100644
index 0000000..5a76890
--- /dev/null
+++ b/src/main/kotlin/com/dulkirfabric/util/GlowingEntityInterface.kt
@@ -0,0 +1,13 @@
+package com.dulkirfabric.util
+
+import java.awt.Color
+
+interface GlowingEntityInterface {
+ fun setDulkirEntityGlow(shouldGlow: Boolean, glowColor: Color, shouldESP: Boolean = false)
+
+ fun shouldDulkirEntityGlow() : Boolean
+
+ fun getDulkirEntityGlowColor() : Color?
+
+ fun shouldDulkirEntityESP() : Boolean
+} \ No newline at end of file
diff --git a/src/main/kotlin/com/dulkirfabric/util/SoundInfo.kt b/src/main/kotlin/com/dulkirfabric/util/SoundInfo.kt
new file mode 100644
index 0000000..c9f339a
--- /dev/null
+++ b/src/main/kotlin/com/dulkirfabric/util/SoundInfo.kt
@@ -0,0 +1,7 @@
+package com.dulkirfabric.util
+
+data class SoundInfo(
+ val path: String,
+ val pitch: Float,
+ val volume: Float
+)
diff --git a/src/main/kotlin/com/dulkirfabric/util/TrackedCooldown.kt b/src/main/kotlin/com/dulkirfabric/util/TrackedCooldown.kt
new file mode 100644
index 0000000..9aa93d7
--- /dev/null
+++ b/src/main/kotlin/com/dulkirfabric/util/TrackedCooldown.kt
@@ -0,0 +1,8 @@
+package com.dulkirfabric.util
+
+// Currently, this will be used to create A list of items that have audible sounds associated with their usages
+data class TrackedCooldown (
+ val itemID: Regex,
+ val cooldownDuration: Int, // in millis
+ var lastUsage: Long, // from System.currentTimeMillis
+) \ No newline at end of file
diff --git a/src/main/kotlin/com/dulkirfabric/util/Utils.kt b/src/main/kotlin/com/dulkirfabric/util/Utils.kt
index ce6665b..ae98cf6 100644
--- a/src/main/kotlin/com/dulkirfabric/util/Utils.kt
+++ b/src/main/kotlin/com/dulkirfabric/util/Utils.kt
@@ -1,7 +1,18 @@
package com.dulkirfabric.util
+import com.dulkirfabric.events.PlaySoundEvent
+
object Utils {
fun isInSkyblock(): Boolean {
return ScoreBoardUtils.getLines() != null
}
+
+ /**
+ * Prints relevant information about a sound that is being displayed
+ */
+ fun debugSound(event: PlaySoundEvent) {
+ println("Path: ${event.sound.id.path}")
+ println("Pitch: ${event.sound.pitch}")
+ println("Volume: ${event.sound.volume}")
+ }
} \ No newline at end of file