Skip to content

Commit

Permalink
Migrate to 1.21-neoforge and make it compilable first
Browse files Browse the repository at this point in the history
  • Loading branch information
ustc-zzzz committed Jul 29, 2024
1 parent f54b423 commit 4b664ce
Show file tree
Hide file tree
Showing 40 changed files with 1,437 additions and 1,385 deletions.
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Disable autocrlf on generated files, they always generate with LF
# Add any extra files or paths here to make git stop saying they
# are changed when only line endings change.
src/generated/**/.cache/cache text eol=lf
src/generated/**/*.json text eol=lf
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ build

# other
eclipse
run_client
run_server
run_test
*.txt
run
runs
run-data

repo
285 changes: 234 additions & 51 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,77 +1,260 @@
plugins {
id 'java-library'
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'net.minecraftforge.gradle' version '6.0.+'
id 'com.github.johnrengelman.shadow' version '8.1.+'
id 'net.neoforged.moddev' version '1.0.14'
}

apply from: 'gradle/teacon-forge.gradle'
// Added by TeaCon
abstract class TeaConDumpPathToGitHub extends DefaultTask {
@Input
abstract Property<String> getPublishName()
@InputFile
abstract RegularFileProperty getTargetFile()
@TaskAction
void dump() {
if (System.env.GITHUB_ACTIONS) {
File theFile = targetFile.getAsFile().get()

java.toolchain.languageVersion = JavaLanguageVersion.of(17)
def outputFile = new File(System.env.GITHUB_OUTPUT)
// Use the env-specific line separator for maximally possible compatibility
def newLine = System.getProperty('line.separator')

// definitions at gradle/teacon-forge.gradle
teacon {
modId = 'slide_show'
modVersion = '0.8.4'
modLicense = 'LGPL-3.0-only'
modGitHubRepo = 'teaconmc/SlideShow'
modAuthors = ['BloCamLimb', '3TUSK', 'ustc-zzzz']
modDescription = 'Minecraft mod, adding a projector that can display online images.'
// Write out new env variable for later usage
outputFile << newLine << "artifact_name=${theFile.getName()}"
outputFile << newLine << "artifact_publish_name=${publishName.get()}"
outputFile << newLine << "artifact_path=${theFile.absolutePath}"
}
}
}

platform = 'forge-1.20-46.0.1'
// parchment = '2022.03.13'
tasks.named('wrapper', Wrapper).configure {
// Define wrapper values here so as to not have to always do so when updating gradlew.properties.
// Switching this to Wrapper.DistributionType.ALL will download the full gradle sources that comes with
// documentation attached on cursor hover of gradle classes and methods. However, this comes with increased
// file size for Gradle. If you do switch this to ALL, run the Gradle wrapper task twice afterwards.
// (Verify by checking gradle/wrapper/gradle-wrapper.properties to see if distributionUrl now points to `-all`)
distributionType = Wrapper.DistributionType.BIN
}

// uncomment these lines if you need
modName = 'Slide Show' // default to repo name
// modGitHubBranch = 1.18-forge // for referring the license
modifyMemberAccess = true // for access transformer
// useDataGeneration = true // for data generation
publishTask = shadowJar // for shadow jar or other usages
lazyTokens = ['minecraft_classpath': { (project.configurations.shadow - project.configurations.minecraft).asPath }] // for runtime tokens
version = mod_version
group = mod_group_id

// use './gradlew -q printModMeta > src/main/resources/META-INF/mods.toml' to generate mod meta
repositories {
mavenLocal()
// Added by TeaCon
maven {
name "JitPack"
url 'https://jitpack.io'
}
// Added by TeaCon
maven {
name "Modrinth"
url "https://api.modrinth.com/maven"
}
}

configurations {
compileClasspath.extendsFrom(shadow)
runtimeClasspath.extendsFrom(shadow)
base {
// Modified by TeaCon
archivesName = "$mod_github_repo-NeoForge-$minecraft_version"
}

repositories {
maven { url 'https://jitpack.io' }
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
// Mojang ships Java 21 to end users starting in 1.20.5, so mods should target Java 21.
java.toolchain.languageVersion = JavaLanguageVersion.of(21)

neoForge {
// Specify the version of NeoForge to use.
version = project.neo_version

parchment {
mappingsVersion = project.parchment_mappings_version
minecraftVersion = project.parchment_minecraft_version
}

// This line is optional. Access Transformers are automatically detected
// accessTransformers = project.files('src/main/resources/META-INF/accesstransformer.cfg')

// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
client {
client()

// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
}

server {
server()
programArgument '--nogui'
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
}

// This run config launches GameTestServer and runs all registered gametests, then exits.
// By default, the server will crash when no gametests are provided.
// The gametest system is also enabled by default for other run configs under the /test command.
gameTestServer {
type = "gameTestServer"
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
}

data {
data()

// example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it
// gameDirectory = project.file('run-data')

// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
}

// applies to all the run configs above
configureEach {
// Recommended logging data for a userdev environment
// The markers can be added/remove as needed separated by commas.
// "SCAN": For mods scan.
// "REGISTRIES": For firing of registry events.
// "REGISTRYDUMP": For getting the contents of all registries.
systemProperty 'forge.logging.markers', 'REGISTRIES'

// Recommended logging level for the console
// You can set various levels here.
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
logLevel = org.slf4j.event.Level.DEBUG
}
}

mods {
// define mod <-> source bindings
// these are used to tell the game which sources are for which mod
// mostly optional in a single mod project
// but multi mod projects should define one per mod
"${mod_id}" {
sourceSet(sourceSets.main)
}
}
}

// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }

// Sets up a dependency configuration called 'localRuntime'.
// This configuration should be used instead of 'runtimeOnly' to declare
// a dependency that will be present for runtime testing but that is
// "optional", meaning it will not be pulled by dependents of this mod.
configurations {
runtimeClasspath.extendsFrom localRuntime
}

dependencies {
shadow 'org.teacon:urlpattern:1.0.1'
shadow 'net.objecthunter:exp4j:0.4.8'
shadow 'org.apache.httpcomponents:httpclient-cache:4.5.13'
// Modified by TeaCon
jarJar implementation('org.teacon:urlpattern') { version { strictly '1.0.1' } }
jarJar implementation('net.objecthunter:exp4j') { version { strictly '0.4.8' } }
jarJar implementation('org.apache.httpcomponents:httpclient-cache') { version { strictly '4.5.13' } }
}

runtimeOnly fg.deobf("maven.modrinth:oculus:HxUtDCCe") // 1.20-1.6.4
// This block of code expands all declared replace properties in the specified resource targets.
// A missing property will result in an error. Properties are expanded using ${} Groovy notation.
// When "copyIdeResources" is enabled, this will also run before the game launches in IDE environments.
// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html
tasks.withType(ProcessResources).configureEach {
var replaceProperties = [
minecraft_version : minecraft_version,
minecraft_version_range: minecraft_version_range,
neo_version : neo_version,
neo_version_range : neo_version_range,
loader_version_range : loader_version_range,
mod_id : mod_id,
mod_name : mod_name,
mod_license : mod_license,
mod_version : mod_version,
mod_authors : mod_authors,
mod_description : mod_description
]
inputs.properties replaceProperties

filesMatching(['META-INF/neoforge.mods.toml']) {
expand replaceProperties
}
}

publishing {
publications {
// Modified by TeaCon
register('release', MavenPublication) {
// noinspection GroovyAssignabilityCheck
from components.java
version = mod_version
groupId = mod_group_id
artifactId = "$mod_github_repo-NeoForge-$minecraft_version"
pom {
name = mod_github_repo
url = "https://github.com/$mod_github_owner/$mod_github_repo"
licenses {
license {
name = mod_license
url = "https://github.com/$mod_github_owner/$mod_github_repo/blob/HEAD/LICENSE"
}
}
organization {
name = 'TeaConMC'
url = 'https://github.com/teaconmc'
}
developers {
for (mod_author in "$mod_authors".split(',')) {
developer { id = mod_author.trim(); name = mod_author.trim() }
}
}
issueManagement {
system = 'GitHub Issues'
url = "https://github.com/$mod_github_owner/$mod_github_repo/issues"
}
scm {
url = "https://github.com/$mod_github_owner/$mod_github_repo"
connection = "scm:git:git://github.com/$mod_github_owner/${mod_github_repo}.git"
developerConnection = "scm:git:[email protected]:$mod_github_owner/${mod_github_repo}.git"
}
}
}
}
repositories {
// Modified by TeaCon
maven {
name "teacon"
url "s3://maven/"
credentials(AwsCredentials) {
accessKey = System.env.ARCHIVE_ACCESS_KEY
secretKey = System.env.ARCHIVE_SECRET_KEY
}
}
}
}

shadowJar {
archiveClassifier.set(null)
configurations = [project.configurations.shadow]
from(file('LICENSE')) { into 'META-INF' rename { "$it-slide-show" } }
dependencies {
it.exclude it.dependency('org.apache.httpcomponents:httpclient:.*')
it.exclude it.dependency('org.apache.httpcomponents:httpcore:.*')
it.exclude it.dependency('commons-logging:commons-logging:.*')
it.exclude it.dependency('commons-codec:commons-codec:.*')
it.exclude it.dependency('org.slf4j:slf4j-api:.*')
// Added by TeaCon
tasks.withType(PublishToMavenRepository).configureEach {
if (repository && repository.name == "archive") {
it.onlyIf {
System.env.MAVEN_USERNAME && System.env.MAVEN_PASSWORD
}
}
relocate 'net.objecthunter.exp4j', 'org.teacon.slides.exp4j'
relocate 'org.teacon.urlpattern', 'org.teacon.slides.urlpattern'
relocate 'org.apache.http.client.cache', 'org.teacon.slides.http.client.cache'
relocate 'org.apache.http.impl.client.cache', 'org.teacon.slides.http.impl.client.cache'
}

jar { it.enabled false }
// Added by TeaCon
tasks.register("githubActionOutput", TeaConDumpPathToGitHub) { task ->
task.onlyIf { System.env.GITHUB_ACTIONS }
task.getTargetFile().set(jar.archiveFile)
task.getPublishName().set("${jar.archiveBaseName.get()}-${version}.jar")
}

reobf {
jar { it.enabled false }
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}

// IDEA no longer automatically downloads sources/javadoc jars for dependencies, so we need to explicitly enable the behavior.
idea {
module {
downloadSources = true
downloadJavadoc = true
}
}
53 changes: 49 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,49 @@
# Ensure enough heap space during deployment
org.gradle.jvmargs=-Xmx3G
# It is said that daemon often brings more issues, so we disable it.
org.gradle.daemon=false
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
org.gradle.jvmargs=-Xmx1G
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configuration-cache=true

#read more on this at https://github.com/neoforged/ModDevGradle?tab=readme-ov-file#better-minecraft-parameter-names--javadoc-parchment
# you can also find the latest versions at: https://parchmentmc.org/docs/getting-started
parchment_minecraft_version=1.21
parchment_mappings_version=2024.07.07
# Environment Properties
# You can find the latest versions here: https://projects.neoforged.net/neoforged/neoforge
# The Minecraft version must agree with the Neo version to get a valid artifact
minecraft_version=1.21
# The Minecraft version range can use any release version of Minecraft as bounds.
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.21,1.21.1)
# The Neo version must agree with the Minecraft version to get a valid artifact
neo_version=21.0.142-beta
# The Neo version range can use any version of Neo as bounds
neo_version_range=[21.0.0-beta,)
# The loader version range can only use the major version of FML as bounds
loader_version_range=[4,)

## Mod Properties

# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63}
# Must match the String constant located in the main mod class annotated with @Mod.
mod_id=slide_show
# The human-readable display name for the mod.
mod_name=Slide Show
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=LGPL-3.0-only
# The mod version. See https://semver.org/
mod_version=0.9.0
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
mod_group_id=org.teacon
# The authors of the mod. This is a simple text string that is used for display purposes in the mod list.
mod_authors=3TUSK, BloCamLimb, ustc-zzzz
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list.
mod_description=Minecraft mod, adding a projector that can display online images.
# Added by TeaCon: gh owner
mod_github_owner=TeaCon
# Added by TeaCon: gh repo name
mod_github_repo=SlideShow
Loading

0 comments on commit 4b664ce

Please sign in to comment.