From 8fc48fc1a4620f44ae8b95d28e743631164f6287 Mon Sep 17 00:00:00 2001 From: gt3ch1 Date: Fri, 6 Sep 2024 18:30:31 -0600 Subject: [PATCH] Doc comments --- .../com/peasenet/main/GavinsModClient.kt | 5 - .../mods/commons/BlockEspTracerCommon.kt | 27 +- .../com/peasenet/mods/esp/BlockEntityEsp.kt | 13 + .../kotlin/com/peasenet/mods/esp/EntityEsp.kt | 82 ++--- .../com/peasenet/mods/esp/ModBlockEsp.kt | 25 +- .../com/peasenet/mods/esp/ModChestEsp.kt | 12 +- .../com/peasenet/mods/esp/ModEntityItemEsp.kt | 21 +- .../peasenet/mods/esp/ModEntityPlayerEsp.kt | 11 +- .../com/peasenet/mods/esp/ModFurnaceEsp.kt | 5 +- .../kotlin/com/peasenet/mods/esp/ModMobEsp.kt | 35 -- .../com/peasenet/mods/misc/ModFreeCam.kt | 64 +++- .../com/peasenet/mods/render/ModFullBright.kt | 10 +- .../com/peasenet/mods/render/ModWaypoint.kt | 49 ++- .../peasenet/mods/tracer/BlockEntityTracer.kt | 13 + .../com/peasenet/mods/tracer/EntityTracer.kt | 13 + .../peasenet/mods/tracer/ModBeehiveTracer.kt | 13 +- .../peasenet/mods/tracer/ModChestTracer.kt | 5 +- .../mods/tracer/ModEntityItemTracer.kt | 5 +- .../mods/tracer/ModEntityPlayerTracer.kt | 37 +- .../peasenet/mods/tracer/ModFurnaceTracer.kt | 12 +- .../com/peasenet/mods/tracer/ModMobTracer.kt | 5 +- .../com/peasenet/mods/tracer/TracerMod.kt | 11 +- .../kotlin/com/peasenet/util/RenderUtils.kt | 337 +----------------- .../com/peasenet/util/math/MathUtils.kt | 24 +- 24 files changed, 258 insertions(+), 576 deletions(-) diff --git a/src/main/kotlin/com/peasenet/main/GavinsModClient.kt b/src/main/kotlin/com/peasenet/main/GavinsModClient.kt index 2bbecfc..3f69f72 100644 --- a/src/main/kotlin/com/peasenet/main/GavinsModClient.kt +++ b/src/main/kotlin/com/peasenet/main/GavinsModClient.kt @@ -47,11 +47,6 @@ class GavinsModClient : ClientModInitializer { if (m.isActive || m.isDeactivating) m.onTick() } }) - WorldRenderEvents.LAST.register(WorldRenderEvents.Last { context: WorldRenderContext -> - RenderUtils.last( - context - ) - }) } diff --git a/src/main/kotlin/com/peasenet/mods/commons/BlockEspTracerCommon.kt b/src/main/kotlin/com/peasenet/mods/commons/BlockEspTracerCommon.kt index 81dac6a..e0ca885 100644 --- a/src/main/kotlin/com/peasenet/mods/commons/BlockEspTracerCommon.kt +++ b/src/main/kotlin/com/peasenet/mods/commons/BlockEspTracerCommon.kt @@ -27,16 +27,11 @@ package com.peasenet.mods.commons import com.peasenet.annotations.Exclude import com.peasenet.config.BlockEspConfig import com.peasenet.config.BlockListConfig -import com.peasenet.config.BlockTracerConfig import com.peasenet.config.commons.IBlockEspTracerConfig -import com.peasenet.gui.mod.GuiBlockSelection -import com.peasenet.gui.mod.tracer.GuiBlockTracer import com.peasenet.main.GavinsMod -import com.peasenet.main.GavinsModClient.Companion.minecraftClient import com.peasenet.main.Settings import com.peasenet.mods.Mod import com.peasenet.mods.ModCategory -import com.peasenet.mods.esp.EspMod import com.peasenet.settings.SettingBuilder import com.peasenet.util.GavBlock import com.peasenet.util.GavChunk @@ -57,6 +52,22 @@ import net.minecraft.util.math.ChunkPos import net.minecraft.world.chunk.Chunk import org.lwjgl.glfw.GLFW +/** + * A class that contains settings and methods used for Block ESP or tracers. + * + * @param T A Configuration that extends IBlockEspTracerConfig. + * @param name The name of the mod. + * @param translationKey The translation key of the mod. + * @param chatCommand The chat command of the mod. + * @param category The category of the mod. + * @param onMenuOpen A lambda that is called when the menu is opened. + * @param keyBinding The key binding of the mod. + * + * @since 09-01-2024 + * @version 09-01-2024 + * @author GT3CH1 + * @see IBlockEspTracerConfig + */ abstract class BlockEspTracerCommon( name: String, translationKey: String, @@ -71,9 +82,9 @@ abstract class BlockEspTracerCommon( return Settings.getConfig(chatCommand) } + // A small vertex buffer for rendering the block outlines. protected var vertexBuffer: VertexBuffer? = null - init { val subSetting = SettingBuilder().setTitle(translationKey).buildSubSetting() val colorSetting = @@ -112,7 +123,9 @@ abstract class BlockEspTracerCommon( val box = Box(-0.5, -0.5, -0.5, 0.5, 0.5, 0.5) RenderUtils.drawOutlinedBox(box, vertexBuffer!!) // search for chunks within render distance - RenderUtils.getVisibleChunks().forEach(this::searchChunk) + GemExecutor.execute { + RenderUtils.getVisibleChunks().forEach(this::searchChunk) + } } override fun onDisable() { diff --git a/src/main/kotlin/com/peasenet/mods/esp/BlockEntityEsp.kt b/src/main/kotlin/com/peasenet/mods/esp/BlockEntityEsp.kt index dbf06d6..d9747dd 100644 --- a/src/main/kotlin/com/peasenet/mods/esp/BlockEntityEsp.kt +++ b/src/main/kotlin/com/peasenet/mods/esp/BlockEntityEsp.kt @@ -32,6 +32,18 @@ import net.minecraft.client.render.GameRenderer import net.minecraft.client.util.math.MatrixStack import net.minecraft.util.math.Box +/** + * A class that represents an ESP mod for block entities. + * @param T The type of block entity to render. + * @param name The name of the mod. + * @param translationKey The translation key of the mod. + * @param chatCommand The chat command of the mod. + * + * @author GT3CH1 + * @version 09-01-2024 + * @since 09-01-2024 + * + */ abstract class BlockEntityEsp( name: String, translationKey: String, chatCommand: String, val filter: (BlockEntity) -> Boolean ) : EspMod( @@ -46,6 +58,7 @@ abstract class BlockEntityEsp( for (z in -RenderUtils.CHUNK_RADIUS..RenderUtils.CHUNK_RADIUS) { val chunk = level!!.getChunk(x + client.getPlayer().chunkPos.x, z + client.getPlayer().chunkPos.z) for ((_, blockEntity) in chunk.blockEntities.filter { filter(it.value) }) { + if (espList.size > 100) return espList.add(blockEntity as T) } } diff --git a/src/main/kotlin/com/peasenet/mods/esp/EntityEsp.kt b/src/main/kotlin/com/peasenet/mods/esp/EntityEsp.kt index 664a0d9..6f17bec 100644 --- a/src/main/kotlin/com/peasenet/mods/esp/EntityEsp.kt +++ b/src/main/kotlin/com/peasenet/mods/esp/EntityEsp.kt @@ -40,7 +40,18 @@ import net.minecraft.util.math.Box import net.minecraft.util.math.MathHelper import net.minecraft.util.math.Vec3d - +/** + * A class that represents an ESP mod for entities. + * @param T The type of entity to render. + * @param name The name of the mod. + * @param translationKey The translation key of the mod. + * @param chatCommand The chat command of the mod. + * + * @author GT3CH1 + * @version 09-01-2024 + * @since 09-01-2024 + * + */ abstract class EntityEsp( name: String, translationKey: String, chatCommand: String, val entityFilter: (Entity) -> Boolean ) : EspMod(name, translationKey, chatCommand) { @@ -57,33 +68,27 @@ abstract class EntityEsp( RenderSystem.setShader(GameRenderer::getPositionColorProgram); RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f) RenderSystem.applyModelViewMatrix() - val region = RenderUtils.getCameraRegionPos() val entry = matrixStack.peek().positionMatrix val tessellator = RenderSystem.renderThreadTesselator() val bufferBuilder = tessellator.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR); - val regionVec = region.toVec3d(); - val start = RenderUtils.getLookVec(partialTicks).add(RenderUtils.getCameraPos()).subtract(regionVec); - - val box = e.boundingBox - val x = MathHelper.lerp(partialTicks, e.lastRenderX.toFloat(), e.x.toFloat()) - e.x - val y = MathHelper.lerp(partialTicks, e.lastRenderY.toFloat(), e.y.toFloat()) - e.y - val z = MathHelper.lerp(partialTicks, e.lastRenderZ.toFloat(), e.z.toFloat()) - e.z - - val lerpedPos = MathUtils.lerp( + for (e in espList) { + var box = e.boundingBox + val lerped = MathUtils.lerp( partialTicks, e.pos, Vec3d(e.lastRenderX, e.lastRenderY, e.lastRenderZ), RenderUtils.getCameraRegionPos() ) - matrixStack.translate(lerpedPos.x, lerpedPos.y, lerpedPos.z) - val color = if (e.type.spawnGroup.isPeaceful) config.peacefulMobColor else config.hostileMobColor - val box2 = Box(x + box.minX, y + box.minY, z + box.minZ, x + box.maxX, y + box.maxY, z + box.maxZ) - - - for (e in espList) { - val center = e.boundingBox.center.subtract(region.toVec3d()) + box = Box( + lerped.x + box.minX, + lerped.y + box.minY, + lerped.z + box.minZ, + lerped.x + box.maxX, + lerped.y + box.maxY, + lerped.z + box.maxZ + ) RenderUtils.drawOutlinedBox( - box, vertexBuffer!!, entry, getColor(e), config.alpha + box, bufferBuilder, entry, getColor(e), config.alpha ) } val end = bufferBuilder.end() @@ -91,40 +96,11 @@ abstract class EntityEsp( RenderUtils.cleanupRender(matrixStack) } -// override fun onRender(matrixStack: MatrixStack, partialTicks: Float) { -// if (espList.isEmpty()) return; -// RenderUtils.setupRender(matrixStack) -// -// val tessellator = RenderSystem.renderThreadTesselator() -// val bufferBuilder = tessellator.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR); -// espList.forEach { e -> -// matrixStack.push() -// -// val entry = matrixStack.peek().positionMatrix -// val box = e.boundingBox -// val x = MathHelper.lerp(partialTicks, e.lastRenderX.toFloat(), e.x.toFloat()) - e.x -// val y = MathHelper.lerp(partialTicks, e.lastRenderY.toFloat(), e.y.toFloat()) - e.y -// val z = MathHelper.lerp(partialTicks, e.lastRenderZ.toFloat(), e.z.toFloat()) - e.z -// -// val lerpedPos = MathUtils.lerp( -// partialTicks, -// e.pos, -// Vec3d(e.lastRenderX, e.lastRenderY, e.lastRenderZ), -// RenderUtils.getCameraRegionPos() -// ) -// matrixStack.translate(lerpedPos.x, lerpedPos.y, lerpedPos.z) -// val color = if (e.type.spawnGroup.isPeaceful) config.peacefulMobColor else config.hostileMobColor -// val box2 = Box(x + box.minX, y + box.minY, z + box.minZ, x + box.maxX, y + box.maxY, z + box.maxZ) -// RenderUtils.drawOutlinedBox( -// box2, bufferBuilder, entry, color, config.alpha -// ) -// matrixStack.pop() -// } -// -// val end = bufferBuilder.end() -// BufferRenderer.drawWithGlobalProgram(end) -// RenderUtils.cleanupRender(matrixStack) -// } + /** + * Gets the color of the entity for rendering. + * @param entity The entity to get the color of. + * @return The color of the entity. + */ abstract fun getColor(entity: T): Color } \ No newline at end of file diff --git a/src/main/kotlin/com/peasenet/mods/esp/ModBlockEsp.kt b/src/main/kotlin/com/peasenet/mods/esp/ModBlockEsp.kt index 04ee850..a9aacfe 100644 --- a/src/main/kotlin/com/peasenet/mods/esp/ModBlockEsp.kt +++ b/src/main/kotlin/com/peasenet/mods/esp/ModBlockEsp.kt @@ -31,10 +31,12 @@ import com.peasenet.main.GavinsModClient.Companion.minecraftClient import com.peasenet.mods.ModCategory import com.peasenet.mods.commons.BlockEspTracerCommon import com.peasenet.util.RenderUtils +import com.peasenet.util.executor.GemExecutor import com.peasenet.util.listeners.BlockUpdateListener import com.peasenet.util.listeners.ChunkUpdateListener import com.peasenet.util.listeners.RenderListener import com.peasenet.util.listeners.WorldRenderListener +import net.minecraft.client.gl.ShaderProgram import net.minecraft.client.gl.VertexBuffer import net.minecraft.client.render.BufferBuilder import net.minecraft.client.render.GameRenderer @@ -49,17 +51,17 @@ import org.lwjgl.opengl.GL11 * An ESP mod that draws boxes around user selected blocks in the world. * * @author GT3CH1 - * @version 09-01-2024 + * @version 09-06-2024 * @since 09-01-2024 * @see EspMod - * + * @see BlockEspTracerCommon */ -class ModBlockEsp : BlockEspTracerCommon( - "Block ESP", +class ModBlockEsp : BlockEspTracerCommon("Block ESP", "gavinsmod.mod.esp.blockesp", "blockesp", ModCategory.ESP, { minecraftClient.setScreen(GuiBlockEsp()) }), RenderListener { + private var count = 0 override fun onEnable() { super.onEnable() @@ -73,6 +75,8 @@ class ModBlockEsp : BlockEspTracerCommon( } override fun onRender(matrixStack: MatrixStack, partialTicks: Float) { + if (chunks.isEmpty()) return + count = 0 RenderUtils.setupRender(matrixStack) synchronized(chunks) { for (chunk in chunks.values.filter { it.inRenderDistance() }) { @@ -80,15 +84,14 @@ class ModBlockEsp : BlockEspTracerCommon( matrixStack.push() val pos = Vec3i(block.x, block.y, block.z).subtract(RenderUtils.getCameraRegionPos().toVec3i()) val box = Box( - pos.x.toDouble(), - pos.y.toDouble(), - pos.z.toDouble(), - pos.x + 1.0, - pos.y + 1.0, - pos.z + 1.0 + pos.x.toDouble(), pos.y.toDouble(), pos.z.toDouble(), pos.x + 1.0, pos.y + 1.0, pos.z + 1.0 ) RenderUtils.drawOutlinedBox( - box, vertexBuffer!!, matrixStack, getSettings().blockColor, getSettings().alpha + box, + vertexBuffer!!, + matrixStack, + color = getSettings().blockColor, + alpha = getSettings().alpha ) matrixStack.pop() } diff --git a/src/main/kotlin/com/peasenet/mods/esp/ModChestEsp.kt b/src/main/kotlin/com/peasenet/mods/esp/ModChestEsp.kt index b2dd5fe..dab6565 100644 --- a/src/main/kotlin/com/peasenet/mods/esp/ModChestEsp.kt +++ b/src/main/kotlin/com/peasenet/mods/esp/ModChestEsp.kt @@ -23,24 +23,18 @@ */ package com.peasenet.mods.esp -import com.mojang.blaze3d.systems.RenderSystem import com.peasenet.gavui.color.Color import com.peasenet.settings.SettingBuilder -import com.peasenet.util.RenderUtils import com.peasenet.util.listeners.RenderListener -import net.minecraft.block.entity.BlockEntity import net.minecraft.block.entity.ChestBlockEntity import net.minecraft.block.entity.EnderChestBlockEntity import net.minecraft.block.entity.ShulkerBoxBlockEntity -import net.minecraft.client.MinecraftClient -import net.minecraft.client.render.GameRenderer -import net.minecraft.client.util.math.MatrixStack -import net.minecraft.util.math.Box /** - * @author gt3ch1 - * @version 03-02-2023 * A mod that allows the client to see an esp (a box) around chests. + * @author gt3ch1 + * @version 03-02-2024 + * @since 03-02-2023 */ class ModChestEsp : BlockEntityEsp("Chest ESP", "gavinsmod.mod.esp.chest", diff --git a/src/main/kotlin/com/peasenet/mods/esp/ModEntityItemEsp.kt b/src/main/kotlin/com/peasenet/mods/esp/ModEntityItemEsp.kt index 220d496..5d3140a 100644 --- a/src/main/kotlin/com/peasenet/mods/esp/ModEntityItemEsp.kt +++ b/src/main/kotlin/com/peasenet/mods/esp/ModEntityItemEsp.kt @@ -23,33 +23,18 @@ */ package com.peasenet.mods.esp -import com.mojang.blaze3d.systems.RenderSystem -import com.peasenet.config.EspConfig import com.peasenet.gavui.color.Color import com.peasenet.main.GavinsModClient -import com.peasenet.main.Settings -import com.peasenet.mods.tracer.EntityTracer import com.peasenet.settings.SettingBuilder -import com.peasenet.util.PlayerUtils -import com.peasenet.util.RenderUtils import com.peasenet.util.RenderUtils.CHUNK_RADIUS -import com.peasenet.util.RenderUtils.getCameraRegionPos -import com.peasenet.util.event.data.EntityRender -import com.peasenet.util.listeners.EntityRenderListener import com.peasenet.util.listeners.RenderListener -import com.peasenet.util.math.MathUtils -import net.minecraft.client.render.GameRenderer -import net.minecraft.client.util.math.MatrixStack -import net.minecraft.entity.EntityType import net.minecraft.entity.ItemEntity -import net.minecraft.util.math.Box -import net.minecraft.util.math.MathHelper -import net.minecraft.util.math.Vec3d /** - * @author gt3ch1 - * @version 03-02-2023 * A mod that allows the player to see an esp (a box) around items. + * @author gt3ch1 + * @version 09-06-2024 + * @since 03-02-2023 */ class ModEntityItemEsp : EntityEsp("Item ESP", "gavinsmod.mod.esp.item", diff --git a/src/main/kotlin/com/peasenet/mods/esp/ModEntityPlayerEsp.kt b/src/main/kotlin/com/peasenet/mods/esp/ModEntityPlayerEsp.kt index 82f1f65..da6aa84 100644 --- a/src/main/kotlin/com/peasenet/mods/esp/ModEntityPlayerEsp.kt +++ b/src/main/kotlin/com/peasenet/mods/esp/ModEntityPlayerEsp.kt @@ -23,19 +23,16 @@ */ package com.peasenet.mods.esp -import com.peasenet.config.EspConfig import com.peasenet.gavui.color.Color -import com.peasenet.main.Settings import com.peasenet.settings.SettingBuilder -import com.peasenet.util.RenderUtils -import com.peasenet.util.event.data.EntityRender -import com.peasenet.util.listeners.EntityRenderListener import net.minecraft.entity.player.PlayerEntity /** - * @author gt3ch1 - * @version 03-02-2023 + * * A mod that allows the player to see an ESP to other players. + * @author gt3ch1 + * @version 09-06-2024 + * @since 03-02-2023 */ class ModEntityPlayerEsp : EntityEsp( "Player ESP", diff --git a/src/main/kotlin/com/peasenet/mods/esp/ModFurnaceEsp.kt b/src/main/kotlin/com/peasenet/mods/esp/ModFurnaceEsp.kt index ad23fe6..f21bfeb 100644 --- a/src/main/kotlin/com/peasenet/mods/esp/ModFurnaceEsp.kt +++ b/src/main/kotlin/com/peasenet/mods/esp/ModFurnaceEsp.kt @@ -35,9 +35,10 @@ import net.minecraft.block.entity.FurnaceBlockEntity import net.minecraft.util.math.Box /** - * @author gt3ch1 - * @version 04-11-2023 * A mod that allows the client to see an esp (a box) around furnaces. + * @author gt3ch1 + * @version 09-06-2024 + * @since 04-11-2023 */ class ModFurnaceEsp : BlockEntityEsp( "Furnace ESP", diff --git a/src/main/kotlin/com/peasenet/mods/esp/ModMobEsp.kt b/src/main/kotlin/com/peasenet/mods/esp/ModMobEsp.kt index f9b566c..d42a17a 100644 --- a/src/main/kotlin/com/peasenet/mods/esp/ModMobEsp.kt +++ b/src/main/kotlin/com/peasenet/mods/esp/ModMobEsp.kt @@ -64,39 +64,4 @@ class ModMobEsp : EntityEsp("Mob ESP", } override fun getColor(): Color = Colors.BLUE - -// override fun onTick() { -// super.onTick() -// espList.clear() -// espList.addAll(client.getWorld().entities.filter { e -> e.isLiving }.filter { e -> e !is PlayerEntity } -// .filter { e -> !e.isRemoved }.filter { e -> config.mobIsShown(e.type) }) -// } - -// override fun onRender(matrixStack: MatrixStack, partialTicks: Float) { -// if (espList.isEmpty()) -// return; -// RenderUtils.setupRender(matrixStack) -// -// espList.forEach { e -> -// matrixStack.push() -// val box = e.boundingBox -// val x = MathHelper.lerp(partialTicks, e.lastRenderX.toFloat(), e.x.toFloat()) - e.x -// val y = MathHelper.lerp(partialTicks, e.lastRenderY.toFloat(), e.y.toFloat()) - e.y -// val z = MathHelper.lerp(partialTicks, e.lastRenderZ.toFloat(), e.z.toFloat()) - e.z -// -// val lerpedPos = Vec3d(x, y, z).subtract(RenderUtils.getCameraRegionPos().toVec3d()) -// matrixStack.translate(lerpedPos.x, lerpedPos.y, lerpedPos.z) -// val color = if (e.type.spawnGroup.isPeaceful) config.peacefulMobColor else config.hostileMobColor -// val box2 = Box(x + box.minX, y + box.minY, z + box.minZ, x + box.maxX, y + box.maxY, z + box.maxZ) -// RenderUtils.drawOutlinedBox( -// box2, -// vertexBuffer!!, -// matrixStack, -// color, -// config.alpha -// ) -// matrixStack.pop() -// } -// RenderUtils.cleanupRender(matrixStack) -// } } \ No newline at end of file diff --git a/src/main/kotlin/com/peasenet/mods/misc/ModFreeCam.kt b/src/main/kotlin/com/peasenet/mods/misc/ModFreeCam.kt index 9afbde7..2604b88 100644 --- a/src/main/kotlin/com/peasenet/mods/misc/ModFreeCam.kt +++ b/src/main/kotlin/com/peasenet/mods/misc/ModFreeCam.kt @@ -23,10 +23,13 @@ */ package com.peasenet.mods.misc +import com.mojang.blaze3d.systems.RenderSystem import com.peasenet.config.EspConfig import com.peasenet.config.MiscConfig import com.peasenet.config.TracerConfig import com.peasenet.main.Settings +import com.peasenet.mods.esp.EspMod +import com.peasenet.mods.esp.EspMod.Companion import com.peasenet.settings.SettingBuilder import com.peasenet.util.FakePlayer import com.peasenet.util.PlayerUtils @@ -35,12 +38,15 @@ import com.peasenet.util.event.AirStrafeEvent import com.peasenet.util.event.data.OutputPacket import com.peasenet.util.listeners.AirStrafeListener import com.peasenet.util.listeners.PacketSendListener +import com.peasenet.util.listeners.RenderListener import com.peasenet.util.listeners.WorldRenderListener +import com.peasenet.util.math.MathUtils import net.minecraft.client.MinecraftClient -import net.minecraft.client.render.BufferBuilder +import net.minecraft.client.render.* import net.minecraft.client.util.math.MatrixStack import net.minecraft.client.world.ClientWorld import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket +import net.minecraft.util.math.Box import net.minecraft.util.math.Vec3d /** @@ -53,7 +59,7 @@ class ModFreeCam : MiscMod( "Freecam", "gavinsmod.mod.misc.freecam", "freecam" -), PacketSendListener, WorldRenderListener, AirStrafeListener { +), PacketSendListener, RenderListener, AirStrafeListener { private var fake: FakePlayer? = null init { @@ -75,7 +81,7 @@ class ModFreeCam : MiscMod( super.activate() fake = FakePlayer() em.subscribe(PacketSendListener::class.java, this) - em.subscribe(WorldRenderListener::class.java, this) + em.subscribe(RenderListener::class.java, this) em.subscribe(AirStrafeListener::class.java, this) } @@ -98,7 +104,7 @@ class ModFreeCam : MiscMod( fake!!.remove() em.unsubscribe(PacketSendListener::class.java, this) - em.unsubscribe(WorldRenderListener::class.java, this) + em.unsubscribe(RenderListener::class.java, this) em.unsubscribe(AirStrafeListener::class.java, this) client.getPlayer().abilities.flying = false client.getPlayer().velocity = Vec3d.ZERO @@ -106,13 +112,6 @@ class ModFreeCam : MiscMod( } - override fun onWorldRender(level: ClientWorld, stack: MatrixStack, bufferBuilder: BufferBuilder, delta: Float) { - val camera = MinecraftClient.getInstance().gameRenderer.camera - val playerPos = PlayerUtils.getNewPlayerPosition(delta, camera) - val aabb = fake!!.boundingBox -// RenderUtils.renderSingleLine(stack, bufferBuilder, playerPos, aabb.center, Settings.getConfig("tracer").playerColor) - RenderUtils.drawBox(stack, bufferBuilder, aabb, Settings.getConfig("esp").playerColor) - } override fun onPacketSend(packet: OutputPacket) { if (packet.packet is PlayerMoveC2SPacket) packet.cancel() @@ -125,9 +124,46 @@ class ModFreeCam : MiscMod( companion object { private val config: MiscConfig - get() { - return Settings.getConfig("misc") - } + get() { + return Settings.getConfig("misc") + } + } + + override fun onRender(matrixStack: MatrixStack, partialTicks: Float) { + RenderUtils.setupRender(matrixStack) + RenderSystem.setShader(GameRenderer::getPositionColorProgram); + RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f) + RenderSystem.applyModelViewMatrix() + val entry = matrixStack.peek().positionMatrix + val tessellator = RenderSystem.renderThreadTesselator() + val bufferBuilder = tessellator.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR); + val e = fake!! + var box = e.boundingBox + val lerped = MathUtils.lerp( + partialTicks, + e.pos, + Vec3d(e.lastRenderX, e.lastRenderY, e.lastRenderZ), + RenderUtils.getCameraRegionPos() + ) + box = Box( + lerped.x + box.minX, + lerped.y + box.minY, + lerped.z + box.minZ, + lerped.x + box.maxX, + lerped.y + box.maxY, + lerped.z + box.maxZ + ) + RenderUtils.drawOutlinedBox( + box, + bufferBuilder, + entry, + Settings.getConfig("esp").playerColor, + Settings.getConfig("esp").alpha + ) + val end = bufferBuilder.end() + BufferRenderer.drawWithGlobalProgram(end) + RenderUtils.cleanupRender(matrixStack) + } } diff --git a/src/main/kotlin/com/peasenet/mods/render/ModFullBright.kt b/src/main/kotlin/com/peasenet/mods/render/ModFullBright.kt index 7ee5953..41875e8 100644 --- a/src/main/kotlin/com/peasenet/mods/render/ModFullBright.kt +++ b/src/main/kotlin/com/peasenet/mods/render/ModFullBright.kt @@ -42,18 +42,14 @@ class ModFullBright : RenderMod( lateinit var fullbrightConfig: FullbrightConfig } init { - fullbrightConfig = Settings.getConfig("fullbright") + fullbrightConfig = Settings.getConfig("fullbright") val gammaFade = SettingBuilder().setTitle("gavinsmod.settings.render.fullbright.gammafade") .setState(fullbrightConfig.gammaFade) -// .setWidth(100) -// .setHeight(10) .buildToggleSetting() gammaFade.setCallback { fullbrightConfig.gammaFade = gammaFade.value } val autoFullBright = SettingBuilder().setTitle("gavinsmod.settings.render.fullbright.autofullbright") .setState(fullbrightConfig.autoFullBright) -// .setWidth(100) -// .setHeight(10) .buildToggleSetting() autoFullBright.setCallback { fullbrightConfig.autoFullBright = autoFullBright.value } @@ -167,12 +163,12 @@ class ModFullBright : RenderMod( val isLastGamma: Boolean get() = gamma <= LAST_GAMMA - fun setLastGamma() { + private fun setLastGamma() { if (gamma > 1) return LAST_GAMMA = gamma } - fun getLastGamma(): Double { + private fun getLastGamma(): Double { return LAST_GAMMA } diff --git a/src/main/kotlin/com/peasenet/mods/render/ModWaypoint.kt b/src/main/kotlin/com/peasenet/mods/render/ModWaypoint.kt index cd4c748..61fee48 100644 --- a/src/main/kotlin/com/peasenet/mods/render/ModWaypoint.kt +++ b/src/main/kotlin/com/peasenet/mods/render/ModWaypoint.kt @@ -23,6 +23,7 @@ */ package com.peasenet.mods.render +import com.mojang.blaze3d.systems.RenderSystem import com.peasenet.config.TracerConfig import com.peasenet.config.WaypointConfig import com.peasenet.gui.mod.waypoint.GuiWaypoint @@ -39,7 +40,12 @@ import com.peasenet.util.event.data.CameraBob import com.peasenet.util.event.data.EntityRender import com.peasenet.util.listeners.CameraBobListener import com.peasenet.util.listeners.EntityRenderListener +import com.peasenet.util.listeners.RenderListener import net.minecraft.client.MinecraftClient +import net.minecraft.client.gl.VertexBuffer +import net.minecraft.client.render.GameRenderer +import net.minecraft.client.render.VertexFormats +import net.minecraft.client.util.math.MatrixStack import net.minecraft.text.Text import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Box @@ -55,14 +61,23 @@ class ModWaypoint : RenderMod( "gavinsmod.mod.render.waypoints", "waypoints", ModCategory.WAYPOINTS -), EntityRenderListener, CameraBobListener { +), RenderListener, CameraBobListener { + + private var vertexBuffer: VertexBuffer? = null + init { + reloadSettings() + } + override fun onEnable() { super.onEnable() - em.subscribe(EntityRenderListener::class.java, this) + vertexBuffer = VertexBuffer(VertexBuffer.Usage.STATIC) + val bb = Box(-0.5, 0.0, -0.5, 0.5, 1.0, 0.5) + RenderUtils.drawOutlinedBox(bb, vertexBuffer!!) + em.subscribe(RenderListener::class.java, this) em.subscribe(CameraBobListener::class.java, this) for (w in Settings.getConfig("waypoints").getLocations()) { if (!w.hasDimensions()) { @@ -76,13 +91,12 @@ class ModWaypoint : RenderMod( override fun onDisable() { super.onDisable() - em.unsubscribe(EntityRenderListener::class.java, this) + em.unsubscribe(RenderListener::class.java, this) em.unsubscribe(CameraBobListener::class.java, this) } override fun reloadSettings() { modSettings.clear() -// setting = SubSetting(setting.gui.width.toInt(), 10, "gavinsmod.mod.render.waypoints") setting = SettingBuilder() .setWidth(100f) .setHeight(10f) @@ -118,22 +132,27 @@ class ModWaypoint : RenderMod( addSetting(clickSetting) } - override fun onEntityRender(er: EntityRender) { + override fun onRender(matrixStack: MatrixStack, partialTicks: Float) { val playerDimension = Dimension.fromValue(MinecraftClient.getInstance().player!!.world.dimension.effects.path!!) + + RenderUtils.setupRender(matrixStack) + RenderSystem.setShader(GameRenderer::getPositionProgram); Settings.getConfig("waypoints").getLocations().stream().filter { obj: Waypoint -> obj.canRender(playerDimension) }.forEach { w: Waypoint -> - val aabb = Box(BlockPos(w.x, w.y, w.z)) - val boxPos = aabb.center -// if (w.isTracerEnabled) RenderUtils.renderSingleLine( -// er.stack, -// er.buffer!!, -// er.playerPos!!, -// boxPos, -// w.color!! -// ) - if (w.isEspEnabled) RenderUtils.drawBox(er.stack, er.buffer, aabb, w.color!!) + val pos = w.pos.subtract(RenderUtils.getCameraRegionPos().toVec3d()) + val bb = Box( + pos.x + 1, + pos.y, + pos.z + 1, + pos.x, + pos.y + 1.0, + pos.z + ) + if (w.isEspEnabled) + RenderUtils.drawOutlinedBox(bb, vertexBuffer!!, matrixStack, w.color!!) } + RenderUtils.resetRenderSystem() } override fun onCameraViewBob(c: CameraBob) { diff --git a/src/main/kotlin/com/peasenet/mods/tracer/BlockEntityTracer.kt b/src/main/kotlin/com/peasenet/mods/tracer/BlockEntityTracer.kt index d31056b..9a7b990 100644 --- a/src/main/kotlin/com/peasenet/mods/tracer/BlockEntityTracer.kt +++ b/src/main/kotlin/com/peasenet/mods/tracer/BlockEntityTracer.kt @@ -11,6 +11,19 @@ import net.minecraft.client.render.VertexFormat import net.minecraft.client.render.VertexFormats import net.minecraft.client.util.math.MatrixStack +/** + * A helper class for creating mods that trace block entities. + * @param T The type of block entity to trace. + * @param name The name of the mod. + * @param translationKey The translation key of the mod. + * @param chatCommand The chat command of the mod. + * @param blockFilter A lambda that filters block entities. + * @see TracerMod + * + * @version 09-06-2024 + * @since 09-06-2024 + * @author GT3CH1 + */ abstract class BlockEntityTracer( name: String, translationKey: String, diff --git a/src/main/kotlin/com/peasenet/mods/tracer/EntityTracer.kt b/src/main/kotlin/com/peasenet/mods/tracer/EntityTracer.kt index 27770b7..7705b9b 100644 --- a/src/main/kotlin/com/peasenet/mods/tracer/EntityTracer.kt +++ b/src/main/kotlin/com/peasenet/mods/tracer/EntityTracer.kt @@ -15,6 +15,19 @@ import net.minecraft.client.util.math.MatrixStack import net.minecraft.entity.Entity import net.minecraft.entity.EntityType +/** + * A tracer mod that traces entities of a specific type. + * @param T The type of entity to trace. + * @param name The name of the mod. + * @param translationKey The translation key of the mod. + * @param chatCommand The chat command to toggle the mod. + * @param entityFilter A filter to determine which entities to trace. + * @see TracerMod + * + * @version 09-06-2024 + * @since 09-06-2024 + * @author GT3CH1 + */ abstract class EntityTracer( name: String, translationKey: String, diff --git a/src/main/kotlin/com/peasenet/mods/tracer/ModBeehiveTracer.kt b/src/main/kotlin/com/peasenet/mods/tracer/ModBeehiveTracer.kt index c44e0c3..206bddb 100644 --- a/src/main/kotlin/com/peasenet/mods/tracer/ModBeehiveTracer.kt +++ b/src/main/kotlin/com/peasenet/mods/tracer/ModBeehiveTracer.kt @@ -23,22 +23,15 @@ */ package com.peasenet.mods.tracer -import com.mojang.blaze3d.systems.RenderSystem import com.peasenet.gavui.color.Color import com.peasenet.settings.SettingBuilder -import com.peasenet.util.RenderUtils -import com.peasenet.util.listeners.RenderListener import net.minecraft.block.entity.BeehiveBlockEntity -import net.minecraft.client.render.BufferRenderer -import net.minecraft.client.render.GameRenderer -import net.minecraft.client.render.VertexFormat -import net.minecraft.client.render.VertexFormats -import net.minecraft.client.util.math.MatrixStack /** - * @author gt3ch1 - * @version 04-11-2023 * A mod that allows the player to see tracers towards beehives. + * @author gt3ch1 + * @version 09-06-2024 + * @since 04-11-2023 */ class ModBeehiveTracer : BlockEntityTracer("Beehive Tracer", "gavinsmod.mod.tracer.beehive", diff --git a/src/main/kotlin/com/peasenet/mods/tracer/ModChestTracer.kt b/src/main/kotlin/com/peasenet/mods/tracer/ModChestTracer.kt index 554e75e..43a0360 100644 --- a/src/main/kotlin/com/peasenet/mods/tracer/ModChestTracer.kt +++ b/src/main/kotlin/com/peasenet/mods/tracer/ModChestTracer.kt @@ -45,9 +45,10 @@ import net.minecraft.client.render.VertexFormats import net.minecraft.client.util.math.MatrixStack /** - * @author gt3ch1 - * @version 04-11-2023 * A mod that allows the player to see tracers towards chests. + * @author gt3ch1 + * @version 09-06-2024 + * @since 04-11-2023 */ class ModChestTracer : BlockEntityTracer( "Chest Tracer", diff --git a/src/main/kotlin/com/peasenet/mods/tracer/ModEntityItemTracer.kt b/src/main/kotlin/com/peasenet/mods/tracer/ModEntityItemTracer.kt index 78efb15..a1be902 100644 --- a/src/main/kotlin/com/peasenet/mods/tracer/ModEntityItemTracer.kt +++ b/src/main/kotlin/com/peasenet/mods/tracer/ModEntityItemTracer.kt @@ -43,9 +43,10 @@ import net.minecraft.entity.ItemEntity import net.minecraft.util.math.Box /** - * @author gt3ch1 - * @version 04-11-2023 * A mod that allows the player to see tracers towards items. + * @author gt3ch1 + * @version 09-06-2024 + * @since 04-11-2023 */ class ModEntityItemTracer : EntityTracer("Item Tracer", "gavinsmod.mod.tracer.item", "itemtracer", { it is ItemEntity }), diff --git a/src/main/kotlin/com/peasenet/mods/tracer/ModEntityPlayerTracer.kt b/src/main/kotlin/com/peasenet/mods/tracer/ModEntityPlayerTracer.kt index 48279c1..a3d27aa 100644 --- a/src/main/kotlin/com/peasenet/mods/tracer/ModEntityPlayerTracer.kt +++ b/src/main/kotlin/com/peasenet/mods/tracer/ModEntityPlayerTracer.kt @@ -24,6 +24,8 @@ package com.peasenet.mods.tracer import com.peasenet.config.TracerConfig +import com.peasenet.gavui.color.Color +import com.peasenet.main.GavinsModClient import com.peasenet.main.Settings import com.peasenet.settings.SettingBuilder import com.peasenet.util.RenderUtils @@ -33,14 +35,16 @@ import net.minecraft.client.util.math.MatrixStack import net.minecraft.entity.player.PlayerEntity /** - * @author gt3ch1 - * @version 04-11-2023 * A mod that allows the player to see a tracer to other players. + * @author gt3ch1 + * @version 09-06-2024 + * @since 04-11-2023 */ -class ModEntityPlayerTracer : TracerMod( +class ModEntityPlayerTracer : EntityTracer( "Player Tracers", "gavinsmod.mod.tracer.player", - "playertracer" + "playertracer", + { it is PlayerEntity && it != GavinsModClient.player } ) { init { val colorSetting = SettingBuilder() @@ -51,29 +55,14 @@ class ModEntityPlayerTracer : TracerMod( addSetting(colorSetting) } -// override fun onEntityRender(er: EntityRender) { -// if (er.buffer == null) return -// if (er.entity !is PlayerEntity) return -// RenderUtils.renderSingleLine( -// er.stack, -// er.buffer!!, -// er.playerPos!!, -// er.center!!, -// config.playerColor, -// config.alpha -// ) -// } -// -// override fun onRenderBlockEntity(er: BlockEntityRender) { -// -// } companion object { private val config: TracerConfig - get() { - return Settings.getConfig("tracer") - } + get() { + return Settings.getConfig("tracer") + } } - override fun onRender(matrixStack: MatrixStack, partialTicks: Float) { + override fun getColor(entity: PlayerEntity): Color { + return config.playerColor } } diff --git a/src/main/kotlin/com/peasenet/mods/tracer/ModFurnaceTracer.kt b/src/main/kotlin/com/peasenet/mods/tracer/ModFurnaceTracer.kt index f2ac6e5..5c59a51 100644 --- a/src/main/kotlin/com/peasenet/mods/tracer/ModFurnaceTracer.kt +++ b/src/main/kotlin/com/peasenet/mods/tracer/ModFurnaceTracer.kt @@ -23,21 +23,15 @@ */ package com.peasenet.mods.tracer -import com.peasenet.config.TracerConfig import com.peasenet.gavui.color.Color -import com.peasenet.main.Settings import com.peasenet.settings.SettingBuilder -import com.peasenet.util.RenderUtils -import com.peasenet.util.event.data.BlockEntityRender -import com.peasenet.util.event.data.EntityRender -import net.minecraft.block.entity.BlockEntity import net.minecraft.block.entity.FurnaceBlockEntity -import net.minecraft.client.util.math.MatrixStack /** - * @author gt3ch1 - * @version 04-11-2023 * A mod that allows the player to see tracers towards furnaces. + * @author gt3ch1 + * @version 09-06-2024 + * @since 04-11-2023 */ class ModFurnaceTracer : BlockEntityTracer("Furnace Tracer", "gavinsmod.mod.tracer.furnace", diff --git a/src/main/kotlin/com/peasenet/mods/tracer/ModMobTracer.kt b/src/main/kotlin/com/peasenet/mods/tracer/ModMobTracer.kt index 8abb4b1..8d6c8dd 100644 --- a/src/main/kotlin/com/peasenet/mods/tracer/ModMobTracer.kt +++ b/src/main/kotlin/com/peasenet/mods/tracer/ModMobTracer.kt @@ -40,9 +40,10 @@ import net.minecraft.entity.LivingEntity import net.minecraft.entity.mob.MobEntity /** - * @author gt3ch1 - * @version 04-01-2023 * A mod that allows the client to see lines, called tracers, towards mobs. + * @author gt3ch1 + * @version 09-06-2024 + * @since 04-01-2023 */ class ModMobTracer : EntityTracer( "Mob Tracer", diff --git a/src/main/kotlin/com/peasenet/mods/tracer/TracerMod.kt b/src/main/kotlin/com/peasenet/mods/tracer/TracerMod.kt index c6bac12..007ece7 100644 --- a/src/main/kotlin/com/peasenet/mods/tracer/TracerMod.kt +++ b/src/main/kotlin/com/peasenet/mods/tracer/TracerMod.kt @@ -62,16 +62,9 @@ import org.lwjgl.glfw.GLFW * @version 07-18-2023 */ abstract class TracerMod( - name: String, - translationKey: String, - chatCommand: String, - keyBinding: Int = GLFW.GLFW_KEY_UNKNOWN + name: String, translationKey: String, chatCommand: String, keyBinding: Int = GLFW.GLFW_KEY_UNKNOWN ) : Mod( - name, - translationKey, - chatCommand, - ModCategory.TRACERS, - keyBinding + name, translationKey, chatCommand, ModCategory.TRACERS, keyBinding ), CameraBobListener, RenderListener { protected var entityList: MutableList = ArrayList() protected var vertexBuffer: VertexBuffer? = null diff --git a/src/main/kotlin/com/peasenet/util/RenderUtils.kt b/src/main/kotlin/com/peasenet/util/RenderUtils.kt index 85c8615..411483f 100644 --- a/src/main/kotlin/com/peasenet/util/RenderUtils.kt +++ b/src/main/kotlin/com/peasenet/util/RenderUtils.kt @@ -28,25 +28,19 @@ import com.peasenet.gavui.color.Color import com.peasenet.gavui.color.Colors import com.peasenet.main.GavinsModClient import com.peasenet.mixinterface.ISimpleOption -import com.peasenet.util.event.* -import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext import net.minecraft.client.MinecraftClient import net.minecraft.client.gl.ShaderProgram import net.minecraft.client.gl.VertexBuffer -import net.minecraft.client.network.ClientPlayerEntity import net.minecraft.client.render.* import net.minecraft.client.util.math.MatrixStack -import net.minecraft.client.world.ClientWorld import net.minecraft.entity.Entity import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Box import net.minecraft.util.math.Vec3d import net.minecraft.world.chunk.Chunk import org.joml.Matrix4f -import org.joml.Vector3d import org.joml.Vector3f import org.lwjgl.opengl.GL11 -import java.util.function.Consumer /** @@ -58,145 +52,13 @@ object RenderUtils { /** * How many chunks away to render things. */ - public var CHUNK_RADIUS = GavinsModClient.minecraftClient.options.viewDistance.value + var CHUNK_RADIUS: Int = GavinsModClient.minecraftClient.options.viewDistance.value /** * The last player configured gamma. */ private var LAST_GAMMA = 0.0 - /** - * Draws a single line in the given color. - * - * @param stack The matrix stack to use. - * @param buffer The buffer to write to. - * @param playerPos The position of the player. - * @param boxPos The center of the location we want to draw a line to. - * @param color The color to draw the line in. - */ - @JvmOverloads - fun renderSingleLine( - stack: MatrixStack, vertexBuffer: VertexBuffer, playerPos: Vec3d, boxPos: Vec3d, color: Color, alpha: Float = 1f - ) { - val matrix4f = stack.peek().positionMatrix - val tessellator = RenderSystem.renderThreadTesselator() - val bufferBuilder = tessellator.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR) - bufferBuilder.vertex(playerPos.x.toFloat(), playerPos.y.toFloat(), playerPos.z.toFloat()) - .color(color.red, color.green, color.blue, alpha) - bufferBuilder.vertex(boxPos.x.toFloat(), boxPos.y.toFloat(), boxPos.z.toFloat()) - .color(color.red, color.green, color.blue, alpha) - val buffer = bufferBuilder.end() - vertexBuffer.bind() - vertexBuffer.upload(buffer) - vertexBuffer.draw(matrix4f, RenderSystem.getProjectionMatrix(), RenderSystem.getShader()) - } - - fun renderSingleLine( - vertexBuffer: VertexBuffer, - matrixStack: MatrixStack, - entityPos: Vec3d, - playerPos: Vec3d, - color: Color, - alpha: Float - ) { - val viewMatrix = matrixStack.peek().positionMatrix - val projMatrix = RenderSystem.getProjectionMatrix() - val shader: ShaderProgram? = RenderSystem.getShader() - val normal = Vec3d(entityPos.x - playerPos.x, entityPos.y - playerPos.y, entityPos.z - playerPos.z) -// normal.normalize() - val matrix4f = matrixStack.peek().positionMatrix - val matrix3f = matrixStack.peek() - - val tessellator = RenderSystem.renderThreadTesselator() - val bufferBuilder = tessellator.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR) - RenderSystem.setShaderColor(color.red, color.green, color.blue, alpha) - bufferBuilder.vertex( - matrix4f, playerPos.getX().toFloat(), playerPos.getY().toFloat(), playerPos.getZ().toFloat() - ).color(color.red, color.green, color.blue, alpha) - .normal(matrix3f, normal.getX().toFloat(), normal.getY().toFloat(), normal.getZ().toFloat()) - bufferBuilder.vertex( - matrix4f, entityPos.getX().toFloat(), entityPos.getY().toFloat(), entityPos.getZ().toFloat() - ).color(color.red, color.green, color.blue, alpha) - .normal(matrix3f, normal.getX().toFloat(), normal.getY().toFloat(), normal.getZ().toFloat()) - val buffer = bufferBuilder.end() - vertexBuffer.bind() - vertexBuffer.upload(buffer) - vertexBuffer.draw(viewMatrix, projMatrix, shader) - - } - - - fun renderSingleLine( - vertexBuffer: VertexBuffer, - matrixStack: MatrixStack, - entity: Entity, - player: ClientPlayerEntity?, - color: Color, - alpha: Float - ) { - val viewMatrix = matrixStack.peek().positionMatrix - val projMatrix = RenderSystem.getProjectionMatrix() - val shader: ShaderProgram? = RenderSystem.getShader() - val normal = Vec3d(entity.x - player!!.x, entity.y - player.y, entity.z - player.z) - normal.normalize() - - - val tessellator = RenderSystem.renderThreadTesselator() - val bufferBuilder = tessellator.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR) - RenderSystem.setShaderColor(color.red, color.green, color.blue, alpha) - bufferBuilder.vertex(entity.x.toFloat(), entity.y.toFloat(), entity.z.toFloat()) - .color(color.red, color.green, color.blue, alpha) - .normal(normal.x.toFloat(), normal.y.toFloat(), normal.z.toFloat()) - bufferBuilder.vertex(player.x.toFloat(), player.y.toFloat(), player.z.toFloat()) - .color(color.red, color.green, color.blue, alpha) - .normal(normal.x.toFloat(), normal.y.toFloat(), normal.z.toFloat()) - val buffer = bufferBuilder.end() - vertexBuffer.bind() - vertexBuffer.upload(buffer) - vertexBuffer.draw(viewMatrix, projMatrix, shader) - - } - - /** - * Processes events for rendering block tracers or esp's in the world. - * @param context The world render context. - */ - fun last(context: WorldRenderContext): Boolean { -// CHUNK_RADIUS = GavinsModClient.minecraftClient.options.viewDistance.value -// val minecraft = MinecraftClient.getInstance() -// val level = minecraft.world -// val player = minecraft.player -// val stack = context.matrixStack() -// assert(stack != null) -// val delta = context.tickCounter().getTickDelta(true) -// val mainCamera = minecraft.gameRenderer.camera -// val camera = mainCamera.pos -// setupRenderSystem() -// stack!!.push() -// val tessellator = RenderSystem.renderThreadTesselator() -// val buffer = tessellator.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR) -// RenderSystem.applyModelViewMatrix() -// stack.translate(-camera.x, -camera.y, -camera.z) -// assert(player != null) -// val playerPos = getNewPlayerPosition(delta, mainCamera) -// assert(level != null) -// val chunkX = player!!.chunkPos.x -// val chunkZ = player.chunkPos.z -//// drawBlockMods(level, stack, buffer, playerPos, chunkX, chunkZ, delta) -//// drawEntityMods(level, player, stack, delta, buffer, playerPos) -//// val event = WorldRenderEvent(level!!, stack, buffer, delta) -//// EventManager.eventManager.call(event) -// try { -// val e = buffer.end() -// BufferRenderer.drawWithGlobalProgram(e) -// } catch (e: IllegalStateException) { -// return false -// } -// stack.pop() -// resetRenderSystem() - return true - } - /** * Resets the render system to the default state. */ @@ -207,168 +69,6 @@ object RenderUtils { GL11.glDisable(GL11.GL_LINE_SMOOTH) } - /** - * Sets up the render system for the tracers and esps to work. - */ - private fun setupRenderSystem() { - RenderSystem.setShader { GameRenderer.getPositionColorProgram() } - RenderSystem.enableBlend() - RenderSystem.setShaderColor(1f, 1f, 1f, 1f) - } - - /** - * Draws Chest ESPs and tracers. - * - * @param level The world. - * @param stack The matrix stack. - * @param buffer The buffer to write to. - * @param playerPos The player's position. - * @param chunkX The player's chunk x. - * @param chunkZ The player's chunk z. - */ - private fun drawBlockMods( - level: ClientWorld?, - stack: MatrixStack, - buffer: BufferBuilder, - playerPos: Vec3d, - chunkX: Int, - chunkZ: Int, - delta: Float - ) { - for (x in -CHUNK_RADIUS..CHUNK_RADIUS) { - for (z in -CHUNK_RADIUS..CHUNK_RADIUS) { - val chunkX1 = chunkX + x - val chunkZ1 = chunkZ + z - if (level!!.getChunk(chunkX1, chunkZ1) != null) { - val chunk = level.getChunk(chunkX1, chunkZ1) - val blockEntities = chunk.blockEntities - for ((blockPos, blockEntity) in blockEntities) { - val aabb = Box(blockPos) - val boxPos = aabb.center - val event = BlockEntityRenderEvent(blockEntity, stack, buffer, boxPos, playerPos, delta) - EventManager.eventManager.call(event) - } - } - } - } - } - - /** - * Draws a box on the world. - * - * @param stack The matrix stack. - * @param buffer The buffer to write to. - * @param aabb The box to draw. - * @param c The color to draw the box in. - */ - @JvmOverloads - fun drawBox(stack: MatrixStack?, buffer: BufferBuilder?, aabb: Box, c: Color, alpha: Float = 1f) { - // draw vertices of the box - val x1 = aabb.minX.toFloat() - val y1 = aabb.minY.toFloat() - val z1 = aabb.minZ.toFloat() - val x2 = aabb.maxX.toFloat() - val y2 = aabb.maxY.toFloat() - val z2 = aabb.maxZ.toFloat() - val matrix4f = stack!!.peek().positionMatrix - val color = c.getAsInt(alpha) - stack.push() - renderPlane(buffer!!, matrix4f, x1, x2, y1, y1, z1, z2, color) - renderPlane(buffer, matrix4f, x2, x2, y1, y2, z1, z2, color) - renderPlane(buffer, matrix4f, x1, x2, y2, y2, z1, z2, color) - renderPlane(buffer, matrix4f, x1, x1, y1, y2, z1, z2, color) - stack.pop() - } - - /** - * Renders a 2 dimensional plane. - * @param buffer The buffer to write to. - * @param matrix4f The matrix to use. - * @param x1 The first x coordinate. - * @param x2 The second x coordinate. - * @param y1 The first y coordinate. - * @param y2 The second y coordinate. - * @param z1 The first z coordinate. - * @param z2 The second z coordinate. - * @param c The color to draw the plane in. - */ - private fun renderPlane( - buffer: BufferBuilder, - matrix4f: Matrix4f, - x1: Float, - x2: Float, - y1: Float, - y2: Float, - z1: Float, - z2: Float, - c: Int - ) { - if (x1 == x2) { - buffer.vertex(matrix4f, x1, y1, z1).color(c) - buffer.vertex(matrix4f, x1, y2, z1).color(c) - - buffer.vertex(matrix4f, x1, y2, z1).color(c) - buffer.vertex(matrix4f, x1, y2, z2).color(c) - - buffer.vertex(matrix4f, x1, y2, z2).color(c) - buffer.vertex(matrix4f, x1, y1, z2).color(c) - - buffer.vertex(matrix4f, x1, y1, z2).color(c) - buffer.vertex(matrix4f, x1, y1, z1).color(c) - } else if (z1 == z2) { - buffer.vertex(matrix4f, x1, y1, z1).color(c) - buffer.vertex(matrix4f, x2, y1, z1).color(c) - - buffer.vertex(matrix4f, x2, y1, z1).color(c) - buffer.vertex(matrix4f, x2, y2, z1).color(c) - - buffer.vertex(matrix4f, x2, y2, z1).color(c) - buffer.vertex(matrix4f, x1, y2, z1).color(c) - - buffer.vertex(matrix4f, x1, y2, z1).color(c) - buffer.vertex(matrix4f, x1, y1, z1).color(c) - } else if (y1 == y2) { - buffer.vertex(matrix4f, x1, y1, z1).color(c) - buffer.vertex(matrix4f, x2, y1, z1).color(c) - - buffer.vertex(matrix4f, x2, y1, z1).color(c) - buffer.vertex(matrix4f, x2, y1, z2).color(c) - - buffer.vertex(matrix4f, x2, y1, z2).color(c) - buffer.vertex(matrix4f, x1, y1, z2).color(c) - - buffer.vertex(matrix4f, x1, y1, z2).color(c) - buffer.vertex(matrix4f, x1, y1, z1).color(c) - } - } - - /** - * Draws the Entity based ESP's and tracers. - * - * @param level The world. - * @param player The player. - * @param stack The matrix stack. - * @param delta The change in time. - * @param buffer The buffer to write to. - * @param playerPos The player's position. - */ - private fun drawEntityMods( - level: ClientWorld?, - player: ClientPlayerEntity?, - stack: MatrixStack, - delta: Float, - buffer: BufferBuilder, - playerPos: Vec3d - ) { - level!!.entities.forEach(Consumer { e: Entity -> - if (e.squaredDistanceTo(player) > CHUNK_RADIUS * 64 * 8 || player === e) return@Consumer - val aabb = e.boundingBox - val boxPos = aabb.center - val event = EntityRenderEvent(e, stack, buffer, boxPos, playerPos, delta) - EventManager.eventManager.call(event) - }) - } - /** * Gets the bounding box of an entity. * @@ -431,36 +131,13 @@ object RenderUtils { val isLastGamma: Boolean get() = gamma <= LAST_GAMMA - /** - * Stores the current gamma value as the last gamma value. - */ - fun setLastGamma() { - if (gamma > 1) return - LAST_GAMMA = gamma - } - /** * Returns the last gamma value before the gamma was set to full bright. */ - fun getLastGamma(): Double { + private fun getLastGamma(): Double { return LAST_GAMMA } - /** - * Increments the gamma value by 0.2f for a smooth transition. - */ - private fun fadeGammaUp() { - gamma += 0.2f - } - - /** - * Decrements the gamma value by 0.2f for a smooth transition. - */ - private fun fadeGammaDown() { - gamma -= 0.2f - if (gamma < getLastGamma()) gamma = getLastGamma() - } - /** * Draws a box on screen. * @@ -530,7 +207,7 @@ object RenderUtils { return camera.pos } - fun getCameraBlockPos(): BlockPos { + private fun getCameraBlockPos(): BlockPos { val camera = GavinsModClient.minecraftClient.entityRenderDispatcher.camera return camera.blockPos } @@ -539,17 +216,16 @@ object RenderUtils { return RegionPos.fromBlockPos(getCameraBlockPos()) } - fun applyRegionalRenderOffset(stack: MatrixStack, region: RegionPos) { + private fun applyRegionalRenderOffset(stack: MatrixStack, region: RegionPos) { val offset = region.toVec3d().subtract(getCameraPos()) stack.translate(offset.x, offset.y, offset.z) } fun drawOutlinedBox(bb: Box, vertexBuffer: VertexBuffer, color: Color = Colors.WHITE, alpha: Float = 1f) { - var tessellator = RenderSystem.renderThreadTesselator() - var bufferBuilder = tessellator.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION); + val tessellator = RenderSystem.renderThreadTesselator() + val bufferBuilder = tessellator.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION); drawOutlinedBox(bb, bufferBuilder) val buffer = bufferBuilder.end() - vertexBuffer.bind() vertexBuffer.upload(buffer) VertexBuffer.unbind() @@ -687,7 +363,6 @@ object RenderUtils { matrixStack.push() val region = getCameraRegionPos() applyRegionalRenderOffset(matrixStack, region); -// RenderSystem.setShader(GameRenderer::getPositionProgram); } } diff --git a/src/main/kotlin/com/peasenet/util/math/MathUtils.kt b/src/main/kotlin/com/peasenet/util/math/MathUtils.kt index 0339b53..59f189f 100644 --- a/src/main/kotlin/com/peasenet/util/math/MathUtils.kt +++ b/src/main/kotlin/com/peasenet/util/math/MathUtils.kt @@ -32,8 +32,10 @@ import kotlin.math.atan2 import kotlin.math.sqrt /** + * A class that contains math utilities. * @author gt3ch1 - * @version 03-02-2023 + * @version 09-06-2024 + * @since 03-02-2023 */ object MathUtils { /** @@ -56,14 +58,28 @@ object MathUtils { return Rotation(pitch, yaw) } + /** + * Returns the linear interpolation of the given position. + * @param delta The delta to lerp by. + * @param pos The current position. + * @param oldPos The old position. + * @return The camera region position. + */ fun lerp(delta: Float, pos: Vec3d, oldPos: Vec3d, region: RegionPos): Vec3d { return lerp(delta, pos, oldPos).subtract(region.toVec3d()) } + /** + * Returns the linear interpolation of the given position. + * @param delta The delta to lerp by. + * @param pos The current position. + * @param oldPos The old position. + * @return The lerp position. + */ fun lerp(delta: Float, pos: Vec3d, oldPos: Vec3d): Vec3d { - val xLerped = MathHelper.lerp(delta.toDouble(), oldPos.x, pos.x) - val yLerped = MathHelper.lerp(delta.toDouble(), oldPos.y, pos.y) - val zLerped = MathHelper.lerp(delta.toDouble(), oldPos.z, pos.z) + val xLerped = MathHelper.lerp(delta.toDouble(), oldPos.x, pos.x) - pos.x + val yLerped = MathHelper.lerp(delta.toDouble(), oldPos.y, pos.y) - pos.y + val zLerped = MathHelper.lerp(delta.toDouble(), oldPos.z, pos.z) - pos.z return Vec3d(xLerped, yLerped, zLerped) } } \ No newline at end of file