Merge pull request #8 from GTNewHorizons/applecore

Add AppleCore compatibility
This commit is contained in:
Martin Robertz authored and GitHub committed 2022-06-04 22:59:44 +02:00
commit 3dc4e0aa29
3 files changed
+87 -43

No files matched your search

+50 -33
View File
@@ -1,4 +1,4 @@
//version: 1644612407
//version: 1652851397
/*
DO NOT CHANGE THIS FILE!
@@ -6,12 +6,11 @@ Also, you may replace this file at any time if there is an update available.
Please check https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/build.gradle for updates.
*/
import org.gradle.internal.logging.text.StyledTextOutput
import org.gradle.internal.logging.text.StyledTextOutputFactory
import org.gradle.internal.logging.text.StyledTextOutput.Style
import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.internal.logging.text.StyledTextOutput.Style
import org.gradle.internal.logging.text.StyledTextOutputFactory
import java.util.concurrent.TimeUnit
@@ -45,13 +44,14 @@ plugins {
id 'eclipse'
id 'scala'
id 'maven-publish'
id 'org.jetbrains.kotlin.jvm' version '1.5.30' apply false
id 'org.jetbrains.kotlin.kapt' version '1.5.30' apply false
id 'org.jetbrains.kotlin.jvm' version '1.5.30' apply false
id 'org.jetbrains.kotlin.kapt' version '1.5.30' apply false
id 'com.google.devtools.ksp' version '1.5.30-1.0.0' apply false
id 'org.ajoberstar.grgit' version '4.1.1'
id 'com.github.johnrengelman.shadow' version '4.0.4'
id 'com.palantir.git-version' version '0.13.0' apply false
id 'com.palantir.git-version' version '0.13.0' apply false
id 'de.undercouch.download' version '5.0.1'
id 'com.github.gmazzo.buildconfig' version '3.0.3' apply false
id 'com.github.gmazzo.buildconfig' version '3.0.3' apply false
}
if (project.file('.git/HEAD').isFile()) {
@@ -104,6 +104,7 @@ checkPropertyExists("usesShadowedDependencies")
checkPropertyExists("developmentEnvironmentUserName")
boolean noPublishedSources = project.findProperty("noPublishedSources") ? project.noPublishedSources.toBoolean() : false
boolean usesMixinDebug = project.findProperty('usesMixinDebug') ?: project.usesMixins.toBoolean()
String javaSourceDir = "src/main/java/"
String scalaSourceDir = "src/main/scala/"
@@ -175,7 +176,7 @@ configurations.all {
try {
'git config core.fileMode false'.execute()
}
catch (Exception e) {
catch (Exception ignored) {
out.style(Style.Failure).println("git isn't installed at all")
}
@@ -185,7 +186,7 @@ String versionOverride = System.getenv("VERSION") ?: null
try {
identifiedVersion = versionOverride == null ? gitVersion() : versionOverride
}
catch (Exception e) {
catch (Exception ignored) {
out.style(Style.Failure).text(
'This mod must be version controlled by Git AND the repository must provide at least one tag,\n' +
'or the VERSION override must be set! ').style(Style.SuccessHeader).text('(Do NOT download from GitHub using the ZIP option, instead\n' +
@@ -199,7 +200,7 @@ ext {
modVersion = identifiedVersion
}
if( identifiedVersion.equals(versionOverride) ) {
if(identifiedVersion == versionOverride) {
out.style(Style.Failure).text('Override version to ').style(Style.Identifier).text(modVersion).style(Style.Failure).println('!\7')
}
@@ -214,13 +215,17 @@ else {
def arguments = []
def jvmArguments = []
if(usesMixins.toBoolean()) {
if (usesMixins.toBoolean()) {
arguments += [
"--tweakClass org.spongepowered.asm.launch.MixinTweaker"
]
jvmArguments += [
"-Dmixin.debug.countInjections=true", "-Dmixin.debug.verbose=true", "-Dmixin.debug.export=true"
"--tweakClass org.spongepowered.asm.launch.MixinTweaker"
]
if (usesMixinDebug.toBoolean()) {
jvmArguments += [
"-Dmixin.debug.countInjections=true",
"-Dmixin.debug.verbose=true",
"-Dmixin.debug.export=true"
]
}
}
minecraft {
@@ -312,18 +317,23 @@ def refMap = "${tasks.compileJava.temporaryDir}" + File.separator + mixingConfig
def mixinSrg = "${tasks.reobf.temporaryDir}" + File.separator + "mixins.srg"
task generateAssets {
if(usesMixins.toBoolean()) {
getFile("/src/main/resources/mixins." + modId + ".json").text = """{
if (usesMixins.toBoolean()) {
def mixinConfigFile = getFile("/src/main/resources/mixins." + modId + ".json");
if (!mixinConfigFile.exists()) {
mixinConfigFile.text = """{
"required": true,
"minVersion": "0.7.11",
"package": "${modGroup}.${mixinsPackage}",
"plugin": "${modGroup}.${mixinPlugin}",
"refmap": "${mixingConfigRefMap}",
"target": "@env(DEFAULT)",
"compatibilityLevel": "JAVA_8"
"compatibilityLevel": "JAVA_8",
"mixins": [],
"client": [],
"server": []
}
"""
}
}
}
@@ -439,7 +449,7 @@ processResources {
def getManifestAttributes() {
def manifestAttributes = [:]
if(containsMixinsAndOrCoreModOnly.toBoolean() == false && (usesMixins.toBoolean() || coreModClass)) {
if(!containsMixinsAndOrCoreModOnly.toBoolean() && (usesMixins.toBoolean() || coreModClass)) {
manifestAttributes += ["FMLCorePluginContainsFMLMod": true]
}
@@ -455,14 +465,14 @@ def getManifestAttributes() {
manifestAttributes += [
"TweakClass" : "org.spongepowered.asm.launch.MixinTweaker",
"MixinConfigs" : "mixins." + modId + ".json",
"ForceLoadAsMod" : containsMixinsAndOrCoreModOnly.toBoolean() == false
"ForceLoadAsMod" : !containsMixinsAndOrCoreModOnly.toBoolean()
]
}
return manifestAttributes
}
task sourcesJar(type: Jar) {
from (sourceSets.main.allJava)
from (sourceSets.main.allSource)
from (file("$projectDir/LICENSE"))
getArchiveClassifier().set('sources')
}
@@ -517,7 +527,7 @@ task devJar(type: Jar) {
}
task apiJar(type: Jar) {
from (sourceSets.main.allJava) {
from (sourceSets.main.allSource) {
include modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/") + '/**'
}
@@ -548,6 +558,9 @@ tasks.withType(GenerateModuleMetadata) {
enabled = false
}
// workaround variable hiding in pom processing
def projectConfigs = project.configurations
publishing {
publications {
maven(MavenPublication) {
@@ -556,7 +569,7 @@ publishing {
artifact source: shadowJar, classifier: ""
}
if(!noPublishedSources) {
artifact source: sourcesJar, classifier: "src"
artifact source: sourcesJar, classifier: "sources"
}
artifact source: usesShadowedDependencies.toBoolean() ? shadowDevJar : devJar, classifier: "dev"
if (apiPackage) {
@@ -568,16 +581,20 @@ publishing {
// Using the identified version, not project.version as it has the prepended 1.7.10
version = System.getenv("RELEASE_VERSION") ?: identifiedVersion
// remove extra garbage from who knows where
// remove extra garbage from minecraft and minecraftDeps configuration
pom.withXml {
def badPomGroup = ['net.minecraft', 'com.google.code.findbugs', 'org.ow2.asm', 'com.typesafe.akka', 'com.typesafe', 'org.scala-lang',
'org.scala-lang.plugins', 'net.sf.jopt-simple', 'lzma', 'com.mojang', 'org.apache.commons', 'org.apache.httpcomponents',
'commons-logging', 'java3d', 'net.sf.trove4j', 'com.ibm.icu', 'com.paulscode', 'io.netty', 'com.google.guava',
'commons-io', 'commons-codec', 'net.java.jinput', 'net.java.jutils', 'com.google.code.gson', 'org.apache.logging.log4j',
'org.lwjgl.lwjgl', 'tv.twitch', 'org.jetbrains.kotlin', '']
def badArtifacts = [:].withDefault {[] as Set<String>}
for (configuration in [projectConfigs.minecraft, projectConfigs.minecraftDeps]) {
for (dependency in configuration.allDependencies) {
badArtifacts[dependency.group == null ? "" : dependency.group] += dependency.name
}
}
// example for specifying extra stuff to ignore
// badArtifacts["org.example.group"] += "artifactName"
Node pomNode = asNode()
pomNode.dependencies.'*'.findAll() {
badPomGroup.contains(it.groupId.text())
badArtifacts[it.groupId.text()].contains(it.artifactId.text())
}.each() {
it.parent().remove(it)
}
@@ -721,7 +738,7 @@ def deobf(String sourceURL, String fileName) {
// Helper methods
def checkPropertyExists(String propertyName) {
if (project.hasProperty(propertyName) == false) {
if (!project.hasProperty(propertyName)) {
throw new GradleException("This project requires a property \"" + propertyName + "\"! Please add it your \"gradle.properties\". You can find all properties and their description here: https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/gradle.properties")
}
}
+1
View File
@@ -7,6 +7,7 @@ dependencies {
compileOnly('com.github.GTNewHorizons:BloodMagic:1.3.6:dev') {transitive=false}
compileOnly('com.github.GTNewHorizons:Botania:1.9.1-GTNH:api') {transitive=false}
compileOnly("com.github.GTNewHorizons:AppleCore:3.1.9:dev") {transitive = false}
compileOnly('curse.maven:ee3-65509:2305023')
}
@@ -2,8 +2,9 @@ package fox.spiteful.forbidden.blocks;
import java.util.Random;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Optional;
import net.minecraft.block.Block;
import net.minecraft.block.BlockCake;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
@@ -16,8 +17,13 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import squeek.applecore.api.food.FoodValues;
import squeek.applecore.api.food.IEdibleBlock;
import squeek.applecore.api.food.ItemFoodProxy;
public class BlockArcaneCake extends Block {
@Optional.Interface(iface = "squeek.applecore.api.food.IEdibleBlock", modid = "AppleCore")
public class BlockArcaneCake extends Block implements IEdibleBlock {
private boolean isEdibleAtMaxHunger = false;
@SideOnly(Side.CLIENT)
private IIcon cakeTopIcon;
@SideOnly(Side.CLIENT)
@@ -105,16 +111,19 @@ public class BlockArcaneCake extends Block {
}
private void eatCakeSlice(World world, int x, int y, int z, EntityPlayer player) {
if (player.canEat(false)) {
if (!player.canEat(isEdibleAtMaxHunger)) return;
if (Loader.isModLoaded("AppleCore")) {
onEatenCompatibility(new ItemStack(this), player);
} else {
player.getFoodStats().addStats(2, 1.0F);
int l = world.getBlockMetadata(x, y, z) + 1;
if (l >= 12) {
world.setBlockToAir(x, y, z);
} else {
world.setBlockMetadataWithNotify(x, y, z, l, 2);
}
}
int nextMeta = world.getBlockMetadata(x, y, z) + 1;
if (nextMeta >= 12) {
world.setBlockToAir(x, y, z);
} else {
world.setBlockMetadataWithNotify(x, y, z, nextMeta, 2);
}
}
@@ -164,4 +173,21 @@ public class BlockArcaneCake extends Block {
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
return new ItemStack(this);
}
// === AppleCore methods ===
@Override
public void setEdibleAtMaxHunger(boolean edibleAtMaxHunger) {
isEdibleAtMaxHunger = edibleAtMaxHunger;
}
@Override
public FoodValues getFoodValues(ItemStack itemStack) {
return new FoodValues(2, 1.0f);
}
@Optional.Method(modid = "AppleCore")
public void onEatenCompatibility(ItemStack itemStack, EntityPlayer player) {
player.getFoodStats().func_151686_a(new ItemFoodProxy(this), itemStack);
}
}