Skip to content

Commit

Permalink
Doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
GT3CH1 committed Sep 7, 2024
1 parent 25c0ee2 commit 8fc48fc
Show file tree
Hide file tree
Showing 24 changed files with 258 additions and 576 deletions.
5 changes: 0 additions & 5 deletions src/main/kotlin/com/peasenet/main/GavinsModClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ class GavinsModClient : ClientModInitializer {
if (m.isActive || m.isDeactivating) m.onTick()
}
})
WorldRenderEvents.LAST.register(WorldRenderEvents.Last { context: WorldRenderContext ->
RenderUtils.last(
context
)
})
}


Expand Down
27 changes: 20 additions & 7 deletions src/main/kotlin/com/peasenet/mods/commons/BlockEspTracerCommon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<T : IBlockEspTracerConfig>(
name: String,
translationKey: String,
Expand All @@ -71,9 +82,9 @@ abstract class BlockEspTracerCommon<T : IBlockEspTracerConfig>(
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 =
Expand Down Expand Up @@ -112,7 +123,9 @@ abstract class BlockEspTracerCommon<T : IBlockEspTracerConfig>(
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() {
Expand Down
13 changes: 13 additions & 0 deletions src/main/kotlin/com/peasenet/mods/esp/BlockEntityEsp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<T : BlockEntity>(
name: String, translationKey: String, chatCommand: String, val filter: (BlockEntity) -> Boolean
) : EspMod<T>(
Expand All @@ -46,6 +58,7 @@ abstract class BlockEntityEsp<T : BlockEntity>(
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)
}
}
Expand Down
82 changes: 29 additions & 53 deletions src/main/kotlin/com/peasenet/mods/esp/EntityEsp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<T : Entity>(
name: String, translationKey: String, chatCommand: String, val entityFilter: (Entity) -> Boolean
) : EspMod<T>(name, translationKey, chatCommand) {
Expand All @@ -57,74 +68,39 @@ abstract class EntityEsp<T : Entity>(
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()
BufferRenderer.drawWithGlobalProgram(end)
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
}
25 changes: 14 additions & 11 deletions src/main/kotlin/com/peasenet/mods/esp/ModBlockEsp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<BlockEspConfig>(
"Block ESP",
class ModBlockEsp : BlockEspTracerCommon<BlockEspConfig>("Block ESP",
"gavinsmod.mod.esp.blockesp",
"blockesp",
ModCategory.ESP,
{ minecraftClient.setScreen(GuiBlockEsp()) }), RenderListener {
private var count = 0

override fun onEnable() {
super.onEnable()
Expand All @@ -73,22 +75,23 @@ class ModBlockEsp : BlockEspTracerCommon<BlockEspConfig>(
}

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() }) {
for (block in chunk.blocks.values) {
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()
}
Expand Down
12 changes: 3 additions & 9 deletions src/main/kotlin/com/peasenet/mods/esp/ModChestEsp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChestBlockEntity>("Chest ESP",
"gavinsmod.mod.esp.chest",
Expand Down
21 changes: 3 additions & 18 deletions src/main/kotlin/com/peasenet/mods/esp/ModEntityItemEsp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemEntity>("Item ESP",
"gavinsmod.mod.esp.item",
Expand Down
11 changes: 4 additions & 7 deletions src/main/kotlin/com/peasenet/mods/esp/ModEntityPlayerEsp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlayerEntity>(
"Player ESP",
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/com/peasenet/mods/esp/ModFurnaceEsp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlockEntity>(
"Furnace ESP",
Expand Down
Loading

0 comments on commit 8fc48fc

Please sign in to comment.