Skip to content
This repository was archived by the owner on Sep 2, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package io.github.homchom.recode.feature.rendering

import com.mojang.blaze3d.vertex.BufferBuilder
import io.github.homchom.recode.feature.feature
import io.github.homchom.recode.mc
import io.github.homchom.recode.mod.config.Config
import io.github.homchom.recode.mod.features.commands.CodeSearcher
import io.github.homchom.recode.render.OutlineBlockEntityEvent
import io.github.homchom.recode.render.RenderBlockEntityEvent
import io.github.homchom.recode.sys.networking.LegacyState
import io.github.homchom.recode.sys.player.DFInfo
import io.github.homchom.recode.ui.rgba
import net.minecraft.client.renderer.RenderType
import net.minecraft.world.level.block.entity.SignBlockEntity
import net.minecraft.world.phys.Vec3
import kotlin.math.sqrt

val FCodeSearch = feature("Code Search") {
Expand All @@ -28,5 +33,80 @@ val FCodeSearch = feature("Code Search") {
}
result
}

RenderBlockEntityEvent.listen { info, result ->
if (info.block is SignBlockEntity
&& DFInfo.currentState.getMode() == LegacyState.Mode.DEV
&& mc.player!!.isCreative
&& CodeSearcher.isSignMatch(info.block)
&& Config.getBoolean("codeSearchTracers")
) {
info.poseStack.pushPose()

try {
val builder = info.bufferSource.getBuffer(RenderType.lines()) as BufferBuilder

var pulseStart = 0f
var pulseEnd = 1f

if (Config.getBoolean("codeSearchPulse")) {
var pulseProgress = (((mc.level!!.gameTime % 40).toFloat() + mc.deltaFrameTime) % 40) / 20

if (Config.getBoolean("codeSearchTwoWayPulse")) {
if (pulseProgress > 1) {
pulseProgress = 2 - pulseProgress
}
} else {
pulseProgress = 1 - (pulseProgress % 1)
}

pulseStart = pulseProgress * 0.8f
pulseEnd = pulseProgress * 0.8f + 0.2f
}

val startPos = Vec3(0.5, 0.5, 0.5)

val endPos = mc.gameRenderer.mainCamera.position
.subtract(
info.block.blockPos.x.toDouble(),
info.block.blockPos.y.toDouble(),
info.block.blockPos.z.toDouble()
)
.add(
mc.gameRenderer.mainCamera.lookVector.x().toDouble(),
mc.gameRenderer.mainCamera.lookVector.y().toDouble(),
mc.gameRenderer.mainCamera.lookVector.z().toDouble(),
)

val lineStart = startPos.lerp(endPos, pulseStart.toDouble())
val lineEnd = startPos.lerp(endPos, pulseEnd.toDouble())

builder.vertex(
info.poseStack.last().pose(),
lineStart.x.toFloat(),
lineStart.y.toFloat(),
lineStart.z.toFloat()
)
builder.color(0f, 1f, 0f, 1f)
builder.normal(0f, 0f, 0f)
builder.endVertex()

builder.vertex(
info.poseStack.last().pose(),
lineEnd.x.toFloat(),
lineEnd.y.toFloat(),
lineEnd.z.toFloat()
)
builder.color(0f, 0f, 1f, 1f)
builder.normal(0f, 0f, 0f)
builder.endVertex()

} catch (e: Exception) {
e.printStackTrace()
}
info.poseStack.popPose()
}
result
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import net.minecraft.world.level.block.entity.SignBlockEntity

val FSignRenderDistance = feature("Sign Render Distance") {
onLoad {
RenderBlockEntityEvent.listen { blockEntity, render ->
if (blockEntity is SignBlockEntity) {
RenderBlockEntityEvent.listen { info, render ->
if (info.block is SignBlockEntity) {
val cameraPos = mc.cameraEntity!!.blockPosition()
val distance = Config.getInteger("signRenderDistance").toDouble()
if (!blockEntity.getBlockPos().closerThan(cameraPos, distance)) {
if (!info.block.getBlockPos().closerThan(cameraPos, distance)) {
return@listen false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class MBlockEntityRenderDispatcher {
public void renderBlockEntities(
BlockEntity blockEntity, float f, PoseStack poseStack,
MultiBufferSource multiBufferSource, CallbackInfo ci) {
if (!RenderBlockEntityEvent.INSTANCE.invoke(blockEntity, true)) {
if (!RenderBlockEntityEvent.INSTANCE.invoke(new RenderBlockInfo(blockEntity, poseStack, multiBufferSource), true)) {
ci.cancel();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,11 @@ public void initialize() {
code.register(new BooleanSetting("showParameterErrors", true));
code.register(new BooleanSetting("previewHeadSkins", true));
this.register(code);

ConfigSubGroup codeSearch = new ConfigSubGroup("code_search");
codeSearch.register(new BooleanSetting("codeSearchTracers", false));
codeSearch.register(new BooleanSetting("codeSearchPulse", false));
codeSearch.register(new BooleanSetting("codeSearchTwoWayPulse", false));
this.register(codeSearch);
}
}
8 changes: 6 additions & 2 deletions src/main/java/io/github/homchom/recode/render/RenderEvents.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package io.github.homchom.recode.render

import com.mojang.blaze3d.vertex.PoseStack
import io.github.homchom.recode.event.*
import io.github.homchom.recode.ui.RGBAColor
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents.BeforeBlockOutline
import net.minecraft.client.renderer.MultiBufferSource
import net.minecraft.world.level.block.entity.BlockEntity
import net.minecraft.world.phys.HitResult

Expand All @@ -19,9 +21,11 @@ object BeforeOutlineBlockEvent :

data class BlockOutlineContext(val worldRenderContext: WorldRenderContext, val hitResult: HitResult?)

data class RenderBlockInfo(val block: BlockEntity, val poseStack: PoseStack, val bufferSource: MultiBufferSource)

object RenderBlockEntityEvent :
CustomEvent<BlockEntity, Boolean> by createEvent(),
ValidatedEvent<BlockEntity>
CustomEvent<RenderBlockInfo, Boolean> by createEvent(),
ValidatedEvent<RenderBlockInfo>

object OutlineBlockEntityEvent :
CustomEvent<BlockEntity, OutlineResult> by DependentEvent(createEvent(), CustomOutlineProcessor)
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/assets/recode/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
"config.recode.option.cpuOnScreen": "Show LagSlayer on Screen",
"config.recode.option.cpuOnScreen.tooltip": "Display the LagSlayer CPU bar on the screen\ndirectly instead of the action bar.",

"config.recode.subcategory.screen_code_search": "Code Search",
"config.recode.subcategory.screen_code_search.tooltip": "Settings related to /search.",
"config.recode.option.codeSearchTracers": "Code Search Tracers",
"config.recode.option.codeSearchTracers.tooltip": "Show Tracers (Lines) towards the /search results.",
"config.recode.option.codeSearchPulse": "Code Search Pulse",
"config.recode.option.codeSearchPulse.tooltip": "Animate the Tracers for the code search.",
"config.recode.option.codeSearchTwoWayPulse": "Code Search Two Way Pulse",
"config.recode.option.codeSearchTwoWayPulse.tooltip": "Animate the Pulse in a towards/away pattern\ninstead of always towards.",

"config.recode.subcategory.commands_automsg": "Auto /msg",
"config.recode.subcategory.commands_automsg.tooltip": "Will set a conversation with someone when\ndoing /msg <player>, any message sent in chat\nwill automatically be sent to that person only.",
Expand Down