Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
62 changes: 48 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,64 @@
# Automatically build the project and run any configured tests for every push
# and submitted pull request. This can help catch issues that only occur on
# certain platforms or Java versions, and provides a first line of defence
# against bad commits.

name: build
on: [pull_request, push]
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-24.04
steps:
- name: checkout repository
- name: Checkout Repository
uses: actions/checkout@v4
- name: validate gradle wrapper

- name: Validate Gradle Wrapper
uses: gradle/actions/wrapper-validation@v4
- name: setup jdk

- name: Setup JDK
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'microsoft'
- name: make gradle wrapper executable

- name: Make Gradle Wrapper Executable
run: chmod +x ./gradlew
- name: build

- name: Build Jar
run: ./gradlew build
- name: capture build artifacts

- name: Capture Build Artifacts
uses: actions/upload-artifact@v4
with:
name: Artifacts
path: build/libs/
name: mod-jar
path: build/libs/*.jar

- name: Read gradle.properties Release Flags
id: release_props
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: |
SHOULD_RELEASE=$(grep -Po '^shouldRelease=.*' gradle.properties | cut -d= -f2 | xargs)

if [ "$SHOULD_RELEASE" != "true" ]; then
echo "shouldRelease is false — skipping release"
exit 0
fi

MOD_VERSION=$(grep -Po '^modVersion=.*' gradle.properties | cut -d= -f2 | xargs)

echo "SHOULD_RELEASE=$SHOULD_RELEASE" >> $GITHUB_OUTPUT
echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "MOD_VERSION=$MOD_VERSION" >> $GITHUB_OUTPUT

- name: Create GitHub Release
if: steps.release_props.outputs.SHOULD_RELEASE == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.release_props.outputs.MOD_VERSION }}.${{ steps.release_props.outputs.SHA_SHORT }}
name: Cobalt v${{ steps.release_props.outputs.MOD_VERSION }}
files: build/libs/*.jar
body: ${{ github.event.head_commit.message }}
env:
GITHUB_TOKEN: ${{ github.token }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<h3 align="center">Cobalt</h3>

![mod-loader](https://img.shields.io/badge/modloader-Fabric-4682b4?style=for-the-badge&logoColor=white)
![minecraft-version](https://img.shields.io/badge/Minecraft-1.20.10-6BAA57?style=for-the-badge&logoColor=white)
![minecraft-version](https://img.shields.io/badge/Minecraft-1.21.10-6BAA57?style=for-the-badge&logoColor=white)
![language](https://img.shields.io/badge/version-1.0.0-FF474C?style=for-the-badge&logoColor=white)

</div>
Expand Down
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ dependencies {
modImplementation("net.fabricmc.fabric-api:fabric-api:${property("fabric_api_version")}")

modRuntimeOnly("me.djtheredstoner:DevAuth-fabric:1.2.1")
runtimeOnly("org.apache.httpcomponents:httpclient:4.5.14")

modImplementation("org.lwjgl:lwjgl-nanovg:${lwjglVersion}")
include("org.lwjgl:lwjgl-nanovg:${lwjglVersion}")
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ shouldRelease=true
lwjglVersion=3.3.3

# https://fabricmc.net/develop/
minecraft_version=1.21.11
loader_version=0.18.4
minecraft_version=1.21.10
loader_version=0.17.3
loom_version=1.13-SNAPSHOT

# Fabric API
fabric_api_version=0.141.1+1.21.11
fabric_kotlin_version=1.13.8+kotlin.2.3.0
# Dependency Versions
fabric_api_version=0.138.3+1.21.10
fabric_kotlin_version=1.13.7+kotlin.2.2.21
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Mixin(CrashReport.class)
public abstract class AddonList_CrashReportMixin {

@Inject(method = "getDetails*", at = @At("HEAD"))
@Inject(method = "getDetails(Ljava/lang/StringBuilder;)V", at = @At("HEAD"))
private void addAddonInfo(StringBuilder crashReportBuilder, CallbackInfo ci) {
String addons = AddonLoader.INSTANCE.getAddons().stream()
.map(info -> info.getFirst().getName() + " v" + info.getFirst().getVersion())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class WorldContext_LevelRendererMixin {

@Unique
private final WorldRenderContext ctx = new WorldRenderContext();

@Shadow
@Final
private RenderBuffers renderBuffers;
Expand All @@ -42,14 +41,9 @@ private void render(GraphicsResourceAllocator allocator, DeltaTracker tickCounte
}


@ModifyExpressionValue(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;prepareCullFrustum(Lorg/joml/Matrix4f;Lorg/joml/Matrix4f;Lnet/minecraft/world/phys/Vec3;)Lnet/minecraft/client/renderer/culling/Frustum;"))
private Frustum onSetupFrustum(Frustum frustum) {
ctx.setFrustum(frustum);
return frustum;
}

@Inject(method = "method_62214", at = @At("RETURN"))
private void postRender(GpuBufferSlice gpuBufferSlice, LevelRenderState levelRenderState, ProfilerFiller profilerFiller, Matrix4f matrix4f, ResourceHandle resourceHandle, ResourceHandle resourceHandle2, boolean bl, ResourceHandle resourceHandle3, ResourceHandle resourceHandle4, CallbackInfo ci) {
private void postRender(GpuBufferSlice gpuBufferSlice, LevelRenderState worldRenderState, ProfilerFiller profiler, Matrix4f matrix4f, ResourceHandle handle, ResourceHandle handle2, boolean bl, Frustum frustum, ResourceHandle handle3, ResourceHandle handle4, CallbackInfo ci) {
ctx.setFrustum(frustum);
new WorldRenderEvent.Last(ctx).post();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/cobalt/Cobalt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object Cobalt : ClientModInitializer {

listOf(
TickScheduler, MainCommand, NotificationManager,
RotationExecutor
RotationExecutor,
).forEach { EventBus.register(it) }

Config.loadModulesConfig()
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/org/cobalt/api/command/CommandManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ import org.cobalt.api.command.annotation.SubCommand

object CommandManager {

private val commandsList = mutableListOf<Command>()
private val commands = mutableListOf<Command>()

@JvmStatic
fun register(vararg commands: Command) {
commands.forEach(commandsList::add)
fun register(command: Command) {
commands.add(command)
}

internal fun dispatchAll() {
ClientCommandRegistrationCallback.EVENT.register(CommandManager::dispatchAll)
}

private fun dispatchAll(dispatcher: CommandDispatcher<FabricClientCommandSource>, access: CommandBuildContext) {
commandsList.forEach { command ->
commands.forEach { command ->
val rootNames = listOf(command.name) + command.aliases

rootNames.forEach { rootName ->
Expand Down
10 changes: 10 additions & 0 deletions src/main/kotlin/org/cobalt/api/util/ChatUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ object ChatUtils {
private val mc: Minecraft =
Minecraft.getInstance()

// used for sendDebug to prevent resending same message multiple times in a row
private var lastMessage: String = ""

/**
* Function to display a message in Minecraft chat with the prefix "[Cobalt Debug]"
*
* @param message The string to send to chat after the prefix
*/
@JvmStatic
fun sendDebug(message: String) {
if (mc.player == null || mc.level == null) return
if (message == lastMessage) return

mc.gui.chat.addMessage(
Component.empty().append(debugPrefix)
.append(Component.literal("${ChatFormatting.RESET}$message"))
)

lastMessage = message
}

/**
Expand All @@ -33,6 +41,8 @@ object ChatUtils {
*/
@JvmStatic
fun sendMessage(message: String) {
if (mc.player == null || mc.level == null) return

mc.gui.chat.addMessage(
Component.empty().append(prefix)
.append(Component.literal("${ChatFormatting.RESET}$message"))
Expand Down
76 changes: 59 additions & 17 deletions src/main/kotlin/org/cobalt/api/util/render/Render3D.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package org.cobalt.api.util.render

import com.mojang.blaze3d.systems.RenderSystem
import java.awt.Color
import net.minecraft.gizmos.Gizmos
import net.minecraft.gizmos.GizmoStyle
import net.minecraft.util.ARGB
import kotlin.math.max
import kotlin.math.min
import net.minecraft.client.renderer.MultiBufferSource
import net.minecraft.client.renderer.ShapeRenderer
import net.minecraft.world.phys.AABB
import net.minecraft.world.phys.Vec3
import org.cobalt.api.event.impl.render.WorldRenderContext
import org.cobalt.internal.helper.RenderLayers
import org.joml.Vector3f

object Render3D {

Expand All @@ -16,15 +20,38 @@ object Render3D {
return
}

val strokeColor = ARGB.color(color.alpha, color.red, color.green, color.blue)
val fillColor = ARGB.color(150, color.red, color.green, color.blue)
val matrix = context.matrixStack ?: return
val bufferSource = context.consumers as? MultiBufferSource.BufferSource ?: return

val style = GizmoStyle.strokeAndFill(strokeColor, 2.5f, fillColor)
val props = Gizmos.cuboid(box, style)
val r = color.red / 255f
val g = color.green / 255f
val b = color.blue / 255f

if (esp) {
props.setAlwaysOnTop()
}
val fillLayer = if (esp) RenderLayers.TRIANGLE_STRIP_ESP else RenderLayers.TRIANGLE_STRIP
val lineLayer = if (esp) RenderLayers.LINE_LIST_ESP else RenderLayers.LINE_LIST

matrix.pushPose()
with(context.camera.position) { matrix.translate(-x, -y, -z) }

ShapeRenderer.addChainedFilledBoxVertices(
matrix,
bufferSource.getBuffer(fillLayer),
box.minX, box.minY, box.minZ,
box.maxX, box.maxY, box.maxZ,
r, g, b, 150 / 255F
)

ShapeRenderer.renderLineBox(
matrix.last(),
bufferSource.getBuffer(lineLayer),
box.minX, box.minY, box.minZ,
box.maxX, box.maxY, box.maxZ,
r, g, b, 1f
)

matrix.popPose()
bufferSource.endBatch(fillLayer)
bufferSource.endBatch(lineLayer)
}

@JvmStatic
Expand All @@ -38,17 +65,32 @@ object Render3D {
) {
if (!FrustumUtils.isVisible(
context.frustum,
minOf(start.x, end.x), minOf(start.y, end.y), minOf(start.z, end.z),
maxOf(start.x, end.x), maxOf(start.y, end.y), maxOf(start.z, end.z)
min(start.x, end.x), min(start.y, end.y), min(start.z, end.z),
max(start.x, end.x), max(start.y, end.y), max(start.z, end.z)
)
) return

val argbColor = ARGB.color(color.alpha, color.red, color.green, color.blue)
val props = Gizmos.line(start, end, argbColor, thickness)
val matrix = context.matrixStack ?: return
val bufferSource = context.consumers as? MultiBufferSource.BufferSource ?: return
val layer = if (esp) RenderLayers.LINE_LIST_ESP else RenderLayers.LINE_LIST
RenderSystem.lineWidth(thickness)

if (esp) {
props.setAlwaysOnTop()
}
matrix.pushPose()
with(context.camera.position) { matrix.translate(-x, -y, -z) }

val startOffset = Vector3f(start.x.toFloat(), start.y.toFloat(), start.z.toFloat())
val direction = end.subtract(start)

ShapeRenderer.renderVector(
matrix,
bufferSource.getBuffer(layer),
startOffset,
direction,
color.rgb
)

matrix.popPose()
bufferSource.endBatch(layer)
}

}
39 changes: 39 additions & 0 deletions src/main/kotlin/org/cobalt/internal/helper/RenderLayers.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.cobalt.internal.helper

import net.minecraft.client.renderer.RenderStateShard
import net.minecraft.client.renderer.RenderType
import net.minecraft.client.renderer.RenderType.CompositeRenderType

internal object RenderLayers {

val LINE_LIST: RenderType = RenderType.create(
"line-list", RenderType.TRANSIENT_BUFFER_SIZE,
RenderPipelines.LINE_LIST,
RenderType.CompositeState.builder()
.setLayeringState(RenderStateShard.VIEW_OFFSET_Z_LAYERING)
.createCompositeState(false)
)

val LINE_LIST_ESP: RenderType = RenderType.create(
"line-list-esp", RenderType.TRANSIENT_BUFFER_SIZE,
RenderPipelines.LINE_LIST_ESP,
RenderType.CompositeState.builder().createCompositeState(false)
)

val TRIANGLE_STRIP: CompositeRenderType = RenderType.create(
"triangle_strip", RenderType.TRANSIENT_BUFFER_SIZE,
false, true,
RenderPipelines.TRIANGLE_STRIP,
RenderType.CompositeState.builder()
.setLayeringState(RenderStateShard.VIEW_OFFSET_Z_LAYERING)
.createCompositeState(false)
)

val TRIANGLE_STRIP_ESP: CompositeRenderType = RenderType.create(
"triangle_strip_esp", RenderType.TRANSIENT_BUFFER_SIZE,
false, true,
RenderPipelines.TRIANGLE_STRIP_ESP,
RenderType.CompositeState.builder().createCompositeState(false)
)

}
Loading
Loading