src_resources
在项目resources文件夹下已置入相关文件:

但从IDEA以runClient配置启动客户端后无法识别mcmod.info文件。

后来又欲在GUI中绘制resources中的纹理png图片,无法正常读取纹理(下图中紫黑色部分):


但使用Gradle从runClient task启动时一切正常。



想实现从IDEA的runClient配置启动时能正常读取并加载resources文件夹下的资源文件。


build.gradle
buildscript {
    ext.kotlin_version = '1.8.22'
    repositories {
        maven { url = 'https://maven.minecraftforge.net/' }
        mavenCentral()
    }
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:5.+'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
        
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'kotlin'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

file "build.properties" withReader {
    def prop = new Properties()
    prop.load(it)
    ext.config = new ConfigSlurper().parse prop
}

version = "${config.jeigenetics.version}"
group = 'srcres.mods.jeigenetics'
archivesBaseName = 'jeigenetics'

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.

minecraft {
    // The mappings can be changed at any time, and must be in the following format.
    // snapshot_YYYYMMDD   Snapshot are built nightly.
    // stable_#            Stables are built at the discretion of the MCP team.
    // Use non-default mappings at your own risk. they may not always work.
    // Simply re-run your setup task after changing the mappings to update your workspace.
    //mappings channel: 'snapshot', version: '20171003-1.12'
    mappings channel: "${config.minecraft.mappings.channel}", version: "${config.minecraft.mappings.version}"

    runs {
        client {
            workingDirectory project.file('run')
            property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
            property 'forge.logging.console.level', 'debug'
        }

        server {
            property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
            property 'forge.logging.console.level', 'debug'
        }
    }

    // Use an access transformer here as access transformers within 3rd-party mods are not scanned in the development
    // environment and the game would crash accordingly providing that these access transformers were not compensated
    // by hand.
    accessTransformer = file('jeigenetics_at_debug.cfg')
}

repositories {
    mavenCentral()
    mavenLocal()
    // Although jcenter is required by Shadowfacts, I'm reluctant to add this repository personally
    // because JCenter has already been deprecated by JFrog as is known. :(
    jcenter()
    maven {
        // location of the maven that hosts JEI files
        name = "Progwml6 maven"
        url = "https://dvs1.progwml6.com/files/maven/"
    }
    maven {
        // location of a maven mirror for JEI files, as a fallback
        name = "ModMaven"
        url = "https://modmaven.dev/"
    }
    maven {
        name = "ic2"
        url = "https://maven.ic2.player.to/"
    }
    maven {
        name = "Shadowfacts"
        url = "https://maven.shadowfacts.net/"
    }
}

dependencies {
    /*
     * Note that the compile, runtime, testCompile, and testRuntime configurations introduced by the Java plugin have
     * been deprecated since Gradle 4.10 (Aug 27, 2018), and were finally removed in Gradle 7.0 (Apr 9, 2021).
     *
     * The aforementioned configurations should be replaced by implementation, runtimeOnly, testImplementation, and
     * testRuntimeOnly, respectively.
     *
     * From: https://stackoverflow.com/questions/23796404/could-not-find-method-compile-for-arguments-gradle
     */

    // Vanilla Minecraft
    minecraft "net.minecraftforge:forge:${config.minecraft.version}-${config.forge.version}"

    // JEI
    // compile against the JEI API but do not include it at runtime
    compileOnly fg.deobf("mezz.jei:jei_${config.minecraft.version}:${config.jei.version}:api")
    // at runtime, use the full JEI jar
    runtimeOnly fg.deobf("mezz.jei:jei_${config.minecraft.version}:${config.jei.version}")

    // Forestry
    compileOnly fg.deobf("net.sengir.forestry:forestry_${config.minecraft.version}:${config.forestry.version}:api")
    runtimeOnly fg.deobf("net.sengir.forestry:forestry_${config.minecraft.version}:${config.forestry.version}")

    // Forgelin
    implementation "net.shadowfacts:Forgelin:${config.forgelin.version}"

    // Kotlin
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

    // Add this forced dependency so as to avoid game crashing when launched from IDEA.
    // Using the 2nd solution from the following link:
    //     https://stackoverflow.com/questions/68377027/minecraft-forge-mod-loader-fml-loading-and-crashing-mc.
    implementation ("net.minecraftforge:mergetool:0.2.3.3") { force = true }
}

jar {
    manifest {
        attributes([
            "Specification-Title": "jeigenetics",
            "Specification-Vendor": "jeigeneticssareus",
            "Specification-Version": "1", // We are version 1 of ourselves
            "Implementation-Title": project.name,
            "Implementation-Version": "${version}",
            "Implementation-Vendor" :"jeigeneticssareus",
            "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
        ])
    }
}

// Example configuration to allow publishing using the maven-publish task
// This is the preferred method to reobfuscate your jar file
jar.finalizedBy('reobfJar')
// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing
//publish.dependsOn('reobfJar')

publishing {
    publications {
        mavenJava(MavenPublication) {
            artifact jar
        }
    }
    repositories {
        maven {
            url "file:///${project.projectDir}/mcmodsrepo"
        }
    }
}

compileKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

compileTestKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}
复制代码
绘制纹理的相关代码(使用了部分JEI API,语言:Kotlin)
package srcres.mods.jeigenetics.jei.recipe.mutation

import forestry.api.genetics.ISpeciesRoot
import mezz.jei.api.IGuiHelper
import mezz.jei.api.gui.IDrawableStatic
import mezz.jei.api.gui.IRecipeLayout
import mezz.jei.api.ingredients.IIngredients
import net.minecraft.item.ItemStack
import net.minecraft.util.ResourceLocation
import srcres.mods.jeigenetics.gui.element.InteractiveDrawableBase
import srcres.mods.jeigenetics.jei.recipe.RecipeCategoryBase

class MutationRecipeCategory(private val root: ISpeciesRoot,
    guiHelper: IGuiHelper, icon: ItemStack) : RecipeCategoryBase() {
    private val background: IDrawableStatic = guiHelper.createDrawable(ResourceLocation(
        "jeigenetics", "textures/recipes.png"), 0, 0, 162, 61)

    override fun getUid() = "srcres.jeigenetics.mutation." + root.uid
    override fun getTitle() = "JEI Genetics Mutation"
    override fun getBackground() = background
    override fun setRecipe(recipeLayout: IRecipeLayout, recipeWrapper: MutationRecipeWrapper, ingredients: IIngredients) {
        val itemStacks = recipeLayout.itemStacks
        itemStacks.init(0, true, 18, 15)
        itemStacks.init(1, true, 71, 15)
        itemStacks.init(2, true, 125, 15)
        itemStacks.set(0, recipeWrapper.p0Stack)
        itemStacks.set(1, recipeWrapper.p1Stack)
        itemStacks.set(2, recipeWrapper.resStack)
    }
}复制代码

第一页 上一页 下一页 最后一页