From d3a87f235a3ff44718db0a8519eb462cd36e1a18 Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Mon, 10 Jun 2024 17:02:05 +0200 Subject: [PATCH] Update to NeoForge 1.20.4 --- .github/workflows/ci.yml | 2 + .gitignore | 2 + build.gradle | 156 ++++++++---------- gradle.properties | 11 +- settings.gradle | 6 +- .../integratedcrafting/Capabilities.java | 18 +- .../integratedcrafting/GeneralConfig.java | 2 +- .../IntegratedCrafting.java | 28 ++-- .../integratedcrafting/RegistryEntries.java | 16 +- .../network/CraftingInterfaceConfig.java | 27 --- ...CraftingNetworkCapabilityConstructors.java | 8 +- .../network/CraftingNetworkConfig.java | 27 --- ...erScreenPartInterfaceCraftingSettings.java | 4 +- .../core/CraftingHelpers.java | 41 ++--- .../core/CraftingJobHandler.java | 6 +- .../core/MissingIngredients.java | 2 +- .../CraftingProcessOverrideBrewingStand.java | 10 +- .../CraftingProcessOverrideCraftingTable.java | 10 +- .../core/network/CraftingNetwork.java | 2 +- .../ContainerPartInterfaceCrafting.java | 4 +- .../ContainerPartInterfaceCraftingConfig.java | 4 +- ...ontainerPartInterfaceCraftingSettings.java | 18 +- ...erPartInterfaceCraftingSettingsConfig.java | 4 +- .../part/PartTypeInterfaceCrafting.java | 43 ++--- .../aspect/CraftingAspectReadBuilders.java | 11 +- .../aspect/CraftingAspectWriteBuilders.java | 2 +- src/main/resources/META-INF/mods.toml | 20 +-- .../craft_crafting_interface.json | 10 +- .../insert_recipe_planks.json | 11 +- .../craft_crafting_writer.json | 10 +- .../autocrafting_trigger/craft_planks.json | 12 +- 31 files changed, 220 insertions(+), 307 deletions(-) delete mode 100644 src/main/java/org/cyclops/integratedcrafting/capability/network/CraftingInterfaceConfig.java delete mode 100644 src/main/java/org/cyclops/integratedcrafting/capability/network/CraftingNetworkConfig.java diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e7c48a11..024329af 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,6 +49,8 @@ jobs: SIGN_STOREPASS: ${{ secrets.SIGN_STOREPASS }} MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} MAVEN_KEY: ${{ secrets.MAVEN_KEY }} + GITHUB_USER: ${{ github.actor }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: 'Test' env: COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} diff --git a/.gitignore b/.gitignore index 2f1e37b2..b50deb84 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ doc/info.txt /build /run +/runs # Ignore project specific files .classpath @@ -17,6 +18,7 @@ repo/* *.iws out/* keystore.jks +.idea # Ignore mac-specific file(s) .DS_Store diff --git a/build.gradle b/build.gradle index a909f26f..94548cf8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,17 @@ plugins { - id 'net.minecraftforge.gradle' version '[6.0,6.2)' - id 'com.matthewprenger.cursegradle' version '1.4.0' + id 'net.neoforged.gradle.userdev' version '7.0.97' + id 'net.darkhax.curseforgegradle' version '1.0.8' id 'com.github.kt3k.coveralls' version '2.12.0' id 'com.diffplug.spotless' version '5.14.3' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'com.modrinth.minotaur' version '2.+' } -apply plugin: 'net.minecraftforge.gradle' apply plugin: 'idea' apply plugin: 'maven-publish' apply plugin: 'jacoco' -import net.minecraftforge.gradle.common.tasks.SignJar +import net.neoforged.gradle.common.tasks.PotentiallySignJar // Determine build number String build_number = "DEV" // this will be referenced as simply build_number from now on. @@ -29,7 +28,10 @@ logger.lifecycle "BUILDING VERSION: " + build_number // Set mod details version = project.mod_version group = "org.cyclops.integratedcrafting" -archivesBaseName = "IntegratedCrafting" +archivesBaseName = "IntegratedCrafting-${project.minecraft_version}-neoforge" +base { + archivesName = archivesBaseName +} // Set Java details java.toolchain.languageVersion = JavaLanguageVersion.of(17) @@ -50,6 +52,7 @@ sourceSets { main test } +sourceSets.main.resources { srcDir 'src/generated/resources' } configurations { modLib @@ -69,38 +72,41 @@ repositories { name "Cyclops Repo" url "https://maven.pkg.github.com/CyclopsMC/packages" credentials { - username = project.findProperty("gpr.user") ?: System.getenv("MAVEN_USERNAME") - password = project.findProperty("gpr.key") ?: System.getenv("MAVEN_KEY") + username = project.findProperty("gpr.user") ?: System.getenv("MAVEN_USERNAME") ?: System.getenv("GITHUB_USER") + password = project.findProperty("gpr.key") ?: System.getenv("MAVEN_KEY") ?: System.getenv("GITHUB_TOKEN") } } } dependencies { - minecraft "net.minecraftforge:forge:${project.minecraft_version}-${project.forge_version}" + implementation "net.neoforged:neoforge:${project.neoforge_version}" // Add something like 'cyclopscore_version_local=0.1.0-DEV' to your gradle.properties if you want to use a custom local CyclopsCore version. if(secrets.cyclopscore_version_local) { - implementation "org.cyclops.cyclopscore:cyclopscore:${project.minecraft_version}-${secrets.cyclopscore_version_local}:deobf" + implementation "org.cyclops.cyclopscore:cyclopscore-${project.minecraft_version}-neoforge:${secrets.cyclopscore_version_local}:deobf" } else { - implementation "org.cyclops.cyclopscore:cyclopscore:${project.minecraft_version}-${project.cyclopscore_version}:deobf" + implementation "org.cyclops.cyclopscore:cyclopscore-${project.minecraft_version}-neoforge:${project.cyclopscore_version}:deobf" } // Add something like 'integrateddynamics_version_local=0.1.0-DEV' to your gradle.properties if you want to use a custom local Integrated Tunnels Compat version. if(secrets.integrateddynamics_version_local) { - implementation "org.cyclops.integrateddynamics:integrateddynamics:${secrets.integrateddynamics_version_local}:deobf" + implementation "org.cyclops.integrateddynamics:integrateddynamics-${project.minecraft_version}-neoforge:${secrets.integrateddynamics_version_local}:deobf" } else { - implementation "org.cyclops.integrateddynamics:integrateddynamics:${project.integrateddynamics_version}:deobf" + implementation "org.cyclops.integrateddynamics:integrateddynamics-${project.minecraft_version}-neoforge:${project.integrateddynamics_version}:deobf" } if(secrets.commoncapabilities_version_local) { - implementation "org.cyclops.commoncapabilities:commoncapabilities:${secrets.commoncapabilities_version_local}:deobf" + implementation "org.cyclops.commoncapabilities:commoncapabilities-${project.minecraft_version}-neoforge:${secrets.commoncapabilities_version_local}:deobf" } else { - implementation fg.deobf("org.cyclops.commoncapabilities:commoncapabilities:${project.commoncapabilities_version}") { // https://dl.bintray.com/cyclopsmc/dev/org/cyclops/commoncapabilities/CommonCapabilities/ + implementation("org.cyclops.commoncapabilities:commoncapabilities-${project.minecraft_version}-neoforge:${project.commoncapabilities_version}:deobf") { // https://dl.bintray.com/cyclopsmc/dev/org/cyclops/commoncapabilities/CommonCapabilities/ transitive = false } } modLib "com.google.re2j:re2j:1.1" + modLib ("io.netty:netty-codec-http:4.1.77.Final") { + transitive = false + } // Project lombok compileOnly 'org.projectlombok:lombok:1.18.22' @@ -111,62 +117,40 @@ dependencies { testImplementation "junit:junit:4.12" } -minecraft { - mappings channel: "official", version: "${project.minecraft_version}" - - accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') - - runs { - client { - workingDirectory project.file('run') - //property 'forge.logging.markers', 'REGISTRIES,REGISTRYDUMP' - property 'forge.logging.console.level', 'debug' - mods { - integratedcrafting { - source sourceSets.main - } - } +runs { + configureEach { + systemProperty 'forge.logging.markers', 'REGISTRIES' + systemProperty 'forge.logging.console.level', 'debug' + systemProperty 'forge.logging.console.level', 'debug' + modSource project.sourceSets.main - lazyToken('minecraft_classpath') { - configurations.modLib.copyRecursive().resolve().collect { it.absolutePath }.join(File.pathSeparator) - } + dependencies { + runtime project.configurations.modLib } + } + + client { + systemProperty 'forge.enabledGameTestNamespaces', project.mod_id + } - server { - workingDirectory project.file('run') - property 'forge.logging.console.level', 'debug' - mods { - integratedcrafting { - source sourceSets.main - } - } - - lazyToken('minecraft_classpath') { - configurations.modLib.copyRecursive().resolve().collect { it.absolutePath }.join(File.pathSeparator) - } - } + server { + systemProperty 'forge.enabledGameTestNamespaces', project.mod_id + programArgument '--nogui' + } - data { - workingDirectory project.file('run') - property 'forge.logging.console.level', 'debug' - args '--mod', 'integratedcrafting', '--all', '--output', file('src/generated/resources/') - mods { - integratedcrafting { - source sourceSets.main - } - } + gameTestServer { + systemProperty 'forge.enabledGameTestNamespaces', project.mod_id + } - lazyToken('minecraft_classpath') { - configurations.modLib.copyRecursive().resolve().collect { it.absolutePath }.join(File.pathSeparator) - } - } + data { + programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() } } if (build_number.equals("RELEASE")) - version = "${project.minecraft_version}-${project.mod_version}" + version = "${project.mod_version}" else - version = "${project.minecraft_version}-${project.mod_version}-${build_number}" + version = "${project.mod_version}-${build_number}" jar { manifest { @@ -182,7 +166,6 @@ jar { ]) } } -jar.finalizedBy('reobfJar') javadoc { source = [sourceSets.main.allJava] @@ -190,7 +173,9 @@ javadoc { options.addStringOption('Xdoclint:accessibility,html,reference,syntax', '-quiet') } -task signJar(type: SignJar, dependsOn: jar) { +task signJar(type: PotentiallySignJar, dependsOn: jar) { + dependsOn(tasks.jar) + onlyIf { System.getenv().SIGN_KEYSTORE } @@ -199,10 +184,9 @@ task signJar(type: SignJar, dependsOn: jar) { alias = System.getenv().SIGN_ALIAS storePass = System.getenv().SIGN_STOREPASS keyPass = System.getenv().SIGN_KEYPASS - inputFile = jar.archivePath - outputFile = jar.archivePath + input = jar.archivePath + output = jar.archivePath } -build.dependsOn signJar task deobfJar(type: Jar) { from sourceSets.main.output @@ -239,34 +223,30 @@ artifacts { archives javadocJar } -curseforge { - if(secrets.curseforge_key) { - apiKey = secrets.curseforge_key +task publishCurseForge(type: net.darkhax.curseforgegradle.TaskPublishCurseForge) { + dependsOn(tasks.jar) + + if(secrets.hasProperty("curseforge_key") && secrets.hasProperty("changelog")) { + apiToken = secrets.curseforge_key } else if(System.getenv().GITHUB_ACTIONS && System.getenv().CURSEFORGE_KEY_SECRET) { - apiKey = System.getenv().CURSEFORGE_KEY_SECRET + apiToken = System.getenv().CURSEFORGE_KEY_SECRET + } else { + apiToken = "DUMMY" } - project { - id = "287357" // my project url is http://minecraft.curseforge.com/mc-mods/287357/ - releaseType = project.project.release_type - addGameVersion project.minecraft_version - mainArtifact(jar) { - relations { - requiredDependency 'cyclops-core' - requiredDependency 'integrated-dynamics' - requiredDependency 'integrated-tunnels' - } - } + def projectId = "287357" // my project url is http://minecraft.curseforge.com/mc-mods/287357/ - changelog = "" - if (new File("resources/changelog/${project.version}.txt").exists()) { - changelog = new File("resources/changelog/${project.version}.txt").text - } - - addArtifact deobfJar - addArtifact sourcesJar - addArtifact javadocJar + def mainFile = upload(projectId, jar) + mainFile.changelogType = "text" + if (new File("resources/changelog/${project.version}.txt").exists()) { + mainFile.changelog = file("resources/changelog/${project.version}.txt") } + mainFile.addGameVersion(project.minecraft_version) + mainFile.addModLoader("NeoForge") + + mainFile.addRequirement('cyclops-core') + mainFile.addRequirement('integrated-dynamics') + mainFile.addRequirement('integrated-tunnels') } modrinth { diff --git a/gradle.properties b/gradle.properties index 237e5c98..442a0587 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,12 +1,13 @@ +mod_id=integratedcrafting mod_version=1.1.7 -minecraft_version=1.20.1 -forge_version=47.0.1 -cyclopscore_version=1.18.4-340 -integrateddynamics_version=1.20.1-1.20.0-661 +minecraft_version=1.20.4 +neoforge_version=20.4.160-beta +cyclopscore_version=1.19.0-423 +integrateddynamics_version=1.21.2-740 release_type=release fingerprint=bd0353b3e8a2810d60dd584e256e364bc3bedd44 -commoncapabilities_version=1.20.1-2.9.0-98 +commoncapabilities_version=2.9.1-116 # Workaround for Spotless bug # https://github.com/diffplug/spotless/issues/834 diff --git a/settings.gradle b/settings.gradle index a30364e8..b359a59d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,10 +1,8 @@ pluginManagement { repositories { + mavenLocal() gradlePluginPortal() - maven { - name = 'MinecraftForge' - url = 'https://maven.minecraftforge.net/' - } + maven { url = 'https://maven.neoforged.net/releases' } } } diff --git a/src/main/java/org/cyclops/integratedcrafting/Capabilities.java b/src/main/java/org/cyclops/integratedcrafting/Capabilities.java index fcd3daf8..72d83f11 100644 --- a/src/main/java/org/cyclops/integratedcrafting/Capabilities.java +++ b/src/main/java/org/cyclops/integratedcrafting/Capabilities.java @@ -1,16 +1,20 @@ package org.cyclops.integratedcrafting; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.CapabilityManager; -import net.minecraftforge.common.capabilities.CapabilityToken; -import org.cyclops.commoncapabilities.api.capability.recipehandler.IRecipeHandler; -import org.cyclops.integrateddynamics.api.ingredient.capability.IPositionedAddonsNetworkIngredientsHandler; +import net.minecraft.resources.ResourceLocation; +import org.cyclops.integratedcrafting.api.crafting.ICraftingInterface; +import org.cyclops.integratedcrafting.api.network.ICraftingNetwork; +import org.cyclops.integrateddynamics.api.network.NetworkCapability; +import org.cyclops.integrateddynamics.api.part.PartCapability; /** * Used capabilities for this mod. * @author rubensworks */ public class Capabilities { - public static Capability RECIPE_HANDLER = CapabilityManager.get(new CapabilityToken<>(){}); - public static Capability POSITIONED_ADDONS_NETWORK_INGREDIENTS_HANDLER = CapabilityManager.get(new CapabilityToken<>(){}); + public static final class CraftingNetwork { + public static final NetworkCapability NETWORK = NetworkCapability.create(new ResourceLocation(Reference.MOD_ID, "crafting_network"), ICraftingNetwork.class); + } + public static final class CraftingInterface { + public static final PartCapability PART = PartCapability.create(new ResourceLocation(Reference.MOD_ID, "crafting_interface"), ICraftingInterface.class); + } } diff --git a/src/main/java/org/cyclops/integratedcrafting/GeneralConfig.java b/src/main/java/org/cyclops/integratedcrafting/GeneralConfig.java index e6a0cd97..83b3dba5 100644 --- a/src/main/java/org/cyclops/integratedcrafting/GeneralConfig.java +++ b/src/main/java/org/cyclops/integratedcrafting/GeneralConfig.java @@ -1,6 +1,6 @@ package org.cyclops.integratedcrafting; -import net.minecraftforge.fml.config.ModConfig; +import net.neoforged.fml.config.ModConfig; import org.cyclops.cyclopscore.config.ConfigurableProperty; import org.cyclops.cyclopscore.config.extendedconfig.DummyConfig; import org.cyclops.cyclopscore.tracking.Analytics; diff --git a/src/main/java/org/cyclops/integratedcrafting/IntegratedCrafting.java b/src/main/java/org/cyclops/integratedcrafting/IntegratedCrafting.java index d61105ba..c8341a84 100644 --- a/src/main/java/org/cyclops/integratedcrafting/IntegratedCrafting.java +++ b/src/main/java/org/cyclops/integratedcrafting/IntegratedCrafting.java @@ -2,13 +2,12 @@ import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import net.minecraftforge.registries.NewRegistryEvent; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.common.Mod; +import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; +import net.neoforged.neoforge.registries.NewRegistryEvent; import org.apache.logging.log4j.Level; import org.cyclops.cyclopscore.config.ConfigHandler; import org.cyclops.cyclopscore.infobook.IInfoBookRegistry; @@ -17,9 +16,7 @@ import org.cyclops.cyclopscore.proxy.IClientProxy; import org.cyclops.cyclopscore.proxy.ICommonProxy; import org.cyclops.integratedcrafting.api.crafting.ICraftingProcessOverrideRegistry; -import org.cyclops.integratedcrafting.capability.network.CraftingInterfaceConfig; import org.cyclops.integratedcrafting.capability.network.CraftingNetworkCapabilityConstructors; -import org.cyclops.integratedcrafting.capability.network.CraftingNetworkConfig; import org.cyclops.integratedcrafting.capability.network.NetworkCraftingHandlerCraftingNetwork; import org.cyclops.integratedcrafting.core.CraftingProcessOverrideRegistry; import org.cyclops.integratedcrafting.core.CraftingProcessOverrides; @@ -46,8 +43,8 @@ public class IntegratedCrafting extends ModBaseVersionable { public static GlobalCounters globalCounters = null; - public IntegratedCrafting() { - super(Reference.MOD_ID, (instance) -> _instance = instance); + public IntegratedCrafting(IEventBus modEventBus) { + super(Reference.MOD_ID, (instance) -> _instance = instance, modEventBus); // Registries getRegistryManager().addRegistry(ICraftingProcessOverrideRegistry.class, CraftingProcessOverrideRegistry.getInstance()); @@ -55,14 +52,14 @@ public IntegratedCrafting() { // Register world storages registerWorldStorage(globalCounters = new GlobalCounters(this)); - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onRegistriesCreate); - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onSetup); + modEventBus.addListener(this::onRegistriesCreate); + modEventBus.addListener(this::onSetup); + modEventBus.register(new CraftingNetworkCapabilityConstructors()); } public void onRegistriesCreate(NewRegistryEvent event) { CraftingAspects.load(); PartTypes.load(); - MinecraftForge.EVENT_BUS.register(new CraftingNetworkCapabilityConstructors()); CraftingProcessOverrides.load(); } @@ -109,9 +106,6 @@ public void onConfigsRegister(ConfigHandler configHandler) { configHandler.addConfigurable(new GeneralConfig()); - configHandler.addConfigurable(new CraftingNetworkConfig()); - configHandler.addConfigurable(new CraftingInterfaceConfig()); - configHandler.addConfigurable(new ContainerPartInterfaceCraftingConfig()); configHandler.addConfigurable(new ContainerPartInterfaceCraftingSettingsConfig()); } diff --git a/src/main/java/org/cyclops/integratedcrafting/RegistryEntries.java b/src/main/java/org/cyclops/integratedcrafting/RegistryEntries.java index 2b544481..9051b4a1 100644 --- a/src/main/java/org/cyclops/integratedcrafting/RegistryEntries.java +++ b/src/main/java/org/cyclops/integratedcrafting/RegistryEntries.java @@ -1,8 +1,10 @@ package org.cyclops.integratedcrafting; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.Item; -import net.minecraftforge.registries.ObjectHolder; +import net.neoforged.neoforge.registries.DeferredHolder; import org.cyclops.integratedcrafting.inventory.container.ContainerPartInterfaceCrafting; import org.cyclops.integratedcrafting.inventory.container.ContainerPartInterfaceCraftingSettings; import org.cyclops.integrateddynamics.item.ItemVariable; @@ -13,14 +15,10 @@ */ public class RegistryEntries { - @ObjectHolder(registryName = "item", value = "integratedcrafting:part_interface_crafting") - public static final Item ITEM_PART_INTERFACE_CRAFTING = null; - @ObjectHolder(registryName = "item", value = "integrateddynamics:variable") - public static final ItemVariable ITEM_VARIABLE = null; + public static final DeferredHolder ITEM_PART_INTERFACE_CRAFTING = DeferredHolder.create(Registries.ITEM, new ResourceLocation("integratedcrafting:part_interface_crafting")); + public static final DeferredHolder ITEM_VARIABLE = DeferredHolder.create(Registries.ITEM, new ResourceLocation("integrateddynamics:variable")); - @ObjectHolder(registryName = "menu", value = "integratedcrafting:part_interface_crafting") - public static final MenuType CONTAINER_INTERFACE_CRAFTING = null; - @ObjectHolder(registryName = "menu", value = "integratedcrafting:part_interface_crafting_settings") - public static final MenuType CONTAINER_INTERFACE_CRAFTING_SETTINGS = null; + public static final DeferredHolder, MenuType> CONTAINER_INTERFACE_CRAFTING = DeferredHolder.create(Registries.MENU, new ResourceLocation("integratedcrafting:part_interface_crafting")); + public static final DeferredHolder, MenuType> CONTAINER_INTERFACE_CRAFTING_SETTINGS = DeferredHolder.create(Registries.MENU, new ResourceLocation("integratedcrafting:part_interface_crafting_settings")); } diff --git a/src/main/java/org/cyclops/integratedcrafting/capability/network/CraftingInterfaceConfig.java b/src/main/java/org/cyclops/integratedcrafting/capability/network/CraftingInterfaceConfig.java deleted file mode 100644 index b94d8912..00000000 --- a/src/main/java/org/cyclops/integratedcrafting/capability/network/CraftingInterfaceConfig.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.cyclops.integratedcrafting.capability.network; - -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.CapabilityManager; -import net.minecraftforge.common.capabilities.CapabilityToken; -import org.cyclops.commoncapabilities.CommonCapabilities; -import org.cyclops.cyclopscore.config.extendedconfig.CapabilityConfig; -import org.cyclops.integratedcrafting.api.crafting.ICraftingInterface; - -/** - * Config for the crafting interface capability. - * @author rubensworks - * - */ -public class CraftingInterfaceConfig extends CapabilityConfig { - - public static Capability CAPABILITY = CapabilityManager.get(new CapabilityToken<>(){}); - - public CraftingInterfaceConfig() { - super( - CommonCapabilities._instance, - "craftingInterface", - ICraftingInterface.class - ); - } - -} diff --git a/src/main/java/org/cyclops/integratedcrafting/capability/network/CraftingNetworkCapabilityConstructors.java b/src/main/java/org/cyclops/integratedcrafting/capability/network/CraftingNetworkCapabilityConstructors.java index cdbad9b9..aa0ec99a 100644 --- a/src/main/java/org/cyclops/integratedcrafting/capability/network/CraftingNetworkCapabilityConstructors.java +++ b/src/main/java/org/cyclops/integratedcrafting/capability/network/CraftingNetworkCapabilityConstructors.java @@ -1,10 +1,9 @@ package org.cyclops.integratedcrafting.capability.network; -import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.neoforged.bus.api.SubscribeEvent; import org.cyclops.cyclopscore.modcompat.capabilities.DefaultCapabilityProvider; +import org.cyclops.integratedcrafting.Capabilities; import org.cyclops.integratedcrafting.core.network.CraftingNetwork; -import org.cyclops.integrateddynamics.Reference; import org.cyclops.integrateddynamics.api.network.AttachCapabilitiesEventNetwork; /** @@ -15,8 +14,7 @@ public class CraftingNetworkCapabilityConstructors { @SubscribeEvent public void onNetworkLoad(AttachCapabilitiesEventNetwork event) { - event.addCapability(new ResourceLocation(Reference.MOD_ID, "crafting_network"), - new DefaultCapabilityProvider<>(() -> CraftingNetworkConfig.CAPABILITY, new CraftingNetwork())); + event.register(Capabilities.CraftingNetwork.NETWORK, new DefaultCapabilityProvider<>(new CraftingNetwork())); } } diff --git a/src/main/java/org/cyclops/integratedcrafting/capability/network/CraftingNetworkConfig.java b/src/main/java/org/cyclops/integratedcrafting/capability/network/CraftingNetworkConfig.java deleted file mode 100644 index 646c434f..00000000 --- a/src/main/java/org/cyclops/integratedcrafting/capability/network/CraftingNetworkConfig.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.cyclops.integratedcrafting.capability.network; - -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.CapabilityManager; -import net.minecraftforge.common.capabilities.CapabilityToken; -import org.cyclops.commoncapabilities.CommonCapabilities; -import org.cyclops.cyclopscore.config.extendedconfig.CapabilityConfig; -import org.cyclops.integratedcrafting.api.network.ICraftingNetwork; - -/** - * Config for the crafting network capability. - * @author rubensworks - * - */ -public class CraftingNetworkConfig extends CapabilityConfig { - - public static Capability CAPABILITY = CapabilityManager.get(new CapabilityToken<>(){}); - - public CraftingNetworkConfig() { - super( - CommonCapabilities._instance, - "craftingNetwork", - ICraftingNetwork.class - ); - } - -} diff --git a/src/main/java/org/cyclops/integratedcrafting/client/gui/ContainerScreenPartInterfaceCraftingSettings.java b/src/main/java/org/cyclops/integratedcrafting/client/gui/ContainerScreenPartInterfaceCraftingSettings.java index 1e00f442..6cea163f 100644 --- a/src/main/java/org/cyclops/integratedcrafting/client/gui/ContainerScreenPartInterfaceCraftingSettings.java +++ b/src/main/java/org/cyclops/integratedcrafting/client/gui/ContainerScreenPartInterfaceCraftingSettings.java @@ -98,7 +98,7 @@ public void init() { ingredientComponentSideSelector = new WidgetArrowedListField>(font, leftPos + 106, topPos + 9, 68, 15, true, Component.translatable("gui.integratedcrafting.partsettings.ingredient"), - true, Lists.newArrayList(IngredientComponent.REGISTRY.getValues())) { + true, Lists.newArrayList(IngredientComponent.REGISTRY)) { @Override protected String activeElementToString(IngredientComponent element) { return L10NHelpers.localize(element.getTranslationKey()); @@ -216,7 +216,7 @@ protected void setSideInDropdownField(IngredientComponent ingredientCompon @Override public void onUpdate(int valueId, CompoundTag value) { super.onUpdate(valueId, value); - for (IngredientComponent ingredientComponent : IngredientComponent.REGISTRY.getValues()) { + for (IngredientComponent ingredientComponent : IngredientComponent.REGISTRY.stream().toList()) { if (valueId == getMenu().getTargetSideOverrideValueId(ingredientComponent)) { int side = getMenu().getTargetSideOverrideValue(ingredientComponent).ordinal(); setSideInDropdownField(ingredientComponent, side == -1 ? getDefaultSide() : Direction.values()[side]); diff --git a/src/main/java/org/cyclops/integratedcrafting/core/CraftingHelpers.java b/src/main/java/org/cyclops/integratedcrafting/core/CraftingHelpers.java index 3850e7f2..d3204e1a 100644 --- a/src/main/java/org/cyclops/integratedcrafting/core/CraftingHelpers.java +++ b/src/main/java/org/cyclops/integratedcrafting/core/CraftingHelpers.java @@ -4,9 +4,8 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import net.minecraft.core.Direction; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraftforge.common.capabilities.ICapabilityProvider; -import net.minecraftforge.common.util.LazyOptional; import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.Level; import org.cyclops.commoncapabilities.api.capability.recipehandler.IPrototypedIngredientAlternatives; @@ -17,6 +16,7 @@ import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; import org.cyclops.commoncapabilities.api.ingredient.MixedIngredients; import org.cyclops.commoncapabilities.api.ingredient.PrototypedIngredient; +import org.cyclops.commoncapabilities.api.ingredient.capability.ICapabilityGetter; import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage; import org.cyclops.commoncapabilities.api.ingredient.storage.IngredientComponentStorageEmpty; import org.cyclops.cyclopscore.helper.BlockEntityHelpers; @@ -35,7 +35,6 @@ import org.cyclops.integratedcrafting.api.crafting.UnknownCraftingRecipeException; import org.cyclops.integratedcrafting.api.network.ICraftingNetwork; import org.cyclops.integratedcrafting.api.recipe.IRecipeIndex; -import org.cyclops.integratedcrafting.capability.network.CraftingNetworkConfig; import org.cyclops.integrateddynamics.IntegratedDynamics; import org.cyclops.integrateddynamics.api.PartStateException; import org.cyclops.integrateddynamics.api.ingredient.capability.IPositionedAddonsNetworkIngredientsHandler; @@ -53,6 +52,7 @@ import java.util.List; import java.util.ListIterator; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.UUID; import java.util.function.Function; @@ -86,11 +86,11 @@ public static INetwork getNetworkChecked(PartPos pos) throws PartStateException * @param network A network. * @return The crafting network. */ - public static LazyOptional getCraftingNetwork(@Nullable INetwork network) { + public static Optional getCraftingNetwork(@Nullable INetwork network) { if (network != null) { - return network.getCapability(CraftingNetworkConfig.CAPABILITY); + return network.getCapability(Capabilities.CraftingNetwork.NETWORK); } - return null; + return Optional.empty(); } /** @@ -111,13 +111,11 @@ public static ICraftingNetwork getCraftingNetworkChecked(@Nullable INetwork netw * @param The matching condition parameter. * @return The storage network. */ - public static LazyOptional> getIngredientsNetwork(INetwork network, + public static Optional> getIngredientsNetwork(INetwork network, IngredientComponent ingredientComponent) { - IPositionedAddonsNetworkIngredientsHandler ingredientsHandler = ingredientComponent.getCapability(Capabilities.POSITIONED_ADDONS_NETWORK_INGREDIENTS_HANDLER).orElse(null); - if (ingredientsHandler != null) { - return ingredientsHandler.getStorage(network); - } - return LazyOptional.empty(); + return ingredientComponent + .getCapability(org.cyclops.integrateddynamics.Capabilities.PositionedAddonsNetworkIngredientsHandler.INGREDIENT) + .flatMap(ingredientsHandler -> ((IPositionedAddonsNetworkIngredientsHandler) ingredientsHandler).getStorage(network)); } /** @@ -164,7 +162,7 @@ public static IIngredientComponentStorage getNetworkStorage(INetwor * @param channel A network channel. */ public static void beforeCalculateCraftingJobs(INetwork network, int channel) { - for (IngredientComponent ingredientComponent : IngredientComponent.REGISTRY.getValues()) { + for (IngredientComponent ingredientComponent : IngredientComponent.REGISTRY.stream().toList()) { IPositionedAddonsNetworkIngredients ingredientsNetwork = getIngredientsNetwork(network, ingredientComponent).orElse(null); if (ingredientsNetwork != null && (ingredientsNetwork.isObservationForcedPending(channel))) { ingredientsNetwork.runObserverSync(); @@ -1485,7 +1483,9 @@ protected static IMixedIngredients compressMixedIngredients(IMixedIngredients mi * ingredients will be re-inserted into the network. * * @param ingredientComponent The ingredient component type. - * @param capabilityProvider The target capability provider. + * @param capabilityType capabilityType The type of capability, usually Block.class, Item.class, or Entity.class. + * @param capabilityGetter A capability provider. + * @param capabilityTarget The capability target for error reporting. * @param side The target side. * @param ingredients The ingredients to insert. * @param storageFallback The storage to insert any failed ingredients back into. Can be null in simulation mode. @@ -1494,14 +1494,16 @@ protected static IMixedIngredients compressMixedIngredients(IMixedIngredients mi * @param The matching condition parameter. * @return If all instances could be inserted. */ - public static boolean insertIngredientCrafting(IngredientComponent ingredientComponent, - ICapabilityProvider capabilityProvider, + public static boolean insertIngredientCrafting(IngredientComponent ingredientComponent, + Class capabilityType, + ICapabilityGetter capabilityGetter, + Object capabilityTarget, @Nullable Direction side, IMixedIngredients ingredients, IIngredientComponentStorage storageFallback, boolean simulate) { IIngredientMatcher matcher = ingredientComponent.getMatcher(); - IIngredientComponentStorage storage = ingredientComponent.getStorage(capabilityProvider, side); + IIngredientComponentStorage storage = ingredientComponent.getStorage(capabilityType, capabilityGetter, side); List instances = ingredients.getInstances(ingredientComponent); List failedInstances = Lists.newArrayList(); boolean ok = true; @@ -1521,7 +1523,7 @@ public static boolean insertIngredientCrafting(IngredientComponent if (!matcher.isEmpty(remaining)) { throw new IllegalStateException("Insertion for a crafting recipe failed" + "due to inconsistent insertion behaviour by destination in simulation " + - "and non-simulation: " + capabilityProvider + ". Lost: " + instances); + "and non-simulation: " + capabilityTarget + ". Lost: " + instances); } } @@ -1561,7 +1563,8 @@ public static boolean insertCrafting(Function, PartPos boolean ok = true; for (Map.Entry, BlockEntity> entry : tileMap.entrySet()) { IIngredientComponentStorage storageNetwork = simulate ? null : getNetworkStorage(network, channel, entry.getKey(), false); - if (!insertIngredientCrafting((IngredientComponent) entry.getKey(), entry.getValue(), + if (!insertIngredientCrafting((IngredientComponent) entry.getKey(), + Block.class, ICapabilityGetter.forBlockEntity(entry.getValue()), entry.getValue(), targetGetter.apply(entry.getKey()).getSide(), ingredients, storageNetwork, simulate)) { ok = false; diff --git a/src/main/java/org/cyclops/integratedcrafting/core/CraftingJobHandler.java b/src/main/java/org/cyclops/integratedcrafting/core/CraftingJobHandler.java index 307e3382..25f12e7b 100644 --- a/src/main/java/org/cyclops/integratedcrafting/core/CraftingJobHandler.java +++ b/src/main/java/org/cyclops/integratedcrafting/core/CraftingJobHandler.java @@ -165,7 +165,7 @@ public void readFromNBT(CompoundTag tag) { for (Tag pendingIngredient : pendingIngredientsList) { CompoundTag pendingIngredientTag = (CompoundTag) pendingIngredient; String componentName = pendingIngredientTag.getString("ingredientComponent"); - IngredientComponent ingredientComponent = IngredientComponent.REGISTRY.getValue(new ResourceLocation(componentName)); + IngredientComponent ingredientComponent = IngredientComponent.REGISTRY.get(new ResourceLocation(componentName)); if (ingredientComponent == null) { throw new IllegalArgumentException("Could not find the ingredient component type " + componentName); } @@ -191,7 +191,7 @@ public void readFromNBT(CompoundTag tag) { for (Tag pendingIngredient : pendingIngredientsList) { CompoundTag pendingIngredientTag = (CompoundTag) pendingIngredient; String componentName = pendingIngredientTag.getString("ingredientComponent"); - IngredientComponent ingredientComponent = IngredientComponent.REGISTRY.getValue(new ResourceLocation(componentName)); + IngredientComponent ingredientComponent = IngredientComponent.REGISTRY.get(new ResourceLocation(componentName)); if (ingredientComponent == null) { throw new IllegalArgumentException("Could not find the ingredient component type " + componentName); } @@ -241,7 +241,7 @@ public void readFromNBT(CompoundTag tag) { this.ingredientComponentTargetOverrides.clear(); CompoundTag targetOverrides = tag.getCompound("targetOverrides"); for (String componentName : targetOverrides.getAllKeys()) { - IngredientComponent component = IngredientComponent.REGISTRY.getValue(new ResourceLocation(componentName)); + IngredientComponent component = IngredientComponent.REGISTRY.get(new ResourceLocation(componentName)); this.ingredientComponentTargetOverrides.put(component, Direction.values()[targetOverrides.getInt(componentName)]); } diff --git a/src/main/java/org/cyclops/integratedcrafting/core/MissingIngredients.java b/src/main/java/org/cyclops/integratedcrafting/core/MissingIngredients.java index d5e7c1ae..316e5217 100644 --- a/src/main/java/org/cyclops/integratedcrafting/core/MissingIngredients.java +++ b/src/main/java/org/cyclops/integratedcrafting/core/MissingIngredients.java @@ -75,7 +75,7 @@ public static CompoundTag serialize(Map, MissingIngred throws IllegalArgumentException { Map, MissingIngredients> map = Maps.newIdentityHashMap(); for (String componentName : tag.getAllKeys()) { - IngredientComponent component = IngredientComponent.REGISTRY.getValue(new ResourceLocation(componentName)); + IngredientComponent component = IngredientComponent.REGISTRY.get(new ResourceLocation(componentName)); if (component == null) { throw new IllegalArgumentException("Could not find the ingredient component type " + componentName); } diff --git a/src/main/java/org/cyclops/integratedcrafting/core/crafting/processoverride/CraftingProcessOverrideBrewingStand.java b/src/main/java/org/cyclops/integratedcrafting/core/crafting/processoverride/CraftingProcessOverrideBrewingStand.java index 4b500de7..fdf0a713 100644 --- a/src/main/java/org/cyclops/integratedcrafting/core/crafting/processoverride/CraftingProcessOverrideBrewingStand.java +++ b/src/main/java/org/cyclops/integratedcrafting/core/crafting/processoverride/CraftingProcessOverrideBrewingStand.java @@ -3,9 +3,9 @@ import net.minecraft.core.Direction; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BrewingStandBlockEntity; -import net.minecraftforge.common.brewing.BrewingRecipeRegistry; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.items.IItemHandler; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.common.brewing.BrewingRecipeRegistry; +import net.neoforged.neoforge.items.IItemHandler; import org.cyclops.commoncapabilities.api.ingredient.IMixedIngredients; import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; import org.cyclops.cyclopscore.helper.BlockEntityHelpers; @@ -51,8 +51,8 @@ public boolean craft(Function, PartPos> targetGetter, // Insert the ingredients into the target return getTile(targetGetter.apply(IngredientComponent.ITEMSTACK)) .map(tile -> { - IItemHandler ingredientHandler = tile.getCapability(ForgeCapabilities.ITEM_HANDLER, SIDE_INGREDIENT).orElse(null); - IItemHandler bottleHandler = tile.getCapability(ForgeCapabilities.ITEM_HANDLER, SIDE_BOTTLE).orElse(null); + IItemHandler ingredientHandler = tile.getLevel().getCapability(Capabilities.ItemHandler.BLOCK, tile.getBlockPos(), tile.getBlockState(), tile, SIDE_INGREDIENT); + IItemHandler bottleHandler = tile.getLevel().getCapability(Capabilities.ItemHandler.BLOCK, tile.getBlockPos(), tile.getBlockState(), tile, SIDE_BOTTLE); if (ingredientHandler != null && bottleHandler != null) { int ingredientSlotIndex = 0; int bottleSlotIndex = 0; diff --git a/src/main/java/org/cyclops/integratedcrafting/core/crafting/processoverride/CraftingProcessOverrideCraftingTable.java b/src/main/java/org/cyclops/integratedcrafting/core/crafting/processoverride/CraftingProcessOverrideCraftingTable.java index 753a45a6..ca0d4341 100644 --- a/src/main/java/org/cyclops/integratedcrafting/core/crafting/processoverride/CraftingProcessOverrideCraftingTable.java +++ b/src/main/java/org/cyclops/integratedcrafting/core/crafting/processoverride/CraftingProcessOverrideCraftingTable.java @@ -4,11 +4,12 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.CraftingRecipe; import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.CraftingTableBlock; -import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.event.ForgeEventFactory; +import net.neoforged.neoforge.common.util.FakePlayer; +import net.neoforged.neoforge.event.EventHooks; import org.cyclops.commoncapabilities.api.ingredient.IMixedIngredients; import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; import org.cyclops.cyclopscore.helper.CraftingHelpers; @@ -56,7 +57,8 @@ public boolean craft(Function, PartPos> targetGetter, CraftingGrid gridSmall = new CraftingGrid(ingredients, 2, 2); return CraftingHelpers.findServerRecipe(RecipeType.CRAFTING, gridSmall, level); }) - .map(recipe -> { + .map(recipeHolder -> { + CraftingRecipe recipe = recipeHolder.value(); ItemStack result = recipe.assemble(grid, level.registryAccess()); if (result.isEmpty()) { @@ -68,7 +70,7 @@ public boolean craft(Function, PartPos> targetGetter, // Fire all required events result.onCraftedBy(target.getPos().getLevel(true), player, 1); - ForgeEventFactory.firePlayerCraftingEvent(player, result, grid); + EventHooks.firePlayerCraftingEvent(player, result, grid); // Insert the result into the sink resultsSink.addResult(IngredientComponent.ITEMSTACK, result); diff --git a/src/main/java/org/cyclops/integratedcrafting/core/network/CraftingNetwork.java b/src/main/java/org/cyclops/integratedcrafting/core/network/CraftingNetwork.java index d332211f..6650f8db 100644 --- a/src/main/java/org/cyclops/integratedcrafting/core/network/CraftingNetwork.java +++ b/src/main/java/org/cyclops/integratedcrafting/core/network/CraftingNetwork.java @@ -8,7 +8,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.IntListIterator; import net.minecraft.world.level.Level; -import net.minecraftforge.server.ServerLifecycleHooks; +import net.neoforged.neoforge.server.ServerLifecycleHooks; import org.cyclops.commoncapabilities.api.capability.recipehandler.IRecipeDefinition; import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; import org.cyclops.cyclopscore.datastructure.MultitransformIterator; diff --git a/src/main/java/org/cyclops/integratedcrafting/inventory/container/ContainerPartInterfaceCrafting.java b/src/main/java/org/cyclops/integratedcrafting/inventory/container/ContainerPartInterfaceCrafting.java index ce91cbf8..9aa7e2fa 100644 --- a/src/main/java/org/cyclops/integratedcrafting/inventory/container/ContainerPartInterfaceCrafting.java +++ b/src/main/java/org/cyclops/integratedcrafting/inventory/container/ContainerPartInterfaceCrafting.java @@ -43,7 +43,7 @@ public ContainerPartInterfaceCrafting(int id, Inventory playerInventory, Friendl public ContainerPartInterfaceCrafting(int id, Inventory playerInventory, Container inventory, Optional target, Optional partContainer, PartTypeInterfaceCrafting partType) { - super(RegistryEntries.CONTAINER_INTERFACE_CRAFTING, id, playerInventory, inventory, target, partContainer, partType); + super(RegistryEntries.CONTAINER_INTERFACE_CRAFTING.get(), id, playerInventory, inventory, target, partContainer, partType); addInventory(inventory, 0, 8, 22, 1, inventory.getContainerSize()); addPlayerInventory(player.getInventory(), 8, 59); @@ -91,7 +91,7 @@ protected Slot createNewSlot(Container inventory, int index, int x, int y) { return new SlotVariable(inventory, index, x, y) { @Override public boolean mayPlace(ItemStack itemStack) { - IVariableFacade variableFacade = RegistryEntries.ITEM_VARIABLE.getVariableFacade(ValueDeseralizationContext.ofAllEnabled(), itemStack); + IVariableFacade variableFacade = RegistryEntries.ITEM_VARIABLE.get().getVariableFacade(ValueDeseralizationContext.ofAllEnabled(), itemStack); return variableFacade != null && ValueHelpers.correspondsTo(variableFacade.getOutputType(), ValueTypes.OBJECT_RECIPE) && super.mayPlace(itemStack); diff --git a/src/main/java/org/cyclops/integratedcrafting/inventory/container/ContainerPartInterfaceCraftingConfig.java b/src/main/java/org/cyclops/integratedcrafting/inventory/container/ContainerPartInterfaceCraftingConfig.java index 160544c0..26e7e895 100644 --- a/src/main/java/org/cyclops/integratedcrafting/inventory/container/ContainerPartInterfaceCraftingConfig.java +++ b/src/main/java/org/cyclops/integratedcrafting/inventory/container/ContainerPartInterfaceCraftingConfig.java @@ -4,8 +4,8 @@ import net.minecraft.client.gui.screens.MenuScreens; import net.minecraft.client.gui.screens.Screen; import net.minecraft.world.flag.FeatureFlags; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import org.cyclops.cyclopscore.client.gui.ScreenFactorySafe; import org.cyclops.cyclopscore.config.extendedconfig.GuiConfig; import org.cyclops.cyclopscore.inventory.container.ContainerTypeData; diff --git a/src/main/java/org/cyclops/integratedcrafting/inventory/container/ContainerPartInterfaceCraftingSettings.java b/src/main/java/org/cyclops/integratedcrafting/inventory/container/ContainerPartInterfaceCraftingSettings.java index 37221b3d..c116f89f 100644 --- a/src/main/java/org/cyclops/integratedcrafting/inventory/container/ContainerPartInterfaceCraftingSettings.java +++ b/src/main/java/org/cyclops/integratedcrafting/inventory/container/ContainerPartInterfaceCraftingSettings.java @@ -2,12 +2,12 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.Container; -import net.minecraft.world.SimpleContainer; -import net.minecraft.network.FriendlyByteBuf; import net.minecraft.core.Direction; +import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.Container; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.entity.player.Inventory; import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; import org.cyclops.cyclopscore.helper.ValueNotifierHelpers; import org.cyclops.integratedcrafting.RegistryEntries; @@ -38,11 +38,11 @@ public ContainerPartInterfaceCraftingSettings(int id, Inventory playerInventory, public ContainerPartInterfaceCraftingSettings(int id, Inventory playerInventory, Container inventory, PartTarget target, Optional partContainer, IPartType partType) { - super(RegistryEntries.CONTAINER_INTERFACE_CRAFTING_SETTINGS, id, playerInventory, inventory, target, partContainer, partType); + super(RegistryEntries.CONTAINER_INTERFACE_CRAFTING_SETTINGS.get(), id, playerInventory, inventory, target, partContainer, partType); lastChannelInterfaceCraftingValueId = getNextValueId(); targetSideOverrideValueIds = Maps.newIdentityHashMap(); - for (ResourceLocation key : Sets.newTreeSet(IngredientComponent.REGISTRY.getKeys())) { // Consistently order keys - IngredientComponent ingredientComponent = IngredientComponent.REGISTRY.getValue(key); + for (ResourceLocation key : Sets.newTreeSet(IngredientComponent.REGISTRY.keySet())) { // Consistently order keys + IngredientComponent ingredientComponent = IngredientComponent.REGISTRY.get(key); targetSideOverrideValueIds.put(ingredientComponent, getNextValueId()); } lastDisableCraftingCheckValueId = getNextValueId(); @@ -58,7 +58,7 @@ protected int getPlayerInventoryOffsetY() { protected void initializeValues() { super.initializeValues(); ValueNotifierHelpers.setValue(this, lastChannelInterfaceCraftingValueId, ((PartTypeInterfaceCrafting.State) getPartState()).getChannelCrafting()); - for (IngredientComponent ingredientComponent : IngredientComponent.REGISTRY.getValues()) { + for (IngredientComponent ingredientComponent : IngredientComponent.REGISTRY.stream().toList()) { ValueNotifierHelpers.setValue(this, getTargetSideOverrideValueId(ingredientComponent), ((PartTypeInterfaceCrafting.State) getPartState()).getIngredientComponentTargetSideOverride(ingredientComponent).ordinal()); } @@ -115,7 +115,7 @@ public void setLastBlockingModeValue(boolean value) { protected void updatePartSettings() { super.updatePartSettings(); ((PartTypeInterfaceCrafting.State) getPartState()).setChannelCrafting(getLastChannelInterfaceValue()); - for (IngredientComponent ingredientComponent : IngredientComponent.REGISTRY.getValues()) { + for (IngredientComponent ingredientComponent : IngredientComponent.REGISTRY.stream().toList()) { ((PartTypeInterfaceCrafting.State) getPartState()).setIngredientComponentTargetSideOverride(ingredientComponent, getTargetSideOverrideValue(ingredientComponent)); } diff --git a/src/main/java/org/cyclops/integratedcrafting/inventory/container/ContainerPartInterfaceCraftingSettingsConfig.java b/src/main/java/org/cyclops/integratedcrafting/inventory/container/ContainerPartInterfaceCraftingSettingsConfig.java index 75cb8bc2..218a29cb 100644 --- a/src/main/java/org/cyclops/integratedcrafting/inventory/container/ContainerPartInterfaceCraftingSettingsConfig.java +++ b/src/main/java/org/cyclops/integratedcrafting/inventory/container/ContainerPartInterfaceCraftingSettingsConfig.java @@ -4,8 +4,8 @@ import net.minecraft.client.gui.screens.MenuScreens; import net.minecraft.client.gui.screens.Screen; import net.minecraft.world.flag.FeatureFlags; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import org.cyclops.cyclopscore.client.gui.ScreenFactorySafe; import org.cyclops.cyclopscore.config.extendedconfig.GuiConfig; import org.cyclops.cyclopscore.inventory.container.ContainerTypeData; diff --git a/src/main/java/org/cyclops/integratedcrafting/part/PartTypeInterfaceCrafting.java b/src/main/java/org/cyclops/integratedcrafting/part/PartTypeInterfaceCrafting.java index fe4fbf9f..af37934d 100644 --- a/src/main/java/org/cyclops/integratedcrafting/part/PartTypeInterfaceCrafting.java +++ b/src/main/java/org/cyclops/integratedcrafting/part/PartTypeInterfaceCrafting.java @@ -23,13 +23,9 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.util.LazyOptional; +import net.neoforged.neoforge.common.NeoForge; import org.apache.commons.lang3.tuple.Triple; import org.apache.logging.log4j.Level; -import org.cyclops.commoncapabilities.api.capability.block.BlockCapabilities; import org.cyclops.commoncapabilities.api.capability.recipehandler.IRecipeDefinition; import org.cyclops.commoncapabilities.api.capability.recipehandler.IRecipeHandler; import org.cyclops.commoncapabilities.api.ingredient.IIngredientMatcher; @@ -51,8 +47,6 @@ import org.cyclops.integratedcrafting.api.crafting.ICraftingInterface; import org.cyclops.integratedcrafting.api.crafting.ICraftingResultsSink; import org.cyclops.integratedcrafting.api.network.ICraftingNetwork; -import org.cyclops.integratedcrafting.capability.network.CraftingInterfaceConfig; -import org.cyclops.integratedcrafting.capability.network.CraftingNetworkConfig; import org.cyclops.integratedcrafting.core.CraftingHelpers; import org.cyclops.integratedcrafting.core.CraftingJobHandler; import org.cyclops.integratedcrafting.core.CraftingProcessOverrides; @@ -68,11 +62,12 @@ import org.cyclops.integrateddynamics.api.network.INetworkIngredientsChannel; import org.cyclops.integrateddynamics.api.network.IPartNetwork; import org.cyclops.integrateddynamics.api.network.IPositionedAddonsNetworkIngredients; +import org.cyclops.integrateddynamics.api.network.NetworkCapability; import org.cyclops.integrateddynamics.api.part.IPartContainer; +import org.cyclops.integrateddynamics.api.part.PartCapability; import org.cyclops.integrateddynamics.api.part.PartPos; import org.cyclops.integrateddynamics.api.part.PartTarget; import org.cyclops.integrateddynamics.api.part.PrioritizedPartPos; -import org.cyclops.integrateddynamics.capability.network.PositionedAddonsNetworkIngredientsHandlerConfig; import org.cyclops.integrateddynamics.core.evaluate.InventoryVariableEvaluator; import org.cyclops.integrateddynamics.core.evaluate.variable.ValueObjectTypeRecipe; import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypes; @@ -184,8 +179,8 @@ public void setPriorityAndChannel(INetwork network, IPartNetwork partNetwork, Pa addTargetToNetwork(network, target, state); } - protected Capability getNetworkCapability() { - return CraftingNetworkConfig.CAPABILITY; + protected NetworkCapability getNetworkCapability() { + return Capabilities.CraftingNetwork.NETWORK; } protected void addTargetToNetwork(INetwork network, PartTarget pos, PartTypeInterfaceCrafting.State state) { @@ -278,7 +273,7 @@ public void update(INetwork network, IPartNetwork partNetwork, PartTarget target protected static IngredientInstanceWrapper insertIntoNetwork(IngredientInstanceWrapper wrapper, INetwork network, int channel) { IPositionedAddonsNetworkIngredients storageNetwork = wrapper.getComponent() - .getCapability(PositionedAddonsNetworkIngredientsHandlerConfig.CAPABILITY) + .getCapability(org.cyclops.integrateddynamics.Capabilities.PositionedAddonsNetworkIngredientsHandler.INGREDIENT) .map(n -> (IPositionedAddonsNetworkIngredients) n.getStorage(network).orElse(null)) .orElse(null); if (storageNetwork != null) { @@ -406,7 +401,7 @@ public void readFromNBT(ValueDeseralizationContext valueDeseralizationContext, C for (Tag instanceTagRaw : tag.getList("inventoryOutputBuffer", Tag.TAG_COMPOUND)) { CompoundTag instanceTag = (CompoundTag) instanceTagRaw; String componentName = instanceTag.getString("component"); - IngredientComponent component = IngredientComponent.REGISTRY.getValue(new ResourceLocation(componentName)); + IngredientComponent component = IngredientComponent.REGISTRY.get(new ResourceLocation(componentName)); this.inventoryOutputBuffer.add(new IngredientInstanceWrapper(component, component.getSerializer().deserializeInstance(instanceTag.get("instance")))); } @@ -535,7 +530,7 @@ protected void reloadRecipe(int slot) { try { IPartNetwork partNetwork = NetworkHelpers.getPartNetworkChecked(network); - MinecraftForge.EVENT_BUS.post(new PartVariableDrivenVariableContentsUpdatedEvent<>(network, + NeoForge.EVENT_BUS.post(new PartVariableDrivenVariableContentsUpdatedEvent<>(network, partNetwork, getTarget(), PartTypes.INTERFACE_CRAFTING, this, lastPlayer, variable, variable != null ? variable.getValue() : null)); @@ -558,13 +553,7 @@ private void delayedReloadRecipe(int slot) { private boolean isValid(IRecipeDefinition recipe) { DimPos dimPos = getTarget().getTarget().getPos(); Direction side = getTarget().getTarget().getSide(); - IRecipeHandler recipeHandler = BlockEntityHelpers.getCapability(dimPos.getLevel(true), dimPos.getBlockPos(), side, Capabilities.RECIPE_HANDLER).orElse(null); - if (recipeHandler == null) { - BlockState blockState = dimPos.getLevel(true).getBlockState(dimPos.getBlockPos()); - recipeHandler = BlockCapabilities.getInstance().getCapability(blockState, Capabilities.RECIPE_HANDLER, - dimPos.getLevel(true), dimPos.getBlockPos(), side) - .orElse(null); - } + IRecipeHandler recipeHandler = BlockEntityHelpers.getCapability(dimPos.getLevel(true), dimPos.getBlockPos(), side, org.cyclops.commoncapabilities.api.capability.Capabilities.RecipeHandler.BLOCK).orElse(null); if (recipeHandler != null) { IMixedIngredients simulatedOutput = recipeHandler.simulate(MixedIngredients.fromRecipeInput(recipe)); if (simulatedOutput != null && !simulatedOutput.isEmpty()) { @@ -706,9 +695,9 @@ public void setShouldAddToCraftingNetwork(boolean shouldAddToCraftingNetwork) { } @Override - public LazyOptional getCapability(Capability capability, INetwork network, IPartNetwork partNetwork, PartTarget target) { - if (capability == CraftingInterfaceConfig.CAPABILITY) { - return LazyOptional.of(() -> this).cast(); + public Optional getCapability(PartTypeInterfaceCrafting partType, PartCapability capability, INetwork network, IPartNetwork partNetwork, PartTarget target) { + if (capability == Capabilities.CraftingInterface.PART) { + return Optional.of((T) this); } // Expose the whole storage @@ -717,15 +706,15 @@ public LazyOptional getCapability(Capability capability, INetwork netw if (ingredientComponent != null) { T cap = wrapStorageCapability(capability, ingredientComponent); if (cap != null) { - return LazyOptional.of(() -> cap); + return Optional.of(cap); } } } - return super.getCapability(capability, network, partNetwork, target); + return super.getCapability(partType, capability, network, partNetwork, target); } - protected C wrapStorageCapability(Capability capability, IngredientComponent ingredientComponent) { + protected C wrapStorageCapability(PartCapability capability, IngredientComponent ingredientComponent) { IIngredientComponentStorage storage = CraftingHelpers.getNetworkStorage(this.network, this.channelCrafting, ingredientComponent, false); @@ -832,7 +821,7 @@ protected void forceObservationOnInsertable(IngredientInstanceWrapper ingredientsNetwork = CraftingHelpers.getIngredientsNetwork(network, oldWrapper.getComponent()).orElse(null); if (ingredientsNetwork != null) { boolean marked = false; - INetworkIngredientsChannel ingredientsNetworkChannel = ingredientsNetwork.getChannelInternal(this.getChannelCrafting()); + INetworkIngredientsChannel ingredientsNetworkChannel = ingredientsNetwork.getChannel(this.getChannelCrafting()); T instance = oldWrapper.getInstance(); for (PartPos position : ingredientsNetworkChannel.findNonFullPositions()) { T instanceOut = ingredientsNetwork.getPositionedStorage(position).insert(instance, true); diff --git a/src/main/java/org/cyclops/integratedcrafting/part/aspect/CraftingAspectReadBuilders.java b/src/main/java/org/cyclops/integratedcrafting/part/aspect/CraftingAspectReadBuilders.java index 560c3c96..7d72a82a 100644 --- a/src/main/java/org/cyclops/integratedcrafting/part/aspect/CraftingAspectReadBuilders.java +++ b/src/main/java/org/cyclops/integratedcrafting/part/aspect/CraftingAspectReadBuilders.java @@ -1,11 +1,10 @@ package org.cyclops.integratedcrafting.part.aspect; -import net.minecraftforge.common.util.LazyOptional; import org.apache.commons.lang3.tuple.Pair; import org.cyclops.cyclopscore.datastructure.DimPos; +import org.cyclops.integratedcrafting.Capabilities; import org.cyclops.integratedcrafting.IntegratedCrafting; import org.cyclops.integratedcrafting.api.network.ICraftingNetwork; -import org.cyclops.integratedcrafting.capability.network.CraftingNetworkConfig; import org.cyclops.integrateddynamics.api.network.INetwork; import org.cyclops.integrateddynamics.api.part.PartTarget; import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties; @@ -15,6 +14,8 @@ import org.cyclops.integrateddynamics.core.part.aspect.build.IAspectValuePropagator; import org.cyclops.integrateddynamics.part.aspect.read.AspectReadBuilders; +import java.util.Optional; + /** * @author rubensworks */ @@ -22,13 +23,13 @@ public class CraftingAspectReadBuilders { public static final class CraftingNetwork { - public static final IAspectValuePropagator, Pair>> PROP_GET_CRAFTING_NETWORK = input -> { + public static final IAspectValuePropagator, Pair>> PROP_GET_CRAFTING_NETWORK = input -> { DimPos dimPos = input.getLeft().getTarget().getPos(); INetwork network = NetworkHelpers.getNetwork(dimPos.getLevel(true), dimPos.getBlockPos(), input.getLeft().getTarget().getSide()).orElse(null); - return Pair.of(input.getRight(), network != null ? network.getCapability(CraftingNetworkConfig.CAPABILITY) : LazyOptional.empty()); + return Pair.of(input.getRight(), network != null ? network.getCapability(Capabilities.CraftingNetwork.NETWORK) : Optional.empty()); }; - public static final AspectBuilder>> + public static final AspectBuilder>> BUILDER_LIST = AspectReadBuilders.BUILDER_LIST .byMod(IntegratedCrafting._instance) .withProperties(AspectReadBuilders.Network.PROPERTIES) diff --git a/src/main/java/org/cyclops/integratedcrafting/part/aspect/CraftingAspectWriteBuilders.java b/src/main/java/org/cyclops/integratedcrafting/part/aspect/CraftingAspectWriteBuilders.java index ed7d6776..8e7f397d 100644 --- a/src/main/java/org/cyclops/integratedcrafting/part/aspect/CraftingAspectWriteBuilders.java +++ b/src/main/java/org/cyclops/integratedcrafting/part/aspect/CraftingAspectWriteBuilders.java @@ -2,7 +2,7 @@ import com.google.common.collect.ImmutableList; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.FluidStack; import org.apache.commons.lang3.tuple.Triple; import org.cyclops.commoncapabilities.api.capability.recipehandler.IRecipeDefinition; import org.cyclops.commoncapabilities.api.ingredient.IIngredientMatcher; diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 70e81f67..b1bf3e71 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader="javafml" -loaderVersion="[47,)" +loaderVersion="[2,)" issueTrackerURL="https://github.com/CyclopsMC/IntegratedCrafting/issues" displayURL="https://www.curseforge.com/minecraft/mc-mods/integrated-crafting" license="MIT" @@ -15,31 +15,31 @@ Craft stuff in Integrated Dynamics networks. ''' [[dependencies.integratedcrafting]] modId="cyclopscore" - mandatory=true - versionRange="[1.18.4,)" + type="required" + versionRange="[1.19.0,)" ordering="NONE" side="BOTH" [[dependencies.integratedcrafting]] modId="integrateddynamics" - mandatory=true + type="required" versionRange="[1.20.0,)" ordering="NONE" side="BOTH" [[dependencies.integratedcrafting]] modId="commoncapabilities" - mandatory=true + type="required" versionRange="[2.9.0,)" ordering="NONE" side="BOTH" [[dependencies.integratedcrafting]] - modId="forge" - mandatory=true - versionRange="[47.0.1,)" + modId="neoforge" + type="required" + versionRange="[20.4,)" ordering="NONE" side="BOTH" [[dependencies.integratedcrafting]] modId="minecraft" - mandatory=true - versionRange="[1.20.1,]" + type="required" + versionRange="[1.20.4,]" ordering="NONE" side="BOTH" diff --git a/src/main/resources/data/integratedcrafting/advancements/autocrafting_setup/craft_crafting_interface.json b/src/main/resources/data/integratedcrafting/advancements/autocrafting_setup/craft_crafting_interface.json index 08db3502..f9f88c82 100644 --- a/src/main/resources/data/integratedcrafting/advancements/autocrafting_setup/craft_crafting_interface.json +++ b/src/main/resources/data/integratedcrafting/advancements/autocrafting_setup/craft_crafting_interface.json @@ -15,13 +15,9 @@ "criteria_0": { "trigger": "cyclopscore:item_crafted", "conditions": { - "items": [ - { - "items": [ - "integratedcrafting:part_interface_crafting" - ] - } - ] + "item": { + "item": "integratedcrafting:part_interface_crafting" + } } } } diff --git a/src/main/resources/data/integratedcrafting/advancements/autocrafting_setup/insert_recipe_planks.json b/src/main/resources/data/integratedcrafting/advancements/autocrafting_setup/insert_recipe_planks.json index 141c14a7..e9f1e772 100644 --- a/src/main/resources/data/integratedcrafting/advancements/autocrafting_setup/insert_recipe_planks.json +++ b/src/main/resources/data/integratedcrafting/advancements/autocrafting_setup/insert_recipe_planks.json @@ -16,11 +16,14 @@ "criteria_0": { "trigger": "integrateddynamics:part_variable_driven", "conditions": { - "parttype": "integratedcrafting:interface_crafting", + "part_type": "integratedcrafting:interface_crafting", "variable": { - "type": "integrateddynamics:valuetype", - "valuetype": "integrateddynamics:recipe", - "value": "{output:{\"minecraft:itemstack\":[{id:\"minecraft:oak_planks\",Count:4b}]},input:{\"minecraft:itemstack\":[{val:[{condition:1,prototype:{id:\"minecraft:oak_log\",Count:1b}}],type:0b}]}}" + "type": "value_type", + "value": { + "type": "serialized", + "value_type": "integrateddynamics:recipe", + "value": "{output:{\"minecraft:itemstack\":[{id:\"minecraft:oak_planks\",Count:4}]},input:{\"minecraft:itemstack\":[{val:[{condition:1,prototype:{id:\"minecraft:oak_log\",Count:1}}],type:0b}]}}" + } } } } diff --git a/src/main/resources/data/integratedcrafting/advancements/autocrafting_trigger/craft_crafting_writer.json b/src/main/resources/data/integratedcrafting/advancements/autocrafting_trigger/craft_crafting_writer.json index 33e54732..c92417a4 100644 --- a/src/main/resources/data/integratedcrafting/advancements/autocrafting_trigger/craft_crafting_writer.json +++ b/src/main/resources/data/integratedcrafting/advancements/autocrafting_trigger/craft_crafting_writer.json @@ -15,13 +15,9 @@ "criteria_0": { "trigger": "cyclopscore:item_crafted", "conditions": { - "items": [ - { - "items": [ - "integratedcrafting:part_crafting_writer" - ] - } - ] + "item": { + "item": "integratedcrafting:part_crafting_writer" + } } } } diff --git a/src/main/resources/data/integratedcrafting/advancements/autocrafting_trigger/craft_planks.json b/src/main/resources/data/integratedcrafting/advancements/autocrafting_trigger/craft_planks.json index 3e04ddfa..d6ba52b0 100644 --- a/src/main/resources/data/integratedcrafting/advancements/autocrafting_trigger/craft_planks.json +++ b/src/main/resources/data/integratedcrafting/advancements/autocrafting_trigger/craft_planks.json @@ -15,15 +15,15 @@ "criteria_0": { "trigger": "integrateddynamics:part_writer_aspect", "conditions": { - "parttype": "integratedcrafting:crafting_writer", + "part_type": "integratedcrafting:crafting_writer", "aspect": "integratedcrafting:write_itemstack_craft", "variable": { - "type": "integrateddynamics:valuetype", - "valuetype": "integrateddynamics:itemstack", + "type": "value_type", "value": { - "items": [ - "minecraft:oak_planks" - ] + "type": "itemstack", + "item": { + "item": "minecraft:oak_planks" + } } } }