From b56cf5d2a1aa1864b43acae69aedde676afafd57 Mon Sep 17 00:00:00 2001 From: inglettronald Date: Fri, 16 Jun 2023 11:56:00 -0500 Subject: wip --- .../com/dulkirfabric/mixin/SoundSystemMixin.java | 20 +++++ src/main/kotlin/com/dulkirfabric/Registrations.kt | 2 + .../kotlin/com/dulkirfabric/config/DulkirConfig.kt | 11 ++- .../com/dulkirfabric/events/PlaySoundEvent.kt | 8 ++ .../com/dulkirfabric/features/RenderBoxTest.kt | 9 +- .../com/dulkirfabric/features/chat/AbiPhoneDND.kt | 45 ++++++++++ src/main/kotlin/com/dulkirfabric/util/TextUtils.kt | 4 + .../com/dulkirfabric/util/WorldRenderUtils.kt | 95 ++++++++++++++++++++++ src/main/resources/1.0 TODO.txt | 4 +- src/main/resources/dulkirmod-fabric.mixins.json | 1 + 10 files changed, 187 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/dulkirfabric/mixin/SoundSystemMixin.java create mode 100644 src/main/kotlin/com/dulkirfabric/events/PlaySoundEvent.kt create mode 100644 src/main/kotlin/com/dulkirfabric/features/chat/AbiPhoneDND.kt (limited to 'src/main') diff --git a/src/main/java/com/dulkirfabric/mixin/SoundSystemMixin.java b/src/main/java/com/dulkirfabric/mixin/SoundSystemMixin.java new file mode 100644 index 0000000..867f91b --- /dev/null +++ b/src/main/java/com/dulkirfabric/mixin/SoundSystemMixin.java @@ -0,0 +1,20 @@ +package com.dulkirfabric.mixin; + +import com.dulkirfabric.events.PlaySoundEvent; +import net.minecraft.client.sound.SoundInstance; +import net.minecraft.client.sound.SoundSystem; +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(SoundSystem.class) +public class SoundSystemMixin { + + @Inject(method = "play(Lnet/minecraft/client/sound/SoundInstance;)V", + at = @At("HEAD"), cancellable = true) + public void onSound(SoundInstance sound, CallbackInfo ci) { + if (new PlaySoundEvent(sound).post()) + ci.cancel(); + } +} diff --git a/src/main/kotlin/com/dulkirfabric/Registrations.kt b/src/main/kotlin/com/dulkirfabric/Registrations.kt index 80e0a95..d15be19 100644 --- a/src/main/kotlin/com/dulkirfabric/Registrations.kt +++ b/src/main/kotlin/com/dulkirfabric/Registrations.kt @@ -9,6 +9,7 @@ import com.dulkirfabric.features.CustomBlockOutline import com.dulkirfabric.features.KeyShortCutImpl import com.dulkirfabric.features.RenderBoxTest import com.dulkirfabric.features.TooltipImpl +import com.dulkirfabric.features.chat.AbiPhoneDND import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents @@ -49,6 +50,7 @@ object Registrations { EVENT_BUS.subscribe(RenderBoxTest) EVENT_BUS.subscribe(TooltipImpl) EVENT_BUS.subscribe(CustomBlockOutline) + EVENT_BUS.subscribe(AbiPhoneDND) } fun registerEvents() { diff --git a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt index fa4e66c..832fae6 100644 --- a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt +++ b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt @@ -76,6 +76,12 @@ class DulkirConfig { .setSaveConsumer { newValue -> configOptions.blockOutlineColor = newValue } .build() ) + general.addEntry( + entryBuilder.mkToggle(Text.literal("AbiPhone DND"), configOptions::abiPhoneDND) + ) + general.addEntry( + entryBuilder.mkToggle(Text.literal("AbiPhone Caller ID"), configOptions::abiPhoneCallerID) + ) val shortcuts = builder.getOrCreateCategory(Text.literal("Shortcuts")) shortcuts.addEntry( @@ -109,7 +115,9 @@ class DulkirConfig { var dynamicKey: InputUtil.Key = UNKNOWN_KEY, var customBlockOutlines: Boolean = false, var blockOutlineThickness: Int = 3, - var blockOutlineColor: Int = 0xFFFFFF + var blockOutlineColor: Int = 0xFFFFFF, + var abiPhoneDND: Boolean = false, + var abiPhoneCallerID: Boolean = false ) @Serializable @@ -153,5 +161,4 @@ class DulkirConfig { } } } - } \ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/events/PlaySoundEvent.kt b/src/main/kotlin/com/dulkirfabric/events/PlaySoundEvent.kt new file mode 100644 index 0000000..b8fd00d --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/events/PlaySoundEvent.kt @@ -0,0 +1,8 @@ +package com.dulkirfabric.events + +import com.dulkirfabric.events.base.CancellableEvent +import net.minecraft.client.sound.SoundInstance + +data class PlaySoundEvent( + val sound: SoundInstance +): CancellableEvent() diff --git a/src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt b/src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt index 6863479..ab52f81 100644 --- a/src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt +++ b/src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt @@ -10,15 +10,10 @@ object RenderBoxTest { @EventHandler fun onRender(event: WorldRenderLastEvent) { - WorldRenderUtils.drawBox( - event.context, Box(0.0, 0.0, 0.0, 1.0, 1.0, 1.0), - Color(255, 255, 255, 255), 10f, true - ) WorldRenderUtils.drawBox( - event.context, Box(2.0, 0.0, 0.0, 3.0, 1.0, 1.0), - Color(1, 255, 1, 255), 10f, false + event.context, Box(-183.0, 78.0, -465.0, -182.0, 79.0, -464.0), + Color(255, 100, 150, 255), 10f, false ) - } } \ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/features/chat/AbiPhoneDND.kt b/src/main/kotlin/com/dulkirfabric/features/chat/AbiPhoneDND.kt new file mode 100644 index 0000000..f3f83e2 --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/features/chat/AbiPhoneDND.kt @@ -0,0 +1,45 @@ +package com.dulkirfabric.features.chat + +import com.dulkirfabric.config.DulkirConfig +import com.dulkirfabric.events.ChatReceivedEvent +import com.dulkirfabric.events.PlaySoundEvent +import com.dulkirfabric.util.TextUtils +import meteordevelopment.orbit.EventHandler + +object AbiPhoneDND { + + private val abiPhoneFormat = "✆ (\\w+) ✆ ".toRegex() + var lastRing = 0L + + //BLOCK ABIPHONE SOUNDS + @EventHandler + fun onSound(event: PlaySoundEvent) { + if (!DulkirConfig.configOptions.abiPhoneDND) return + if (System.currentTimeMillis() - lastRing < 5000) { + if (event.sound.sound.identifier.path == "note.pling" && event.sound.volume == 0.69f && event.sound.pitch == 1.6666666f) { + event.isCancelled = true + } + } + } + + @EventHandler + fun handle(event: ChatReceivedEvent) { + if (!DulkirConfig.configOptions.abiPhoneDND) return + val unformatted: String = TextUtils.stripColorCodes(event.message) + if (unformatted matches abiPhoneFormat && !unformatted.contains("Elle") && !unformatted.contains("Dean")) { + val matchResult = abiPhoneFormat.find(unformatted) + event.isCancelled = true + lastRing = System.currentTimeMillis() + if (DulkirConfig.configOptions.abiPhoneCallerID) { + val blocked = if (Math.random() < .001) "Breefing" + else matchResult?.groups?.get(1)?.value + TextUtils.info("§6Call blocked from $blocked!") + } + } + if (unformatted.startsWith("✆ Ring...") && unformatted.endsWith("[PICK UP]") + && System.currentTimeMillis() - lastRing < 5000 + ) { + event.isCancelled + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/util/TextUtils.kt b/src/main/kotlin/com/dulkirfabric/util/TextUtils.kt index 6f904ac..c239ba0 100644 --- a/src/main/kotlin/com/dulkirfabric/util/TextUtils.kt +++ b/src/main/kotlin/com/dulkirfabric/util/TextUtils.kt @@ -28,4 +28,8 @@ object TextUtils { fun sendCommand(command: String) { mc.player?.networkHandler?.sendChatCommand(command) } + + fun stripColorCodes(string: String): String { + return string.replace("§.".toRegex(), "") + } } \ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt b/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt index aa0b05c..d14c11b 100644 --- a/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt +++ b/src/main/kotlin/com/dulkirfabric/util/WorldRenderUtils.kt @@ -43,6 +43,11 @@ object WorldRenderUtils { .next() } + /** + * Draws a box in world space, given the coordinates of the box, thickness of the lines, and color. + * TODO: write a more custom rendering function so we don't have to do this ugly translation of + * Minecraft's screen space rendering logic to a world space rendering function. + */ fun drawBox( context: WorldRenderContext, box: Box, @@ -103,4 +108,94 @@ object WorldRenderUtils { RenderSystem.enableCull() matrices.pop() } + + /** + * This draw line function is intended to be used for drawing very few lines, as it's not the most efficient. + * For drawing many lines in a series, save them to an array and use the drawLineArray function. + */ + fun drawLine(context: WorldRenderContext, startPos: Vec3d, endPos: Vec3d, color: Color, thickness: Float, depthTest: Boolean = true) { + val matrices = context.matrixStack() + matrices.push() + val prevShader = RenderSystem.getShader() + RenderSystem.setShader(GameRenderer::getRenderTypeLinesProgram) + RenderSystem.disableBlend() + RenderSystem.disableCull() + // RenderSystem.defaultBlendFunc() + RenderSystem.setShaderColor(color.red / 255f, color.green / 255f, color.blue / 255f, color.alpha / 255f) + if (!depthTest) { + RenderSystem.disableDepthTest() + RenderSystem.depthMask(false) + } else { + RenderSystem.enableDepthTest() + } + matrices.translate(-context.camera().pos.x, -context.camera().pos.y, -context.camera().pos.z) + val tess = RenderSystem.renderThreadTesselator() + val buf = tess.buffer + val me = matrices.peek() + + buf.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES) + buf.fixedColor(255, 255, 255, 255) + + line(me, buf, startPos.x.toFloat(), startPos.y.toFloat(), startPos.z.toFloat(), endPos.x.toFloat(), endPos.y.toFloat(), endPos.z.toFloat(), thickness) + + buf.unfixColor() + tess.draw() + + RenderSystem.depthMask(true) + RenderSystem.enableDepthTest() + RenderSystem.enableBlend() + RenderSystem.setShaderColor( + 1f, 1f, 1f, 1f + ) + RenderSystem.setShader { prevShader } + RenderSystem.enableCull() + matrices.pop() + } + + /** + * This function is intended to be used for drawing many lines in a series, as it's more efficient than the + * drawLine function being called many times in series. + */ + fun drawLineArray(context: WorldRenderContext, posArr: List, color: Color, thickness: Float, depthTest: Boolean = true) { + val matrices = context.matrixStack() + matrices.push() + val prevShader = RenderSystem.getShader() + RenderSystem.setShader(GameRenderer::getRenderTypeLinesProgram) + RenderSystem.disableBlend() + RenderSystem.disableCull() + // RenderSystem.defaultBlendFunc() + RenderSystem.setShaderColor(color.red / 255f, color.green / 255f, color.blue / 255f, color.alpha / 255f) + if (!depthTest) { + RenderSystem.disableDepthTest() + RenderSystem.depthMask(false) + } else { + RenderSystem.enableDepthTest() + } + matrices.translate(-context.camera().pos.x, -context.camera().pos.y, -context.camera().pos.z) + val tess = RenderSystem.renderThreadTesselator() + val buf = tess.buffer + val me = matrices.peek() + + buf.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES) + buf.fixedColor(255, 255, 255, 255) + + for (i in 0 until posArr.size - 1) { + val startPos = posArr[i] + val endPos = posArr[i + 1] + line(me, buf, startPos.x.toFloat(), startPos.y.toFloat(), startPos.z.toFloat(), endPos.x.toFloat(), endPos.y.toFloat(), endPos.z.toFloat(), thickness) + } + + buf.unfixColor() + tess.draw() + + RenderSystem.depthMask(true) + RenderSystem.enableDepthTest() + RenderSystem.enableBlend() + RenderSystem.setShaderColor( + 1f, 1f, 1f, 1f + ) + RenderSystem.setShader { prevShader } + RenderSystem.enableCull() + matrices.pop() + } } \ No newline at end of file diff --git a/src/main/resources/1.0 TODO.txt b/src/main/resources/1.0 TODO.txt index 7557aaf..821e53d 100644 --- a/src/main/resources/1.0 TODO.txt +++ b/src/main/resources/1.0 TODO.txt @@ -6,15 +6,13 @@ - HUD ELEMENTS CODE - selected block outline customization -LIST OF EASY STUFF: - - Secret Chime with a custom sound +LIST OF EASY STUFF:\ - Broken Hyp - Abiphone DND - double hook noot noota RENDERING TO-DO: - - Line - Tracer - Filled box - Outline Circle diff --git a/src/main/resources/dulkirmod-fabric.mixins.json b/src/main/resources/dulkirmod-fabric.mixins.json index 759e752..e8ac46a 100644 --- a/src/main/resources/dulkirmod-fabric.mixins.json +++ b/src/main/resources/dulkirmod-fabric.mixins.json @@ -6,6 +6,7 @@ "defaultRequire": 1 }, "client": [ + "SoundSystemMixin", "io.HandledScreenMixin", "render.DrawContextMixin", "render.GameMenuScreenMixin", -- cgit