Skip to content

Commit 83fe852

Browse files
committed
(janky) stonecutter implementation + compile against more mc versions
1 parent 016ffbd commit 83fe852

File tree

11 files changed

+154
-76
lines changed

11 files changed

+154
-76
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
run: chmod +x ./gradlew
2929

3030
- name: Build
31-
run: ./gradlew build --no-daemon
31+
run: ./gradlew chiseledBuild --no-daemon
3232

3333
- name: Upload Build Artifacts
3434
uses: actions/upload-artifact@v4

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,22 @@ MineMarkCore<MyStyle, MyRenderObject> core = MineMarkCore.<MyStyle, MyRenderObje
8989

9090
Then you have to call `core.parse(myStyle, markdown)` to parse the markdown, this will return a `MineMarkElement`.
9191
This element has a `draw`, `beforeDraw` and `onMouseClick` method that should be called by your rendering
92-
implementation.
92+
implementation.
93+
94+
## Building
95+
96+
To build MineMark, you should run the `chiseledBuild` task or build a specific subproject, the root `build` task will
97+
throw errors!
98+
99+
Example to build everything:
100+
```shell
101+
./gradlew chiseledBuild
102+
```
103+
Example to build the root project:
104+
```shell
105+
./gradlew :build
106+
```
107+
Example to build the elementa subproject project:
108+
```shell
109+
./gradlew elementa:build
110+
```

build.gradle.kts

Lines changed: 75 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -36,62 +36,81 @@ java {
3636
targetCompatibility = JavaVersion.VERSION_1_8
3737
}
3838

39-
//tasks {
40-
// register("chiseledBuild") {
41-
// project.subprojects.forEach { subProject ->
42-
// if (!subProject.name.contains("minecraft")) {
43-
// dependsOn(subProject.tasks.named("build"))
44-
// }
45-
// }
46-
// }
47-
//}
48-
49-
//allprojects {
50-
// apply(plugin = "java-library")
51-
// apply(plugin = "maven-publish")
52-
//
53-
// java {
54-
// withSourcesJar()
55-
// withJavadocJar()
56-
// }
57-
//
58-
// repositories {
59-
// mavenCentral()
60-
// }
61-
//
62-
// publishing {
63-
// publications {
64-
// var name = project.name.lowercase()
65-
// name = if (name != "minemark") "minemark-$name" else "minemark-core"
66-
// register<MavenPublication>(name) {
67-
// groupId = "dev.dediamondpro"
68-
// artifactId = name
69-
//
70-
// from(components["java"])
71-
// }
72-
// }
73-
// repositories {
74-
// maven {
75-
// name = "diamond"
76-
//
77-
// url = uri("https://maven.dediamondpro.dev/releases")
78-
//
79-
// credentials {
80-
// username = System.getenv("MAVEN_DIAMOND_USER")
81-
// password = System.getenv("MAVEN_DIAMOND_PASSWORD")
82-
// }
83-
//
84-
// version = rootProject.version
85-
// }
86-
// }
87-
// }
88-
//}
89-
90-
//subprojects {
91-
// dependencies {
92-
// implementation(project.rootProject)
93-
// }
94-
//}
39+
tasks {
40+
register("chiseledBuild") {
41+
project.allprojects.forEach { subProject ->
42+
if (!subProject.name.contains("minecraft")) {
43+
dependsOn(subProject.tasks.named("build"))
44+
}
45+
}
46+
}
47+
register("chiseledPublish") {
48+
project.allprojects.forEach { subProject ->
49+
if (!subProject.name.contains("minecraft")) {
50+
dependsOn(subProject.tasks.named("publish"))
51+
}
52+
}
53+
}
54+
register("chiseledPublishToMavenLocal") {
55+
project.allprojects.forEach { subProject ->
56+
if (!subProject.name.contains("minecraft")) {
57+
dependsOn(subProject.tasks.named("publishToMavenLocal"))
58+
}
59+
}
60+
}
61+
}
62+
63+
allprojects {
64+
apply(plugin = "java-library")
65+
apply(plugin = "maven-publish")
66+
67+
java {
68+
withSourcesJar()
69+
withJavadocJar()
70+
}
71+
72+
repositories {
73+
mavenCentral()
74+
}
75+
76+
publishing {
77+
publications {
78+
var name = project.name.lowercase()
79+
name = if (project.parent?.name == "minecraft") {
80+
"minemark-minecraft-$name"
81+
} else if (name != "minemark") {
82+
"minemark-$name"
83+
} else "minemark-core"
84+
85+
register<MavenPublication>(name) {
86+
groupId = "dev.dediamondpro"
87+
artifactId = name
88+
89+
from(components["java"])
90+
}
91+
}
92+
repositories {
93+
maven {
94+
name = "diamond"
95+
96+
url = uri("https://maven.dediamondpro.dev/releases")
97+
98+
credentials {
99+
username = System.getenv("MAVEN_DIAMOND_USER")
100+
password = System.getenv("MAVEN_DIAMOND_PASSWORD")
101+
}
102+
103+
version = rootProject.version
104+
}
105+
}
106+
}
107+
}
108+
109+
subprojects {
110+
dependencies {
111+
implementation(project.rootProject)
112+
}
113+
}
95114

96115
tasks.test {
97116
useJUnitPlatform()

elementa/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,4 @@ dependencies {
3636
implementation(libs.elementa)
3737
implementation(libs.commonmark.ext.striketrough)
3838
implementation(libs.commonmark.ext.tables)
39-
implementation(project.rootProject)
4039
}

minecraft/build.gradle.kts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import dev.dediamondpro.buildsource.VersionDefinition
2020

2121
plugins {
2222
id("dev.architectury.loom") version "1.10-SNAPSHOT"
23-
id("dev.kikugie.stonecutter")
2423
}
2524

2625
buildscript {
@@ -54,19 +53,30 @@ val forgeVersion = VersionDefinition(
5453
"1.21.4" to "1.21.4-54.1.0",
5554
"1.21.5" to "1.21.5-55.0.4"
5655
)
56+
val neoForgeVersion = VersionDefinition(
57+
"1.21.1" to "21.1.95",
58+
"1.21.4" to "21.4.124",
59+
"1.21.5" to "21.5.34-beta"
60+
)
61+
62+
repositories {
63+
mavenCentral()
64+
maven("https://maven.neoforged.net/releases/")
65+
}
5766

5867
dependencies {
5968
minecraft("com.mojang:minecraft:${mcPlatform.versionString}")
6069
mappings(loom.officialMojangMappings())
6170

6271
implementation(libs.commonmark.ext.striketrough)
6372
implementation(libs.commonmark.ext.tables)
64-
implementation(project.rootProject)
6573

6674
if (mcPlatform.isFabric) {
6775
modImplementation("net.fabricmc:fabric-loader:0.16.10")
6876
} else if (mcPlatform.isForge) {
6977
"forge"("net.minecraftforge:forge:${forgeVersion.get(mcPlatform)}")
78+
} else if (mcPlatform.isNeoForge) {
79+
"neoForge"("net.neoforged:neoforge:${neoForgeVersion.get(mcPlatform)}")
7080
}
7181

7282
if (buildTestMod) {

minecraft/src/main/java/dev/dediamondpro/minemark/minecraft/elements/MarkdownImageElement.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public void drawImage(MarkdownDynamicImage image, float x, float y, float width,
3939

4040
@Override
4141
public void close() {
42-
image.close();
42+
if (image != null) {
43+
image.close();
44+
}
4345
super.close();
4446
}
4547
}

minecraft/src/main/java/dev/dediamondpro/minemark/minecraft/platform/MarkdownDynamicImage.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,32 @@
2626
import java.io.IOException;
2727

2828
public class MarkdownDynamicImage implements Closeable {
29-
private final ResourceLocation identifier;
29+
private static long identifierCounter = 0;
3030

31-
public MarkdownDynamicImage(ResourceLocation identifier) {
32-
this.identifier = identifier;
31+
private NativeImage image;
32+
private ResourceLocation identifier = null;
33+
34+
public MarkdownDynamicImage(NativeImage image) {
35+
this.image = image;
3336
}
3437

3538
public void draw(int x, int y, int width, int height, MarkdownRenderer renderer) {
39+
if (identifier == null) {
40+
// Upload here to make sure we are on the correct thread, this can be an issue on 1.21.5 for some reason
41+
DynamicTexture texture = new DynamicTexture(/*? if >=1.21.5 {*/ null, /*?}*/ image);
42+
//? if <1.21 {
43+
/*ResourceLocation identifier = new ResourceLocation("minemark", "dynamic-image-" + (identifierCounter++));
44+
*///?} else
45+
ResourceLocation identifier = ResourceLocation.fromNamespaceAndPath("minemark", "dynamic-image-" + (identifierCounter++));
46+
Minecraft.getInstance().getTextureManager().register(identifier, texture);
47+
this.identifier = identifier;
48+
image = null;
49+
}
3650
renderer.drawTexture(identifier, x, y, width, height);
3751
}
3852

3953
@Override
4054
public void close() {
4155
Minecraft.getInstance().getTextureManager().release(identifier);
4256
}
43-
44-
public static MarkdownDynamicImage of(NativeImage image) throws IOException {
45-
DynamicTexture texture = new DynamicTexture(image);
46-
ResourceLocation identifier = Minecraft.getInstance().getTextureManager().register("minemark", texture);
47-
return new MarkdownDynamicImage(identifier);
48-
}
4957
}

minecraft/src/main/java/dev/dediamondpro/minemark/minecraft/platform/MarkdownRenderer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import net.minecraft.client.gui.GuiGraphics;
2222
import net.minecraft.resources.ResourceLocation;
2323
import net.minecraft.client.Minecraft;
24+
import net.minecraft.client.renderer.RenderType;
2425

2526
public class MarkdownRenderer {
2627
private final GuiGraphics context;
@@ -59,7 +60,7 @@ public void drawRect(int x, int y, int width, int height, int color) {
5960
}
6061

6162
public void drawTexture(ResourceLocation identifier, int x, int y, int width, int height) {
62-
context.blit(identifier, x, y, 0, 0, width, height, width, height);
63+
context.blit(/*? >=1.21.2 {*/ RenderType::guiTextured, /*?}*/ identifier, x, y, 0, 0, width, height, width, height);
6364
}
6465

6566
public GuiGraphics getDrawContext() {

minecraft/src/main/java/dev/dediamondpro/minemark/minecraft/utils/MinecraftImageProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void getImage(String src, Consumer<Dimension> dimensionCallback, Consumer
4848
ByteArrayOutputStream out = new ByteArrayOutputStream();
4949
ImageIO.write(bufferedImage, "png", out);
5050
NativeImage nativeImage = NativeImage.read(new ByteArrayInputStream(out.toByteArray()));
51-
imageCallback.accept(MarkdownDynamicImage.of(nativeImage));
51+
imageCallback.accept(new MarkdownDynamicImage(nativeImage));
5252
} catch (IOException e) {
5353
e.printStackTrace();
5454
}

minecraft/stonecutter.gradle.kts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
plugins {
22
id("dev.kikugie.stonecutter")
33
}
4-
stonecutter active "1.20.1-fabric"
4+
stonecutter active "1.21.5-fabric" /* [SC] DO NOT EDIT */
5+
6+
stonecutter registerChiseled tasks.register("chiseledBuild", stonecutter.chiseled) {
7+
group = "project"
8+
ofTask("build")
9+
}
10+
11+
stonecutter registerChiseled tasks.register("chiseledPublish", stonecutter.chiseled) {
12+
group = "project"
13+
ofTask("publish")
14+
}
15+
16+
stonecutter registerChiseled tasks.register("chiseledPublishToMavenLocal", stonecutter.chiseled) {
17+
group = "project"
18+
ofTask("publishToMavenLocal")
19+
}

0 commit comments

Comments
 (0)