From a54195f3770ee5543c93288a27da6e385d175a61 Mon Sep 17 00:00:00 2001 From: Minecraftschurli Date: Mon, 19 Feb 2024 10:38:43 +0100 Subject: [PATCH] update to 1.20.4 (#14) --- .github/workflows/build.yml | 2 +- build.gradle.kts | 296 +++--------------- gradle.properties | 40 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle.kts | 25 +- .../potionbundles/ClientHandler.java | 16 +- .../potionbundles/ClientSidedGetter.java | 4 +- .../potionbundles/Config.java | 20 +- .../potionbundles/JEICompat.java | 12 +- .../potionbundles/LingeringPotionBundle.java | 2 +- .../potionbundles/PotionBundle.java | 4 +- .../potionbundles/PotionBundleRecipe.java | 49 ++- .../potionbundles/PotionBundleUtils.java | 5 +- .../potionbundles/PotionBundles.java | 41 +-- .../potionbundles/SidedGetter.java | 4 +- .../potionbundles/SplashPotionBundle.java | 2 +- src/main/resources/META-INF/mods.toml | 31 -- .../potionbundles/test/PotionBundleTest.java | 4 +- 18 files changed, 150 insertions(+), 409 deletions(-) delete mode 100644 src/main/resources/META-INF/mods.toml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e037cb1..d649dcf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ on: - "version/[0-9]**" paths-ignore: - "*.md" - - "LICENSE.md" + - "LICENSE" tags-ignore: - "[0-9]+.[0-9]+.[0-9]+-[0-9]+.[0-9]+.[0-9]+" - "[0-9]+.[0-9]+-[0-9]+.[0-9]+.[0-9]+" diff --git a/build.gradle.kts b/build.gradle.kts index 4db26bf..514d7ac 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,74 +1,9 @@ -//file:noinspection GroovyAssignabilityCheck -import groovy.json.JsonSlurper -import groovy.json.JsonOutput -import groovy.util.Node -import groovy.util.NodeList -import java.time.Instant -import java.time.format.DateTimeFormatter -import java.util.* - -val mod_group: String by project -val mc_version: String by project -val mod_version: String by project -val mod_id: String by project -val forge_version: String by project -val jei_version: String by project -val java_version: String by project -val mappings_channel: String by project -val mappings_version: String by project -val vendor: String by project -val github: String by project -val mod_name: String by project -val mod_url: String by project - - -fun Project.fileTree(dir: String, include: String) = fileTree("dir" to dir, "include" to include) - plugins { - `maven-publish` - eclipse idea - java - id("net.minecraftforge.gradle") - id("org.parchmentmc.librarian.forgegradle") -} - -//-------------- - -group = mod_group -version = "${mc_version}-${mod_version}" -base { - archivesName.set(mod_id) -} - -if (System.getenv("RELEASE_TYPE") != null) { - status = System.getenv("RELEASE_TYPE").lowercase() - if (status == "snapshot") status = (status as String).uppercase() -} else { - status = "SNAPSHOT" -} - -if (status != "release") { - version = "${version}-${status}" -} - -java { - withSourcesJar() - - toolchain.languageVersion.set(JavaLanguageVersion.of(java_version)) -} - -sourceSets { - main { - resources { - srcDir("src/main/generated") - } - } + id ("com.github.minecraftschurlimods.helperplugin") } repositories { - mavenLocal() - mavenCentral() maven { name = "blamejared Maven" url = uri("https://maven.blamejared.com") @@ -79,203 +14,46 @@ repositories { } } -configurations.testImplementation.configure { extendsFrom(configurations.minecraft.get()) } - dependencies { - minecraft("net.minecraftforge:forge:${mc_version}-${forge_version}") - compileOnly(fg.deobf("mezz.jei:jei-1.20-common-api:${jei_version}")) - runtimeOnly(fg.deobf("mezz.jei:jei-1.20-forge:${jei_version}")) + implementation(helper.neoforge()) + compileOnly("mezz.jei:jei-1.20.4-common-api:${project.properties["jei_version"]}") + runtimeOnly("mezz.jei:jei-1.20.4-neoforge:${project.properties["jei_version"]}") implementation("org.jetbrains:annotations:23.0.0") - testImplementation(sourceSets.main.map { it.output }) -} - -minecraft { - mappings(mappings_channel, mappings_version) - copyIdeResources.set(true) - runs { - create("client") { - workingDirectory(file("run")) - property("forge.logging.console.level", "debug") - mods.register(mod_id) { - source(sourceSets.main.get()) - } - } - create("server") { - workingDirectory(file("run")) - property("forge.logging.console.level", "debug") - mods.register(mod_id) { - source(sourceSets.main.get()) - } - } - create("data") { - workingDirectory(file("run")) - property("forge.logging.console.level", "debug") - args("--mod", mod_id, "--all", "--output", file("src/main/generated/"), "--existing", file("src/main/resources/")) - mods.register(mod_id) { - source(sourceSets.main.get()) - } - } - create("gameTestServer") { - workingDirectory(file("run")) - singleInstance(true) - jvmArg("-ea") // Enable assertions - property("forge.logging.markers", "REGISTRIES") - property("forge.enabledGameTestNamespaces", mod_id) - mods.register(mod_id) { - source(sourceSets.main.get()) - source(sourceSets.test.get()) - } - } - } } -tasks { - withType().configureEach { - options.encoding = "UTF-8" - } - processResources { - val buildProps = project.properties.toMutableMap() - buildProps.values.removeIf { it !is CharSequence && it !is Number && it !is Boolean } - inputs.properties(buildProps) - - filesMatching("META-INF/mods.toml") { - expand(buildProps) - } - // minify json files - doLast { - fileTree(dir = outputs.files.asPath, include = "**/*.json").forEach { - it.writeText(JsonOutput.toJson(JsonSlurper().parse(it))) - } - } - } - named("jar") { - from(sourceSets.main.map { it.output }) - finalizedBy("reobfJar") - } - named("sourcesJar") { - duplicatesStrategy = DuplicatesStrategy.INCLUDE - from(sourceSets.main.map { it.allSource }) - } - withType().configureEach { - var extension = "" - if (archiveClassifier.isPresent) { - extension = archiveClassifier.get() - if (extension != "") { - extension = "-$extension" - } - } - manifest { - attributes(mapOf( - "Maven-Artifact" to "${mod_group}:${base.archivesName}:${project.version}", - "Specification-Title" to base.archivesName, - "Specification-Vendor" to vendor, - "Specification-Version" to "1", - "Implementation-Title" to "${base.archivesName}${extension}", - "Implementation-Version" to mod_version, - "Implementation-Vendor" to vendor, - "Built-On-Java" to "${System.getProperty("java.vm.version")} (${System.getProperty("java.vm.vendor")})", - "Built-On" to "${mc_version}-${forge_version}", - "Timestamp" to DateTimeFormatter.ISO_INSTANT.format(Instant.now()), - "FMLModType" to "MOD" - )) - } - } - register("reobf") { - dependsOn(named("reobfJar")) - } - register("setupGithubActions") { - doLast { - println("##[set-output name=modid;]${mod_id}") - println("##[set-output name=version;]${project.version}") - } - } - withType().configureEach { - enabled = false - } -} - -artifacts { - archives(tasks.named("jar")) - archives(tasks.named("sourcesJar")) -} - -reobf { - create("jar") { - classpath.from(sourceSets.main.map { it.compileClasspath }) - } -} - -idea.module.excludeDirs.addAll(arrayOf("run", "out", "libs").map(::file)) - -publishing { - publications.create("${base.archivesName.get()}ToMaven") { - groupId = project.group as String - artifactId = base.archivesName.get() - version = project.version as String - from(components["java"]) - pom { - name.set(mod_name) - url.set(mod_url) - packaging = "jar" - scm { - connection.set("scm:git:git://github.com/${github}.git") - developerConnection.set("scm:git:git@github.com:${github}.git") - url.set("https://github.com/${github}") - } - issueManagement { - system.set("github") - url.set("https://github.com/${github}/issues") - } - organization { - name.set("Minecraftschurli Mods") - url.set("https://github.com/MinecraftschurliMods") - } - developers { - developer { - id.set("minecraftschurli") - name.set("Minecraftschurli") - url.set("https://github.com/Minecraftschurli") - email.set("minecraftschurli@gmail.com") - organization.set("Minecraftschurli Mods") - organizationUrl.set("https://github.com/MinecraftschurliMods") - timezone.set("Europe/Vienna") - } - developer { - id.set("ichhabehunger54") - name.set("IchHabeHunger54") - url.set("https://github.com/IchHabeHunger54") - organization.set("Minecraftschurli Mods") - organizationUrl.set("https://github.com/MinecraftschurliMods") - timezone.set("Europe/Vienna") - } - } - withXml { - val rootNode = asNode() - val dependencies: NodeList = (rootNode.get("dependencies") as NodeList) - val dependencyList = dependencies.getAt("dependency") - for (dependency in dependencyList) { - val dependencyNode = dependency as Node - val version = ((((dependencyNode.get("version") as NodeList).last() as Node).value() as NodeList).last() as String) - if (version.contains("_mapped_")) { - assert(dependencyNode.parent().remove(dependencyNode)) - } - } - } - } - } - repositories { - maven { - if ((System.getenv("MAVEN_USER") != null) - && (System.getenv("MAVEN_PASSWORD") != null) - && (System.getenv("MAVEN_URL") != null)) { - url = uri(System.getenv("MAVEN_URL")) - credentials { - username = System.getenv("MAVEN_USER") - password = System.getenv("MAVEN_PASSWORD") - } - } else { - url = uri("$buildDir/repo") - } +helper.withTestSourceSet() +helper.withCommonRuns() +helper.withGameTestRuns() +helper.modproperties.put( + "catalogueItemIcon", helper.projectId.map { "$it:potion_bundle{Potion:\"minecraft:water\"}" } +) +helper.dependency( + "jei", + project.properties["jei_version_range"] as String, + "optional" +) + +helper.publication.pom { + organization { + name = "Minecraftschurli Mods" + url = "https://github.com/MinecraftschurliMods" + } + developers { + developer { + id = "minecraftschurli" + name = "Minecraftschurli" + email = "minecraftschurli@gmail.com" + organization = "Minecraftschurli Mods" + organizationUrl = "https://github.com/Minecraftschurli" + timezone = "Europe/Vienna" + } + developer { + id = "ichhabehunger54" + name = "IchHabeHunger54" + url = "https://github.com/IchHabeHunger54" + organization = "Minecraftschurli Mods" + organizationUrl = "https://github.com/MinecraftschurliMods" + timezone = "Europe/Vienna" } } } diff --git a/gradle.properties b/gradle.properties index 61ababe..a6381ac 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,34 +1,38 @@ -org.gradle.jvmargs=-Xmx3G +org.gradle.jvmargs=-Xmx4G org.gradle.daemon=false +org.gradle.caching=true mod_group=com.github.minecraftschurlimods mod_id=potionbundles -mod_name=Potion Bundles mod_version=1.8 -mod_url=https://www.curseforge.com/minecraft/mc-mods/potion-bundles +mod_name=Potion Bundles mod_authors=IchHabeHunger54, Minecraftschurli mod_description=Potions can now be bound into bundles, to save inventory space. -url=https://www.curseforge.com/minecraft/mc-mods/potion-bundles -github=MinecraftschurliMods/PotionBundles - vendor=MinecraftschurliMods java_version=17 -forgegradle_version=[6.0,6.2) -librarian_version=1.+ +url=https://www.curseforge.com/minecraft/mc-mods/potion-bundles + +github.owner=MinecraftschurliMods +github.repo=PotionBundles + +license.name=GPLv3 +license.url=https://www.gnu.org/licenses/gpl-3.0.en.html +license.file=LICENSE -loader_version_range=[46,) +neogradle.subsystems.parchment.minecraftVersion=1.20.3 +neogradle.subsystems.parchment.mappingsVersion=2023.12.31 -mc_version=1.20 -mc_version_range=[1.20,1.20.2) +mc_version=1.20.4 +mc_version_range=[1.20.4,1.20.5) -forge_version=46.0.1 -forge_version_range=[46.0.1,) +neo_version=20.4.80-beta +neo_version_range=[20.4.80-beta,20.5) -mappings_version=1.20 -mappings_channel=official +mc-publish.curseforge=382836 +mc-publish.modrinth=ZZLWU8jS -jei_version=14.0.0.4 +loader.version=[1,) -curse_project_id=382836 -modrinth_project_id=ZZLWU8jS +jei_version=17.3.0.49 +jei_version_range=[17.3,18) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fae0804..17655d0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle.kts b/settings.gradle.kts index 42d20ba..be69756 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,27 +1,18 @@ pluginManagement { plugins { - `maven-publish` - eclipse - idea - java - val forgegradle_version: String by settings - val librarian_version: String by settings - id("net.minecraftforge.gradle") version(forgegradle_version) - id("org.parchmentmc.librarian.forgegradle") version(librarian_version) + id("net.neoforged.gradle.userdev") version "7.0.80" + id("com.github.minecraftschurlimods.helperplugin") version "1.3" } repositories { + mavenLocal() gradlePluginPortal() - maven { - name = "MinecraftForge" - url = uri("https://maven.minecraftforge.net/") - } - maven { - name = "Parchment" - url = uri("https://maven.parchmentmc.org") - } + maven { url = uri("https://maven.neoforged.net/releases") } + maven { url = uri("https://minecraftschurli.ddns.net/repository/maven-public") } } } plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0" -} \ No newline at end of file +} + +rootProject.name = "PotionBundles" diff --git a/src/main/java/com/github/minecraftschurlimods/potionbundles/ClientHandler.java b/src/main/java/com/github/minecraftschurlimods/potionbundles/ClientHandler.java index a240af8..e11650d 100644 --- a/src/main/java/com/github/minecraftschurlimods/potionbundles/ClientHandler.java +++ b/src/main/java/com/github/minecraftschurlimods/potionbundles/ClientHandler.java @@ -5,12 +5,12 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraft.world.item.alchemy.PotionUtils; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.client.event.RegisterColorHandlersEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod; +import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; +import net.neoforged.neoforge.registries.DeferredHolder; @Mod.EventBusSubscriber(value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD, modid = PotionBundles.MODID) public class ClientHandler { @@ -20,7 +20,7 @@ public static void clientSetup(FMLClientSetupEvent e) { @SuppressWarnings("deprecation") ItemPropertyFunction propertyFunction = (stack, world, living, seed) -> !stack.hasTag() || !stack.getOrCreateTag().contains(PotionBundleUtils.USES_KEY) ? 0 : PotionBundleUtils.getUses(stack); ResourceLocation uses = new ResourceLocation(PotionBundles.MODID, "uses"); - for (RegistryObject item : PotionBundles.ITEMS.getEntries()) { + for (DeferredHolder item : PotionBundles.ITEMS.getEntries()) { ItemProperties.register(item.get(), uses, propertyFunction); } }); @@ -28,6 +28,6 @@ public static void clientSetup(FMLClientSetupEvent e) { @SubscribeEvent public static void registerItemColorHandler(RegisterColorHandlersEvent.Item e) { - e.register((stack, index) -> index > 0 ? -1 : PotionUtils.getColor(stack), PotionBundles.ITEMS.getEntries().stream().map(RegistryObject::get).toArray(Item[]::new)); + e.register((stack, index) -> index > 0 ? -1 : PotionUtils.getColor(stack), PotionBundles.ITEMS.getEntries().stream().map(DeferredHolder::get).toArray(Item[]::new)); } } diff --git a/src/main/java/com/github/minecraftschurlimods/potionbundles/ClientSidedGetter.java b/src/main/java/com/github/minecraftschurlimods/potionbundles/ClientSidedGetter.java index 6627711..1e8fb0c 100644 --- a/src/main/java/com/github/minecraftschurlimods/potionbundles/ClientSidedGetter.java +++ b/src/main/java/com/github/minecraftschurlimods/potionbundles/ClientSidedGetter.java @@ -5,8 +5,8 @@ import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.core.RegistryAccess; import net.minecraft.world.item.crafting.RecipeManager; -import net.minecraftforge.fml.util.thread.EffectiveSide; -import net.minecraftforge.server.ServerLifecycleHooks; +import net.neoforged.fml.util.thread.EffectiveSide; +import net.neoforged.neoforge.server.ServerLifecycleHooks; import org.jetbrains.annotations.Nullable; public class ClientSidedGetter { diff --git a/src/main/java/com/github/minecraftschurlimods/potionbundles/Config.java b/src/main/java/com/github/minecraftschurlimods/potionbundles/Config.java index 9f4aa09..44f070f 100644 --- a/src/main/java/com/github/minecraftschurlimods/potionbundles/Config.java +++ b/src/main/java/com/github/minecraftschurlimods/potionbundles/Config.java @@ -1,28 +1,28 @@ package com.github.minecraftschurlimods.potionbundles; -import net.minecraftforge.common.ForgeConfigSpec; +import net.neoforged.neoforge.common.ModConfigSpec; import org.apache.commons.lang3.tuple.Pair; public class Config { - static final ForgeConfigSpec clientSpec; + static final ModConfigSpec clientSpec; public static final Config.Client CLIENT; - static final ForgeConfigSpec serverSpec; + static final ModConfigSpec serverSpec; public static final Config.Server SERVER; static { - Pair clientPair = new ForgeConfigSpec.Builder().configure(Config.Client::new); + Pair clientPair = new ModConfigSpec.Builder().configure(Config.Client::new); clientSpec = clientPair.getRight(); CLIENT = clientPair.getLeft(); - Pair serverPair = new ForgeConfigSpec.Builder().configure(Config.Server::new); + Pair serverPair = new ModConfigSpec.Builder().configure(Config.Server::new); serverSpec = serverPair.getRight(); SERVER = serverPair.getLeft(); } public static class Client { - public final ForgeConfigSpec.IntValue durabilityBarColor; - public final ForgeConfigSpec.BooleanValue showDurabilityBar; + public final ModConfigSpec.IntValue durabilityBarColor; + public final ModConfigSpec.BooleanValue showDurabilityBar; - Client(ForgeConfigSpec.Builder builder) { + Client(ModConfigSpec.Builder builder) { durabilityBarColor = builder .comment("What color the damage bar of a potion bundle should have. Set to -1 to not display a damage bar.") .translation("config." + PotionBundles.MODID + ".durabilityBarColor") @@ -35,9 +35,9 @@ public static class Client { } public static class Server { - public final ForgeConfigSpec.BooleanValue returnString; + public final ModConfigSpec.BooleanValue returnString; - Server(ForgeConfigSpec.Builder builder) { + Server(ModConfigSpec.Builder builder) { returnString = builder .comment("Whether to return the string upon finishing the bundle or not.") .translation("config." + PotionBundles.MODID + ".returnString") diff --git a/src/main/java/com/github/minecraftschurlimods/potionbundles/JEICompat.java b/src/main/java/com/github/minecraftschurlimods/potionbundles/JEICompat.java index 55bf7a9..b5227c4 100644 --- a/src/main/java/com/github/minecraftschurlimods/potionbundles/JEICompat.java +++ b/src/main/java/com/github/minecraftschurlimods/potionbundles/JEICompat.java @@ -11,12 +11,12 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.core.NonNullList; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.alchemy.PotionUtils; import net.minecraft.world.item.crafting.*; -import net.minecraftforge.registries.ForgeRegistries; import java.util.Objects; import java.util.stream.Stream; @@ -35,6 +35,7 @@ public void registerRecipes(final IRecipeRegistration registration) { RecipeManager recipeManager = level.getRecipeManager(); var recipes = recipeManager.getAllRecipesFor(RecipeType.CRAFTING) .stream() + .map(RecipeHolder::value) .filter(PotionBundleRecipe.class::isInstance) .map(PotionBundleRecipe.class::cast) .flatMap(this::mapRecipes) @@ -42,13 +43,12 @@ public void registerRecipes(final IRecipeRegistration registration) { registration.addRecipes(RecipeTypes.CRAFTING, recipes); } - private Stream mapRecipes(final PotionBundleRecipe recipe) { + private Stream> mapRecipes(final PotionBundleRecipe recipe) { String group = "jei.potionbundle"; AbstractPotionBundle bundleItem = recipe.getBundleItem(); int maxUses = bundleItem.getMaxUses(); Item potionItem = recipe.getPotionItem(); - return ForgeRegistries.POTIONS - .getValues() + return BuiltInRegistries.POTION .stream() .map(potion -> { Ingredient potionIngredient = Ingredient.of(PotionUtils.setPotion(new ItemStack(potionItem), potion)); @@ -60,13 +60,13 @@ private Stream mapRecipes(final PotionBundleRecipe recipe) { ItemStack output = PotionUtils.setPotion(new ItemStack(bundleItem), potion); PotionBundleUtils.setUses(output, maxUses); ResourceLocation id = new ResourceLocation(ModIds.MINECRAFT_ID, group + "." + output.getDescriptionId() + "." + potion.getName("")); - return new ShapelessRecipe(id, group, CraftingBookCategory.EQUIPMENT, output, inputs); + return new RecipeHolder<>(id, new ShapelessRecipe(group, CraftingBookCategory.EQUIPMENT, output, inputs)); }); } @Override public void registerItemSubtypes(ISubtypeRegistration r) { - IIngredientSubtypeInterpreter byPotion = (ingredient, context) -> String.valueOf(ForgeRegistries.POTIONS.getKey(PotionUtils.getPotion(ingredient))); + IIngredientSubtypeInterpreter byPotion = (ingredient, context) -> String.valueOf(BuiltInRegistries.POTION.getKey(PotionUtils.getPotion(ingredient))); r.registerSubtypeInterpreter(VanillaTypes.ITEM_STACK, PotionBundles.POTION_BUNDLE.get(), byPotion); r.registerSubtypeInterpreter(VanillaTypes.ITEM_STACK, PotionBundles.SPLASH_POTION_BUNDLE.get(), byPotion); r.registerSubtypeInterpreter(VanillaTypes.ITEM_STACK, PotionBundles.LINGERING_POTION_BUNDLE.get(), byPotion); diff --git a/src/main/java/com/github/minecraftschurlimods/potionbundles/LingeringPotionBundle.java b/src/main/java/com/github/minecraftschurlimods/potionbundles/LingeringPotionBundle.java index 4434e4a..8f65646 100644 --- a/src/main/java/com/github/minecraftschurlimods/potionbundles/LingeringPotionBundle.java +++ b/src/main/java/com/github/minecraftschurlimods/potionbundles/LingeringPotionBundle.java @@ -15,7 +15,7 @@ public class LingeringPotionBundle extends AbstractThrowablePotionBundle { @Override public void appendHoverText(ItemStack stack, @Nullable Level world, List tooltip, TooltipFlag flag) { - PotionUtils.addPotionTooltip(stack, tooltip, 0.25F); + PotionUtils.addPotionTooltip(stack, tooltip, 0.25F, world == null ? 20.0F : world.tickRateManager().tickrate()); super.appendHoverText(stack, world, tooltip, flag); } diff --git a/src/main/java/com/github/minecraftschurlimods/potionbundles/PotionBundle.java b/src/main/java/com/github/minecraftschurlimods/potionbundles/PotionBundle.java index 3cc29f5..34fae4e 100644 --- a/src/main/java/com/github/minecraftschurlimods/potionbundles/PotionBundle.java +++ b/src/main/java/com/github/minecraftschurlimods/potionbundles/PotionBundle.java @@ -12,7 +12,7 @@ import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.alchemy.PotionUtils; import net.minecraft.world.level.Level; -import net.minecraftforge.items.ItemHandlerHelper; +import net.neoforged.neoforge.items.ItemHandlerHelper; import org.jetbrains.annotations.Nullable; import java.util.List; @@ -20,7 +20,7 @@ public class PotionBundle extends AbstractPotionBundle { @Override public void appendHoverText(ItemStack stack, @Nullable Level world, List tooltip, TooltipFlag flag) { - PotionUtils.addPotionTooltip(stack, tooltip, 1.0F); + PotionUtils.addPotionTooltip(stack, tooltip, 1.0F, world == null ? 20.0F : world.tickRateManager().tickrate()); super.appendHoverText(stack, world, tooltip, flag); } diff --git a/src/main/java/com/github/minecraftschurlimods/potionbundles/PotionBundleRecipe.java b/src/main/java/com/github/minecraftschurlimods/potionbundles/PotionBundleRecipe.java index 0a7f0cc..10422cb 100644 --- a/src/main/java/com/github/minecraftschurlimods/potionbundles/PotionBundleRecipe.java +++ b/src/main/java/com/github/minecraftschurlimods/potionbundles/PotionBundleRecipe.java @@ -1,10 +1,11 @@ package com.github.minecraftschurlimods.potionbundles; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.core.RegistryAccess; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.inventory.CraftingContainer; import net.minecraft.world.item.Item; @@ -17,19 +18,23 @@ import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.level.Level; -import net.minecraftforge.registries.ForgeRegistries; -import org.jetbrains.annotations.Nullable; import java.util.List; -import java.util.Objects; +import java.util.function.Function; public class PotionBundleRecipe extends CustomRecipe { + private static final Codec CODEC = RecordCodecBuilder.create(inst -> inst.group( + Ingredient.CODEC_NONEMPTY.fieldOf("string").forGetter(PotionBundleRecipe::getString), + BuiltInRegistries.ITEM.byNameCodec().fieldOf("potion").forGetter(PotionBundleRecipe::getPotionItem), + BuiltInRegistries.ITEM.byNameCodec().comapFlatMap(bundle -> bundle instanceof AbstractPotionBundle bundle1 ? DataResult.success(bundle1) : DataResult.error(() -> "The defined PotionBundle is not an instance of AbstractPotionBundle"), Function.identity()).fieldOf("bundle").forGetter(PotionBundleRecipe::getBundleItem) + ).apply(inst, PotionBundleRecipe::new)); + private final Ingredient string; private final Item potion; private final AbstractPotionBundle bundle; - public PotionBundleRecipe(ResourceLocation id, Ingredient string, Item potion, AbstractPotionBundle bundle) { - super(id, CraftingBookCategory.EQUIPMENT); + public PotionBundleRecipe(Ingredient string, Item potion, AbstractPotionBundle bundle) { + super(CraftingBookCategory.EQUIPMENT); this.string = string; this.potion = potion; this.bundle = bundle; @@ -112,36 +117,24 @@ public Ingredient getString() { static class Serializer implements RecipeSerializer { @Override - public PotionBundleRecipe fromJson(ResourceLocation rl, JsonObject json) { - Ingredient string = Ingredient.fromJson(json.get("string")); - Item potion = ForgeRegistries.ITEMS.getValue(ResourceLocation.tryParse(json.get("potion").getAsString())); - if (potion == null) - throw new JsonParseException("Tried using an invalid item as potion item for recipe " + rl); - Item bundle = ForgeRegistries.ITEMS.getValue(ResourceLocation.tryParse(json.get("bundle").getAsString())); - if (bundle == null) - throw new JsonParseException("Tried using an invalid item as potion bundle item for recipe " + rl); - if (bundle instanceof AbstractPotionBundle bundle1) - return new PotionBundleRecipe(rl, string, potion, bundle1); - else - throw new JsonParseException("The defined PotionBundle is not an instance of AbstractPotionBundle in recipe " + rl); + public Codec codec() { + return CODEC; } - @Nullable @Override - public PotionBundleRecipe fromNetwork(ResourceLocation rl, FriendlyByteBuf buf) { + public PotionBundleRecipe fromNetwork(FriendlyByteBuf buf) { Ingredient string = Ingredient.fromNetwork(buf); - Item potion = ForgeRegistries.ITEMS.getValue(buf.readResourceLocation()); - Item bundle = ForgeRegistries.ITEMS.getValue(buf.readResourceLocation()); - assert potion != null; + Item potion = BuiltInRegistries.ITEM.get(buf.readResourceLocation()); + Item bundle = BuiltInRegistries.ITEM.get(buf.readResourceLocation()); assert bundle instanceof AbstractPotionBundle; - return new PotionBundleRecipe(rl, string, potion, (AbstractPotionBundle) bundle); + return new PotionBundleRecipe(string, potion, (AbstractPotionBundle) bundle); } @Override public void toNetwork(FriendlyByteBuf buf, PotionBundleRecipe recipe) { recipe.string.toNetwork(buf); - buf.writeResourceLocation(Objects.requireNonNull(ForgeRegistries.ITEMS.getKey(recipe.potion))); - buf.writeResourceLocation(Objects.requireNonNull(ForgeRegistries.ITEMS.getKey(recipe.bundle))); + buf.writeResourceLocation(BuiltInRegistries.ITEM.getKey(recipe.potion)); + buf.writeResourceLocation(BuiltInRegistries.ITEM.getKey(recipe.bundle)); } } } diff --git a/src/main/java/com/github/minecraftschurlimods/potionbundles/PotionBundleUtils.java b/src/main/java/com/github/minecraftschurlimods/potionbundles/PotionBundleUtils.java index aa3177c..57d7cc8 100644 --- a/src/main/java/com/github/minecraftschurlimods/potionbundles/PotionBundleUtils.java +++ b/src/main/java/com/github/minecraftschurlimods/potionbundles/PotionBundleUtils.java @@ -1,8 +1,10 @@ package com.github.minecraftschurlimods.potionbundles; +import net.minecraft.nbt.CompoundTag; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; +import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.Level; import org.jetbrains.annotations.Nullable; @@ -31,7 +33,7 @@ public static ItemStack getString(ItemStack stack) { } public static void setString(ItemStack stack, ItemStack string) { - stack.getOrCreateTag().put(STRING_KEY, string.serializeNBT()); + stack.getOrCreateTag().put(STRING_KEY, string.save(new CompoundTag())); } @Nullable @@ -39,6 +41,7 @@ public static Item getPotionForBundle(Level world, AbstractPotionBundle bundle) return world.getRecipeManager() .getAllRecipesFor(RecipeType.CRAFTING) .stream() + .map(RecipeHolder::value) .filter(recipe -> recipe.getSerializer() == PotionBundles.POTION_BUNDLE_RECIPE_SERIALIZER.get()) .filter(PotionBundleRecipe.class::isInstance) .map(PotionBundleRecipe.class::cast) diff --git a/src/main/java/com/github/minecraftschurlimods/potionbundles/PotionBundles.java b/src/main/java/com/github/minecraftschurlimods/potionbundles/PotionBundles.java index dcef67e..c834eab 100644 --- a/src/main/java/com/github/minecraftschurlimods/potionbundles/PotionBundles.java +++ b/src/main/java/com/github/minecraftschurlimods/potionbundles/PotionBundles.java @@ -2,23 +2,26 @@ import com.mojang.logging.LogUtils; import net.minecraft.core.RegistryAccess; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; import net.minecraft.world.item.CreativeModeTabs; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.alchemy.Potion; import net.minecraft.world.item.alchemy.Potions; import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.item.crafting.RecipeManager; import net.minecraft.world.item.crafting.RecipeSerializer; -import net.minecraftforge.event.BuildCreativeModeTabContentsEvent; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.config.ModConfig; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.ModLoadingContext; +import net.neoforged.fml.common.Mod; +import net.neoforged.fml.config.ModConfig; +import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext; +import net.neoforged.neoforge.registries.DeferredHolder; +import net.neoforged.neoforge.registries.DeferredItem; +import net.neoforged.neoforge.registries.DeferredRegister; import org.slf4j.Logger; import java.util.List; @@ -28,15 +31,14 @@ public class PotionBundles { public static final String MODID = "potionbundles"; public static final int POTION_BUNDLE_SIZE = 3; static final Logger LOGGER = LogUtils.getLogger(); - static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID); - static final DeferredRegister> RECIPE_SERIALIZERS = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, MODID); - public static final RegistryObject POTION_BUNDLE = ITEMS.register("potion_bundle", PotionBundle::new); - public static final RegistryObject SPLASH_POTION_BUNDLE = ITEMS.register("splash_potion_bundle", SplashPotionBundle::new); - public static final RegistryObject LINGERING_POTION_BUNDLE = ITEMS.register("lingering_potion_bundle", LingeringPotionBundle::new); - public static final RegistryObject> POTION_BUNDLE_RECIPE_SERIALIZER = RECIPE_SERIALIZERS.register("crafting_special_potion_bundle", PotionBundleRecipe.Serializer::new); + static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MODID); + static final DeferredRegister> RECIPE_SERIALIZERS = DeferredRegister.create(Registries.RECIPE_SERIALIZER, MODID); + public static final DeferredItem POTION_BUNDLE = ITEMS.register("potion_bundle", PotionBundle::new); + public static final DeferredItem SPLASH_POTION_BUNDLE = ITEMS.register("splash_potion_bundle", SplashPotionBundle::new); + public static final DeferredItem LINGERING_POTION_BUNDLE = ITEMS.register("lingering_potion_bundle", LingeringPotionBundle::new); + public static final DeferredHolder, RecipeSerializer> POTION_BUNDLE_RECIPE_SERIALIZER = RECIPE_SERIALIZERS.register("crafting_special_potion_bundle", PotionBundleRecipe.Serializer::new); - public PotionBundles() { - final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); + public PotionBundles(IEventBus modEventBus) { ITEMS.register(modEventBus); RECIPE_SERIALIZERS.register(modEventBus); modEventBus.addListener(PotionBundles::registerItemsToCreativeTabs); @@ -69,7 +71,7 @@ private static void registerItemsToCreativeTabs(BuildCreativeModeTabContentsEven } private static void addBundlesForAllPotions(BuildCreativeModeTabContentsEvent populator, AbstractPotionBundle bundle, ItemStack string) { - for (Potion potion : ForgeRegistries.POTIONS.getValues()) { + for (Potion potion : BuiltInRegistries.POTION) { if (potion == Potions.EMPTY) continue; ItemStack stack = bundle.createStack(string, potion, List.of(), null); if (!stack.isEmpty()) populator.accept(stack); @@ -77,7 +79,8 @@ private static void addBundlesForAllPotions(BuildCreativeModeTabContentsEvent po } private static ItemStack getStringFromRecipe(AbstractPotionBundle bundle, RegistryAccess registryAccess, RecipeManager recipeManager) { - for (Recipe recipe : recipeManager.getRecipes()) { + for (RecipeHolder holder : recipeManager.getRecipes()) { + Recipe recipe = holder.value(); if (recipe.getSerializer() != POTION_BUNDLE_RECIPE_SERIALIZER.get()) continue; if (recipe.getResultItem(registryAccess).getItem() != bundle) continue; for (ItemStack stack : ((PotionBundleRecipe) recipe).getString().getItems()) { diff --git a/src/main/java/com/github/minecraftschurlimods/potionbundles/SidedGetter.java b/src/main/java/com/github/minecraftschurlimods/potionbundles/SidedGetter.java index 1cdc826..c59ee76 100644 --- a/src/main/java/com/github/minecraftschurlimods/potionbundles/SidedGetter.java +++ b/src/main/java/com/github/minecraftschurlimods/potionbundles/SidedGetter.java @@ -2,8 +2,8 @@ import net.minecraft.core.RegistryAccess; import net.minecraft.world.item.crafting.RecipeManager; -import net.minecraftforge.fml.loading.FMLEnvironment; -import net.minecraftforge.server.ServerLifecycleHooks; +import net.neoforged.fml.loading.FMLEnvironment; +import net.neoforged.neoforge.server.ServerLifecycleHooks; import org.jetbrains.annotations.Nullable; public class SidedGetter { diff --git a/src/main/java/com/github/minecraftschurlimods/potionbundles/SplashPotionBundle.java b/src/main/java/com/github/minecraftschurlimods/potionbundles/SplashPotionBundle.java index 10bd983..eb5e31c 100644 --- a/src/main/java/com/github/minecraftschurlimods/potionbundles/SplashPotionBundle.java +++ b/src/main/java/com/github/minecraftschurlimods/potionbundles/SplashPotionBundle.java @@ -15,7 +15,7 @@ public class SplashPotionBundle extends AbstractThrowablePotionBundle { @Override public void appendHoverText(ItemStack stack, @Nullable Level world, List tooltip, TooltipFlag flag) { - PotionUtils.addPotionTooltip(stack, tooltip, 1F); + PotionUtils.addPotionTooltip(stack, tooltip, 1F, world == null ? 20.0F : world.tickRateManager().tickrate()); super.appendHoverText(stack, world, tooltip, flag); } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml deleted file mode 100644 index 5159c64..0000000 --- a/src/main/resources/META-INF/mods.toml +++ /dev/null @@ -1,31 +0,0 @@ -modLoader="javafml" -loaderVersion="${loader_version_range}" -license="GPLv3" - -[[mods]] - modId="${mod_id}" - version="${mod_version}" - displayName="${mod_name}" - displayURL="${mod_url}" - authors="${mod_authors}" - description='''${mod_description}''' - [custom.mc-publish] - modrinth = "${modrinth_project_id}" - curseforge = ${curse_project_id} - -[[dependencies.${mod_id}]] - modId="forge" - versionRange="${forge_version_range}" - mandatory=true - ordering="NONE" - side="BOTH" - -[[dependencies.${mod_id}]] - modId="minecraft" - versionRange="${mc_version_range}" - mandatory=true - ordering="NONE" - side="BOTH" - -[modproperties.${mod_id}] - catalogueItemIcon="potionbundles:potion_bundle{Potion:\"minecraft:water\"}" diff --git a/src/test/java/com/github/minecraftschurlimods/potionbundles/test/PotionBundleTest.java b/src/test/java/com/github/minecraftschurlimods/potionbundles/test/PotionBundleTest.java index 79e6eeb..dff35ab 100644 --- a/src/test/java/com/github/minecraftschurlimods/potionbundles/test/PotionBundleTest.java +++ b/src/test/java/com/github/minecraftschurlimods/potionbundles/test/PotionBundleTest.java @@ -18,8 +18,8 @@ import net.minecraft.world.item.alchemy.PotionUtils; import net.minecraft.world.item.alchemy.Potions; import net.minecraft.world.phys.Vec3; -import net.minecraftforge.gametest.GameTestHolder; -import net.minecraftforge.gametest.PrefixGameTestTemplate; +import net.neoforged.neoforge.gametest.GameTestHolder; +import net.neoforged.neoforge.gametest.PrefixGameTestTemplate; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull;