Skip to content

Commit 7744dc0

Browse files
committed
feat: Add 1.21.5 support
1 parent ca169c1 commit 7744dc0

File tree

14 files changed

+765
-7
lines changed

14 files changed

+765
-7
lines changed

build-src/src/main/kotlin/moulconfig.fabric.gradle.kts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@ the<UniminedExtension>().minecraft {
1919
}
2020

2121
fabric {
22-
loader("0.16.9")
22+
loader("0.16.13")
2323
if (hasAW)
2424
accessWidener(aF)
2525
}
26+
mods {
27+
this.modImplementation {
28+
this.mixinRemap {
29+
this.enableBaseMixin()
30+
}
31+
}
32+
}
2633
runs {
2734
config("client") {
2835
jvmArgs("-Dmoulconfig.testmod=true")

build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
plugins {
32
base
43
id("moulconfig.base")
@@ -10,6 +9,9 @@ mkdocs {
109
python {
1110
pip("mkdocs-zettelkasten:0.1.9")
1211
}
12+
publish {
13+
docPath = ""
14+
}
1315
strict = false
1416
}
1517

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
mc_legacy = "1.8.9"
33
mcp = "22-1.8.9"
44
forge_loader = "11.15.1.2318-1.8.9"
5-
mkdocs = "2.4.0"
5+
mkdocs = "4.0.1"
66

77
[libraries]
88

99
[plugins]
10-
mkdocs = { id = "ru.vyarus.mkdocs", version.ref = "mkdocs" }
10+
mkdocs = { id = "ru.vyarus.mkdocs-build", version.ref = "mkdocs" }
1111

modern/1.21.4/gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
moulconfig.minecraft=1.21.4
2-
moulconfig.yarn=1
3-
moulconfig.fabric=0.111.0+1.21.4
2+
moulconfig.yarn=8
3+
moulconfig.fabric=0.119.2+1.21.4

modern/1.21.5/build.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
plugins {
2+
id("moulconfig.fabric")
3+
}
4+
fabricDeps {
5+
impl("fabric-command-api-v2")
6+
}
7+
8+
java.toolchain.languageVersion.set(JavaLanguageVersion.of(21))
9+

modern/1.21.5/gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
moulconfig.minecraft=1.21.5
2+
moulconfig.yarn=1
3+
moulconfig.fabric=0.119.9+1.21.5
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package io.github.notenoughupdates.moulconfig.gui
2+
3+
import io.github.notenoughupdates.moulconfig.platform.ModernRenderContext
4+
import net.minecraft.client.MinecraftClient
5+
import net.minecraft.client.gui.DrawContext
6+
import net.minecraft.client.gui.screen.Screen
7+
import net.minecraft.text.Text
8+
9+
/**
10+
* Wrapper for a [GuiContext]. Fabric specific equivalent of GuiScreenElementWrapperNew.
11+
*/
12+
open class GuiComponentWrapper(
13+
val context: GuiContext,
14+
label: Text = Text.literal("")
15+
) : Screen(label) {
16+
init {
17+
context.setCloseRequestHandler(this::close)
18+
}
19+
20+
open fun createContext(drawContext: DrawContext? = null): GuiImmediateContext {
21+
val mouse = MinecraftClient.getInstance().mouse
22+
val window = client!!.window
23+
val x = (mouse.x * window.scaledWidth.toDouble() / window.width.toDouble()).toInt()
24+
val y = (mouse.y * window.scaledHeight.toDouble() / window.height.toDouble()).toInt()
25+
return GuiImmediateContext(
26+
ModernRenderContext(
27+
drawContext ?: DrawContext(
28+
MinecraftClient.getInstance(),
29+
MinecraftClient.getInstance().bufferBuilders.entityVertexConsumers
30+
)
31+
),
32+
0, 0,
33+
window.scaledWidth,
34+
window.scaledHeight,
35+
x, y, x, y, x.toFloat(), y.toFloat()
36+
)
37+
}
38+
39+
override fun close() {
40+
if (context.onBeforeClose() == CloseEventListener.CloseAction.NO_OBJECTIONS_TO_CLOSE) {
41+
super.close()
42+
}
43+
}
44+
45+
override fun removed() {
46+
context.onAfterClose()
47+
}
48+
49+
50+
override fun render(drawContext: DrawContext?, i: Int, j: Int, f: Float) {
51+
super.render(drawContext, i, j, f)
52+
val ctx = createContext(drawContext)
53+
context.root.render(ctx)
54+
ctx.renderContext.doDrawTooltip()
55+
}
56+
57+
override fun charTyped(c: Char, i: Int): Boolean {
58+
return context.root.keyboardEvent(KeyboardEvent.CharTyped(c), createContext())
59+
}
60+
61+
override fun keyPressed(i: Int, j: Int, k: Int): Boolean {
62+
if (context.root.keyboardEvent(KeyboardEvent.KeyPressed(i, true), createContext()))
63+
return true
64+
if (i == 256) {
65+
if (context.focusedElement != null) {
66+
context.focusedElement = null
67+
} else {
68+
close()
69+
}
70+
return true
71+
}
72+
return false
73+
}
74+
75+
override fun keyReleased(i: Int, j: Int, k: Int): Boolean {
76+
return context.root.keyboardEvent(KeyboardEvent.KeyPressed(i, false), createContext())
77+
}
78+
79+
override fun mouseMoved(d: Double, e: Double) {
80+
val ctx = createContext()
81+
val di = d.toInt()
82+
val ei = e.toInt()
83+
val event = MouseEvent.Move(d.toFloat() - ctx.mouseX, e.toFloat() - ctx.mouseY)
84+
val repositionedContext = ctx.copy(mouseX = di, mouseY = ei, absoluteMouseX = di, absoluteMouseY = ei)
85+
context.root.mouseEvent(event, repositionedContext)
86+
}
87+
88+
override fun mouseClicked(d: Double, e: Double, i: Int): Boolean {
89+
return context.root.mouseEvent(MouseEvent.Click(i, true), createContext())
90+
}
91+
92+
override fun mouseReleased(d: Double, e: Double, i: Int): Boolean {
93+
return context.root.mouseEvent(MouseEvent.Click(i, false), createContext())
94+
}
95+
96+
override fun mouseScrolled(
97+
mouseX: Double,
98+
mouseY: Double,
99+
horizontalAmount: Double,
100+
verticalAmount: Double
101+
): Boolean {
102+
return context.root.mouseEvent(MouseEvent.Scroll(verticalAmount.toFloat()), createContext())
103+
}
104+
105+
override fun mouseDragged(d: Double, e: Double, i: Int, f: Double, g: Double): Boolean {
106+
return true
107+
}
108+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package io.github.notenoughupdates.moulconfig.gui
2+
3+
import io.github.notenoughupdates.moulconfig.common.IMinecraft
4+
import net.minecraft.client.gui.DrawContext
5+
import net.minecraft.client.gui.screen.Screen
6+
import net.minecraft.text.Text
7+
8+
class GuiElementWrapper(
9+
val guiElement: GuiElement,
10+
) : Screen(Text.literal("")) {
11+
override fun render(context: DrawContext?, mouseX: Int, mouseY: Int, delta: Float) {
12+
super.render(context, mouseX, mouseY, delta)
13+
guiElement.render()
14+
}
15+
16+
override fun charTyped(c: Char, i: Int): Boolean {
17+
guiElement.keyboardInput(KeyboardEvent.CharTyped(c))
18+
return true
19+
}
20+
21+
override fun keyPressed(i: Int, j: Int, k: Int): Boolean {
22+
if (guiElement.keyboardInput(KeyboardEvent.KeyPressed(i, true)))
23+
return true
24+
if (i == 256) {
25+
close()
26+
return true
27+
}
28+
return false
29+
}
30+
31+
override fun keyReleased(i: Int, j: Int, k: Int): Boolean {
32+
return guiElement.keyboardInput(KeyboardEvent.KeyPressed(i, false))
33+
}
34+
35+
override fun mouseMoved(d: Double, e: Double) {
36+
val di = d.toInt()
37+
val ei = e.toInt()
38+
val event = MouseEvent.Move(d.toFloat() - IMinecraft.instance.mouseX, e.toFloat() - IMinecraft.instance.mouseY)
39+
guiElement.mouseInput(di, ei, event)
40+
}
41+
42+
override fun mouseClicked(d: Double, e: Double, i: Int): Boolean {
43+
return guiElement.mouseInput(d.toInt(), e.toInt(), MouseEvent.Click(i, true))
44+
}
45+
46+
override fun mouseReleased(d: Double, e: Double, i: Int): Boolean {
47+
return guiElement.mouseInput(d.toInt(), e.toInt(), MouseEvent.Click(i, false))
48+
}
49+
50+
override fun mouseScrolled(
51+
mouseX: Double,
52+
mouseY: Double,
53+
horizontalAmount: Double,
54+
verticalAmount: Double
55+
): Boolean {
56+
return guiElement.mouseInput(
57+
mouseX.toInt(),
58+
mouseY.toInt(),
59+
MouseEvent.Scroll(verticalAmount.toFloat()),
60+
)
61+
}
62+
63+
override fun mouseDragged(d: Double, e: Double, i: Int, f: Double, g: Double): Boolean {
64+
return true // TODO?
65+
}
66+
67+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package io.github.notenoughupdates.moulconfig.platform
2+
3+
import io.github.notenoughupdates.moulconfig.common.IFontRenderer
4+
import net.minecraft.client.font.TextRenderer
5+
import net.minecraft.client.util.ChatMessages
6+
import net.minecraft.text.Text
7+
8+
class ModernFontRenderer(val textRenderer: TextRenderer) :
9+
IFontRenderer {
10+
override val height: Int
11+
get() = textRenderer.fontHeight
12+
13+
override fun getStringWidth(string: String): Int {
14+
return textRenderer.getWidth(string)
15+
}
16+
17+
override fun getCharWidth(char: Char): Int {
18+
return textRenderer.getWidth(char + "")
19+
}
20+
21+
override fun splitText(text: String, width: Int): List<String> {
22+
val lines = ChatMessages.breakRenderedChatMessageLines(Text.literal(text), width, textRenderer)
23+
val strings: MutableList<String> = ArrayList(lines.size)
24+
for (iChatComponent in lines) {
25+
var formattedText = ""
26+
iChatComponent.accept { i, style, j ->
27+
formattedText += j.toChar()
28+
true
29+
}
30+
strings.add(formattedText)
31+
}
32+
return strings
33+
34+
}
35+
36+
override fun trimStringToWidth(string: String, maxWidth: Int, reverse: Boolean): String {
37+
return textRenderer.trimToWidth(string, maxWidth, reverse)
38+
}
39+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package io.github.notenoughupdates.moulconfig.platform
2+
3+
import io.github.notenoughupdates.moulconfig.common.IItemStack
4+
import io.github.notenoughupdates.moulconfig.common.MyResourceLocation
5+
import net.minecraft.client.MinecraftClient
6+
import net.minecraft.item.Item
7+
import net.minecraft.item.ItemStack
8+
import net.minecraft.item.tooltip.TooltipType
9+
import net.minecraft.registry.Registries
10+
import net.minecraft.world.World
11+
12+
class ModernItemStack private constructor(val backing: ItemStack) : IItemStack {
13+
override fun getLore(): List<String> {
14+
return backing.getTooltip(Item.TooltipContext.create(null as World?), MinecraftClient.getInstance().player, TooltipType.BASIC).map { it.string }
15+
}
16+
17+
override fun getDisplayName(): String {
18+
return backing.name.string
19+
}
20+
21+
override fun getStackSize(): Int {
22+
return backing.count
23+
}
24+
25+
override fun getItemId(): MyResourceLocation {
26+
return MoulConfigPlatform.fromIdentifier(Registries.ITEM.getId(backing.item))
27+
}
28+
29+
companion object {
30+
@JvmStatic
31+
fun of(itemStack: ItemStack): IItemStack {
32+
return ModernItemStack(itemStack)
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)