Skip to content

Commit

Permalink
feat: Minecraft 1.21.1 (#4)
Browse files Browse the repository at this point in the history
* ci: make builds faster by disabling gradle daemons

See https://discuss.gradle.org/t/gradle-daemon-in-ci/20053

* chore: initial conversion to 1.21.1

* fix(doc): link to GameRenderer#render

* fix(InGameHudMixin): update params
  • Loading branch information
DataM0del authored Dec 22, 2024
1 parent d1d2549 commit 733a40e
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
java-version: 21
distribution: 'microsoft'
- name: build
run: ./gradlew build
run: ./gradlew build --no-daemon
- name: capture build artifacts
uses: actions/upload-artifact@v4
with:
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.16.4
yarn_mappings=1.16.4+build.9
loader_version=0.15.11
minecraft_version=1.21.1
yarn_mappings=1.21.1+build.3
loader_version=0.16.9

# Mod Properties
mod_version=1.0.0
maven_group=info.opensigma
archives_base_name=opensigma

# Dependencies
fabric_version=0.42.0+1.16
fabric_version=0.110.0+1.21.1
orbit_version=0.2.4
reflections_version=0.10.2
kotlin_version=2.1.0
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/info/opensigma/mixin/ClientConnectionMixin.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package info.opensigma.mixin;


import info.opensigma.OpenSigma;
import info.opensigma.event.impl.packet.ReceivePacketEvent;
import info.opensigma.event.impl.packet.SendPacketEvent;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.Packet;
import net.minecraft.network.PacketCallbacks;
import net.minecraft.network.packet.Packet;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -17,14 +15,14 @@
@Mixin(ClientConnection.class)
public class ClientConnectionMixin {
@Inject(
method = "send(Lnet/minecraft/network/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V",
method = "sendInternal",
at = @At(value = "HEAD")
)
public void onSend(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> callback, CallbackInfo ci) {
public void onSend(Packet<?> packet, PacketCallbacks callbacks, boolean flush, CallbackInfo ci) {
OpenSigma.getInstance().getEventBus().post(new SendPacketEvent(packet));
}
@Inject(
method = "channelRead0(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/Packet;)V",
method = "channelRead0(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/packet/Packet;)V",
at = @At(value = "HEAD")
)
public void onReceive(ChannelHandlerContext channelHandlerContext, Packet<?> packet, CallbackInfo ci) {
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/info/opensigma/mixin/GameRendererMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@
import info.opensigma.event.impl.render.Render2DEvent;
import info.opensigma.event.impl.render.Render3DEvent;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.RenderTickCounter;
import net.minecraft.client.util.math.MatrixStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
* Hooks [{@link GameRenderer#renderWorld(float, long, MatrixStack)}] to post [{@link Render2DEvent}] events.
* We aren't hooking [{@link GameRenderer#render(float, long, boolean)}
* Hooks [{@link GameRenderer#renderWorld(RenderTickCounter)}] to post [{@link Render2DEvent}] events.
* We aren't hooking [{@link GameRenderer#render(RenderTickCounter, boolean)}
* because something else could call this, & we wouldn't send the event when we should've,
* even though it doesn't really matter.
*/

@Mixin(GameRenderer.class)
public class GameRendererMixin {
@Inject(method = "renderWorld", at = @At(value = "HEAD"))
public void onRenderWorld(float tickDelta, long limitTime, MatrixStack matrix, CallbackInfo ci) {
OpenSigma.getInstance().getEventBus().post(new Render3DEvent(tickDelta, limitTime));
public void onRenderWorld(RenderTickCounter tickCounter, CallbackInfo ci) {
OpenSigma.getInstance().getEventBus().post(new Render3DEvent(tickCounter.getTickDelta(true), tickCounter.getLastDuration()));
}
}
6 changes: 4 additions & 2 deletions src/main/java/info/opensigma/mixin/InGameHudMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import info.opensigma.OpenSigma;
import info.opensigma.event.impl.render.Render2DEvent;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.render.RenderTickCounter;
import net.minecraft.client.util.math.MatrixStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -12,7 +14,7 @@
@Mixin(InGameHud.class)
public class InGameHudMixin {
@Inject(method = "render", at = @At("TAIL"))
private void onRender(MatrixStack matrices, float tickDelta, CallbackInfo ci) {
OpenSigma.getInstance().getEventBus().post(new Render2DEvent(matrices, tickDelta));
private void onRender(DrawContext context, RenderTickCounter tickCounter, CallbackInfo ci) {
OpenSigma.getInstance().getEventBus().post(new Render2DEvent(context.getMatrices(), tickCounter.getTickDelta(true)));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.opensigma.event.impl.packet

import info.opensigma.event.type.CancellableEvent
import net.minecraft.network.Packet
import net.minecraft.network.packet.Packet

class ReceivePacketEvent(val packet: Packet<*>) : CancellableEvent()
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package info.opensigma.event.impl.packet

import info.opensigma.event.type.CancellableEvent
import net.minecraft.network.Packet
import net.minecraft.network.packet.Packet

class SendPacketEvent : CancellableEvent {
var packet: Packet<*>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package info.opensigma.event.impl.render

data class Render3DEvent(val tickDelta: Float, val startTime: Long)
data class Render3DEvent(val tickDelta: Float, val startTime: Float)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ClickGuiModule : Module("ClickGui", "ClickGui", GLFW.GLFW_KEY_RIGHT_SHIFT)
private val clickGui = ClickGui()

override fun onEnable() {
client?.openScreen(clickGui)
client?.setScreen(clickGui)

toggle()
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/info/opensigma/ui/clickgui/ClickGui.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package info.opensigma.ui.clickgui
import info.opensigma.module.data.ModuleCategory
import info.opensigma.ui.clickgui.frame.Frame
import info.opensigma.ui.clickgui.frame.impl.CategoryFrame
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.gui.screen.Screen
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.text.Text

class ClickGui : Screen(Text.of("ClickGui")) {

private val frames = mutableListOf<Frame>()
override fun isPauseScreen(): Boolean {
override fun shouldPause(): Boolean {
return false
}

Expand All @@ -31,8 +31,8 @@ class ClickGui : Screen(Text.of("ClickGui")) {
}
}

override fun render(matrices: MatrixStack, mouseX: Int, mouseY: Int, delta: Float) =
frames.forEach { it.draw(matrices, mouseX, mouseY) }
override fun render(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) =
frames.forEach { it.render(context, mouseX, mouseY, delta) }

override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean =
frames.any { it.mouseClick(mouseX, mouseY, button) }
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/info/opensigma/ui/clickgui/frame/Frame.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package info.opensigma.ui.clickgui.frame

import info.opensigma.system.IMinecraft
import info.opensigma.util.math.GeometryUtils
import net.minecraft.client.gui.DrawableHelper
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.gui.Drawable

abstract class Frame : DrawableHelper(), IMinecraft {
abstract class Frame : Drawable, IMinecraft {

open var posX = 0.0
open var posY = 0.0
Expand All @@ -14,16 +14,16 @@ abstract class Frame : DrawableHelper(), IMinecraft {
private var dragX = 0.0
private var dragY = 0.0

fun draw(matrices: MatrixStack, mouseX: Int, mouseY: Int) {
override fun render(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) {
if (dragging) {
posX = mouseX - dragX
posY = mouseY - dragY
}

drawFrame(matrices, mouseX, mouseY)
drawFrame(context, mouseX, mouseY, delta)
}

protected abstract fun drawFrame(matrices: MatrixStack, mouseX: Int, mouseY: Int)
protected abstract fun drawFrame(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float)

fun mouseClick(mouseX: Double, mouseY: Double, button: Int): Boolean {
if (GeometryUtils.isInBounds(mouseX, mouseY, posX, posY, getInteractionBounds()[0], getInteractionBounds()[1], true)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package info.opensigma.ui.clickgui.frame.impl

import info.opensigma.ui.clickgui.frame.Frame
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.util.math.MatrixStack
import java.awt.Color

class CategoryFrame(
override var posX: Double,
override var posY: Double
) : Frame() {
override fun drawFrame(matrices: MatrixStack, mouseX: Int, mouseY: Int) {
fill(matrices, posX.toInt(), posY.toInt(), (posX + 100).toInt(), (posY + 30).toInt(), Color(255, 255, 255, 210).rgb)
fill(matrices, posX.toInt(), (posY + 30).toInt(), (posX + 100).toInt(), (posY + 160).toInt(), -1)
override fun drawFrame(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) {
context.fill(
posX.toInt(), posY.toInt(),
(posX + 100).toInt(), (posY + 30).toInt(),
Color(255, 255, 255, 210).rgb
)
context.fill(
posX.toInt(), (posY + 30).toInt(),
(posX + 100).toInt(), (posY + 160).toInt(),
-1
)
}

override fun mouseClickFrame(mouseX: Double, mouseY: Double, button: Int) = false
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"depends": {
"fabricloader": ">=0.15.11",
"fabric-language-kotlin": ">=1.13.0+kotlin.${kotlin_version}",
"minecraft": "~1.16.4",
"minecraft": "~1.21.1",
"java": ">=8",
"fabric": "*"
}
Expand Down

0 comments on commit 733a40e

Please sign in to comment.