Skip to content

Commit

Permalink
Added support for 1.20.2 for neo forge.
Browse files Browse the repository at this point in the history
  • Loading branch information
RealYusufIsmail committed Nov 13, 2023
1 parent 1379c36 commit 6cde581
Show file tree
Hide file tree
Showing 87 changed files with 937 additions and 912 deletions.
64 changes: 64 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ allprojects {
subprojects {
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "jacoco")
apply(plugin = "com.diffplug.spotless")

dependencies {
// Json
Expand All @@ -64,6 +65,69 @@ subprojects {
}
finalizedBy("jacocoTestCoverageVerification")
}

spotless {
kotlin {
// Excludes build folder since it contains generated java classes.
targetExclude("build/**")
ktfmt("0.42").dropboxStyle()

licenseHeader(
"""/*
* Copyright 2023 RealYusufIsmail.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ """)
}

kotlinGradle {
target("**/*.gradle.kts")
ktfmt("0.42").dropboxStyle()
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}

java {
target("**/*.java")
googleJavaFormat()
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
licenseHeader(
"""/*
* Copyright 2023 RealYusufIsmail.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ """)
}
}
}

spotless {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ object CustomArmourCraftingTableRecipeBuilder {
key: Map<Char, Ingredient>,
advancement: Advancement.Builder,
advancementId: ResourceLocation,
showNotification: Boolean,
val enchantmentsAndLevels: EnchantmentsAndLevels,
val hideFlags: Boolean,
private val showNotification: Boolean,
private val enchantmentsAndLevels: EnchantmentsAndLevels,
private val hideFlags: Boolean,
) : FinishedRecipe {
override fun serializeRecipeData(jsonObject: JsonObject) {
if (group.isNotEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,6 @@ object CustomToolCraftingTableRecipeBuilder : RecipeBuilder {
return this
}

fun addEnchantments(
enchantmentsAndLevels: EnchantmentsAndLevels
): CustomToolCraftingTableRecipeBuilder {
this.enchantmentsAndLevels.addAll(enchantmentsAndLevels)
return this
}

fun hideFlags(hideFlags: Int): CustomToolCraftingTableRecipeBuilder {
this.hideFlags = hideFlags
return this
Expand Down Expand Up @@ -238,9 +231,9 @@ object CustomToolCraftingTableRecipeBuilder : RecipeBuilder {
key: Map<Char, Ingredient>,
advancement: Advancement.Builder,
advancementId: ResourceLocation,
showNotification: Boolean,
enchantmentsAndLevels: EnchantmentsAndLevels,
hideFlags: Int = 0,
private val showNotification: Boolean,
private val enchantmentsAndLevels: EnchantmentsAndLevels,
private val hideFlags: Int = 0,
) : FinishedRecipe {
override fun serializeRecipeData(jsonObject: JsonObject) {
if (group.isNotEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import net.minecraft.world.item.enchantment.Enchantment

class EnchantmentsAndLevels : MutableMap<Enchantment, Int> by mutableMapOf() {

fun add(enchantment: net.minecraft.world.item.enchantment.Enchantment, level: Int) {
fun add(enchantment: Enchantment, level: Int) {
put(enchantment, level)
}

Expand Down
6 changes: 6 additions & 0 deletions neoforge/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

# [1.20.2-2.0.0.beta2] - 2023-11-13

### Added support for 1.20.2 for neo forge. No longer works with forge mods.
### Fixed some minor issues.
### Removed support for JEI for neo forge. Will be added back in the future once support for neo forge 1.20.2 is added.

## [1.20.1-1.0.7.beta2] - 2023-10-24

### Added support for new forge. Changelog for both versions will now be split.
Expand Down
141 changes: 52 additions & 89 deletions neoforge/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import net.minecraftforge.gradle.userdev.UserDevExtension

plugins {
kotlin("jvm") version "1.9.10"
id("net.neoforged.gradle") version "[6.0.18,6.2)"
id("org.parchmentmc.librarian.forgegradle") version "1.+"
id("net.neoforged.gradle.userdev") version "7.0.26"
}

project.version = properties["modVersion"] as String
Expand All @@ -14,6 +11,8 @@ val mcVersion = properties["mcVersion"] as String
var projectId = properties["projectId"] as String
val modId = properties["modId"] as String

java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))

println(
"""
Java: ${System.getProperty("java.version")}
Expand All @@ -22,92 +21,35 @@ println(
"""
.trimIndent())

configure<UserDevExtension> {
mappings("parchment", "2023.09.03-$mcVersion")

accessTransformer("src/main/resources/META-INF/accesstransformer.cfg")

runs {
create("client") {
workingDirectory(file("run"))

// add mixin
property("mixin.env.remapRefMap", "true")
property(
"mixin.env.refMapRemappingFile", "${projectDir}/build/createSrgToMcp/output.srg")

// Recommended logging data for a userdev environment
property("forge.logging.markers", "SCAN,REGISTRIES,REGISTRYDUMP")

// Recommended logging level for the console
property("forge.logging.console.level", "debug")

mods { create(modId) { source(sourceSets["main"]) } }
}

create("server") {
workingDirectory(file("run"))

// add mixin
property("mixin.env.remapRefMap", "true")
property(
"mixin.env.refMapRemappingFile", "${projectDir}/build/createSrgToMcp/output.srg")

// Recommended logging data for a userdev environment
property("forge.logging.markers", "SCAN,REGISTRIES,REGISTRYDUMP")
accessTransformers.file("src/main/resources/META-INF/accesstransformer.cfg")

// Recommended logging level for the console
property("forge.logging.console.level", "debug")

mods { create(modId) { source(sourceSets["main"]) } }
}

create("gameTestServer") {
workingDirectory(file("run"))

// add mixin
property("mixin.env.remapRefMap", "true")
property(
"mixin.env.refMapRemappingFile", "${projectDir}/build/createSrgToMcp/output.srg")

// Recommended logging data for a userdev environment
property("forge.logging.markers", "SCAN,REGISTRIES,REGISTRYDUMP")

// Recommended logging level for the console
property("forge.logging.console.level", "debug")

mods { create(modId) { source(sourceSets["main"]) } }
}

create("data") {
workingDirectory(file("run-data"))
// add mixin
property("mixin.env.remapRefMap", "true")
property(
"mixin.env.refMapRemappingFile", "${projectDir}/build/createSrgToMcp/output.srg")
runs {
configureEach {
systemProperty("forge.logging.markers", "SCAN,REGISTRIES,REGISTRYDUMP")
systemProperty("forge.logging.console.level", "debug")
modSource(project.sourceSets.main.get())
}

// Recommended logging data for a userdev environment
property("forge.logging.markers", "SCAN,REGISTRIES,REGISTRYDUMP")
create("client") { systemProperty("forge.enabledGameTestNamespaces", modId) }

// Recommended logging level for the console
property("forge.logging.console.level", "debug")
create("server") {
systemProperty("forge.enabledGameTestNamespaces", modId)
programArguments.set(listOf("--nogui"))
}

// Specify the mod id for data generation, where to output the resulting resource, and
// where to look for existing resources.
args(
"--mod",
modId,
"--all",
"--output",
file("src/generated/resources/"),
"--existing",
file("src/main/resources/"))
create("gameTestServer") { systemProperty("forge.enabledGameTestNamespaces", modId) }

mods { create(modId) { source(sourceSets["main"]) } }
create("data") {
workingDirectory(file("run-data"))

// 'runData' is renamed to 'runDataGenerator' to make it more clear what it does.
taskName = "runDataGenerator"
}
programArguments.addAll(
"--mod",
modId,
"--all",
"--output",
file("src/generated/resources/").absolutePath,
"--existing",
file("src/main/resources/").absolutePath)
}
}

Expand All @@ -116,10 +58,10 @@ sourceSets.main { resources.srcDir("src/generated/resources") }
configurations { compileOnly { extendsFrom(configurations.annotationProcessor.get()) } }

dependencies {
minecraft("net.neoforged:forge:${mcVersion}-" + properties["neoForgeVersion"])
implementation("net.neoforged:neoforge:" + properties["neoForgeVersion"])

// kotlin forge
implementation("thedarkcolour:kotlinforforge:" + properties["kotlinForForgeVersion"])
implementation("thedarkcolour:kotlinforforge-neoforge:" + properties["kotlinForForgeVersion"])

// Logger
implementation("ch.qos.logback:logback-classic:" + properties["logbackVersion"])
Expand All @@ -129,9 +71,10 @@ dependencies {
implementation("io.github.realyusufismail:realyusufismailcore-neo:" + properties["coreVersion"])

// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
compileOnly(fg.deobf("mezz.jei:jei-${mcVersion}-common-api:" + properties["jeiVersion"]))
compileOnly(fg.deobf("mezz.jei:jei-${mcVersion}-forge-api:" + properties["jeiVersion"]))
runtimeOnly(fg.deobf("mezz.jei:jei-${mcVersion}-forge:" + properties["jeiVersion"]))
// TODO: Reinstate support once JEI releases support for NEoForge.
// compileOnly("mezz.jei:jei-${mcVersion}-common-api:" + properties["jeiVersion"])
// compileOnly("mezz.jei:jei-${mcVersion}-forge-api:" + properties["jeiVersion"])
// runtimeOnly("mezz.jei:jei-${mcVersion}-forge:" + properties["jeiVersion"])

// lombok
compileOnly("org.projectlombok:lombok:" + properties["lombokVersion"])
Expand Down Expand Up @@ -162,3 +105,23 @@ tasks.create("cfPublish", net.darkhax.curseforgegradle.TaskPublishCurseForge::cl
mainFile.addModLoader("NeoForge")
mainFile.addGameVersion(mcVersion)
}

tasks.withType(ProcessResources::class.java) {
val replaceProperties =
mapOf(
"minecraft_version" to mcVersion,
"minecraft_version_range" to "[1.20.2,1.21)",
"neo_version" to properties["neoForgeVersion"],
"neo_version_range" to "[20.2)",
"loader_version_range" to "[1,)",
"mod_id" to modId,
"mod_license" to "Apache-2.0",
"mod_version" to project.version,
"mod_authors" to "RealYusufIsmail",
"mod_description" to "A Minecraft mod that adds more armour and tools",
"pack_format_number" to "18")

inputs.properties(replaceProperties)

filesMatching(listOf("META-INF/mods.toml", "pack.mcmeta")) { expand(replaceProperties) }
}
12 changes: 6 additions & 6 deletions neoforge/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ kotlin.code.style=official
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

modVersion = 1.20.1-1.0.7.beta2
mcVersion = 1.20.1
modVersion = 1.20.2-2.0.0.beta2
mcVersion = 1.20.2
projectId = 480779
modId = armourandtoolsmod

neoForgeVersion = 47.1.76
kotlinForForgeVersion = 4.4.0
neoForgeVersion = 20.2.35-beta
kotlinForForgeVersion = 4.6.1
logbackVersion = 1.4.11
junitVersion = 5.10.0
coreVersion = 1.20.1-1.0.2
jeiVersion = 15.2.0.27
coreVersion = 1.20.2-1.0.3
jeiVersion = 16.0.0.28
lombokVersion = 1.18.30
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.network.NetworkHooks;
import net.neoforged.neoforge.network.NetworkHooks;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,19 @@ protected void init() {
this.widthTooNarrow,
this.menu);
this.leftPos = this.recipeBookComponent.updateScreenPosition(this.width, this.imageWidth);
this.leftPos = this.recipeBookComponent.updateScreenPosition(this.width, this.imageWidth);
this.addRenderableWidget(
new ImageButton(
this.leftPos + 5,
this.height / 2 - 49,
20,
18,
0,
0,
19,
RECIPE_BUTTON_LOCATION,
(p_98484_) -> {
RecipeBookComponent.RECIPE_BUTTON_SPRITES,
(p_289630_) -> {
this.recipeBookComponent.toggleVisibility();
this.leftPos =
this.recipeBookComponent.updateScreenPosition(this.width, this.imageWidth);
p_98484_.setPosition(this.leftPos + 5, this.height / 2 - 49);
p_289630_.setPosition(this.leftPos + 5, this.height / 2 - 49);
}));
this.addWidget(this.recipeBookComponent);
this.setInitialFocus(this.recipeBookComponent);
Expand All @@ -90,7 +88,6 @@ public void containerTick() {
* @param pPartialTick the partial tick time.
*/
public void render(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
this.renderBackground(pGuiGraphics);
if (this.recipeBookComponent.isVisible() && this.widthTooNarrow) {
this.renderBg(pGuiGraphics, pPartialTick, pMouseX, pMouseY);
this.recipeBookComponent.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick);
Expand Down
Loading

0 comments on commit 6cde581

Please sign in to comment.