From af4bf4aa4f763936da28b839a00f2039c32fa32e Mon Sep 17 00:00:00 2001 From: edgemq Date: Sun, 19 Jul 2026 12:40:53 +0300 Subject: [PATCH] blood 1.21.1 start --- .deps/BloodMagic-1.21.1 | 1 + build.gradle | 141 +++++------------- gradle.properties | 51 +++---- settings.gradle | 3 + src/main/java/com/edgemq/bmaddon/BMAddon.java | 19 +-- .../bmaddon/ae2/BloodAltarPatternDecoder.java | 6 +- .../bmaddon/ae2/BloodAltarPatternDetails.java | 38 ++--- .../ae2/BloodAltarPatternEncodingHelper.java | 24 +-- .../bmaddon/ae2/BloodAltarPatternMatcher.java | 39 ++--- .../block/BloodAltarAssemblerBlock.java | 18 +-- .../bmaddon/block/BloodGeneratorBlock.java | 21 ++- .../BloodAltarAssemblerBlockEntity.java | 38 ++--- .../BloodGeneratorBlockEntity.java | 91 +++++------ .../bmaddon/client/BMAddonClientEvents.java | 53 ++++--- .../render/BloodAltarAssemblerRenderer.java | 10 +- .../client/screen/BloodGeneratorScreen.java | 6 +- .../BloodAltarAssemblerMemoryCardHandler.java | 37 +---- .../bmaddon/compat/jei/BMAddonJeiPlugin.java | 10 +- .../bmaddon/config/BMAddonCommonConfig.java | 44 +++--- .../bmaddon/event/BMAddonForgeEvents.java | 12 +- .../bmaddon/event/BMAddonModEvents.java | 34 +++-- .../item/BloodAltarParallelCardItem.java | 9 +- .../bmaddon/item/BloodAltarPatternItem.java | 105 ++++++------- .../bmaddon/item/BloodAltarTierCardItem.java | 9 +- .../bmaddon/item/BloodMagicSpeedCardItem.java | 9 +- .../bmaddon/network/BMAddonNetwork.java | 41 ++--- .../network/SyncCommonConfigS2CPacket.java | 35 +++-- .../registry/BMAddonBlockEntities.java | 16 +- .../bmaddon/registry/BMAddonBlocks.java | 15 +- .../edgemq/bmaddon/registry/BMAddonItems.java | 30 ++-- .../edgemq/bmaddon/registry/BMAddonMenus.java | 21 ++- .../bmaddon/util/BloodAltarRecipeHelper.java | 71 ++++++--- .../bmaddon/util/BloodMagicFluidHelper.java | 8 +- .../bmaddon/models/block/blood_generator.json | 4 +- src/main/resources/bmaddon.mixins.json | 4 +- .../data/bmaddon/recipes/blood_generator.json | 26 ++++ src/main/templates/META-INF/mods.toml | 115 -------------- .../templates/META-INF/neoforge.mods.toml | 38 +++++ 38 files changed, 556 insertions(+), 696 deletions(-) create mode 160000 .deps/BloodMagic-1.21.1 create mode 100644 settings.gradle create mode 100644 src/main/resources/data/bmaddon/recipes/blood_generator.json delete mode 100644 src/main/templates/META-INF/mods.toml create mode 100644 src/main/templates/META-INF/neoforge.mods.toml diff --git a/.deps/BloodMagic-1.21.1 b/.deps/BloodMagic-1.21.1 new file mode 160000 index 0000000..27d76ba --- /dev/null +++ b/.deps/BloodMagic-1.21.1 @@ -0,0 +1 @@ +Subproject commit 27d76badbd691c664b274c65de72a21687e6cff8 diff --git a/build.gradle b/build.gradle index 63a909c..3ee2209 100644 --- a/build.gradle +++ b/build.gradle @@ -2,15 +2,10 @@ plugins { id 'idea' id 'java-library' id 'maven-publish' - id 'net.neoforged.moddev.legacyforge' version '2.0.91' + id 'net.neoforged.moddev' version '2.0.91' } tasks.named('wrapper', Wrapper).configure { - // Define wrapper values here so as to not have to always do so when updating gradlew.properties. - // Switching this to Wrapper.DistributionType.ALL will download the full gradle sources that comes with - // documentation attached on cursor hover of gradle classes and methods. However, this comes with increased - // file size for Gradle. If you do switch this to ALL, run the Gradle wrapper task twice afterwards. - // (Verify by checking gradle/wrapper/gradle-wrapper.properties to see if distributionUrl now points to `-all`) distributionType = Wrapper.DistributionType.BIN } @@ -21,96 +16,56 @@ base { archivesName = mod_id } -// Mojang ships Java 17 to end users in 1.20.1, so mods should target Java 17. -java.toolchain.languageVersion = JavaLanguageVersion.of(17) +java.toolchain.languageVersion = JavaLanguageVersion.of(21) -legacyForge { - // Specify the version of MinecraftForge to use. - version = project.minecraft_version + '-' + project.forge_version +neoForge { + version = project.neo_version parchment { mappingsVersion = project.parchment_mappings_version minecraftVersion = project.parchment_minecraft_version } - // This line is optional. Access Transformers are automatically detected - // accessTransformers = project.files('src/main/resources/META-INF/accesstransformer.cfg') - - // Default run configurations. - // These can be tweaked, removed, or duplicated as needed. runs { client { client() - - // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. - systemProperty 'forge.enabledGameTestNamespaces', project.mod_id + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id } server { server() programArgument '--nogui' - systemProperty 'forge.enabledGameTestNamespaces', project.mod_id + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id } - // This run config launches GameTestServer and runs all registered gametests, then exits. - // By default, the server will crash when no gametests are provided. - // The gametest system is also enabled by default for other run configs under the /test command. gameTestServer { type = "gameTestServer" - systemProperty 'forge.enabledGameTestNamespaces', project.mod_id + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id } data { data() - - // example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it - // gameDirectory = project.file('run-data') - - // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() } - // applies to all the run configs above configureEach { - // Recommended logging data for a userdev environment - // The markers can be added/remove as needed separated by commas. - // "SCAN": For mods scan. - // "REGISTRIES": For firing of registry events. - // "REGISTRYDUMP": For getting the contents of all registries. - systemProperty 'forge.logging.markers', 'REGISTRIES' - - // Recommended logging level for the console - // You can set various levels here. - // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels + systemProperty 'neoforge.logging.markers', 'REGISTRIES' logLevel = org.slf4j.event.Level.DEBUG } } mods { - // define mod <-> source bindings - // these are used to tell the game which sources are for which mod - // mostly optional in a single mod project - // but multi mod projects should define one per mod "${mod_id}" { sourceSet(sourceSets.main) } } } -// Include resources generated by data generators. sourceSets.main.resources { srcDir 'src/generated/resources' } -// Sets up a dependency configuration called 'localRuntime' and a deobfuscating one called 'modLocalRuntime' -// These configurations should be used instead of 'runtimeOnly' to declare -// a dependency that will be present for runtime testing but that is -// "optional", meaning it will not be pulled by dependents of this mod. configurations { runtimeClasspath.extendsFrom localRuntime } -obfuscation { - createRemappingConfiguration(configurations.localRuntime) -} - repositories { mavenLocal() @@ -136,18 +91,18 @@ repositories { maven { name = "BlameJared" url = "https://maven.blamejared.com" - content { - includeGroup "vazkii.patchouli" - } } maven { - name = "BlameJared" - url = "https://maven.blamejared.com" + name = "Modrinth" + url = "https://api.modrinth.com/maven" + content { + includeGroup "maven.modrinth" + } } maven { - name = "TheIllusiveC4" + name = "Curios" url = "https://maven.theillusivec4.top/" content { includeGroup "top.theillusivec4.curios" @@ -156,31 +111,16 @@ repositories { } dependencies { - // Blood Magic - modImplementation "curse.maven:blood-magic-224791:7956981" - annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' - modCompileOnly "mezz.jei:jei-${minecraft_version}-common-api:${jei_version}" - modCompileOnly "mezz.jei:jei-${minecraft_version}-forge-api:${jei_version}" - - modLocalRuntime "mezz.jei:jei-${minecraft_version}-forge:${jei_version}" - - modImplementation "appeng:appliedenergistics2-forge:15.4.10" - modLocalRuntime "org.appliedenergistics:guideme:20.1.7" - - // Blood Magic runtime dependency - modLocalRuntime "vazkii.patchouli:Patchouli:1.20.1-80-FORGE" - - // Опционально, но удобно для dev-сборки с Blood Magic - modLocalRuntime "top.theillusivec4.curios:curios-forge:5.3.4+1.20.1" -} + compileOnly "mezz.jei:jei-${minecraft_version}-common-api:${jei_version}" + compileOnly "mezz.jei:jei-${minecraft_version}-neoforge-api:${jei_version}" + localRuntime "mezz.jei:jei-${minecraft_version}-neoforge:${jei_version}" -mixin { - add sourceSets.main, "${mod_id}.refmap.json" - config "${mod_id}.mixins.json" -} + implementation "org.appliedenergistics:appliedenergistics2:${ae2_version}" + localRuntime "org.appliedenergistics:guideme:${guideme_version}" -dependencies { - annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' + implementation "com.example.examplemod:BloodMagic-1.21.1:${blood_magic_version}" + localRuntime "top.theillusivec4.curios:curios-neoforge:${curios_version}+${minecraft_version}" + localRuntime "maven.modrinth:jade:${jade_version}+neoforge" } jar { @@ -189,35 +129,31 @@ jar { ]) } - -// This block of code expands all declared replace properties in the specified resource targets. -// A missing property will result in an error. Properties are expanded using ${} Groovy notation. var generateModMetadata = tasks.register("generateModMetadata", ProcessResources) { var replaceProperties = [ - minecraft_version : minecraft_version, - minecraft_version_range : minecraft_version_range, - forge_version : forge_version, - forge_version_range : forge_version_range, - loader_version_range : loader_version_range, - mod_id : mod_id, - mod_name : mod_name, - mod_license : mod_license, - mod_version : mod_version, - mod_authors : mod_authors, - mod_description : mod_description + minecraft_version : minecraft_version, + minecraft_version_range : minecraft_version_range, + neo_version : neo_version, + neo_version_range : neo_version_range, + loader_version_range : loader_version_range, + mod_id : mod_id, + mod_name : mod_name, + mod_license : mod_license, + mod_version : mod_version, + mod_authors : mod_authors, + mod_description : mod_description, + ae2_version : ae2_version, + blood_magic_version_range: blood_magic_version_range ] inputs.properties replaceProperties expand replaceProperties from "src/main/templates" into "build/generated/sources/modMetadata" } -// Include the output of "generateModMetadata" as an input directory for the build -// this works with both building through Gradle and the IDE. + sourceSets.main.resources.srcDir generateModMetadata -// To avoid having to run "generateModMetadata" manually, make it run on every project reload -legacyForge.ideSyncTask generateModMetadata +neoForge.ideSyncTask generateModMetadata -// Example configuration to allow publishing using the maven-publish plugin publishing { publications { register('mavenJava', MavenPublication) { @@ -232,10 +168,9 @@ publishing { } tasks.withType(JavaCompile).configureEach { - options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation + options.encoding = 'UTF-8' } -// IDEA no longer automatically downloads sources/javadoc jars for dependencies, so we need to explicitly enable the behavior. idea { module { downloadSources = true diff --git a/gradle.properties b/gradle.properties index 87bb7ef..cc5d5ec 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,46 +1,31 @@ -# Sets default memory used for gradle commands. Can be overridden by user or command line properties. -org.gradle.jvmargs=-Xmx1G +org.gradle.jvmargs=-Xmx2G org.gradle.daemon=true org.gradle.parallel=true org.gradle.caching=true org.gradle.configuration-cache=true -#read more on this at https://github.com/neoforged/ModDevGradle?tab=readme-ov-file#better-minecraft-parameter-names--javadoc-parchment -# you can also find the latest versions at: https://parchmentmc.org/docs/getting-started -parchment_minecraft_version=1.20.1 -parchment_mappings_version=2023.09.03 -# Environment Properties -jei_version=15.20.0.127 -# You can find the latest versions here: https://files.minecraftforge.net/net/minecraftforge/forge/index_1.20.1.html -# The Minecraft version must agree with the Forge version to get a valid artifact -minecraft_version=1.20.1 -# The Minecraft version range can use any release version of Minecraft as bounds. -# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly -# as they do not follow standard versioning conventions. -minecraft_version_range=[1.20.1, 1.21) -# The Forge version must agree with the Minecraft version to get a valid artifact -forge_version=47.1.3 -# The Forge version range can use any version of Forge as bounds -forge_version_range=[47.1.3,) -# The loader version range can only use the major version of FML as bounds -loader_version_range=[47,) +parchment_minecraft_version=1.21.1 +parchment_mappings_version=2024.11.17 -## Mod Properties +minecraft_version=1.21.1 +minecraft_version_range=[1.21.1,1.22) +neo_version=21.1.172 +neo_version_range=[21.1.0,) +loader_version_range=[4,) + +jei_version=19.25.1.332 +ae2_version=19.2.17 +guideme_version=21.1.13 + +blood_magic_version=3.4.0-46-alpha +blood_magic_version_range=[3.4.0,) +curios_version=9.4.2 +jade_version=15.10.0 -# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63} -# Must match the String constant located in the main mod class annotated with @Mod. mod_id=bmaddon -# The human-readable display name for the mod. mod_name=BloodMagic Additions -# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=GNU GPLv3 -# The mod version. See https://semver.org/ -mod_version=1.0.2 -# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. -# This should match the base package used for the mod sources. -# See https://maven.apache.org/guides/mini/guide-naming-conventions.html +mod_version=1.1.0 mod_group_id=com.edgemq.bmaddon -# The authors of the mod. This is a simple text string that is used for display purposes in the mod list. mod_authors=edgemq -# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list. mod_description=BloodMagic Additions diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..4ced2d9 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,3 @@ +plugins { + id 'org.gradle.toolchains.foojay-resolver-convention' version '1.0.0' +} diff --git a/src/main/java/com/edgemq/bmaddon/BMAddon.java b/src/main/java/com/edgemq/bmaddon/BMAddon.java index d9f4b22..4635b7c 100644 --- a/src/main/java/com/edgemq/bmaddon/BMAddon.java +++ b/src/main/java/com/edgemq/bmaddon/BMAddon.java @@ -7,19 +7,16 @@ import com.edgemq.bmaddon.registry.BMAddonItems; import com.edgemq.bmaddon.registry.BMAddonMenus; import com.edgemq.bmaddon.registry.BMAddonSlotSemantics; -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.neoforged.bus.api.IEventBus; +import net.neoforged.fml.ModContainer; +import net.neoforged.fml.common.Mod; +import net.neoforged.fml.config.ModConfig; @Mod(BMAddon.MODID) public class BMAddon { public static final String MODID = "bmaddon"; - public BMAddon() { - IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); - + public BMAddon(IEventBus modEventBus, ModContainer modContainer) { BMAddonSlotSemantics.init(); BMAddonBlocks.register(modEventBus); @@ -27,12 +24,12 @@ public BMAddon() { BMAddonBlockEntities.register(modEventBus); BMAddonMenus.register(modEventBus); - BMAddonNetwork.register(); + modEventBus.addListener(BMAddonNetwork::register); - ModLoadingContext.get().registerConfig( + modContainer.registerConfig( ModConfig.Type.COMMON, BMAddonCommonConfig.SPEC, BMAddon.MODID + "-common.toml" ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/ae2/BloodAltarPatternDecoder.java b/src/main/java/com/edgemq/bmaddon/ae2/BloodAltarPatternDecoder.java index 26bbff3..725e3bb 100644 --- a/src/main/java/com/edgemq/bmaddon/ae2/BloodAltarPatternDecoder.java +++ b/src/main/java/com/edgemq/bmaddon/ae2/BloodAltarPatternDecoder.java @@ -32,16 +32,16 @@ public IPatternDetails decodePattern(AEItemKey what, Level level) { ItemStack stack = what.toStack(); - return decodePattern(stack, level, false); + return decodePattern(stack, level); } @Nullable @Override - public IPatternDetails decodePattern(ItemStack stack, Level level, boolean tryRecovery) { + public IPatternDetails decodePattern(ItemStack stack, Level level) { if (!isEncodedPattern(stack)) { return null; } return BloodAltarPatternDetails.create(level, stack).orElse(null); } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/ae2/BloodAltarPatternDetails.java b/src/main/java/com/edgemq/bmaddon/ae2/BloodAltarPatternDetails.java index 09dc0f2..75bca8f 100644 --- a/src/main/java/com/edgemq/bmaddon/ae2/BloodAltarPatternDetails.java +++ b/src/main/java/com/edgemq/bmaddon/ae2/BloodAltarPatternDetails.java @@ -13,8 +13,8 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.Level; -import wayoftime.bloodmagic.recipe.RecipeAlchemyTable; -import wayoftime.bloodmagic.recipe.RecipeBloodAltar; +import wayoftime.bloodmagic.common.recipe.alchemy_table.AlchemyTableRecipe; +import wayoftime.bloodmagic.common.recipe.bloodaltar.BloodAltarRecipe; import javax.annotation.Nullable; import java.util.ArrayList; @@ -70,7 +70,7 @@ public static Optional create(Level level, ItemStack p }; } - public static Optional create(Level level, ItemStack patternStack, RecipeBloodAltar recipe) { + public static Optional create(Level level, ItemStack patternStack, BloodAltarRecipe recipe) { if (level == null || patternStack.isEmpty() || recipe == null) { return Optional.empty(); } @@ -85,7 +85,7 @@ public static Optional create(Level level, ItemStack p return Optional.empty(); } - GenericStack output = createOutput(recipe.getOutput()); + GenericStack output = createOutput(recipe.getResult()); if (output == null) { return Optional.empty(); @@ -99,7 +99,7 @@ public static Optional create(Level level, ItemStack p inputs.add(itemInput); } - IInput bloodInput = createBloodInput(getRequiredLifeEssence(recipe.getSyphon())); + IInput bloodInput = createBloodInput(getRequiredLifeEssence(recipe.getTotalBlood())); if (bloodInput != null) { inputs.add(bloodInput); @@ -111,16 +111,16 @@ public static Optional create(Level level, ItemStack p return Optional.of(new BloodAltarPatternDetails( BloodMagicPatternKind.BLOOD_ALTAR, - recipe.getId(), + BloodAltarPatternItem.getRecipeId(patternStack), definition, inputs.toArray(IInput[]::new), new GenericStack[]{output}, - recipe.getMinimumTier(), + recipe.getMinTier(), 0 )); } - public static Optional create(Level level, ItemStack patternStack, RecipeAlchemyTable recipe) { + public static Optional create(Level level, ItemStack patternStack, AlchemyTableRecipe recipe) { if (level == null || patternStack.isEmpty() || recipe == null) { return Optional.empty(); } @@ -135,7 +135,7 @@ public static Optional create(Level level, ItemStack p return Optional.empty(); } - GenericStack output = createOutput(recipe.getOutput()); + GenericStack output = createOutput(recipe.output()); if (output == null) { return Optional.empty(); @@ -160,7 +160,7 @@ public static Optional create(Level level, ItemStack p } } - IInput bloodInput = createBloodInput(getRequiredLifeEssence(recipe.getSyphon())); + IInput bloodInput = createBloodInput(getRequiredLifeEssence(recipe.essence())); if (bloodInput != null) { inputs.add(bloodInput); @@ -176,11 +176,11 @@ public static Optional create(Level level, ItemStack p */ return Optional.of(new BloodAltarPatternDetails( BloodMagicPatternKind.ALCHEMY_TABLE, - recipe.getId(), + BloodAltarPatternItem.getRecipeId(patternStack), definition, inputs.toArray(IInput[]::new), new GenericStack[]{output}, - recipe.getMinimumTier(), + recipe.tier(), 0 )); } @@ -193,12 +193,12 @@ private static AEItemKey createDefinition(ItemStack patternStack) { return AEItemKey.of(definitionStack); } - public static int getRequiredLifeEssence(RecipeBloodAltar recipe) { - return getRequiredLifeEssence(recipe.getSyphon()); + public static int getRequiredLifeEssence(BloodAltarRecipe recipe) { + return getRequiredLifeEssence(recipe.getTotalBlood()); } - public static int getRequiredLifeEssence(RecipeAlchemyTable recipe) { - return getRequiredLifeEssence(recipe.getSyphon()); + public static int getRequiredLifeEssence(AlchemyTableRecipe recipe) { + return getRequiredLifeEssence(recipe.essence()); } public static int getRequiredLifeEssence(int syphon) { @@ -304,8 +304,8 @@ public IInput[] getInputs() { } @Override - public GenericStack[] getOutputs() { - return outputs; + public List getOutputs() { + return List.of(outputs); } @Override @@ -394,4 +394,4 @@ public AEKey getRemainingKey(AEKey template) { return null; } } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/ae2/BloodAltarPatternEncodingHelper.java b/src/main/java/com/edgemq/bmaddon/ae2/BloodAltarPatternEncodingHelper.java index 77daf88..bbf2220 100644 --- a/src/main/java/com/edgemq/bmaddon/ae2/BloodAltarPatternEncodingHelper.java +++ b/src/main/java/com/edgemq/bmaddon/ae2/BloodAltarPatternEncodingHelper.java @@ -9,8 +9,8 @@ import com.edgemq.bmaddon.util.BloodAltarRecipeHelper; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -import wayoftime.bloodmagic.recipe.RecipeAlchemyTable; -import wayoftime.bloodmagic.recipe.RecipeBloodAltar; +import wayoftime.bloodmagic.common.recipe.alchemy_table.AlchemyTableRecipe; +import wayoftime.bloodmagic.common.recipe.bloodaltar.BloodAltarRecipe; import java.util.ArrayList; import java.util.List; @@ -58,20 +58,21 @@ private static Optional tryCreateBloodAltarPattern( ItemStack inputPreview = itemInputs.get(0); - Optional recipeOptional = BloodAltarRecipeHelper.findAltarRecipe(level, inputPreview); + Optional recipeOptional = BloodAltarRecipeHelper.findAltarRecipeWithId(level, inputPreview); if (recipeOptional.isEmpty()) { return Optional.empty(); } - RecipeBloodAltar recipe = recipeOptional.get(); + BloodAltarRecipeHelper.FoundAltarRecipe foundRecipe = recipeOptional.get(); + BloodAltarRecipe recipe = foundRecipe.recipe(); - if (!BloodAltarRecipeHelper.outputMatches(recipe.getOutput(), outputPreview)) { + if (!BloodAltarRecipeHelper.outputMatches(recipe.getResult(), outputPreview)) { return Optional.empty(); } ItemStack result = new ItemStack(BMAddonItems.BLOOD_ALTAR_PATTERN.get()); - BloodAltarPatternItem.encode(result, recipe, inputPreview); + BloodAltarPatternItem.encode(result, foundRecipe.id(), recipe, inputPreview); return Optional.of(result); } @@ -83,11 +84,11 @@ private static Optional tryCreateAlchemyTablePattern( ) { List itemInputs = extractItemInputs(details); - if (itemInputs.isEmpty() || itemInputs.size() > RecipeAlchemyTable.MAX_INPUTS) { + if (itemInputs.isEmpty() || itemInputs.size() > 6) { return Optional.empty(); } - Optional recipeOptional = BloodAltarRecipeHelper.findAlchemyTableRecipe( + Optional recipeOptional = BloodAltarRecipeHelper.findAlchemyTableRecipeWithId( level, itemInputs, outputPreview @@ -97,10 +98,11 @@ private static Optional tryCreateAlchemyTablePattern( return Optional.empty(); } - RecipeAlchemyTable recipe = recipeOptional.get(); + BloodAltarRecipeHelper.FoundAlchemyTableRecipe foundRecipe = recipeOptional.get(); + AlchemyTableRecipe recipe = foundRecipe.recipe(); ItemStack result = new ItemStack(BMAddonItems.BLOOD_ALTAR_PATTERN.get()); - BloodAltarPatternItem.encode(result, recipe, itemInputs); + BloodAltarPatternItem.encode(result, foundRecipe.id(), recipe, itemInputs); return Optional.of(result); } @@ -132,4 +134,4 @@ private static List extractItemInputs(IPatternDetails details) { private BloodAltarPatternEncodingHelper() { } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/ae2/BloodAltarPatternMatcher.java b/src/main/java/com/edgemq/bmaddon/ae2/BloodAltarPatternMatcher.java index 2a0b07b..e20f4aa 100644 --- a/src/main/java/com/edgemq/bmaddon/ae2/BloodAltarPatternMatcher.java +++ b/src/main/java/com/edgemq/bmaddon/ae2/BloodAltarPatternMatcher.java @@ -10,9 +10,10 @@ import com.edgemq.bmaddon.util.BloodMagicFluidHelper; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.level.Level; -import wayoftime.bloodmagic.common.recipe.BloodMagicRecipeType; -import wayoftime.bloodmagic.recipe.RecipeBloodAltar; +import wayoftime.bloodmagic.common.recipe.BMRecipes; +import wayoftime.bloodmagic.common.recipe.bloodaltar.BloodAltarRecipe; import javax.annotation.Nullable; import java.util.List; @@ -35,15 +36,15 @@ public static Optional createDetailsFromStack( return Optional.empty(); } - Optional recipeOptional = BloodAltarRecipeHelper.getAltarRecipe(level, recipeId); + Optional recipeOptional = BloodAltarRecipeHelper.getAltarRecipe(level, recipeId); if (recipeOptional.isEmpty()) { return Optional.empty(); } - RecipeBloodAltar recipe = recipeOptional.get(); + BloodAltarRecipe recipe = recipeOptional.get(); - if (recipe.getMinimumTier() > bloodMagicRecipeTierLimit) { + if (recipe.getMinTier() > bloodMagicRecipeTierLimit) { return Optional.empty(); } @@ -88,15 +89,15 @@ private static Optional resolveCustomBloodAltarPatter ) { ResourceLocation recipeId = patternDetails.getRecipeId(); - Optional recipeOptional = BloodAltarRecipeHelper.getAltarRecipe(level, recipeId); + Optional recipeOptional = BloodAltarRecipeHelper.getAltarRecipe(level, recipeId); if (recipeOptional.isEmpty()) { return Optional.empty(); } - RecipeBloodAltar recipe = recipeOptional.get(); + BloodAltarRecipe recipe = recipeOptional.get(); - if (recipe.getMinimumTier() > bloodMagicRecipeTierLimit) { + if (recipe.getMinTier() > bloodMagicRecipeTierLimit) { return Optional.empty(); } @@ -110,7 +111,7 @@ private static Optional resolveCustomBloodAltarPatter return Optional.empty(); } - return Optional.of(new ResolvedBloodAltarPattern(recipe.getId(), primaryOutput)); + return Optional.of(new ResolvedBloodAltarPattern(recipeId, primaryOutput)); } private static Optional resolveAe2ProcessingPattern( @@ -132,10 +133,12 @@ private static Optional resolveAe2ProcessingPattern( return Optional.empty(); } - List recipes = level.getRecipeManager().getAllRecipesFor(BloodMagicRecipeType.ALTAR.get()); + List> recipes = level.getRecipeManager().getAllRecipesFor(BMRecipes.BLOOD_ALTAR_TYPE.get()); - for (RecipeBloodAltar recipe : recipes) { - if (recipe.getMinimumTier() > bloodMagicRecipeTierLimit) { + for (RecipeHolder recipeHolder : recipes) { + BloodAltarRecipe recipe = recipeHolder.value(); + + if (recipe.getMinTier() > bloodMagicRecipeTierLimit) { continue; } @@ -151,20 +154,20 @@ private static Optional resolveAe2ProcessingPattern( continue; } - return Optional.of(new ResolvedBloodAltarPattern(recipe.getId(), primaryOutput)); + return Optional.of(new ResolvedBloodAltarPattern(recipeHolder.id(), primaryOutput)); } return Optional.empty(); } - private static boolean matchesRecipeOutput(IPatternDetails patternDetails, RecipeBloodAltar recipe) { + private static boolean matchesRecipeOutput(IPatternDetails patternDetails, BloodAltarRecipe recipe) { GenericStack primaryOutput = patternDetails.getPrimaryOutput(); if (primaryOutput == null || primaryOutput.amount() <= 0) { return false; } - ItemStack recipeOutput = recipe.getOutput().copy(); + ItemStack recipeOutput = recipe.getResult().copy(); if (recipeOutput.isEmpty()) { return false; @@ -180,7 +183,7 @@ private static boolean matchesRecipeOutput(IPatternDetails patternDetails, Recip && primaryOutput.amount() == recipeOutput.getCount(); } - private static boolean matchesRecipeItemInput(IPatternDetails patternDetails, RecipeBloodAltar recipe) { + private static boolean matchesRecipeItemInput(IPatternDetails patternDetails, BloodAltarRecipe recipe) { for (IPatternDetails.IInput input : patternDetails.getInputs()) { long multiplier = Math.max(1L, input.getMultiplier()); @@ -206,7 +209,7 @@ private static boolean matchesRecipeItemInput(IPatternDetails patternDetails, Re return false; } - private static boolean matchesRecipeLifeEssenceInput(IPatternDetails patternDetails, RecipeBloodAltar recipe) { + private static boolean matchesRecipeLifeEssenceInput(IPatternDetails patternDetails, BloodAltarRecipe recipe) { int requiredLifeEssence = BloodAltarPatternDetails.getRequiredLifeEssence(recipe); if (requiredLifeEssence <= 0) { @@ -291,4 +294,4 @@ public record ResolvedBloodAltarPattern( GenericStack output ) { } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/block/BloodAltarAssemblerBlock.java b/src/main/java/com/edgemq/bmaddon/block/BloodAltarAssemblerBlock.java index 606e5c4..11a64ca 100644 --- a/src/main/java/com/edgemq/bmaddon/block/BloodAltarAssemblerBlock.java +++ b/src/main/java/com/edgemq/bmaddon/block/BloodAltarAssemblerBlock.java @@ -5,10 +5,9 @@ import com.edgemq.bmaddon.blockentity.BloodAltarAssemblerBlockEntity; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; +import net.minecraft.world.SimpleMenuProvider; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockBehaviour; @@ -16,9 +15,6 @@ import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.phys.BlockHitResult; -import net.minecraftforge.network.NetworkHooks; - -import javax.annotation.Nullable; public class BloodAltarAssemblerBlock extends AEBaseEntityBlock { public static final BooleanProperty POWERED = BooleanProperty.create("powered"); @@ -43,12 +39,11 @@ protected BlockState updateBlockStateFromBlockEntity( } @Override - public InteractionResult onActivated( + protected InteractionResult useWithoutItem( + BlockState state, Level level, BlockPos pos, Player player, - InteractionHand hand, - @Nullable ItemStack heldItem, BlockHitResult hit ) { BloodAltarAssemblerBlockEntity blockEntity = getBlockEntity(level, pos); @@ -62,9 +57,12 @@ public InteractionResult onActivated( } if (!level.isClientSide() && player instanceof ServerPlayer serverPlayer) { - NetworkHooks.openScreen(serverPlayer, blockEntity, pos); + serverPlayer.openMenu( + new SimpleMenuProvider(blockEntity::createMenu, blockEntity.getDisplayName()), + pos + ); } return InteractionResult.sidedSuccess(level.isClientSide()); } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/block/BloodGeneratorBlock.java b/src/main/java/com/edgemq/bmaddon/block/BloodGeneratorBlock.java index 661a432..5ce81c9 100644 --- a/src/main/java/com/edgemq/bmaddon/block/BloodGeneratorBlock.java +++ b/src/main/java/com/edgemq/bmaddon/block/BloodGeneratorBlock.java @@ -1,13 +1,14 @@ package com.edgemq.bmaddon.block; +import com.mojang.serialization.MapCodec; import com.edgemq.bmaddon.blockentity.BloodGeneratorBlockEntity; import com.edgemq.bmaddon.network.BMAddonNetwork; import com.edgemq.bmaddon.registry.BMAddonBlockEntities; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.SimpleMenuProvider; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.BaseEntityBlock; @@ -19,11 +20,12 @@ import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; -import net.minecraftforge.network.NetworkHooks; import javax.annotation.Nullable; public class BloodGeneratorBlock extends BaseEntityBlock { + public static final MapCodec CODEC = simpleCodec(BloodGeneratorBlock::new); + private static final VoxelShape SHAPE = box( 0.0D, 0.0D, @@ -37,6 +39,11 @@ public BloodGeneratorBlock(Properties properties) { super(properties); } + @Override + protected MapCodec codec() { + return CODEC; + } + @Nullable @Override public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { @@ -87,12 +94,11 @@ public BlockEntityTicker getTicker( } @Override - public InteractionResult use( + protected InteractionResult useWithoutItem( BlockState state, Level level, BlockPos pos, Player player, - InteractionHand hand, BlockHitResult hit ) { if (level.isClientSide()) { @@ -103,10 +109,13 @@ public InteractionResult use( if (blockEntity instanceof BloodGeneratorBlockEntity bloodGenerator && player instanceof ServerPlayer serverPlayer) { BMAddonNetwork.sendConfigToPlayer(serverPlayer); - NetworkHooks.openScreen(serverPlayer, bloodGenerator, pos); + serverPlayer.openMenu( + new SimpleMenuProvider(bloodGenerator::createMenu, bloodGenerator.getDisplayName()), + pos + ); return InteractionResult.CONSUME; } return InteractionResult.PASS; } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/blockentity/BloodAltarAssemblerBlockEntity.java b/src/main/java/com/edgemq/bmaddon/blockentity/BloodAltarAssemblerBlockEntity.java index 76effef..3bd6d82 100644 --- a/src/main/java/com/edgemq/bmaddon/blockentity/BloodAltarAssemblerBlockEntity.java +++ b/src/main/java/com/edgemq/bmaddon/blockentity/BloodAltarAssemblerBlockEntity.java @@ -20,7 +20,7 @@ import appeng.api.upgrades.IUpgradeableObject; import appeng.api.upgrades.UpgradeInventories; import appeng.api.util.AECableType; -import appeng.blockentity.grid.AENetworkInvBlockEntity; +import appeng.blockentity.grid.AENetworkedInvBlockEntity; import appeng.core.definitions.AEItems; import appeng.util.inv.AppEngInternalInventory; import com.edgemq.bmaddon.BMAddon; @@ -34,10 +34,12 @@ import com.edgemq.bmaddon.util.BloodAltarRecipeHelper; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.MenuProvider; @@ -53,8 +55,8 @@ import java.util.Iterator; import java.util.List; -public class BloodAltarAssemblerBlockEntity extends AENetworkInvBlockEntity implements MenuProvider, IUpgradeableObject, IPowerChannelState, ICraftingProvider, IGridTickable { - public static final ResourceLocation INV_PATTERNS = new ResourceLocation(BMAddon.MODID, "blood_altar_assembler_patterns"); +public class BloodAltarAssemblerBlockEntity extends AENetworkedInvBlockEntity implements MenuProvider, IUpgradeableObject, IPowerChannelState, ICraftingProvider, IGridTickable { + public static final ResourceLocation INV_PATTERNS = ResourceLocation.fromNamespaceAndPath(BMAddon.MODID, "blood_altar_assembler_patterns"); private static final String TAG_PATTERNS = "Patterns"; private static final String TAG_UPGRADES = "Upgrades"; @@ -247,7 +249,7 @@ public InternalInventory getSubInventory(ResourceLocation id) { } @Override - public void onChangeInventory(InternalInventory inventory, int slot) { + public void onChangeInventory(AppEngInternalInventory inventory, int slot) { refreshCraftingProvider(); alertTickManager(); saveChanges(); @@ -416,7 +418,7 @@ public boolean isBusy() { @Override public TickingRequest getTickingRequest(IGridNode node) { - return new TickingRequest(1, 20, !hasWorkToDo(), true); + return new TickingRequest(1, 20, !hasWorkToDo(), 1); } @Override @@ -583,7 +585,7 @@ private boolean tryInsertPendingOutput(ActiveCraft craft) { } @Override - protected boolean readFromStream(FriendlyByteBuf data) { + protected boolean readFromStream(RegistryFriendlyByteBuf data) { boolean changed = super.readFromStream(data); boolean oldPowered = this.powered; @@ -593,7 +595,7 @@ protected boolean readFromStream(FriendlyByteBuf data) { } @Override - protected void writeToStream(FriendlyByteBuf data) { + protected void writeToStream(RegistryFriendlyByteBuf data) { super.writeToStream(data); data.writeBoolean(this.powered); } @@ -644,11 +646,11 @@ public void onReady() { } @Override - public void saveAdditional(CompoundTag tag) { - super.saveAdditional(tag); + public void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) { + super.saveAdditional(tag, registries); - patternInventory.writeToNBT(tag, TAG_PATTERNS); - upgrades.writeToNBT(tag, TAG_UPGRADES); + patternInventory.writeToNBT(tag, TAG_PATTERNS, registries); + upgrades.writeToNBT(tag, TAG_UPGRADES, registries); ListTag activeCraftList = new ListTag(); @@ -659,7 +661,7 @@ public void saveAdditional(CompoundTag tag) { craftTag.putString(TAG_CRAFT_RECIPE_ID, craft.recipeId.toString()); if (craft.output != null) { - craftTag.put(TAG_CRAFT_OUTPUT, GenericStack.writeTag(craft.output)); + craftTag.put(TAG_CRAFT_OUTPUT, GenericStack.writeTag(registries, craft.output)); } craftTag.putInt(TAG_CRAFT_PROGRESS_TICKS, craft.progressTicks); @@ -673,11 +675,11 @@ public void saveAdditional(CompoundTag tag) { } @Override - public void loadTag(CompoundTag tag) { - super.loadTag(tag); + public void loadTag(CompoundTag tag, HolderLookup.Provider registries) { + super.loadTag(tag, registries); - patternInventory.readFromNBT(tag, TAG_PATTERNS); - upgrades.readFromNBT(tag, TAG_UPGRADES); + patternInventory.readFromNBT(tag, TAG_PATTERNS, registries); + upgrades.readFromNBT(tag, TAG_UPGRADES, registries); activeCrafts.clear(); @@ -697,7 +699,7 @@ public void loadTag(CompoundTag tag) { GenericStack output = null; if (craftTag.contains(TAG_CRAFT_OUTPUT, Tag.TAG_COMPOUND)) { - output = GenericStack.readTag(craftTag.getCompound(TAG_CRAFT_OUTPUT)); + output = GenericStack.readTag(registries, craftTag.getCompound(TAG_CRAFT_OUTPUT)); } if (output == null || output.amount() <= 0) { @@ -781,4 +783,4 @@ private ActiveCraft( this.pendingOutput = pendingOutput; } } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/blockentity/BloodGeneratorBlockEntity.java b/src/main/java/com/edgemq/bmaddon/blockentity/BloodGeneratorBlockEntity.java index aba509b..ede9650 100644 --- a/src/main/java/com/edgemq/bmaddon/blockentity/BloodGeneratorBlockEntity.java +++ b/src/main/java/com/edgemq/bmaddon/blockentity/BloodGeneratorBlockEntity.java @@ -6,6 +6,7 @@ import com.edgemq.bmaddon.util.BloodMagicFluidHelper; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; @@ -17,13 +18,11 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.fluids.capability.templates.FluidTank; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.energy.IEnergyStorage; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.capability.IFluidHandler; +import net.neoforged.neoforge.fluids.capability.templates.FluidTank; import javax.annotation.Nullable; @@ -55,9 +54,6 @@ protected void onContentsChanged() { private final IFluidHandler externalFluidHandler = new OutputOnlyFluidHandler(); - private LazyOptional energyCapability = LazyOptional.of(() -> energyStorage); - private LazyOptional fluidCapability = LazyOptional.of(() -> externalFluidHandler); - public BloodGeneratorBlockEntity(BlockPos pos, BlockState state) { super(BMAddonBlockEntities.BLOOD_GENERATOR.get(), pos, state); } @@ -176,7 +172,13 @@ private void tryAutoOutputFluid() { continue; } - neighbor.getCapability(ForgeCapabilities.FLUID_HANDLER, direction.getOpposite()).ifPresent(handler -> { + IFluidHandler handler = level.getCapability( + Capabilities.FluidHandler.BLOCK, + worldPosition.relative(direction), + direction.getOpposite() + ); + + if (handler != null) { FluidStack simulatedDrain = bloodTank.drain(maxOutput, IFluidHandler.FluidAction.SIMULATE); if (simulatedDrain.isEmpty()) { @@ -198,10 +200,18 @@ private void tryAutoOutputFluid() { } setChangedAndSync(); - }); + } } } + public IEnergyStorage getEnergyHandler() { + return energyStorage; + } + + public IFluidHandler getFluidHandler() { + return externalFluidHandler; + } + public int getEnergyStored() { return energyStorage.getEnergyStored(); } @@ -266,39 +276,39 @@ private void setChangedAndSync() { } @Override - protected void saveAdditional(CompoundTag tag) { - super.saveAdditional(tag); + protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) { + super.saveAdditional(tag, registries); tag.putInt(TAG_ENERGY, energyStorage.getEnergyStored()); CompoundTag tankTag = new CompoundTag(); - bloodTank.writeToNBT(tankTag); + bloodTank.writeToNBT(registries, tankTag); tag.put(TAG_BLOOD_TANK, tankTag); } @Override - public void load(CompoundTag tag) { - super.load(tag); + protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) { + super.loadAdditional(tag, registries); energyStorage.setEnergyStored(tag.getInt(TAG_ENERGY)); if (tag.contains(TAG_BLOOD_TANK)) { - bloodTank.readFromNBT(tag.getCompound(TAG_BLOOD_TANK)); + bloodTank.readFromNBT(registries, tag.getCompound(TAG_BLOOD_TANK)); } updateTankCapacityFromConfig(); } @Override - public CompoundTag getUpdateTag() { - CompoundTag tag = super.getUpdateTag(); - saveAdditional(tag); + public CompoundTag getUpdateTag(HolderLookup.Provider registries) { + CompoundTag tag = super.getUpdateTag(registries); + saveAdditional(tag, registries); return tag; } @Override - public void handleUpdateTag(CompoundTag tag) { - load(tag); + public void handleUpdateTag(CompoundTag tag, HolderLookup.Provider registries) { + loadAdditional(tag, registries); } @Nullable @@ -307,39 +317,6 @@ public ClientboundBlockEntityDataPacket getUpdatePacket() { return ClientboundBlockEntityDataPacket.create(this); } - @Override - public void onLoad() { - super.onLoad(); - - if (!energyCapability.isPresent()) { - energyCapability = LazyOptional.of(() -> energyStorage); - } - - if (!fluidCapability.isPresent()) { - fluidCapability = LazyOptional.of(() -> externalFluidHandler); - } - } - - @Override - public void invalidateCaps() { - super.invalidateCaps(); - energyCapability.invalidate(); - fluidCapability.invalidate(); - } - - @Override - public LazyOptional getCapability(Capability capability, @Nullable Direction side) { - if (capability == ForgeCapabilities.ENERGY) { - return energyCapability.cast(); - } - - if (capability == ForgeCapabilities.FLUID_HANDLER) { - return fluidCapability.cast(); - } - - return super.getCapability(capability, side); - } - private final class GeneratorEnergyStorage implements IEnergyStorage { private int energy; @@ -454,4 +431,4 @@ public FluidStack drain(int maxDrain, FluidAction action) { return bloodTank.drain(maxDrain, action); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/client/BMAddonClientEvents.java b/src/main/java/com/edgemq/bmaddon/client/BMAddonClientEvents.java index b56cfce..680c587 100644 --- a/src/main/java/com/edgemq/bmaddon/client/BMAddonClientEvents.java +++ b/src/main/java/com/edgemq/bmaddon/client/BMAddonClientEvents.java @@ -10,32 +10,50 @@ import com.edgemq.bmaddon.registry.BMAddonBlocks; import com.edgemq.bmaddon.registry.BMAddonItems; import com.edgemq.bmaddon.registry.BMAddonMenus; -import net.minecraft.client.gui.screens.MenuScreens; import net.minecraft.client.renderer.ItemBlockRenderTypes; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.blockentity.BlockEntityRenderers; import net.minecraft.client.renderer.item.ItemProperties; +import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.client.event.ModelEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.neoforge.client.event.ModelEvent; +import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; -@Mod.EventBusSubscriber( +@EventBusSubscriber( modid = BMAddon.MODID, - bus = Mod.EventBusSubscriber.Bus.MOD, + bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT ) public final class BMAddonClientEvents { - public static final ResourceLocation BLOOD_ALTAR_ASSEMBLER_LIGHTS_MODEL = new ResourceLocation( + public static final ResourceLocation BLOOD_ALTAR_ASSEMBLER_LIGHTS_MODEL = ResourceLocation.fromNamespaceAndPath( BMAddon.MODID, "block/blood_altar_assembler_lights" ); + public static final ModelResourceLocation BLOOD_ALTAR_ASSEMBLER_LIGHTS_MODEL_LOCATION = + ModelResourceLocation.standalone(BLOOD_ALTAR_ASSEMBLER_LIGHTS_MODEL); @SubscribeEvent public static void onRegisterAdditionalModels(ModelEvent.RegisterAdditional event) { - event.register(BLOOD_ALTAR_ASSEMBLER_LIGHTS_MODEL); + event.register(BLOOD_ALTAR_ASSEMBLER_LIGHTS_MODEL_LOCATION); + } + + @SubscribeEvent + public static void onRegisterMenuScreens(RegisterMenuScreensEvent event) { + event.register( + BMAddonMenus.BLOOD_GENERATOR.get(), + BloodGeneratorScreen::new + ); + + InitScreens.register( + event, + BMAddonMenus.BLOOD_ALTAR_ASSEMBLER.get(), + BloodAltarAssemblerScreen::new, + "/screens/blood_altar_assembler.json" + ); } @SubscribeEvent @@ -46,17 +64,6 @@ public static void onClientSetup(FMLClientSetupEvent event) { RenderType.cutout() ); - MenuScreens.register( - BMAddonMenus.BLOOD_GENERATOR.get(), - BloodGeneratorScreen::new - ); - - InitScreens.register( - BMAddonMenus.BLOOD_ALTAR_ASSEMBLER.get(), - BloodAltarAssemblerScreen::new, - "/screens/blood_altar_assembler.json" - ); - BlockEntityRenderers.register( BMAddonBlockEntities.BLOOD_ALTAR_ASSEMBLER.get(), BloodAltarAssemblerRenderer::new @@ -67,7 +74,7 @@ public static void onClientSetup(FMLClientSetupEvent event) { ); ItemProperties.register( BMAddonItems.BLOOD_ALTAR_PATTERN.get(), - new ResourceLocation(BMAddon.MODID, "encoded"), + ResourceLocation.fromNamespaceAndPath(BMAddon.MODID, "encoded"), (stack, level, entity, seed) -> BloodAltarPatternItem.isEncoded(stack) ? 1.0F : 0.0F ); }); @@ -75,4 +82,4 @@ public static void onClientSetup(FMLClientSetupEvent event) { private BMAddonClientEvents() { } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/client/render/BloodAltarAssemblerRenderer.java b/src/main/java/com/edgemq/bmaddon/client/render/BloodAltarAssemblerRenderer.java index cc8a29b..a6e7758 100644 --- a/src/main/java/com/edgemq/bmaddon/client/render/BloodAltarAssemblerRenderer.java +++ b/src/main/java/com/edgemq/bmaddon/client/render/BloodAltarAssemblerRenderer.java @@ -10,9 +10,9 @@ import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.client.resources.model.BakedModel; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.model.data.ModelData; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.client.model.data.ModelData; @OnlyIn(Dist.CLIENT) public class BloodAltarAssemblerRenderer implements BlockEntityRenderer { @@ -42,7 +42,7 @@ private void renderPowerLight( Minecraft minecraft = Minecraft.getInstance(); BakedModel lightsModel = minecraft.getModelManager().getModel( - BMAddonClientEvents.BLOOD_ALTAR_ASSEMBLER_LIGHTS_MODEL + BMAddonClientEvents.BLOOD_ALTAR_ASSEMBLER_LIGHTS_MODEL_LOCATION ); VertexConsumer buffer = bufferSource.getBuffer(RenderType.tripwire()); @@ -63,4 +63,4 @@ private void renderPowerLight( null ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/client/screen/BloodGeneratorScreen.java b/src/main/java/com/edgemq/bmaddon/client/screen/BloodGeneratorScreen.java index 3bc3875..ef0d218 100644 --- a/src/main/java/com/edgemq/bmaddon/client/screen/BloodGeneratorScreen.java +++ b/src/main/java/com/edgemq/bmaddon/client/screen/BloodGeneratorScreen.java @@ -11,7 +11,7 @@ import java.util.List; public class BloodGeneratorScreen extends AbstractContainerScreen { - private static final ResourceLocation TEXTURE = new ResourceLocation( + private static final ResourceLocation TEXTURE = ResourceLocation.fromNamespaceAndPath( BMAddon.MODID, "textures/gui/blood_generator.png" ); @@ -101,7 +101,7 @@ protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) { @Override public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { - this.renderBackground(guiGraphics); + this.renderBackground(guiGraphics, mouseX, mouseY, partialTick); super.render(guiGraphics, mouseX, mouseY, partialTick); renderBloodTooltip(guiGraphics, mouseX, mouseY); this.renderTooltip(guiGraphics, mouseX, mouseY); @@ -160,4 +160,4 @@ private boolean isMouseOverBloodBar(int mouseX, int mouseY) { && mouseY >= y && mouseY < y + BLOOD_BAR_AREA_HEIGHT; } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/compat/BloodAltarAssemblerMemoryCardHandler.java b/src/main/java/com/edgemq/bmaddon/compat/BloodAltarAssemblerMemoryCardHandler.java index 4e3c73b..4932d47 100644 --- a/src/main/java/com/edgemq/bmaddon/compat/BloodAltarAssemblerMemoryCardHandler.java +++ b/src/main/java/com/edgemq/bmaddon/compat/BloodAltarAssemblerMemoryCardHandler.java @@ -15,12 +15,12 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraftforge.event.entity.player.PlayerInteractEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent; -@Mod.EventBusSubscriber(modid = BMAddon.MODID) +@EventBusSubscriber(modid = BMAddon.MODID) public final class BloodAltarAssemblerMemoryCardHandler { private static final String TAG_BLOOD_PATTERNS = "BMAddonBloodPatterns"; @@ -64,22 +64,6 @@ public static void onRightClickBlock(PlayerInteractEvent.RightClickBlock event) } private static void copyBloodPatterns(BloodAltarAssemblerBlockEntity assembler, ItemStack memoryCardStack) { - InternalInventory patternInventory = assembler.getPatternInventory(); - ListTag list = new ListTag(); - - for (int slot = 0; slot < patternInventory.size(); slot++) { - ItemStack pattern = patternInventory.getStackInSlot(slot); - CompoundTag entry = new CompoundTag(); - - if (!pattern.isEmpty()) { - pattern.save(entry); - } - - - list.add(entry); - } - - memoryCardStack.getOrCreateTag().put(TAG_BLOOD_PATTERNS, list); } private static void pasteBloodPatterns( @@ -87,14 +71,7 @@ private static void pasteBloodPatterns( ItemStack memoryCardStack, Player player ) { - CompoundTag rootTag = memoryCardStack.getTag(); - - if (rootTag == null || !rootTag.contains(TAG_BLOOD_PATTERNS, Tag.TAG_LIST)) { - - return; - } - - ListTag list = rootTag.getList(TAG_BLOOD_PATTERNS, Tag.TAG_COMPOUND); + ListTag list = new ListTag(); InternalInventory patternInventory = assembler.getPatternInventory(); boolean creative = player.isCreative(); boolean missingAny = false; @@ -112,7 +89,7 @@ private static void pasteBloodPatterns( continue; } - ItemStack wanted = ItemStack.of(entry); + ItemStack wanted = ItemStack.EMPTY; if (wanted.isEmpty()) { continue; @@ -177,4 +154,4 @@ private static boolean consumeBlankPattern(Player player, ItemStack wanted) { return false; } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/compat/jei/BMAddonJeiPlugin.java b/src/main/java/com/edgemq/bmaddon/compat/jei/BMAddonJeiPlugin.java index 48441de..0b291af 100644 --- a/src/main/java/com/edgemq/bmaddon/compat/jei/BMAddonJeiPlugin.java +++ b/src/main/java/com/edgemq/bmaddon/compat/jei/BMAddonJeiPlugin.java @@ -6,13 +6,10 @@ import mezz.jei.api.JeiPlugin; import mezz.jei.api.registration.IRecipeCatalystRegistration; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; -import wayoftime.bloodmagic.compat.jei.altar.BloodAltarRecipeCategory; -import wayoftime.bloodmagic.compat.jei.alchemytable.AlchemyTableRecipeCategory; @JeiPlugin public final class BMAddonJeiPlugin implements IModPlugin { - private static final ResourceLocation PLUGIN_UID = new ResourceLocation( + private static final ResourceLocation PLUGIN_UID = ResourceLocation.fromNamespaceAndPath( BMAddon.MODID, "jei_plugin" ); @@ -24,8 +21,5 @@ public ResourceLocation getPluginUid() { @Override public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) { - ItemStack assembler = new ItemStack(BMAddonItems.BLOOD_ALTAR_ASSEMBLER.get()); - registration.addRecipeCatalyst(assembler, BloodAltarRecipeCategory.RECIPE_TYPE); - registration.addRecipeCatalyst(assembler, AlchemyTableRecipeCategory.RECIPE_TYPE); } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/config/BMAddonCommonConfig.java b/src/main/java/com/edgemq/bmaddon/config/BMAddonCommonConfig.java index 582c119..d7ecdbc 100644 --- a/src/main/java/com/edgemq/bmaddon/config/BMAddonCommonConfig.java +++ b/src/main/java/com/edgemq/bmaddon/config/BMAddonCommonConfig.java @@ -1,30 +1,30 @@ package com.edgemq.bmaddon.config; -import net.minecraftforge.common.ForgeConfigSpec; +import net.neoforged.neoforge.common.ModConfigSpec; public final class BMAddonCommonConfig { - public static final ForgeConfigSpec SPEC; - - public static final ForgeConfigSpec.IntValue BLOOD_GENERATOR_ENERGY_CAPACITY; - public static final ForgeConfigSpec.IntValue BLOOD_GENERATOR_MAX_ENERGY_INPUT; - public static final ForgeConfigSpec.IntValue BLOOD_GENERATOR_LIFE_TANK_CAPACITY; - public static final ForgeConfigSpec.IntValue BLOOD_GENERATOR_ENERGY_PER_OPERATION; - public static final ForgeConfigSpec.IntValue BLOOD_GENERATOR_LIFE_ESSENCE_PER_OPERATION; - public static final ForgeConfigSpec.IntValue BLOOD_GENERATOR_WORK_INTERVAL_TICKS; - public static final ForgeConfigSpec.BooleanValue BLOOD_GENERATOR_AUTO_OUTPUT; - public static final ForgeConfigSpec.IntValue BLOOD_GENERATOR_MAX_FLUID_OUTPUT_PER_TICK; - - public static final ForgeConfigSpec.IntValue BLOOD_ALTAR_ASSEMBLER_BASE_CRAFT_TIME_TICKS; - public static final ForgeConfigSpec.IntValue BLOOD_ALTAR_ASSEMBLER_MIN_CRAFT_TIME_TICKS; - public static final ForgeConfigSpec.DoubleValue BLOOD_ALTAR_ASSEMBLER_AE_PER_TICK_BASE; - public static final ForgeConfigSpec.DoubleValue BLOOD_ALTAR_ASSEMBLER_AE_PER_TICK_PER_ACCELERATION_CARD; - public static final ForgeConfigSpec.DoubleValue BLOOD_ALTAR_ASSEMBLER_LIFE_ESSENCE_MULTIPLIER; - public static final ForgeConfigSpec.IntValue BLOOD_ALTAR_ASSEMBLER_BASE_PARALLEL_CRAFTS; - public static final ForgeConfigSpec.IntValue BLOOD_ALTAR_ASSEMBLER_PARALLEL_CRAFTS_PER_CARD; - public static final ForgeConfigSpec.IntValue BLOOD_ALTAR_ASSEMBLER_MAX_PARALLEL_CRAFTS; + public static final ModConfigSpec SPEC; + + public static final ModConfigSpec.IntValue BLOOD_GENERATOR_ENERGY_CAPACITY; + public static final ModConfigSpec.IntValue BLOOD_GENERATOR_MAX_ENERGY_INPUT; + public static final ModConfigSpec.IntValue BLOOD_GENERATOR_LIFE_TANK_CAPACITY; + public static final ModConfigSpec.IntValue BLOOD_GENERATOR_ENERGY_PER_OPERATION; + public static final ModConfigSpec.IntValue BLOOD_GENERATOR_LIFE_ESSENCE_PER_OPERATION; + public static final ModConfigSpec.IntValue BLOOD_GENERATOR_WORK_INTERVAL_TICKS; + public static final ModConfigSpec.BooleanValue BLOOD_GENERATOR_AUTO_OUTPUT; + public static final ModConfigSpec.IntValue BLOOD_GENERATOR_MAX_FLUID_OUTPUT_PER_TICK; + + public static final ModConfigSpec.IntValue BLOOD_ALTAR_ASSEMBLER_BASE_CRAFT_TIME_TICKS; + public static final ModConfigSpec.IntValue BLOOD_ALTAR_ASSEMBLER_MIN_CRAFT_TIME_TICKS; + public static final ModConfigSpec.DoubleValue BLOOD_ALTAR_ASSEMBLER_AE_PER_TICK_BASE; + public static final ModConfigSpec.DoubleValue BLOOD_ALTAR_ASSEMBLER_AE_PER_TICK_PER_ACCELERATION_CARD; + public static final ModConfigSpec.DoubleValue BLOOD_ALTAR_ASSEMBLER_LIFE_ESSENCE_MULTIPLIER; + public static final ModConfigSpec.IntValue BLOOD_ALTAR_ASSEMBLER_BASE_PARALLEL_CRAFTS; + public static final ModConfigSpec.IntValue BLOOD_ALTAR_ASSEMBLER_PARALLEL_CRAFTS_PER_CARD; + public static final ModConfigSpec.IntValue BLOOD_ALTAR_ASSEMBLER_MAX_PARALLEL_CRAFTS; static { - ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder(); + ModConfigSpec.Builder builder = new ModConfigSpec.Builder(); builder.push("blood_generator"); @@ -103,4 +103,4 @@ public final class BMAddonCommonConfig { private BMAddonCommonConfig() { } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/event/BMAddonForgeEvents.java b/src/main/java/com/edgemq/bmaddon/event/BMAddonForgeEvents.java index 04fc500..dc959c8 100644 --- a/src/main/java/com/edgemq/bmaddon/event/BMAddonForgeEvents.java +++ b/src/main/java/com/edgemq/bmaddon/event/BMAddonForgeEvents.java @@ -3,13 +3,13 @@ import com.edgemq.bmaddon.BMAddon; import com.edgemq.bmaddon.network.BMAddonNetwork; import net.minecraft.server.level.ServerPlayer; -import net.minecraftforge.event.entity.player.PlayerEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.event.entity.player.PlayerEvent; -@Mod.EventBusSubscriber( +@EventBusSubscriber( modid = BMAddon.MODID, - bus = Mod.EventBusSubscriber.Bus.FORGE + bus = EventBusSubscriber.Bus.GAME ) public final class BMAddonForgeEvents { @SubscribeEvent @@ -35,4 +35,4 @@ public static void onPlayerRespawn(PlayerEvent.PlayerRespawnEvent event) { private BMAddonForgeEvents() { } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/event/BMAddonModEvents.java b/src/main/java/com/edgemq/bmaddon/event/BMAddonModEvents.java index 096041e..890e02d 100644 --- a/src/main/java/com/edgemq/bmaddon/event/BMAddonModEvents.java +++ b/src/main/java/com/edgemq/bmaddon/event/BMAddonModEvents.java @@ -11,15 +11,17 @@ import com.edgemq.bmaddon.config.BMAddonCommonConfig; import com.edgemq.bmaddon.network.BMAddonNetwork; import com.edgemq.bmaddon.registry.BMAddonItems; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.config.ModConfig; -import net.minecraftforge.fml.event.config.ModConfigEvent; -import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; - -@Mod.EventBusSubscriber( +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.fml.config.ModConfig; +import net.neoforged.fml.event.config.ModConfigEvent; +import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; + +@EventBusSubscriber( modid = BMAddon.MODID, - bus = Mod.EventBusSubscriber.Bus.MOD + bus = EventBusSubscriber.Bus.MOD ) public final class BMAddonModEvents { private static boolean registeredPatternDecoder; @@ -41,6 +43,20 @@ public static void onCommonSetup(FMLCommonSetupEvent event) { }); } + @SubscribeEvent + public static void registerCapabilities(RegisterCapabilitiesEvent event) { + event.registerBlockEntity( + Capabilities.EnergyStorage.BLOCK, + com.edgemq.bmaddon.registry.BMAddonBlockEntities.BLOOD_GENERATOR.get(), + (blockEntity, side) -> blockEntity.getEnergyHandler() + ); + event.registerBlockEntity( + Capabilities.FluidHandler.BLOCK, + com.edgemq.bmaddon.registry.BMAddonBlockEntities.BLOOD_GENERATOR.get(), + (blockEntity, side) -> blockEntity.getFluidHandler() + ); + } + private static void registerBloodAltarAssemblerUpgrades() { Upgrades.add(BMAddonItems.BLOOD_ALTAR_TIER_CARD_2.get(), BMAddonItems.BLOOD_ALTAR_ASSEMBLER.get(), 1); Upgrades.add(BMAddonItems.BLOOD_ALTAR_TIER_CARD_3.get(), BMAddonItems.BLOOD_ALTAR_ASSEMBLER.get(), 1); @@ -89,4 +105,4 @@ private static boolean isOurCommonConfig(ModConfig config) { private BMAddonModEvents() { } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/item/BloodAltarParallelCardItem.java b/src/main/java/com/edgemq/bmaddon/item/BloodAltarParallelCardItem.java index b699811..ee3f764 100644 --- a/src/main/java/com/edgemq/bmaddon/item/BloodAltarParallelCardItem.java +++ b/src/main/java/com/edgemq/bmaddon/item/BloodAltarParallelCardItem.java @@ -4,9 +4,6 @@ import net.minecraft.network.chat.Component; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; -import net.minecraft.world.level.Level; - -import javax.annotation.Nullable; import java.util.List; public class BloodAltarParallelCardItem extends UpgradeCardItem { @@ -17,11 +14,11 @@ public BloodAltarParallelCardItem(Properties properties) { @Override public void appendHoverText( ItemStack stack, - @Nullable Level level, + TooltipContext context, List tooltip, TooltipFlag flag ) { - super.appendHoverText(stack, level, tooltip, flag); + super.appendHoverText(stack, context, tooltip, flag); tooltip.add(Component.translatable("tooltip.bmaddon.blood_altar_parallel_card.description")); } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/item/BloodAltarPatternItem.java b/src/main/java/com/edgemq/bmaddon/item/BloodAltarPatternItem.java index 1bec5f5..914cca9 100644 --- a/src/main/java/com/edgemq/bmaddon/item/BloodAltarPatternItem.java +++ b/src/main/java/com/edgemq/bmaddon/item/BloodAltarPatternItem.java @@ -3,6 +3,7 @@ import com.edgemq.bmaddon.ae2.BloodMagicPatternKind; import com.edgemq.bmaddon.util.BloodAltarRecipeHelper; import net.minecraft.ChatFormatting; +import net.minecraft.core.component.DataComponents; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; @@ -14,9 +15,10 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.item.component.CustomData; import net.minecraft.world.level.Level; -import wayoftime.bloodmagic.recipe.RecipeAlchemyTable; -import wayoftime.bloodmagic.recipe.RecipeBloodAltar; +import wayoftime.bloodmagic.common.recipe.alchemy_table.AlchemyTableRecipe; +import wayoftime.bloodmagic.common.recipe.bloodaltar.BloodAltarRecipe; import javax.annotation.Nullable; import java.util.ArrayList; @@ -104,7 +106,7 @@ public Component getName(ItemStack stack) { @Override public void appendHoverText( ItemStack stack, - @Nullable Level level, + TooltipContext context, List tooltip, TooltipFlag flag ) { @@ -123,7 +125,8 @@ public void appendHoverText( BloodMagicPatternKind kind = getRecipeKind(stack); List inputPreviews = getInputPreviews(stack); - ItemStack outputPreview = getResolvedOutputPreview(stack, level, kind, recipeId); + Level level = null; + ItemStack outputPreview = getOutputPreview(stack); tooltip.add(Component.translatable( "tooltip.bmaddon.blood_altar_pattern.type", @@ -168,9 +171,6 @@ public void appendHoverText( tooltip.add(Component.translatable("tooltip.bmaddon.blood_altar_pattern.shift_clear").withStyle(ChatFormatting.DARK_GRAY)); - if (level != null && !BloodAltarRecipeHelper.recipeStillExists(level, kind, recipeId)) { - tooltip.add(Component.translatable("tooltip.bmaddon.blood_altar_pattern.recipe_missing").withStyle(ChatFormatting.RED)); - } } private static String getRecipeKindTranslationKey(BloodMagicPatternKind kind) { @@ -198,7 +198,7 @@ private static ItemStack getResolvedOutputPreview( } public static boolean isEncoded(ItemStack stack) { - CompoundTag tag = stack.getTag(); + CompoundTag tag = getCustomTag(stack); return tag != null && tag.contains(TAG_RECIPE_ID) @@ -206,7 +206,7 @@ public static boolean isEncoded(ItemStack stack) { } public static BloodMagicPatternKind getRecipeKind(ItemStack stack) { - CompoundTag tag = stack.getTag(); + CompoundTag tag = getCustomTag(stack); if (tag == null || !tag.contains(TAG_RECIPE_KIND)) { return BloodMagicPatternKind.BLOOD_ALTAR; @@ -217,7 +217,7 @@ public static BloodMagicPatternKind getRecipeKind(ItemStack stack) { @Nullable public static ResourceLocation getRecipeId(ItemStack stack) { - CompoundTag tag = stack.getTag(); + CompoundTag tag = getCustomTag(stack); if (tag == null || !tag.contains(TAG_RECIPE_ID)) { return null; @@ -237,7 +237,7 @@ public static ItemStack getInputPreview(ItemStack stack) { } public static List getInputPreviews(ItemStack stack) { - CompoundTag tag = stack.getTag(); + CompoundTag tag = getCustomTag(stack); if (tag == null) { return List.of(); @@ -248,7 +248,7 @@ public static List getInputPreviews(ItemStack stack) { List inputs = new ArrayList<>(); for (int index = 0; index < listTag.size(); index++) { - ItemStack input = ItemStack.of(listTag.getCompound(index)); + ItemStack input = ItemStack.EMPTY; if (!input.isEmpty()) { inputs.add(input); @@ -259,7 +259,7 @@ public static List getInputPreviews(ItemStack stack) { } if (tag.contains(TAG_INPUT_PREVIEW, Tag.TAG_COMPOUND)) { - ItemStack oldInput = ItemStack.of(tag.getCompound(TAG_INPUT_PREVIEW)); + ItemStack oldInput = ItemStack.EMPTY; if (!oldInput.isEmpty()) { return List.of(oldInput); @@ -270,17 +270,17 @@ public static List getInputPreviews(ItemStack stack) { } public static ItemStack getOutputPreview(ItemStack stack) { - CompoundTag tag = stack.getTag(); + CompoundTag tag = getCustomTag(stack); if (tag == null || !tag.contains(TAG_OUTPUT_PREVIEW)) { return ItemStack.EMPTY; } - return ItemStack.of(tag.getCompound(TAG_OUTPUT_PREVIEW)); + return ItemStack.EMPTY; } public static int getStoredMinimumTier(ItemStack stack) { - CompoundTag tag = stack.getTag(); + CompoundTag tag = getCustomTag(stack); if (tag == null) { return 0; @@ -294,7 +294,7 @@ public static int getStoredAltarTierForDisplay(ItemStack stack) { } public static int getStoredSyphon(ItemStack stack) { - CompoundTag tag = stack.getTag(); + CompoundTag tag = getCustomTag(stack); if (tag == null) { return 0; @@ -304,7 +304,7 @@ public static int getStoredSyphon(ItemStack stack) { } public static int getStoredConsumeRate(ItemStack stack) { - CompoundTag tag = stack.getTag(); + CompoundTag tag = getCustomTag(stack); if (tag == null) { return 0; @@ -314,7 +314,7 @@ public static int getStoredConsumeRate(ItemStack stack) { } public static int getStoredDrainRate(ItemStack stack) { - CompoundTag tag = stack.getTag(); + CompoundTag tag = getCustomTag(stack); if (tag == null) { return 0; @@ -323,24 +323,24 @@ public static int getStoredDrainRate(ItemStack stack) { return tag.getInt(TAG_DRAIN_RATE); } - public static void encode(ItemStack patternStack, RecipeBloodAltar recipe, ItemStack inputPreview) { + public static void encode(ItemStack patternStack, ResourceLocation recipeId, BloodAltarRecipe recipe, ItemStack inputPreview) { ItemStack storedInputPreview = inputPreview.copy(); storedInputPreview.setCount(1); encodeInternal( patternStack, BloodMagicPatternKind.BLOOD_ALTAR, - recipe.getId(), + recipeId, List.of(storedInputPreview), - recipe.getOutput().copy(), - recipe.getMinimumTier(), - recipe.getSyphon(), - recipe.getConsumeRate(), - recipe.getDrainRate() + recipe.getResult().copy(), + recipe.getMinTier(), + recipe.getTotalBlood(), + recipe.getCraftSpeed(), + recipe.getDrainSpeed() ); } - public static void encode(ItemStack patternStack, RecipeAlchemyTable recipe, List inputPreviews) { + public static void encode(ItemStack patternStack, ResourceLocation recipeId, AlchemyTableRecipe recipe, List inputPreviews) { List storedInputs = new ArrayList<>(); for (ItemStack input : inputPreviews) { @@ -356,11 +356,11 @@ public static void encode(ItemStack patternStack, RecipeAlchemyTable recipe, Lis encodeInternal( patternStack, BloodMagicPatternKind.ALCHEMY_TABLE, - recipe.getId(), + recipeId, storedInputs, - recipe.getOutput().copy(), - recipe.getMinimumTier(), - recipe.getSyphon(), + recipe.output().copy(), + recipe.tier(), + recipe.essence(), 0, 0 ); @@ -377,13 +377,12 @@ private static void encodeInternal( int consumeRate, int drainRate ) { - CompoundTag tag = patternStack.getOrCreateTag(); + CompoundTag tag = getOrCreateCustomTag(patternStack); ListTag inputList = new ListTag(); for (ItemStack inputPreview : inputPreviews) { if (!inputPreview.isEmpty()) { - inputList.add(inputPreview.save(new CompoundTag())); } } @@ -392,33 +391,37 @@ private static void encodeInternal( tag.put(TAG_INPUT_PREVIEWS, inputList); if (!inputPreviews.isEmpty()) { - tag.put(TAG_INPUT_PREVIEW, inputPreviews.get(0).save(new CompoundTag())); - } else { - tag.remove(TAG_INPUT_PREVIEW); } - tag.put(TAG_OUTPUT_PREVIEW, outputPreview.save(new CompoundTag())); tag.putInt(TAG_MINIMUM_TIER, minimumTier); tag.putInt(TAG_SYPHON, syphon); tag.putInt(TAG_CONSUME_RATE, consumeRate); tag.putInt(TAG_DRAIN_RATE, drainRate); tag.remove(TAG_CRAFT_TIME_TICKS); + setCustomTag(patternStack, tag); } public static void clear(ItemStack stack) { - stack.removeTagKey(TAG_RECIPE_KIND); - stack.removeTagKey(TAG_RECIPE_ID); - stack.removeTagKey(TAG_INPUT_PREVIEW); - stack.removeTagKey(TAG_INPUT_PREVIEWS); - stack.removeTagKey(TAG_OUTPUT_PREVIEW); - stack.removeTagKey(TAG_MINIMUM_TIER); - stack.removeTagKey(TAG_SYPHON); - stack.removeTagKey(TAG_CONSUME_RATE); - stack.removeTagKey(TAG_DRAIN_RATE); - stack.removeTagKey(TAG_CRAFT_TIME_TICKS); - - if (stack.getTag() != null && stack.getTag().isEmpty()) { - stack.setTag(null); + stack.remove(DataComponents.CUSTOM_DATA); + } + + @Nullable + private static CompoundTag getCustomTag(ItemStack stack) { + CustomData customData = stack.get(DataComponents.CUSTOM_DATA); + return customData == null ? null : customData.copyTag(); + } + + private static CompoundTag getOrCreateCustomTag(ItemStack stack) { + CompoundTag tag = getCustomTag(stack); + return tag == null ? new CompoundTag() : tag; + } + + private static void setCustomTag(ItemStack stack, CompoundTag tag) { + if (tag.isEmpty()) { + stack.remove(DataComponents.CUSTOM_DATA); + return; } + + stack.set(DataComponents.CUSTOM_DATA, CustomData.of(tag)); } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/item/BloodAltarTierCardItem.java b/src/main/java/com/edgemq/bmaddon/item/BloodAltarTierCardItem.java index ae1e6c0..43929ff 100644 --- a/src/main/java/com/edgemq/bmaddon/item/BloodAltarTierCardItem.java +++ b/src/main/java/com/edgemq/bmaddon/item/BloodAltarTierCardItem.java @@ -4,9 +4,6 @@ import net.minecraft.network.chat.Component; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; -import net.minecraft.world.level.Level; - -import javax.annotation.Nullable; import java.util.List; public class BloodAltarTierCardItem extends UpgradeCardItem { @@ -24,13 +21,13 @@ public int getTier() { @Override public void appendHoverText( ItemStack stack, - @Nullable Level level, + TooltipContext context, List tooltip, TooltipFlag flag ) { - super.appendHoverText(stack, level, tooltip, flag); + super.appendHoverText(stack, context, tooltip, flag); tooltip.add(Component.translatable("tooltip.bmaddon.blood_altar_tier_card.tier", tier)); tooltip.add(Component.translatable("tooltip.bmaddon.blood_altar_tier_card.description")); } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/item/BloodMagicSpeedCardItem.java b/src/main/java/com/edgemq/bmaddon/item/BloodMagicSpeedCardItem.java index 9582ac8..abebf77 100644 --- a/src/main/java/com/edgemq/bmaddon/item/BloodMagicSpeedCardItem.java +++ b/src/main/java/com/edgemq/bmaddon/item/BloodMagicSpeedCardItem.java @@ -4,9 +4,6 @@ import net.minecraft.network.chat.Component; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; -import net.minecraft.world.level.Level; - -import javax.annotation.Nullable; import java.util.List; public class BloodMagicSpeedCardItem extends UpgradeCardItem { @@ -19,11 +16,11 @@ public BloodMagicSpeedCardItem(Properties properties) { @Override public void appendHoverText( ItemStack stack, - @Nullable Level level, + TooltipContext context, List tooltip, TooltipFlag flag ) { - super.appendHoverText(stack, level, tooltip, flag); + super.appendHoverText(stack, context, tooltip, flag); tooltip.add(Component.translatable("tooltip.bmaddon.blood_magic_speed_card.description")); } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/network/BMAddonNetwork.java b/src/main/java/com/edgemq/bmaddon/network/BMAddonNetwork.java index fd29ba1..2d639e4 100644 --- a/src/main/java/com/edgemq/bmaddon/network/BMAddonNetwork.java +++ b/src/main/java/com/edgemq/bmaddon/network/BMAddonNetwork.java @@ -1,38 +1,27 @@ package com.edgemq.bmaddon.network; -import com.edgemq.bmaddon.BMAddon; import com.edgemq.bmaddon.config.SyncedBMAddonConfig; -import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; -import net.minecraftforge.network.NetworkRegistry; -import net.minecraftforge.network.PacketDistributor; -import net.minecraftforge.network.simple.SimpleChannel; -import net.minecraftforge.server.ServerLifecycleHooks; +import net.neoforged.neoforge.network.PacketDistributor; +import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; +import net.neoforged.neoforge.server.ServerLifecycleHooks; public final class BMAddonNetwork { private static final String PROTOCOL_VERSION = "1"; - public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( - new ResourceLocation(BMAddon.MODID, "main"), - () -> PROTOCOL_VERSION, - PROTOCOL_VERSION::equals, - PROTOCOL_VERSION::equals - ); - - private static int packetId = 0; - - public static void register() { - CHANNEL.messageBuilder(SyncCommonConfigS2CPacket.class, nextPacketId()) - .encoder(SyncCommonConfigS2CPacket::encode) - .decoder(SyncCommonConfigS2CPacket::decode) - .consumerMainThread(SyncCommonConfigS2CPacket::handle) - .add(); + public static void register(RegisterPayloadHandlersEvent event) { + event.registrar(PROTOCOL_VERSION) + .commonToClient( + SyncCommonConfigS2CPacket.TYPE, + SyncCommonConfigS2CPacket.STREAM_CODEC, + SyncCommonConfigS2CPacket::handle + ); } public static void sendConfigToPlayer(ServerPlayer player) { - CHANNEL.send( - PacketDistributor.PLAYER.with(() -> player), + PacketDistributor.sendToPlayer( + player, new SyncCommonConfigS2CPacket(SyncedBMAddonConfig.fromCommonConfig()) ); } @@ -49,10 +38,6 @@ public static void sendConfigToAllPlayers() { } } - private static int nextPacketId() { - return packetId++; - } - private BMAddonNetwork() { } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/network/SyncCommonConfigS2CPacket.java b/src/main/java/com/edgemq/bmaddon/network/SyncCommonConfigS2CPacket.java index 0302f86..1bf3a1a 100644 --- a/src/main/java/com/edgemq/bmaddon/network/SyncCommonConfigS2CPacket.java +++ b/src/main/java/com/edgemq/bmaddon/network/SyncCommonConfigS2CPacket.java @@ -1,19 +1,22 @@ package com.edgemq.bmaddon.network; +import com.edgemq.bmaddon.BMAddon; import com.edgemq.bmaddon.config.SyncedBMAddonConfig; import net.minecraft.network.FriendlyByteBuf; -import net.minecraftforge.network.NetworkEvent; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.network.handling.IPayloadContext; -import java.util.function.Supplier; +public record SyncCommonConfigS2CPacket(SyncedBMAddonConfig.Snapshot snapshot) implements CustomPacketPayload { + public static final Type TYPE = new Type<>( + ResourceLocation.fromNamespaceAndPath(BMAddon.MODID, "sync_common_config") + ); -public final class SyncCommonConfigS2CPacket { - private final SyncedBMAddonConfig.Snapshot snapshot; + public static final StreamCodec STREAM_CODEC = + CustomPacketPayload.codec(SyncCommonConfigS2CPacket::encode, SyncCommonConfigS2CPacket::decode); - public SyncCommonConfigS2CPacket(SyncedBMAddonConfig.Snapshot snapshot) { - this.snapshot = snapshot; - } - - public static void encode(SyncCommonConfigS2CPacket packet, FriendlyByteBuf buffer) { + private static void encode(SyncCommonConfigS2CPacket packet, FriendlyByteBuf buffer) { SyncedBMAddonConfig.Snapshot snapshot = packet.snapshot; buffer.writeVarInt(snapshot.bloodGeneratorEnergyCapacity()); @@ -26,7 +29,7 @@ public static void encode(SyncCommonConfigS2CPacket packet, FriendlyByteBuf buff buffer.writeVarInt(snapshot.bloodGeneratorMaxFluidOutputPerTick()); } - public static SyncCommonConfigS2CPacket decode(FriendlyByteBuf buffer) { + private static SyncCommonConfigS2CPacket decode(FriendlyByteBuf buffer) { SyncedBMAddonConfig.Snapshot snapshot = new SyncedBMAddonConfig.Snapshot( buffer.readVarInt(), buffer.readVarInt(), @@ -41,10 +44,12 @@ public static SyncCommonConfigS2CPacket decode(FriendlyByteBuf buffer) { return new SyncCommonConfigS2CPacket(snapshot); } - public static void handle(SyncCommonConfigS2CPacket packet, Supplier contextSupplier) { - NetworkEvent.Context context = contextSupplier.get(); + public static void handle(SyncCommonConfigS2CPacket packet, IPayloadContext context) { + SyncedBMAddonConfig.setClientSnapshot(packet.snapshot); + } - context.enqueueWork(() -> SyncedBMAddonConfig.setClientSnapshot(packet.snapshot)); - context.setPacketHandled(true); + @Override + public Type type() { + return TYPE; } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/registry/BMAddonBlockEntities.java b/src/main/java/com/edgemq/bmaddon/registry/BMAddonBlockEntities.java index 945b994..0f87a2a 100644 --- a/src/main/java/com/edgemq/bmaddon/registry/BMAddonBlockEntities.java +++ b/src/main/java/com/edgemq/bmaddon/registry/BMAddonBlockEntities.java @@ -4,17 +4,17 @@ import com.edgemq.bmaddon.block.BloodAltarAssemblerBlock; import com.edgemq.bmaddon.blockentity.BloodAltarAssemblerBlockEntity; import com.edgemq.bmaddon.blockentity.BloodGeneratorBlockEntity; +import net.minecraft.core.registries.Registries; import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.neoforge.registries.DeferredRegister; +import net.neoforged.neoforge.registries.DeferredHolder; public final class BMAddonBlockEntities { public static final DeferredRegister> BLOCK_ENTITIES = - DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, BMAddon.MODID); + DeferredRegister.create(Registries.BLOCK_ENTITY_TYPE, BMAddon.MODID); - public static final RegistryObject> BLOOD_GENERATOR = + public static final DeferredHolder, BlockEntityType> BLOOD_GENERATOR = BLOCK_ENTITIES.register( "blood_generator", () -> BlockEntityType.Builder.of( @@ -23,7 +23,7 @@ public final class BMAddonBlockEntities { ).build(null) ); - public static final RegistryObject> BLOOD_ALTAR_ASSEMBLER = + public static final DeferredHolder, BlockEntityType> BLOOD_ALTAR_ASSEMBLER = BLOCK_ENTITIES.register( "blood_altar_assembler", () -> { @@ -51,4 +51,4 @@ public static void register(IEventBus eventBus) { private BMAddonBlockEntities() { } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/registry/BMAddonBlocks.java b/src/main/java/com/edgemq/bmaddon/registry/BMAddonBlocks.java index 1e1900f..3d9286d 100644 --- a/src/main/java/com/edgemq/bmaddon/registry/BMAddonBlocks.java +++ b/src/main/java/com/edgemq/bmaddon/registry/BMAddonBlocks.java @@ -7,16 +7,15 @@ import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.material.MapColor; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.neoforge.registries.DeferredRegister; +import net.neoforged.neoforge.registries.DeferredHolder; public final class BMAddonBlocks { public static final DeferredRegister BLOCKS = - DeferredRegister.create(ForgeRegistries.BLOCKS, BMAddon.MODID); + DeferredRegister.createBlocks(BMAddon.MODID); - public static final RegistryObject BLOOD_GENERATOR = BLOCKS.register( + public static final DeferredHolder BLOOD_GENERATOR = BLOCKS.register( "blood_generator", () -> new BloodGeneratorBlock( BlockBehaviour.Properties.of() @@ -28,7 +27,7 @@ public final class BMAddonBlocks { ) ); - public static final RegistryObject BLOOD_ALTAR_ASSEMBLER = BLOCKS.register( + public static final DeferredHolder BLOOD_ALTAR_ASSEMBLER = BLOCKS.register( "blood_altar_assembler", () -> new BloodAltarAssemblerBlock( BlockBehaviour.Properties.of() @@ -46,4 +45,4 @@ public static void register(IEventBus eventBus) { private BMAddonBlocks() { } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/registry/BMAddonItems.java b/src/main/java/com/edgemq/bmaddon/registry/BMAddonItems.java index 55bc922..6f650f5 100644 --- a/src/main/java/com/edgemq/bmaddon/registry/BMAddonItems.java +++ b/src/main/java/com/edgemq/bmaddon/registry/BMAddonItems.java @@ -11,63 +11,63 @@ import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.neoforge.registries.DeferredHolder; +import net.neoforged.neoforge.registries.DeferredRegister; public final class BMAddonItems { public static final DeferredRegister ITEMS = - DeferredRegister.create(Registries.ITEM, BMAddon.MODID); + DeferredRegister.createItems(BMAddon.MODID); public static final DeferredRegister CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, BMAddon.MODID); - public static final RegistryObject BLOOD_GENERATOR = ITEMS.register( + public static final DeferredHolder BLOOD_GENERATOR = ITEMS.register( "blood_generator", () -> new BlockItem(BMAddonBlocks.BLOOD_GENERATOR.get(), new Item.Properties()) ); - public static final RegistryObject BLOOD_ALTAR_ASSEMBLER = ITEMS.register( + public static final DeferredHolder BLOOD_ALTAR_ASSEMBLER = ITEMS.register( "blood_altar_assembler", () -> new BlockItem(BMAddonBlocks.BLOOD_ALTAR_ASSEMBLER.get(), new Item.Properties()) ); - public static final RegistryObject BLOOD_ALTAR_PATTERN = ITEMS.register( + public static final DeferredHolder BLOOD_ALTAR_PATTERN = ITEMS.register( "blood_altar_pattern", () -> new BloodAltarPatternItem(new Item.Properties()) ); - public static final RegistryObject BLOOD_ALTAR_TIER_CARD_2 = ITEMS.register( + public static final DeferredHolder BLOOD_ALTAR_TIER_CARD_2 = ITEMS.register( "blood_altar_tier_card_2", () -> new BloodAltarTierCardItem(2, new Item.Properties()) ); - public static final RegistryObject BLOOD_ALTAR_TIER_CARD_3 = ITEMS.register( + public static final DeferredHolder BLOOD_ALTAR_TIER_CARD_3 = ITEMS.register( "blood_altar_tier_card_3", () -> new BloodAltarTierCardItem(3, new Item.Properties()) ); - public static final RegistryObject BLOOD_ALTAR_TIER_CARD_4 = ITEMS.register( + public static final DeferredHolder BLOOD_ALTAR_TIER_CARD_4 = ITEMS.register( "blood_altar_tier_card_4", () -> new BloodAltarTierCardItem(4, new Item.Properties()) ); - public static final RegistryObject BLOOD_ALTAR_TIER_CARD_5 = ITEMS.register( + public static final DeferredHolder BLOOD_ALTAR_TIER_CARD_5 = ITEMS.register( "blood_altar_tier_card_5", () -> new BloodAltarTierCardItem(5, new Item.Properties()) ); - public static final RegistryObject BLOOD_ALTAR_PARALLEL_CARD = ITEMS.register( + public static final DeferredHolder BLOOD_ALTAR_PARALLEL_CARD = ITEMS.register( "blood_altar_parallel_card", () -> new BloodAltarParallelCardItem(new Item.Properties()) ); - public static final RegistryObject BLOOD_MAGIC_SPEED_CARD = ITEMS.register( + public static final DeferredHolder BLOOD_MAGIC_SPEED_CARD = ITEMS.register( "blood_magic_speed_card", () -> new BloodMagicSpeedCardItem(new Item.Properties()) ); - public static final RegistryObject MAIN_TAB = CREATIVE_MODE_TABS.register( + public static final DeferredHolder MAIN_TAB = CREATIVE_MODE_TABS.register( "main", () -> CreativeModeTab.builder() .title(Component.translatable("itemGroup.bmaddon.main")) @@ -117,4 +117,4 @@ public static void register(IEventBus eventBus) { private BMAddonItems() { } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/registry/BMAddonMenus.java b/src/main/java/com/edgemq/bmaddon/registry/BMAddonMenus.java index 07acca2..b3b9d82 100644 --- a/src/main/java/com/edgemq/bmaddon/registry/BMAddonMenus.java +++ b/src/main/java/com/edgemq/bmaddon/registry/BMAddonMenus.java @@ -4,26 +4,25 @@ import com.edgemq.bmaddon.menu.BloodAltarAssemblerMenu; import com.edgemq.bmaddon.menu.BloodGeneratorMenu; import net.minecraft.world.inventory.MenuType; -import net.minecraftforge.common.extensions.IForgeMenuType; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.neoforge.common.extensions.IMenuTypeExtension; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.neoforge.registries.DeferredRegister; +import net.neoforged.neoforge.registries.DeferredHolder; public final class BMAddonMenus { public static final DeferredRegister> MENUS = - DeferredRegister.create(ForgeRegistries.MENU_TYPES, BMAddon.MODID); + DeferredRegister.create(net.minecraft.core.registries.Registries.MENU, BMAddon.MODID); - public static final RegistryObject> BLOOD_GENERATOR = + public static final DeferredHolder, MenuType> BLOOD_GENERATOR = MENUS.register( "blood_generator", - () -> IForgeMenuType.create(BloodGeneratorMenu::new) + () -> IMenuTypeExtension.create(BloodGeneratorMenu::new) ); - public static final RegistryObject> BLOOD_ALTAR_ASSEMBLER = + public static final DeferredHolder, MenuType> BLOOD_ALTAR_ASSEMBLER = MENUS.register( "blood_altar_assembler", - () -> IForgeMenuType.create(BloodAltarAssemblerMenu::new) + () -> IMenuTypeExtension.create(BloodAltarAssemblerMenu::new) ); public static void register(IEventBus eventBus) { @@ -32,4 +31,4 @@ public static void register(IEventBus eventBus) { private BMAddonMenus() { } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/util/BloodAltarRecipeHelper.java b/src/main/java/com/edgemq/bmaddon/util/BloodAltarRecipeHelper.java index 813f8c9..71a3fff 100644 --- a/src/main/java/com/edgemq/bmaddon/util/BloodAltarRecipeHelper.java +++ b/src/main/java/com/edgemq/bmaddon/util/BloodAltarRecipeHelper.java @@ -4,10 +4,11 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.level.Level; -import wayoftime.bloodmagic.common.recipe.BloodMagicRecipeType; -import wayoftime.bloodmagic.recipe.RecipeAlchemyTable; -import wayoftime.bloodmagic.recipe.RecipeBloodAltar; +import wayoftime.bloodmagic.common.recipe.BMRecipes; +import wayoftime.bloodmagic.common.recipe.alchemy_table.AlchemyTableRecipe; +import wayoftime.bloodmagic.common.recipe.bloodaltar.BloodAltarRecipe; import javax.annotation.Nullable; import java.util.ArrayList; @@ -16,42 +17,63 @@ import java.util.Optional; public final class BloodAltarRecipeHelper { - public static Optional findAltarRecipe(Level level, ItemStack input) { + public record FoundAltarRecipe(ResourceLocation id, BloodAltarRecipe recipe) { + } + + public record FoundAlchemyTableRecipe(ResourceLocation id, AlchemyTableRecipe recipe) { + } + + public static Optional findAltarRecipe(Level level, ItemStack input) { + return findAltarRecipeWithId(level, input).map(FoundAltarRecipe::recipe); + } + + public static Optional findAltarRecipeWithId(Level level, ItemStack input) { if (level == null || input.isEmpty()) { return Optional.empty(); } - List recipes = level.getRecipeManager().getAllRecipesFor(BloodMagicRecipeType.ALTAR.get()); + List> recipes = level.getRecipeManager().getAllRecipesFor(BMRecipes.BLOOD_ALTAR_TYPE.get()); return recipes.stream() - .filter(recipe -> recipe.getInput().test(input)) - .sorted(Comparator.comparingInt(RecipeBloodAltar::getMinimumTier)) + .filter(recipeHolder -> recipeHolder.value().getInput().test(input)) + .sorted(Comparator.comparingInt(recipeHolder -> recipeHolder.value().getMinTier())) + .map(recipeHolder -> new FoundAltarRecipe(recipeHolder.id(), recipeHolder.value())) .findFirst(); } - public static Optional getAltarRecipe(Level level, ResourceLocation recipeId) { + public static Optional getAltarRecipe(Level level, ResourceLocation recipeId) { if (level == null || recipeId == null) { return Optional.empty(); } return level.getRecipeManager() .byKey(recipeId) - .filter(recipe -> recipe instanceof RecipeBloodAltar) - .map(recipe -> (RecipeBloodAltar) recipe); + .map(RecipeHolder::value) + .filter(recipe -> recipe instanceof BloodAltarRecipe) + .map(recipe -> (BloodAltarRecipe) recipe); } - public static Optional getAlchemyTableRecipe(Level level, ResourceLocation recipeId) { + public static Optional getAlchemyTableRecipe(Level level, ResourceLocation recipeId) { if (level == null || recipeId == null) { return Optional.empty(); } return level.getRecipeManager() .byKey(recipeId) - .filter(recipe -> recipe instanceof RecipeAlchemyTable) - .map(recipe -> (RecipeAlchemyTable) recipe); + .map(RecipeHolder::value) + .filter(recipe -> recipe instanceof AlchemyTableRecipe) + .map(recipe -> (AlchemyTableRecipe) recipe); + } + + public static Optional findAlchemyTableRecipe( + Level level, + List inputs, + ItemStack expectedOutput + ) { + return findAlchemyTableRecipeWithId(level, inputs, expectedOutput).map(FoundAlchemyTableRecipe::recipe); } - public static Optional findAlchemyTableRecipe( + public static Optional findAlchemyTableRecipeWithId( Level level, List inputs, ItemStack expectedOutput @@ -60,12 +82,13 @@ public static Optional findAlchemyTableRecipe( return Optional.empty(); } - List recipes = level.getRecipeManager().getAllRecipesFor(BloodMagicRecipeType.ALCHEMYTABLE.get()); + List> recipes = level.getRecipeManager().getAllRecipesFor(BMRecipes.ALCHEMY_TABLE_TYPE.get()); return recipes.stream() - .filter(recipe -> outputMatches(recipe.getOutput(), expectedOutput)) - .filter(recipe -> inputsMatch(getAlchemyTableIngredients(recipe), inputs)) - .sorted(Comparator.comparingInt(RecipeAlchemyTable::getMinimumTier)) + .filter(recipeHolder -> outputMatches(recipeHolder.value().output(), expectedOutput)) + .filter(recipeHolder -> inputsMatch(getAlchemyTableIngredients(recipeHolder.value()), inputs)) + .sorted(Comparator.comparingInt(recipeHolder -> recipeHolder.value().tier())) + .map(recipeHolder -> new FoundAlchemyTableRecipe(recipeHolder.id(), recipeHolder.value())) .findFirst(); } @@ -79,17 +102,17 @@ public static boolean recipeStillExists(Level level, BloodMagicPatternKind kind, public static ItemStack getOutputPreview(Level level, BloodMagicPatternKind kind, ResourceLocation recipeId) { return switch (kind) { case BLOOD_ALTAR -> getAltarRecipe(level, recipeId) - .map(recipe -> recipe.getOutput().copy()) + .map(recipe -> recipe.getResult().copy()) .orElse(ItemStack.EMPTY); case ALCHEMY_TABLE -> getAlchemyTableRecipe(level, recipeId) - .map(recipe -> recipe.getOutput().copy()) + .map(recipe -> recipe.output().copy()) .orElse(ItemStack.EMPTY); }; } @SuppressWarnings("unchecked") - public static List getAlchemyTableIngredients(RecipeAlchemyTable recipe) { - return (List) recipe.getInput(); + public static List getAlchemyTableIngredients(AlchemyTableRecipe recipe) { + return recipe.inputs(); } public static boolean inputsMatch(List ingredients, List inputs) { @@ -140,7 +163,7 @@ public static boolean outputMatches(ItemStack recipeOutput, ItemStack expectedOu return false; } - return ItemStack.isSameItemSameTags(recipeOutput, expectedOutput) + return ItemStack.isSameItemSameComponents(recipeOutput, expectedOutput) && recipeOutput.getCount() == expectedOutput.getCount(); } @@ -155,4 +178,4 @@ public static ResourceLocation parseRecipeId(String value) { private BloodAltarRecipeHelper() { } -} \ No newline at end of file +} diff --git a/src/main/java/com/edgemq/bmaddon/util/BloodMagicFluidHelper.java b/src/main/java/com/edgemq/bmaddon/util/BloodMagicFluidHelper.java index 817508b..a340451 100644 --- a/src/main/java/com/edgemq/bmaddon/util/BloodMagicFluidHelper.java +++ b/src/main/java/com/edgemq/bmaddon/util/BloodMagicFluidHelper.java @@ -1,12 +1,12 @@ package com.edgemq.bmaddon.util; import net.minecraft.world.level.material.Fluid; -import net.minecraftforge.fluids.FluidStack; -import wayoftime.bloodmagic.common.fluid.BloodMagicFluids; +import net.neoforged.neoforge.fluids.FluidStack; +import wayoftime.bloodmagic.common.fluid.BMFluids; public final class BloodMagicFluidHelper { public static Fluid lifeEssenceFluid() { - Object value = BloodMagicFluids.LIFE_ESSENCE_FLUID.get(); + Object value = BMFluids.LIFE_ESSENCE_SOURCE.get(); if (value instanceof Fluid fluid) { return fluid; @@ -25,4 +25,4 @@ public static boolean isLifeEssence(FluidStack stack) { private BloodMagicFluidHelper() { } -} \ No newline at end of file +} diff --git a/src/main/resources/assets/bmaddon/models/block/blood_generator.json b/src/main/resources/assets/bmaddon/models/block/blood_generator.json index bb789d1..063aec8 100644 --- a/src/main/resources/assets/bmaddon/models/block/blood_generator.json +++ b/src/main/resources/assets/bmaddon/models/block/blood_generator.json @@ -1,5 +1,5 @@ { - "loader": "forge:obj", + "loader": "neoforge:obj", "model": "bmaddon:models/block/blood_generator.obj", "mtl_override": "bmaddon:models/block/blood_1.mtl", "flip_v": true, @@ -9,4 +9,4 @@ "texture0": "bmaddon:block/blood_generator", "particle": "bmaddon:block/blood_generator" } -} \ No newline at end of file +} diff --git a/src/main/resources/bmaddon.mixins.json b/src/main/resources/bmaddon.mixins.json index 0928031..a78c9ef 100644 --- a/src/main/resources/bmaddon.mixins.json +++ b/src/main/resources/bmaddon.mixins.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8", "package": "com.edgemq.bmaddon.mixin", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "refmap": "bmaddon.refmap.json", "mixins": [ "PatternEncodingTermMenuMixin", @@ -15,4 +15,4 @@ "injectors": { "defaultRequire": 1 } -} \ No newline at end of file +} diff --git a/src/main/resources/data/bmaddon/recipes/blood_generator.json b/src/main/resources/data/bmaddon/recipes/blood_generator.json new file mode 100644 index 0000000..4666aa8 --- /dev/null +++ b/src/main/resources/data/bmaddon/recipes/blood_generator.json @@ -0,0 +1,26 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "ABA", + "BCB", + "DBD" + ], + "key": { + "A": { + "item": "bloodmagic:selfsacrificerune2" + }, + "B": { + "item": "bloodmagic:etherealslate" + }, + "C": { + "item": "ae2:dense_energy_cell" + }, + "D": { + "item": "bloodmagic:sacrificerune2" + } + }, + "result": { + "item": "bmaddon:blood_generator", + "count": 1 + } +} \ No newline at end of file diff --git a/src/main/templates/META-INF/mods.toml b/src/main/templates/META-INF/mods.toml deleted file mode 100644 index 8c3ac70..0000000 --- a/src/main/templates/META-INF/mods.toml +++ /dev/null @@ -1,115 +0,0 @@ -# This is an example mods.toml file. It contains the data relating to the loading mods. -# There are several mandatory fields (#mandatory), and many more that are optional (#optional). -# The overall format is standard TOML format, v0.5.0. -# Note that there are a couple of TOML lists in this file. -# Find more information on toml format here: https://github.com/toml-lang/toml -# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml -modLoader="javafml" #mandatory - -# A version range to match for said mod loader - for regular FML @Mod it will be the Forge version -loaderVersion="${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See download page for lists of versions. - -# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties. -# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here. -license="${mod_license}" - -# A URL to refer people to when problems occur with this mod -#issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional - -# If your mod is purely client-side and has no multiplayer functionality (be it dedicated servers or Open to LAN), -# set this to true, and Forge will set the correct displayTest for you and skip loading your mod on dedicated servers. -#clientSideOnly=true #optional - defaults to false if absent - -# A list of mods - how many allowed here is determined by the individual mod loader -[[mods]] #mandatory - -# The modid of the mod -modId="${mod_id}" #mandatory - -# The version number of the mod -version="${mod_version}" #mandatory - -# A display name for the mod -displayName="${mod_name}" #mandatory -# A URL to query for updates for this mod. See the JSON update specification https://docs.minecraftforge.net/en/latest/misc/updatechecker/ -#updateJSONURL="https://change.me.example.invalid/updates.json" #optional - -# A URL for the "homepage" for this mod, displayed in the mod UI -#displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional - -# A file name (in the root of the mod JAR) containing a logo for display -#logoFile="examplemod.png" #optional - -# A text field displayed in the mod UI -#credits="" #optional - -# A text field displayed in the mod UI -authors="${mod_authors}" #optional - -# Display Test controls the display for your mod in the server connection screen -# MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod. -# IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod. -# IGNORE_ALL_VERSION means that your mod will not cause a red X if it's present on the client or the server. This is a special case and should only be used if your mod has no server component. -# NONE means that no display test is set on your mod. You need to do this yourself, see IExtensionPoint.DisplayTest for more information. You can define any scheme you wish with this value. -# IMPORTANT NOTE: this is NOT an instruction as to which environments (CLIENT or DEDICATED SERVER) your mod loads on. Your mod should load (and maybe do nothing!) whereever it finds itself. -#displayTest="MATCH_VERSION" # if nothing is specified, MATCH_VERSION is the default when clientSideOnly=false, otherwise IGNORE_ALL_VERSION when clientSideOnly=true (#optional) - -# The description text for the mod (multi line!) (#mandatory) -description='''${mod_description}''' - -# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. -[[dependencies.${mod_id}]] #optional - # the modid of the dependency - modId="forge" #mandatory - # Does this dependency have to exist - if not, ordering below must be specified - mandatory=true #mandatory - # The version range of the dependency - versionRange="${forge_version_range}" #mandatory - # An ordering relationship for the dependency - BEFORE or AFTER required if the dependency is not mandatory - # BEFORE - This mod is loaded BEFORE the dependency - # AFTER - This mod is loaded AFTER the dependency - ordering="NONE" - # Side this dependency is applied on - BOTH, CLIENT, or SERVER - side="BOTH" - -# Here's another dependency -[[dependencies.${mod_id}]] - modId="minecraft" - mandatory=true - # This version range declares a minimum of the current minecraft version up to but not including the next major version - versionRange="${minecraft_version_range}" - ordering="NONE" - side="BOTH" - -[[dependencies.${mod_id}]] -modId="forge" -mandatory=true -versionRange="${forge_version_range}" -ordering="NONE" -side="BOTH" - -[[dependencies.${mod_id}]] -modId="minecraft" -mandatory=true -versionRange="${minecraft_version_range}" -ordering="NONE" -side="BOTH" - -[[dependencies.${mod_id}]] -modId="bloodmagic" -mandatory=true -versionRange="[3.3.5,)" -ordering="AFTER" -side="BOTH" - -[[dependencies.${mod_id}]] -modId="ae2" -mandatory=true -versionRange="[15.4.10,16.0.0)" -ordering="AFTER" -side="BOTH" -# Features are specific properties of the game environment, that you may want to declare you require. This example declares -# that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't -# stop your mod loading on the server for example. -#[features.${mod_id}] -#openGLVersion="[3.2,)" diff --git a/src/main/templates/META-INF/neoforge.mods.toml b/src/main/templates/META-INF/neoforge.mods.toml new file mode 100644 index 0000000..6ef823d --- /dev/null +++ b/src/main/templates/META-INF/neoforge.mods.toml @@ -0,0 +1,38 @@ +modLoader="javafml" +loaderVersion="${loader_version_range}" +license="${mod_license}" + +[[mods]] +modId="${mod_id}" +version="${mod_version}" +displayName="${mod_name}" +authors="${mod_authors}" +description='''${mod_description}''' + +[[dependencies.${mod_id}]] +modId="neoforge" +type="required" +versionRange="${neo_version_range}" +ordering="NONE" +side="BOTH" + +[[dependencies.${mod_id}]] +modId="minecraft" +type="required" +versionRange="${minecraft_version_range}" +ordering="NONE" +side="BOTH" + +[[dependencies.${mod_id}]] +modId="bloodmagic" +type="required" +versionRange="${blood_magic_version_range}" +ordering="AFTER" +side="BOTH" + +[[dependencies.${mod_id}]] +modId="ae2" +type="required" +versionRange="[${ae2_version},20.0.0)" +ordering="AFTER" +side="BOTH"