diff options
Diffstat (limited to 'src/main')
5 files changed, 88 insertions, 1 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/Registrations.kt b/src/main/kotlin/com/dulkirfabric/Registrations.kt index 4ef80e9..80e0a95 100644 --- a/src/main/kotlin/com/dulkirfabric/Registrations.kt +++ b/src/main/kotlin/com/dulkirfabric/Registrations.kt @@ -5,6 +5,7 @@ import com.dulkirfabric.commands.ConfigCommand import com.dulkirfabric.commands.DynamicKeyCommand import com.dulkirfabric.commands.JoinDungeonCommands import com.dulkirfabric.events.* +import com.dulkirfabric.features.CustomBlockOutline import com.dulkirfabric.features.KeyShortCutImpl import com.dulkirfabric.features.RenderBoxTest import com.dulkirfabric.features.TooltipImpl @@ -47,6 +48,7 @@ object Registrations { EVENT_BUS.subscribe(KeyShortCutImpl) EVENT_BUS.subscribe(RenderBoxTest) EVENT_BUS.subscribe(TooltipImpl) + EVENT_BUS.subscribe(CustomBlockOutline) } fun registerEvents() { @@ -71,5 +73,10 @@ object Registrations { }) } ) + WorldRenderEvents.BLOCK_OUTLINE.register( + WorldRenderEvents.BlockOutline { worldRenderContext, blockOutlineContext -> + !BlockOutlineEvent(worldRenderContext, blockOutlineContext).post() + } + ) } }
\ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt index 16fa366..fa4e66c 100644 --- a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt +++ b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt @@ -29,6 +29,7 @@ import net.minecraft.client.util.InputUtil.UNKNOWN_KEY import net.minecraft.text.LiteralTextContent import net.minecraft.text.MutableText import net.minecraft.text.Text +import net.minecraft.text.TextColor import net.minecraft.util.Formatting import net.minecraft.util.Identifier import java.io.File @@ -62,6 +63,19 @@ class DulkirConfig { general.addEntry( entryBuilder.mkToggle(Text.literal("Ignore Reverse Third Person"), configOptions::ignoreReverseThirdPerson) ) + general.addEntry( + entryBuilder.mkToggle(Text.literal("Custom Block outlines"), configOptions::customBlockOutlines) + ) + general.addEntry( + entryBuilder.startIntSlider(Text.literal("Line Thickness"), configOptions.blockOutlineThickness, 1, 5) + .setSaveConsumer { newValue -> configOptions.blockOutlineThickness = newValue } + .build() + ) + general.addEntry( + entryBuilder.startColorField(Text.literal("Outline Color"), TextColor.fromRgb(configOptions.blockOutlineColor)) + .setSaveConsumer { newValue -> configOptions.blockOutlineColor = newValue } + .build() + ) val shortcuts = builder.getOrCreateCategory(Text.literal("Shortcuts")) shortcuts.addEntry( @@ -92,7 +106,10 @@ class DulkirConfig { var inventoryScale: Int = 3, var macrosList: List<Macro> = listOf(Macro(UNKNOWN_KEY, "")), var ignoreReverseThirdPerson: Boolean = false, - var dynamicKey: InputUtil.Key = UNKNOWN_KEY + var dynamicKey: InputUtil.Key = UNKNOWN_KEY, + var customBlockOutlines: Boolean = false, + var blockOutlineThickness: Int = 3, + var blockOutlineColor: Int = 0xFFFFFF ) @Serializable diff --git a/src/main/kotlin/com/dulkirfabric/events/BlockOutlineEvent.kt b/src/main/kotlin/com/dulkirfabric/events/BlockOutlineEvent.kt new file mode 100644 index 0000000..7228537 --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/events/BlockOutlineEvent.kt @@ -0,0 +1,10 @@ +package com.dulkirfabric.events + +import com.dulkirfabric.events.base.CancellableEvent +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext.BlockOutlineContext + +data class BlockOutlineEvent( + val worldRenderContext: WorldRenderContext, + val blockOutlineContext: BlockOutlineContext +): CancellableEvent() diff --git a/src/main/kotlin/com/dulkirfabric/features/CustomBlockOutline.kt b/src/main/kotlin/com/dulkirfabric/features/CustomBlockOutline.kt new file mode 100644 index 0000000..df306e1 --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/features/CustomBlockOutline.kt @@ -0,0 +1,32 @@ +package com.dulkirfabric.features + +import com.dulkirfabric.config.DulkirConfig +import com.dulkirfabric.events.BlockOutlineEvent +import com.dulkirfabric.util.ColorUtil +import com.dulkirfabric.util.WorldRenderUtils +import meteordevelopment.orbit.EventHandler +import net.minecraft.util.math.Box + +object CustomBlockOutline { + + /** + * This is kind of a lazy implementation, but it works. + * Notes: This always draws a 1x1x1 box around the block you're looking at. This is not accurate for all blocks, + * because not all blocks have a 1x1x1 bounding box. It will still tell you the correct block you're looking at correctly. + */ + @EventHandler + fun onBlockOutline(event: BlockOutlineEvent) { + if (!DulkirConfig.configOptions.customBlockOutlines) return + val blockPos = event.blockOutlineContext.blockPos() + val x = blockPos.x.toDouble() + val y = blockPos.y.toDouble() + val z = blockPos.z.toDouble() + val color = ColorUtil.toRGB(DulkirConfig.configOptions.blockOutlineColor) + + WorldRenderUtils.drawBox( + event.worldRenderContext, Box(x, y, z, x + 1, y + 1, z + 1), + color, 3f * DulkirConfig.configOptions.blockOutlineThickness, true + ) + event.isCancelled = true + } +}
\ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/util/ColorUtil.kt b/src/main/kotlin/com/dulkirfabric/util/ColorUtil.kt new file mode 100644 index 0000000..0a89dbd --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/util/ColorUtil.kt @@ -0,0 +1,21 @@ +package com.dulkirfabric.util + +import java.awt.Color + +object ColorUtil { + private fun getRed (colorInt: Int): Int { + return colorInt shr 16 and 255 + } + + private fun getGreen (colorInt: Int): Int { + return colorInt shr 8 and 255 + } + + private fun getBlue (colorInt: Int): Int { + return colorInt and 255 + } + + fun toRGB (colorInt: Int) : Color { + return Color(getRed(colorInt), getGreen(colorInt), getBlue(colorInt)) + } +}
\ No newline at end of file |