Skip to content

Commit

Permalink
rainstom-data
Browse files Browse the repository at this point in the history
  • Loading branch information
nishimura0731 committed Feb 3, 2024
1 parent 5ff405e commit d7a0f04
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 126 deletions.
20 changes: 0 additions & 20 deletions .github/workflows/pr.yaml

This file was deleted.

29 changes: 29 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Publish
on: [ push ]
concurrency: ci-${{ github.ref }}
jobs:
publish:
permissions:
contents: write
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[CI-SKIP]')"
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
cache: gradle
- name: Generate build number
id: buildnumber
uses: onyxmueller/[email protected]
with:
token: ${{ secrets.github_token }}
prefix: ${{ github.ref_name }}
- name: Publish
uses: uTen2c/[email protected]
with:
repo: ${{ secrets.REPO }}
token-user: ${{ secrets.TOKEN_USER }}
token: ${{ secrets.TOKEN }}
publish-task: publish -Peula=true
30 changes: 0 additions & 30 deletions .github/workflows/snapshot-release.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public enum DataGenType {
ITEM_TAGS("tags/item_tags", new ItemTagGenerator()),

DAMAGE_TYPES("damage_types", new GenericResourceGenerator("damage_type")),
SOUND_TYPES("sound_types", new SoundTypeGenerator()), // SoundTypeGeneratorを追加

TRIM_MATERIALS("trim_materials", new GenericResourceGenerator("trim_material")),
TRIM_PATTERNS("trim_patterns", new GenericResourceGenerator("trim_pattern")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.EmptyBlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.FallingBlock;
import net.minecraft.world.level.block.FireBlock;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.CollisionContext;
Expand All @@ -20,6 +17,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -138,6 +136,7 @@ private void writeState(Block block, BlockState blockState, JsonObject blockJson
appendState(blockJson, state, "replaceable", blockState.canBeReplaced(), false, boolean.class);
appendState(blockJson, state, "solid", blockState.isSolid(), boolean.class);
appendState(blockJson, state, "solidBlocking", blockState.blocksMotion(), boolean.class);
appendState(blockJson, state, "soundType", getSoundTypeName(blockState.getSoundType()), String.class);
// Shapes (Hit-boxes)
appendState(blockJson, state, "shape", blockState.getShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO).toAabbs().toString(), String.class);
appendState(blockJson, state, "collisionShape", blockState.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO).toAabbs().toString(), String.class);
Expand Down Expand Up @@ -182,6 +181,20 @@ private static boolean isFlammable(@NotNull BlockState blockState) {
}
}

private static @NotNull String getSoundTypeName(@NotNull SoundType soundType) {
return Arrays.stream(SoundType.class.getDeclaredFields())
.filter(field -> {
try {
return field.get(null) == soundType;
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
})
.map(Field::getName)
.findFirst()
.orElseThrow();
}

static {
try {
canBurn = FireBlock.class.getDeclaredMethod("canBurn", BlockState.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package net.minestom.generators;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.minecraft.world.level.block.SoundType;
import net.minestom.datagen.DataGenerator;

import java.util.Arrays;

public class SoundTypeGenerator extends DataGenerator {
@Override
public JsonElement generate() throws Exception {
final var jsonObject = new JsonObject();
Arrays.stream(SoundType.class.getDeclaredFields())
.filter(field -> {
try {
return field.get(null) instanceof SoundType;
} catch (Throwable e) {
return false;
}
})
.forEach(field -> {
try {
final var name = field.getName();
final var soundType = (SoundType) field.get(null);
final var obj = new JsonObject();
obj.addProperty("volume", soundType.volume);
obj.addProperty("pitch", soundType.pitch);
obj.addProperty("breakSound", soundType.getBreakSound().getLocation().toString());
obj.addProperty("stepSound", soundType.getStepSound().getLocation().toString());
obj.addProperty("placeSound", soundType.getPlaceSound().getLocation().toString());
obj.addProperty("hitSound", soundType.getHitSound().getLocation().toString());
obj.addProperty("fallSound", soundType.getFallSound().getLocation().toString());
jsonObject.add(name, obj);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
});
return jsonObject;
}
}
100 changes: 29 additions & 71 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ plugins {
alias(libs.plugins.vanilla.gradle) apply false

`maven-publish`
signing
alias(libs.plugins.nexuspublish)
}

group = "net.minestom"
version = System.getenv("TAG_VERSION") ?: "${libs.versions.minecraft.get()}-dev"
val publishPath = System.getenv()["PUBLISH_PATH"]
val branch = System.getenv()["GITHUB_REF_NAME"] ?: "unknown"
val buildNumber = System.getenv()["BUILD_NUMBER"] ?: "local-SNAPSHOT"
val outputDirectory = (findProperty("output") ?: rootDir.resolve("MinestomData").absolutePath) as String

group = "net.rainbootsmc"
version = "$branch+build.$buildNumber"
description = "Generator for Minecraft game data values"

java {
Expand Down Expand Up @@ -38,8 +41,8 @@ tasks.register("generateData") {
val eulaTxt = File("${rootProject.projectDir}/eula.txt")
logger.warn("The file must be located at '${eulaTxt.absolutePath}'.")
if ((eulaTxt.exists() && eulaTxt.readText(Charsets.UTF_8).equals("eula=true", true))
|| project.properties["eula"].toString().toBoolean()
|| System.getenv("EULA")?.toBoolean() == true
|| project.properties["eula"].toString().toBoolean()
|| System.getenv("EULA")?.toBoolean() == true
) {
logger.warn("")
logger.warn("The EULA has been accepted and signed.")
Expand All @@ -59,77 +62,32 @@ tasks.register("generateData") {
})
}

tasks.processResources.get().dependsOn("generateData")

nexusPublishing {
this.packageGroup.set("net.minestom")
tasks.register<Jar>("dataJar") {
dependsOn("generateData")

repositories.sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))

if (System.getenv("SONATYPE_USERNAME") != null) {
username.set(System.getenv("SONATYPE_USERNAME"))
password.set(System.getenv("SONATYPE_PASSWORD"))
}
}
archiveBaseName.set("rainstom-data")
archiveVersion.set(libs.versions.minecraft)
destinationDirectory.set(layout.buildDirectory.dir("dist"))
from(outputDirectory)
}

publishing.publications.create<MavenPublication>("maven") {
groupId = "net.minestom"
artifactId = "data"
version = project.version.toString()

from(project.components["java"])
tasks.processResources.get().dependsOn("generateData")

pom {
name.set("data")
description.set("Minecraft game data values")
url.set("https://github.com/minestom/MinestomDataGenerator")
publishing {
publications {
create<MavenPublication>("maven") {
groupId = "net.rainbootsmc"
artifactId = "rainstom-data"
version = project.version.toString()

licenses {
license {
name.set("Apache 2.0")
url.set("https://github.com/minestom/MinestomDataGenerator/blob/main/LICENSE")
}
artifact(tasks.getByName("dataJar"))
}

developers {
developer {
id.set("mworzala")
name.set("Matt Worzala")
email.set("[email protected]")
}
developer {
id.set("TheMode")
}
if (publishPath != null) {
repositories {
maven {
url = uri(publishPath)
}
}

issueManagement {
system.set("GitHub")
url.set("https://github.com/minestom/MinestomDataGenerator/issues")
}

scm {
connection.set("scm:git:git://github.com/minestom/MinestomDataGenerator.git")
developerConnection.set("scm:git:[email protected]:minestom/MinestomDataGenerator.git")
url.set("https://github.com/minestom/MinestomDataGenerator")
tag.set("HEAD")
}

ciManagement {
system.set("Github Actions")
url.set("https://github.com/minestom/MinestomDataGenerator/actions")
}
}
}

signing {
isRequired = System.getenv("CI") != null

val privateKey = System.getenv("GPG_PRIVATE_KEY")
val keyPassphrase = System.getenv()["GPG_PASSPHRASE"]
useInMemoryPgpKeys(privateKey, keyPassphrase)

sign(publishing.publications)
}
}
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//enableFeaturePreview("VERSION_CATALOGS")

rootProject.name = "minestom-ce-data"
rootProject.name = "rainstom-data"
// DataGenerator
include("DataGenerator")

Expand Down

0 comments on commit d7a0f04

Please sign in to comment.